orderPaySn.js 4.3 KB

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