diffOrder.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. Page({
  4. data: {
  5. // 0创建,1发起支付中,2支付成功,3退款,4取消
  6. id:'',
  7. diffList:[],
  8. orderInfo:{
  9. },
  10. },
  11. onLoad: function (options) {
  12. // 页面初始化 options为页面跳转所带来的参数
  13. console.log(options);
  14. this.setData({
  15. id: options.id,
  16. });
  17. // this.getDiffOrder();
  18. },
  19. onShow: function () {
  20. // 页面显示
  21. this.getDiffOrder();
  22. },
  23. onPullDownRefresh() {
  24. wx.showNavigationBarLoading(); //在标题栏中显示加载
  25. this.getDiffOrder();
  26. wx.hideNavigationBarLoading(); //完成停止加载
  27. wx.stopPullDownRefresh(); //停止下拉刷新
  28. },
  29. getDiffOrder: function () {
  30. wx.showLoading({
  31. title: '加载中'
  32. });
  33. util.request(api.getDiffList, {
  34. bookDetailId: this.data.id
  35. }).then(res=> {
  36. wx.hideLoading();
  37. if (res.errno === 0) {
  38. this.setData({
  39. diffList:res.data.diffList,
  40. orderInfo:res.data.bookDetail
  41. });
  42. }
  43. }).catch(err=> {
  44. console.log(err);
  45. wx.hideLoading();
  46. });
  47. },
  48. diffDetail(e){
  49. let difNo=e.currentTarget.dataset.no;
  50. wx.navigateTo({
  51. url: '/pages/diffOrderDetail/diffOrderDetail?difNo='+difNo,
  52. });
  53. },
  54. goPay(e){
  55. wx.showLoading({
  56. title: '加载中'
  57. });
  58. let difNo=e.currentTarget.dataset.no;
  59. util.request(api.prepayDiff, {
  60. diffOrderNo: difNo
  61. }).then(res=> {
  62. wx.hideLoading();
  63. if (res.errno === 0) {
  64. let payParam=res.data;
  65. wx.requestPayment({
  66. 'timeStamp': payParam.timeStamp,
  67. 'nonceStr': payParam.nonceStr,
  68. 'package': payParam.packageValue,
  69. 'signType': payParam.signType,
  70. 'paySign': payParam.paySign,
  71. success: function(res) {
  72. console.log("支付过程成功");
  73. wx.showToast({
  74. title: '支付成功',
  75. duration:3000,
  76. mask:true,
  77. });
  78. setTimeout(()=>{
  79. wx.navigateTo({
  80. url: '/pages/diffOrderDetail/diffOrderDetail?difNo='+difNo,
  81. });
  82. },4000);
  83. },
  84. fail: function(res) {
  85. console.log("支付过程失败");
  86. util.showErrorToast('支付失败');
  87. },
  88. complete: function(res) {
  89. console.log("支付过程结束")
  90. }
  91. });
  92. }else{
  93. wx.showToast({
  94. title: res.errmsg,
  95. icon:'none',
  96. duration:3000
  97. })
  98. }
  99. }).catch(err=> {
  100. console.log(err);
  101. wx.hideLoading();
  102. });
  103. },
  104. // “去付款”按钮点击效果
  105. payOrder: function () {
  106. let that = this;
  107. util.request(api.OrderPayCheck, {
  108. orderId: that.data.orderInfo.id
  109. }, 'POST').then(function (res) {
  110. if (res.errno === 0) {
  111. const outOrderNo = res.data;
  112. console.log(res);
  113. wx.continueToPay({
  114. // orderId: this.data.orderId, // 内部订单号
  115. outOrderNo: outOrderNo, // 外部订单号 2个订单号必填一个
  116. success: res => {
  117. console.log(res);
  118. const {
  119. orderId,
  120. outOrderNo
  121. } = res;
  122. console.log('success res', res);
  123. console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  124. wx.redirectTo({
  125. url: '/pages/ucenter/order/order'
  126. });
  127. },
  128. fail: res => {
  129. console.log(res);
  130. const {
  131. orderId,
  132. outOrderNo,
  133. errNo,
  134. errMsg,
  135. errLogId
  136. } = res;
  137. if (errLogId) {
  138. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  139. }
  140. if (orderId || outOrderNo) {
  141. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  142. }
  143. util.showErrorToast('支付失败');
  144. },
  145. });
  146. }
  147. });
  148. },
  149. onReady: function () {
  150. // 页面渲染完成
  151. },
  152. onHide: function () {
  153. console.log('onHide');
  154. // clearInterval(this.data.timer);
  155. },
  156. onUnload: function () {
  157. console.log('onunload');
  158. },
  159. });