C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
4.7 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/youhuiquanma/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: 2500
  97. });
  98. }
  99. },
  100. fail: res => {
  101. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  102. console.log(res);
  103. return;
  104. },
  105. complete: res => {
  106. console.log(res);
  107. if (res.errMsg == "requestPayment:ok") {
  108. } else {
  109. wx.showToast({
  110. title: "支付失败",
  111. image: "./../../../assets/img/fail.png",
  112. duration: 1500,
  113. mask: false
  114. });
  115. }
  116. return;
  117. }
  118. });
  119. /// End payment --------
  120. });
  121. } else {
  122. // 免费券
  123. that.payOrderUpdate(orderId, "0", 1) // 支付成功
  124. .then(res => {
  125. wx.showToast({
  126. title: "支付成功",
  127. duration: 3000
  128. });
  129. });
  130. }
  131. },
  132. /**
  133. * 支付订单更新
  134. */
  135. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  136. // 支付成功
  137. Http.post({
  138. url: config.api.payOrderUpdate,
  139. data: {
  140. payOrderId: payOrderId,
  141. orderId: orderId,
  142. status: status,
  143. reason: reason
  144. }
  145. })
  146. .then(res => {
  147. console.log("payOrderUpdate then", res);
  148. // wx.showToast({
  149. // title: "购买成功",
  150. // duration: 2500
  151. // });
  152. })
  153. .catch(err => {
  154. console.log("payOrderUpdate catch", err);
  155. });
  156. },
  157. /**
  158. * 生命周期函数--监听页面初次渲染完成
  159. */
  160. onReady: function() {},
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function(options) {},
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function() {},
  169. /**
  170. * 生命周期函数--监听页面卸载
  171. */
  172. onUnload: function() {},
  173. /**
  174. * 页面相关事件处理函数--监听用户下拉动作
  175. */
  176. onPullDownRefresh: function() {},
  177. /**
  178. * 页面上拉触底事件的处理函数
  179. */
  180. onReachBottom: function() {},
  181. /**
  182. * 用户点击右上角分享
  183. */
  184. onShareAppMessage: function() {}
  185. });