C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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