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.

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