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.

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