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.

201 lines
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. setInter: null,
  16. mystatus: null
  17. },
  18. powerDrawer: function (e) {
  19. let that = this;
  20. /**
  21. * couponOrderStatus
  22. * 0 未使用
  23. 1 已使用
  24. 2 已过期
  25. 3 已经退款
  26. */
  27. console.log(e);
  28. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  29. wx.navigateTo({
  30. url: `/pages/orderquanma/index?quancode=${
  31. e.currentTarget.dataset.quancode
  32. }&title=${e.currentTarget.dataset.title}&subtitle=${
  33. e.currentTarget.dataset.subtitle
  34. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  35. e.currentTarget.dataset.couponorderstatus
  36. }&sight=${that.data.sight}`
  37. });
  38. console.log(e.currentTarget.dataset.couponorderstatus);
  39. } else {
  40. wx.navigateTo({
  41. url: `/pages/orderquanma/index?quancode=${
  42. e.currentTarget.dataset.quancode
  43. }&title=${e.currentTarget.dataset.title}&subtitle=${
  44. e.currentTarget.dataset.subtitle
  45. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${
  46. that.data.mystatus
  47. }&sight=${that.data.sight}`
  48. });
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. onLoad: function (options) {
  55. let that = this;
  56. this.setData({
  57. orderId: options.orderId
  58. });
  59. wx.showLoading({
  60. title: "加载中"
  61. });
  62. setTimeout(function () {
  63. wx.hideLoading();
  64. }, 1500);
  65. Http.get({
  66. url: config.api.orderDetail,
  67. data: {
  68. orderId: options.orderId
  69. }
  70. }).then(res => {
  71. that.setData({
  72. order: res.data
  73. });
  74. //createDate 创建时间
  75. var createDate = util.formatTime(res.data.createDate, "yyyy-MM-dd hh:mm:ss");
  76. console.log(createDate);
  77. that.setData({
  78. createDate: createDate
  79. });
  80. });
  81. },
  82. /**
  83. * 发起支付
  84. */
  85. orderFunc(e) {
  86. var that = this;
  87. wx.showLoading({
  88. title: "加载中..."
  89. });
  90. const orderId = "" + that.data.orderId;
  91. if (that.data.order.payment > 0) {
  92. // 支付金额不为0
  93. Http.post({
  94. url: config.api.payOrderCreate,
  95. data: {
  96. orderId: orderId
  97. }
  98. }).then(res => {
  99. console.log(res);
  100. /// Begin payment ----
  101. var payOrderId = "" + res.data.payOrderId;
  102. wx.hideLoading();
  103. wx.requestPayment({
  104. timeStamp: res.data.timeStamp,
  105. nonceStr: res.data.nonceStr,
  106. package: res.data.package,
  107. signType: (res.data.signType) ? res.data.signType : "MD5",
  108. paySign: res.data.paySign,
  109. success: res => {
  110. console.log(res);
  111. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  112. /**
  113. * @Meo
  114. * 更新订单的状态
  115. */
  116. console.log(res);
  117. if (res.errMsg == "requestPayment:ok") {
  118. wx.showToast({
  119. title: "购买成功",
  120. duration: 2000,
  121. image: "./../../../assets/img/success.png",
  122. mask: false,
  123. success: function () {
  124. wx.showLoading({
  125. title: "加载中..."
  126. });
  127. setTimeout(function () {
  128. wx.hideLoading();
  129. }, 1600);
  130. setTimeout(() => {
  131. wx.navigateTo({
  132. url: `/pages/order/detail/index?orderId=${
  133. that.data.orderId
  134. }`
  135. });
  136. }, 1600);
  137. }
  138. });
  139. }
  140. },
  141. fail: res => {
  142. that.payOrderUpdate(that.data.orderId, payOrderId, 2);
  143. console.log(res);
  144. return;
  145. },
  146. });
  147. /// End payment --------
  148. });
  149. } else {
  150. // 免费券
  151. that.payOrderUpdate(orderId, "0", 1) // 支付成功
  152. wx.showToast({
  153. title: "支付成功",
  154. duration: 2000,
  155. image: "./../../../assets/img/success.png",
  156. });
  157. }
  158. },
  159. /**
  160. * 支付订单更新
  161. */
  162. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  163. // 支付成功
  164. Http.post({
  165. url: config.api.payOrderUpdate,
  166. data: {
  167. payOrderId: payOrderId,
  168. orderId: orderId,
  169. status: status,
  170. reason: reason
  171. }
  172. })
  173. .then(res => {
  174. console.log("payOrderUpdate then", res);
  175. })
  176. .catch(err => {
  177. console.log("payOrderUpdate catch", err);
  178. });
  179. },
  180. /**
  181. * 生命周期函数--监听页面初次渲染完成
  182. */
  183. onShow: function () {
  184. let that = this;
  185. wx.getScreenBrightness({
  186. success: function (res) {
  187. that.setData({
  188. sight: res.value
  189. })
  190. }
  191. })
  192. }
  193. });