orderPaySn.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. const getReq = require('./../../config.js').getReq
  2. let appInstance = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. order_info: {},
  9. defaultAddress: null,
  10. firstLoad: true
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. let pay_sn = options.pay_sn;
  17. this.getDatas(pay_sn);
  18. console.log(111);
  19. },
  20. getDatas(pay_sn) {
  21. let self = this;
  22. wx.showLoading({
  23. title: '加载中',
  24. })
  25. getReq({
  26. act: 'member_order',
  27. op: 'pay_info',
  28. pay_sn: pay_sn
  29. }, function (res) {
  30. wx.hideLoading();
  31. if (res.code == 200) {
  32. self.setData({
  33. defaultAddress: {
  34. mob_phone: res.datas.order.reciver_info.mob_phone,
  35. true_name: res.datas.order.reciver_info.reciver_name,
  36. area_info: res.datas.order.reciver_info.area,
  37. address: res.datas.order.reciver_info.street
  38. },
  39. order_info: res.datas.order.order_info,
  40. firstLoad: false
  41. });
  42. }
  43. else {
  44. wx.showToast({
  45. icon: 'none',
  46. title: res.message,
  47. duration: 2000
  48. })
  49. }
  50. })
  51. },
  52. getGoodsList(summary, goods_list) {
  53. let newGoodsList = []
  54. goods_list.map((item, index) => {
  55. summary.find((list, key) => {
  56. if (item.goods_id == list.goods_id) {
  57. let goods_item = list
  58. goods_item.goods_num = item.goods_num
  59. newGoodsList.push(goods_item)
  60. return true
  61. }
  62. })
  63. })
  64. return newGoodsList
  65. },
  66. toPay() {
  67. let params = {
  68. act: 'member_order',
  69. op: 'pay',
  70. pay_sn: this.data['order_info']['pay_sn'],
  71. payment: 'minipay'
  72. }
  73. getReq(params, function (res) {
  74. if (res.code == 200) {
  75. let param = res.datas.param.data;
  76. wx.requestPayment({
  77. timeStamp: param.timeStamp, //时间戳,自1970年以来的秒数
  78. nonceStr: param.nonceStr, //随机串
  79. package: param.package,
  80. signType: param.signType, //微信签名方式:
  81. paySign: param.paySign, //微信签名
  82. success: function (res) {
  83. // wx.showToast({
  84. // icon: 'none',
  85. // title: res,
  86. // duration: 2000
  87. // })
  88. wx.reLaunch({
  89. url: "/pages/index/index"
  90. })
  91. console.log("成功:" + res);
  92. console.log('支付成功')
  93. },
  94. fail: function (res) {
  95. wx.showToast({
  96. icon: 'none',
  97. title: res,
  98. duration: 2000
  99. })
  100. console.log("失败:" + res);
  101. }
  102. });
  103. }
  104. })
  105. },
  106. /**
  107. * 生命周期函数--监听页面初次渲染完成
  108. */
  109. onReady: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面显示
  113. */
  114. onShow: function () {
  115. if (!this.data.firstLoad) {
  116. let defaultAddress = appInstance.globalData.defaultAddress
  117. if (defaultAddress) {
  118. this.setData({
  119. defaultAddress
  120. })
  121. }
  122. }
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload: function () {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom: function () {
  143. }
  144. })