C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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