orderPaySn.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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('pay_sn:', 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. 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.redirectTo({
  84. url: "/pages/order_tabs/orderTabs?state_type=state_pay"
  85. })
  86. console.log("成功:", res);
  87. console.log('支付成功')
  88. },
  89. fail: function (res) {
  90. setTimeout(() => {
  91. wx.showToast({
  92. icon: 'none',
  93. title: res.errMsg,
  94. duration: 2000
  95. })
  96. }, 200);
  97. console.log("失败:", res);
  98. }
  99. });
  100. }
  101. })
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面显示
  110. */
  111. onShow: function () {
  112. if (!this.data.firstLoad) {
  113. let defaultAddress = appInstance.globalData.defaultAddress
  114. if (defaultAddress) {
  115. this.setData({
  116. defaultAddress
  117. })
  118. }
  119. }
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function () {
  140. }
  141. })