C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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