C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

216 行
5.3 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. }, 1500);
  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-dd 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. },
  116. fail: res => {
  117. that.payOrderUpdate(that.data.orderId, payOrderId, 2,'','fail');
  118. console.log(res);
  119. return;
  120. },
  121. });
  122. /// End payment --------
  123. });
  124. } else {
  125. // 免费券
  126. that.payOrderUpdate(orderId, "0", 1) // 支付成功
  127. wx.showToast({
  128. title: "支付成功",
  129. duration: 2000,
  130. image: "./../../../assets/img/success.png",
  131. });
  132. }
  133. },
  134. /**
  135. * 支付订单更新
  136. */
  137. payOrderUpdate: (orderId, payOrderId, status, reason,type) => {
  138. // 支付成功
  139. Http.post({
  140. url: config.api.payOrderUpdate,
  141. data: {
  142. payOrderId: payOrderId,
  143. orderId: orderId,
  144. status: status,
  145. reason: reason
  146. }
  147. })
  148. .then(res => {
  149. if (!type) {
  150. wx.showToast({
  151. title: "购买成功",
  152. duration: 2000,
  153. image: "./../../../assets/img/success.png",
  154. mask: false,
  155. success: function () {
  156. wx.showLoading({
  157. title: "加载中..."
  158. });
  159. setTimeout(function () {
  160. wx.hideLoading();
  161. }, 1600);
  162. setTimeout(() => {
  163. wx.navigateTo({
  164. url: `/pages/order/detail/index?orderId=${orderId}`
  165. });
  166. }, 1600);
  167. }
  168. });
  169. }
  170. })
  171. .catch(err => {
  172. console.log("payOrderUpdate catch", err);
  173. });
  174. },
  175. /**
  176. * 生命周期函数--监听页面初次渲染完成
  177. */
  178. onShow: function () {
  179. let that = this;
  180. wx.getScreenBrightness({
  181. success: function (res) {
  182. that.setData({
  183. sight: res.value
  184. })
  185. }
  186. });
  187. },
  188. /**
  189. * 生命周期函数--监听页面隐藏
  190. */
  191. onHide: function () {},
  192. /**
  193. * 页面相关事件处理函数--监听用户下拉动作
  194. */
  195. onPullDownRefresh: function () {},
  196. /**
  197. * 页面上拉触底事件的处理函数
  198. */
  199. onReachBottom: function () {},
  200. /**
  201. * 用户点击右上角分享
  202. */
  203. onShareAppMessage: function () {}
  204. });