orderCompletion.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // pages/welfareMall/order/orderCompletion.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import { parseTime } from '../../../utils/util'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. page: 1,
  11. pageSize: 10,
  12. lock: false,
  13. noResult: false,
  14. noMore: false,
  15. isLogin: false,
  16. orderDetail: null,
  17. orderSn: '',
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. var that = this;
  24. that.orderSn = options.ordersn
  25. this.setData({
  26. isLogin: getMobileCache() != '',
  27. orderSn: options.ordersn,
  28. })
  29. if(this.data.isLogin){
  30. this.getOrder(that.orderSn);
  31. this.data.orderSn = options.ordersn;
  32. }
  33. },
  34. /**
  35. *
  36. * 订单数据
  37. */
  38. getOrder: function(data) {
  39. WelfareMall.getOrder({
  40. mobile: getMobileCache(),
  41. orderSn: data,
  42. }).then(res => {
  43. if (res.code == 200) {
  44. this.userOrderistView(res.data)
  45. }
  46. this.data.lock = false
  47. }).catch(_ => {
  48. console.log(_)
  49. this.data.lock = false
  50. })
  51. },
  52. userOrderistView: function(data) {
  53. if (!data) {
  54. console.log("订单详情数据为空");
  55. return
  56. }
  57. //对象转换
  58. this.data.orderDetail = data
  59. this.setData({
  60. mobileTop:getMobileCache(),
  61. orderDetail: this.data.orderDetail
  62. })
  63. },
  64. /**
  65. *
  66. * 取消订单
  67. */
  68. toCancelOrder(e) {
  69. wx.showModal({
  70. title: '取消订单',
  71. content: '',
  72. showCancel: true,//是否显示取消按钮
  73. cancelText:"取消",//默认是“取消”
  74. cancelColor:'black',//取消文字的颜色
  75. confirmText:"确定",//默认是“确定”
  76. confirmColor: 'black',//确定文字的颜色
  77. success: res => {if (res.cancel) {
  78. //点击取消,默认隐藏弹框
  79. } else {
  80. //点击确定
  81. WelfareMall.cancelOrder({
  82. mobile: getMobileCache(),
  83. orderSn: this.data.orderSn,
  84. }).then(res => {
  85. if (res.code == 200) {
  86. wx.showToast({
  87. title: '取消订单成功',
  88. icon: 'none',
  89. duration: 1500
  90. });
  91. this.onLoad(this.options);
  92. }
  93. this.data.lock = false
  94. }).catch(_ => {
  95. console.log(_)
  96. this.data.lock = false
  97. })
  98. }
  99. },
  100. fail: function (res) {
  101. console.log(res)
  102. },//接口调用失败的回调函数
  103. })
  104. },
  105. /**
  106. * 获取订单参数
  107. */
  108. async goPay() {
  109. let res = await WelfareMall.getPayParams({
  110. mobile: getMobileCache(),
  111. orderSn: this.data.orderSn,
  112. openId: wx.getStorageSync('loginInfo').openId,
  113. thirdPartyName: 'coupon-activity',
  114. payCode: "HSAY-COUPON",
  115. });
  116. console.log(res);
  117. // res = res.wxPrePayVo
  118. wx.requestPayment({
  119. timeStamp: res.wxPrePayVo.timeStamp,
  120. package: res.wxPrePayVo.pack,
  121. nonceStr: res.wxPrePayVo.nonceStr,
  122. signType: res.wxPrePayVo.signType,
  123. paySign: res.wxPrePayVo.paySign,
  124. success: function (res) {
  125. //支付成功,跳转领取成功页面
  126. wx.reLaunch({
  127. url: '/pages/couponSuccess/couponSuccess'
  128. })
  129. },
  130. fail: function (res) {
  131. console.log('payerror')
  132. console.log(res);
  133. }
  134. })
  135. },
  136. /**
  137. * 生命周期函数--监听页面初次渲染完成
  138. */
  139. onReady: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面显示
  143. */
  144. onShow: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面隐藏
  148. */
  149. onHide: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面卸载
  153. */
  154. onUnload: function () {
  155. },
  156. /**
  157. * 页面相关事件处理函数--监听用户下拉动作
  158. */
  159. onPullDownRefresh: function () {
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom: function () {
  165. },
  166. /**
  167. * 用户点击右上角分享
  168. */
  169. onShareAppMessage: function () {
  170. }
  171. })