TransactionPage.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. order: null,
  13. stationName:'',//油站名
  14. // order: {
  15. // oilName: '好名字',
  16. // nozzle: "1",
  17. // volume: "1",
  18. // amount: "1",
  19. // payAmount: "1",
  20. // discount: "1-1",
  21. // orderId: "1",
  22. // time: "2025-4-3"
  23. // },
  24. oprationBtn1: '',
  25. oprationBtn2: '对此订单有疑问?'
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(options) {
  31. const link = decodeURIComponent(options.q) // 获取到二维码原始链接
  32. var id = link.split('wxapp?id=')[1];
  33. if (id == undefined) {
  34. id = options.id;
  35. }
  36. this.setData({
  37. nozzleId: id
  38. })
  39. this.getStationInfo()
  40. this.getOrder()
  41. },
  42. /**
  43. * 生命周期函数--监听页面初次渲染完成
  44. */
  45. onReady() {
  46. },
  47. /**
  48. * 生命周期函数--监听页面显示
  49. */
  50. onShow() {
  51. },
  52. /**
  53. * 生命周期函数--监听页面隐藏
  54. */
  55. onHide() {
  56. },
  57. /**
  58. * 生命周期函数--监听页面卸载
  59. */
  60. onUnload() {
  61. },
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh() {
  66. this.getOrder()
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom() {
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage() {
  77. },
  78. /** 获取站点信息 */
  79. getStationInfo() {
  80. const that = this;
  81. api.request_GetSiteInfo().then(res => {
  82. if (res.data.statusCode == 203) {
  83. //若为203,证明还未登录,跳转到登录页,这里可能刚从主页跳转过来,频繁的跳转可能会跳转页面超时,故而加上延时
  84. setTimeout(() => {
  85. wx.navigateTo({
  86. url: '../login/login'
  87. })
  88. }, 500)
  89. return
  90. }
  91. console.log("站点信息", res)
  92. const name = res.data.data.site.name;
  93. that.setData({
  94. stationName:name,
  95. })
  96. })
  97. },
  98. /** 获取订单信息 */
  99. getOrder() {
  100. wx.showLoading({
  101. title: '正在获取订单',
  102. })
  103. api.request_GetMiniProgramTransactionsUnpaidNozzle(Number(this.data.nozzleId))
  104. .then(res => {
  105. wx.hideLoading()
  106. wx.stopPullDownRefresh()
  107. if (res.data.statusCode == 203) {
  108. //若为203,证明还未登录,跳转到登录页,这里可能刚从主页跳转过来,频繁的跳转可能会跳转页面超时,故而加上延时
  109. setTimeout(() => {
  110. wx.navigateTo({
  111. url: '../login/login'
  112. })
  113. }, 500)
  114. return
  115. }
  116. console.log("获取到未支付订单", res)
  117. var order = res.data.data[0];
  118. var time = util.formatDateNotSecond(order.fuelItemTransactionEndTime);
  119. this.setData({
  120. order: {
  121. oilName: order.productName,
  122. nozzle: order.nozzleId,
  123. volume: order.originalQty,
  124. amount: order.originalAmount,
  125. payAmount: order.actualPaymentAmount,
  126. discount: order.originalAmount - order.actualPaymentAmount,
  127. orderId: order.id,
  128. time: time,
  129. price:order.price,
  130. station:this.data.stationName
  131. }
  132. })
  133. }).catch(err => {
  134. wx.hideLoading()
  135. console.log("未获取到未支付订单")
  136. })
  137. },
  138. /** 后支付查看更多交易 */
  139. toMordOrderPage() {
  140. wx.showLoading({
  141. title: '正在跳转',
  142. })
  143. var that = this;
  144. wx.navigateTo({
  145. url: '../moreOrder/moreOrder?nozzle=' + this.data.nozzleId+'&stationName=' + this.data.stationName,
  146. events: {
  147. acceptOrderFromMoreOrder: function (data) {
  148. console.log("获取到传送过来的订单", data)
  149. that.setData({
  150. order: data
  151. })
  152. }
  153. }
  154. })
  155. wx.hideLoading()
  156. },
  157. /** 支付按钮点击事件 */
  158. toPay() {
  159. wx.showLoading({
  160. title: '正在跳转',
  161. })
  162. this.subMessage()
  163. // var that = this;
  164. // api.request_wechatPay(this.data.order.orderId).then(res => {
  165. // console.log("支付结果", res)
  166. // if(res.data.statusCode != 200) {
  167. // wx.hideLoading()
  168. // wx.showModal({
  169. // title: '提示',
  170. // content: '支付失败',
  171. // })
  172. // return
  173. // }
  174. // this.subMessage()
  175. // // this.pay()
  176. // }).catch(err => {
  177. // wx.hideLoading()
  178. // console.log("支付失败", err)
  179. // wx.showModal({
  180. // title: '提示',
  181. // content: '支付失败',
  182. // })
  183. // })
  184. },
  185. /** 订阅消息模板 */
  186. subMessage() {
  187. const that = this;
  188. wx.requestSubscribeMessage({
  189. tmplIds: ['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'], // 最多支持3条
  190. success(res) {
  191. that.pay()
  192. // 'accept'表示用户同意订阅该条id对应的模板消息
  193. if (res['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'] === 'accept') {
  194. // 用户同意订阅,调用云函数或服务器接口发送订阅消息
  195. // wx.cloud.callFunction({
  196. // name: 'sendSubscribeMessage',
  197. // data: {
  198. // templateId: '配置好的模板ID',
  199. // openid: 'o8pFb5cWH1KkBDvGls2X7yMiFkGA',
  200. // data: {
  201. // thing1: {
  202. // value: '活动名称'
  203. // },
  204. // // 其他参数...
  205. // }
  206. // },
  207. // success(res) {
  208. // console.log('订阅消息发送成功', res)
  209. // },
  210. // fail(err) {
  211. // console.error('订阅消息发送失败', err)
  212. // }
  213. // })
  214. }
  215. },
  216. fail(err) {
  217. that.pay()
  218. wx.showModal({
  219. title: '提示',
  220. content: '目前暂未获取到未支付订单',
  221. })
  222. }
  223. })
  224. },
  225. pay() {
  226. const that = this;
  227. api.request_wechatPay(this.data.order.orderId)
  228. .then(res => {
  229. wx.requestPayment({
  230. timeStamp: res.data.data.unifiedOrderResult.timeStamp,
  231. nonceStr: res.data.data.unifiedOrderResult.nonceStr,
  232. package: res.data.data.unifiedOrderResult.package,
  233. signType: res.data.data.unifiedOrderResult.signType,
  234. paySign: res.data.data.unifiedOrderResult.paySign,
  235. success: res => {
  236. wx.hideLoading()
  237. that.sendMessage()
  238. that.toPayResult()
  239. },
  240. fail: res => {
  241. wx.hideLoading()
  242. wx.showModal({
  243. title: '提示',
  244. content: '支付失败',
  245. })
  246. }
  247. })
  248. });
  249. },
  250. /** 发送消息模板 */
  251. sendMessage() {
  252. const message = {
  253. trxid: this.data.order.orderId,
  254. orderType: '支付'
  255. }
  256. api.request_sendMessage(message).then(res => {
  257. console.log("发送消息模板结果", res)
  258. }).catch(err => {
  259. console.log("发送消息模板失败", err)
  260. })
  261. },
  262. /** 跳转到支付结果页 */
  263. toPayResult() {
  264. wx.redirectTo({
  265. url: '../payResult/payResult',
  266. })
  267. },
  268. /** 跳转到支付结果页(不用这个) */
  269. toPayResult_back() {
  270. const that = this;
  271. setTimeout(function () {
  272. wx.navigateTo({
  273. url: '../payResult/payResult?nozzle=' + that.data.nozzleId,
  274. events: {
  275. acceptOrderFromPayResult: function (data) {
  276. console.log("获取到来自result页面传送过来的订单", data)
  277. that.setData({
  278. order: data
  279. })
  280. }
  281. }
  282. })
  283. }, 500)
  284. }
  285. })