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

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