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.

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