orderPaySn.js 3.8 KB

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