TransactionPage.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. const {
  2. default: api
  3. } = require("../../js/api");
  4. const util = require('../../utils/util.js')
  5. // pages/orderConfirm/orderConfirm.js
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. nozzleId: 0,
  12. type: '后支付',
  13. order: null,
  14. oprationBtn1: '',
  15. oprationBtn2: '对此订单有疑问?',
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. const link = decodeURIComponent(options.q) // 获取到二维码原始链接
  22. var id = link.split('wxapp?id=')[1];
  23. if (id == undefined) {
  24. id = options.id;
  25. }
  26. this.setData({
  27. nozzleId: id
  28. })
  29. this.getOrder()
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady() {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow() {
  40. },
  41. /**
  42. * 生命周期函数--监听页面隐藏
  43. */
  44. onHide() {
  45. },
  46. /**
  47. * 生命周期函数--监听页面卸载
  48. */
  49. onUnload() {
  50. },
  51. /**
  52. * 页面相关事件处理函数--监听用户下拉动作
  53. */
  54. onPullDownRefresh() {
  55. },
  56. /**
  57. * 页面上拉触底事件的处理函数
  58. */
  59. onReachBottom() {
  60. },
  61. /**
  62. * 用户点击右上角分享
  63. */
  64. onShareAppMessage() {
  65. },
  66. /** 获取订单信息 */
  67. getOrder() {
  68. api.request_GetMiniProgramTransactionsUnpaidNozzle(Number(this.data.nozzleId))
  69. .then(res => {
  70. if (res.data.statusCode == 203) {
  71. //若为203,证明还未登录,跳转到登录页,这里可能刚从主页跳转过来,频繁的跳转可能会跳转页面超时,故而加上延时
  72. setTimeout(() => {
  73. wx.navigateTo({
  74. url: '../login/login'
  75. })
  76. }, 500)
  77. return
  78. }
  79. console.log("获取到未支付订单", res)
  80. var order = res.data.data[0];
  81. var time = util.formatDateNotSecond(order.fuelItemTransactionEndTime);
  82. this.setData({
  83. order: {
  84. oilName: order.productName,
  85. nozzle: order.nozzleId,
  86. volume: order.originalQty,
  87. amount: order.originalAmount,
  88. payAmount: order.actualPaymentAmount,
  89. discount: order.originalAmount - order.actualPaymentAmount,
  90. orderId: order.id,
  91. time: time
  92. }
  93. })
  94. }).catch(err => {
  95. console.log("未获取到未支付订单")
  96. })
  97. },
  98. /** 后支付查看更多交易 */
  99. toMordOrderPage() {
  100. var that = this;
  101. wx.navigateTo({
  102. url: '../moreOrder/moreOrder?nozzle=' + this.data.nozzleId,
  103. events: {
  104. acceptOrderFromMoreOrder: function (data) {
  105. console.log("获取到传送过来的订单", data)
  106. that.setData({
  107. order: data
  108. })
  109. }
  110. }
  111. })
  112. },
  113. /** 支付按钮点击事件 */
  114. toPay() {
  115. api.request_wechatPay(this.data.order.orderId).then(res => {
  116. console.log("支付结果", res)
  117. this.pay()
  118. }).catch(err => {
  119. console.log("支付失败", err)
  120. })
  121. },
  122. pay() {
  123. api.request_wechatPay(this.data.order.orderId)
  124. .then(res => {
  125. wx.requestPayment({
  126. timeStamp: res.data.data.unifiedOrderResult.timeStamp,
  127. nonceStr: res.data.data.unifiedOrderResult.nonceStr,
  128. package: res.data.data.unifiedOrderResult.package,
  129. signType: res.data.data.unifiedOrderResult.signType,
  130. paySign: res.data.data.unifiedOrderResult.paySign,
  131. success: res => {
  132. wx.hideLoading()
  133. wx.showToast({
  134. title: '支付成功!',
  135. })
  136. setTimeout(function () {
  137. wx.redirectTo({
  138. url: '../scan/scan',
  139. })
  140. }, 2000)
  141. },
  142. fail: res => {
  143. wx.hideLoading()
  144. wx.showModal({
  145. title: '支付失败',
  146. content: res.errMsg + '请稍后再试',
  147. showCancel: false,
  148. success(res) {
  149. }
  150. })
  151. }
  152. })
  153. });
  154. },
  155. })