C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

210 行
5.1 KiB

  1. let config = require("../../../config/config.js");
  2. let util = require("../../../utils/util");
  3. let Http = require("../../../utils/HttpBasics");
  4. let app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. showModalStatus: false,
  11. flag: 0,
  12. order: null,
  13. orderId: null
  14. },
  15. /**
  16. * 点击弹出二维码
  17. * 然后再关闭
  18. */
  19. powerDrawer: function(e) {
  20. // couponOrderStatus
  21. // 0 未使用
  22. // 1 已使用
  23. // 2 已过期
  24. // 3 已经退款
  25. console.log(e);
  26. wx.navigateTo({
  27. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode}&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle}&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${e.currentTarget.dataset.couponorderstatus}`,
  28. })
  29. console.log(e.currentTarget.dataset.quancode);
  30. console.log(e.currentTarget.dataset.couponorderstatus);
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function(options) {
  36. let that = this;
  37. console.log(options.orderId);
  38. console.log(options.flag + "我是付款的标识");
  39. this.setData({
  40. orderId: options.orderId
  41. })
  42. Http.get({
  43. url: config.api.orderDetail,
  44. data: {
  45. orderId: options.orderId
  46. }
  47. }).then(res => {
  48. console.log(res);
  49. console.log("我是订单详情");
  50. that.setData({
  51. order: res.data
  52. });
  53. //createDate 创建时间
  54. var createDate = util.fmtDate(res.data.createDate);
  55. console.log(createDate);
  56. that.setData({
  57. createDate: createDate
  58. });
  59. });
  60. },
  61. /**
  62. * 发起支付
  63. */
  64. orderFunc(e) {
  65. var that = this;
  66. wx.showLoading({
  67. title: "加载中..."
  68. });
  69. const orderId = "" + that.data.orderId;
  70. if (that.data.order.payment > 0) {
  71. // 支付金额不为0
  72. Http.post({
  73. url: config.api.payOrderCreate,
  74. data: {
  75. orderId: orderId
  76. }
  77. }).then(res => {
  78. console.log(res);
  79. /// Begin payment ----
  80. var payOrderId = "" + res.data.payOrderId;
  81. wx.hideLoading();
  82. wx.requestPayment({
  83. timeStamp: res.data.timeStamp,
  84. nonceStr: res.data.nonceStr,
  85. package: res.data.package,
  86. signType: "MD5",
  87. paySign: res.data.paySign,
  88. success: res => {
  89. console.log(res);
  90. console.log("姐在检查付款异常");
  91. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  92. console.log(res);
  93. if (res.errMsg == "requestPayment:ok") {
  94. wx.showToast({
  95. title: "购买成功",
  96. duration: 2000,
  97. image: "./../../../assets/img/success.png",
  98. mask:false,
  99. success:function(){
  100. wx.redirectTo({
  101. url: `/pages/order/detail/index?orderId=${that.data.orderId}`,
  102. })
  103. }
  104. });
  105. }
  106. },
  107. fail: res => {
  108. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  109. console.log(res);
  110. return;
  111. },
  112. complete: res => {
  113. console.log(res);
  114. if (res.errMsg == "requestPayment:ok") {
  115. } else {
  116. wx.showToast({
  117. title: "支付失败",
  118. image: "./../../../assets/img/fail.png",
  119. duration: 2000,
  120. mask: false
  121. });
  122. }
  123. return;
  124. }
  125. });
  126. /// End payment --------
  127. });
  128. } else {
  129. // 免费券
  130. that.payOrderUpdate(orderId, "0", 1) // 支付成功
  131. .then(res => {
  132. wx.showToast({
  133. title: "支付成功",
  134. duration: 2000,
  135. image: "./../../../assets/img/success.png",
  136. });
  137. });
  138. }
  139. },
  140. /**
  141. * 支付订单更新
  142. */
  143. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  144. // 支付成功
  145. Http.post({
  146. url: config.api.payOrderUpdate,
  147. data: {
  148. payOrderId: payOrderId,
  149. orderId: orderId,
  150. status: status,
  151. reason: reason
  152. }
  153. })
  154. .then(res => {
  155. console.log("payOrderUpdate then", res);
  156. // wx.showToast({
  157. // title: "购买成功",
  158. // duration: 2500
  159. // });
  160. })
  161. .catch(err => {
  162. console.log("payOrderUpdate catch", err);
  163. });
  164. },
  165. /**
  166. * 生命周期函数--监听页面初次渲染完成
  167. */
  168. onReady: function() {},
  169. /**
  170. * 生命周期函数--监听页面显示
  171. */
  172. onShow: function(options) {},
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide: function() {},
  177. /**
  178. * 生命周期函数--监听页面卸载
  179. */
  180. onUnload: function() {},
  181. /**
  182. * 页面相关事件处理函数--监听用户下拉动作
  183. */
  184. onPullDownRefresh: function() {},
  185. /**
  186. * 页面上拉触底事件的处理函数
  187. */
  188. onReachBottom: function() {},
  189. /**
  190. * 用户点击右上角分享
  191. */
  192. onShareAppMessage: function() {}
  193. });