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.

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