C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

260 rindas
6.8 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. /**
  16. * 点击弹出二维码
  17. * 然后再关闭
  18. */
  19. powerDrawer: function(e) {
  20. // var currentStatu = e.currentTarget.dataset.statu;
  21. wx.navigateTo({
  22. url: `/pages/youhuiquanma/index?quancode=${e.currentTarget.dataset.quancode}&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle}&remark=${e.currentTarget.dataset.remark}`,
  23. })
  24. // console.log(e.currentTarget.dataset.statu);
  25. console.log(e.currentTarget.dataset.quancode);
  26. // this.utils(currentStatu, e.currentTarget.dataset.quancode);
  27. },
  28. // utils: function(currentStatu, quancode) {
  29. // /* 动画部分 */
  30. // // 第1步:创建动画实例
  31. // var animation = wx.createAnimation({
  32. // duration: 200, //动画时长
  33. // timingFunction: "linear", //线性
  34. // delay: 0 //0则不延迟
  35. // }); // 第2步:这个动画实例赋给当前的动画实例
  36. // this.animation = animation; // 第3步:执行第一组动画
  37. // animation.opacity(0).step(); // 第4步:导出动画对象赋给数据对象储存
  38. // this.setData({
  39. // animationData: animation.export()
  40. // }); // 第5步:设置定时器到指定时候后,执行第二组动画
  41. // setTimeout(
  42. // function() {
  43. // // 执行第二组动画
  44. // animation.opacity(1).step(); // 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象
  45. // this.setData({
  46. // animationData: animation
  47. // }); //关闭
  48. // if (currentStatu == "close") {
  49. // this.setData({
  50. // showModalStatus: false
  51. // });
  52. // }
  53. // }.bind(this),
  54. // 20
  55. // );
  56. // // 显示
  57. // if (currentStatu == "open") {
  58. // this.setData({
  59. // showModalStatus: true
  60. // });
  61. // this.data.flag++;
  62. // console.log(this.data.flag);
  63. // util.barcode("barcode" + this.data.flag, quancode, 500, 100);
  64. // util.qrcode("qrcode" + this.data.flag, quancode, 350, 350);
  65. // this.setData({
  66. // flag: this.data.flag
  67. // });
  68. // }
  69. // },
  70. /**
  71. * 生命周期函数--监听页面加载
  72. */
  73. onLoad: function(options) {
  74. let that = this;
  75. console.log(options.orderId);
  76. console.log(options.flag + "我是付款的标识");
  77. this.setData({
  78. orderId: options.orderId
  79. })
  80. Http.get({
  81. url: config.api.orderDetail,
  82. data: {
  83. orderId: options.orderId
  84. }
  85. }).then(res => {
  86. console.log(res);
  87. console.log("我是订单详情");
  88. that.setData({
  89. order: res.data
  90. });
  91. //createDate 创建时间
  92. var createDate = util.fmtDate(res.data.createDate);
  93. console.log(createDate);
  94. that.setData({
  95. createDate: createDate
  96. });
  97. });
  98. },
  99. /**
  100. * 发起支付
  101. */
  102. orderFunc(e) {
  103. var that = this;
  104. wx.showLoading({
  105. title: "加载中..."
  106. });
  107. const orderId = "" + that.data.orderId;
  108. if (that.data.order.payment > 0) {
  109. // 支付金额不为0
  110. Http.post({
  111. url: config.api.payOrderCreate,
  112. data: {
  113. orderId: orderId
  114. }
  115. }).then(res => {
  116. console.log(res);
  117. /// Begin payment ----
  118. var payOrderId = "" + res.data.payOrderId;
  119. wx.hideLoading();
  120. wx.requestPayment({
  121. timeStamp: res.data.timeStamp,
  122. nonceStr: res.data.nonceStr,
  123. package: res.data.package,
  124. signType: "MD5",
  125. paySign: res.data.paySign,
  126. success: res => {
  127. console.log(res);
  128. console.log("姐在检查付款异常");
  129. that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功
  130. console.log(res);
  131. if (res.errMsg == "requestPayment:ok") {
  132. wx.showToast({
  133. title: "购买成功",
  134. duration: 2500
  135. });
  136. }
  137. wx.navigateBack({
  138. delta: 2
  139. });
  140. },
  141. fail: res => {
  142. that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败
  143. console.log(res);
  144. return;
  145. },
  146. complete: res => {
  147. console.log(res);
  148. console.log("支付完成");
  149. // var url = res.data.url;
  150. // console.log("get url", url);
  151. if (res.errMsg == "requestPayment:ok") {
  152. wx.showModal({
  153. title: "提示",
  154. content: "支付成功"
  155. });
  156. // if (url) {
  157. // setTimeout(function () {
  158. // wx.redirectTo({
  159. // url: "/pages" + url
  160. // });
  161. // }, 2000);
  162. // } else {
  163. // setTimeout(() => {
  164. // wx.navigateBack();
  165. // }, 2000);
  166. // }
  167. } else {
  168. wx.showToast({
  169. title: "支付失败",
  170. image: "./../../../assets/img/fail.png",
  171. duration: 1500,
  172. mask: false
  173. });
  174. }
  175. return;
  176. }
  177. });
  178. /// End payment --------
  179. });
  180. } else {
  181. // 免费券
  182. that.payOrderUpdate(orderId, "0", 1) // 支付成功
  183. .then(res => {
  184. wx.showToast({
  185. title: "支付成功",
  186. duration: 3000
  187. });
  188. });
  189. }
  190. },
  191. /**
  192. * 支付订单更新
  193. */
  194. payOrderUpdate: (orderId, payOrderId, status, reason) => {
  195. // 支付成功
  196. Http.post({
  197. url: config.api.payOrderUpdate,
  198. data: {
  199. payOrderId: payOrderId,
  200. orderId: orderId,
  201. status: status,
  202. reason: reason
  203. }
  204. })
  205. .then(res => {
  206. console.log("payOrderUpdate then", res);
  207. // wx.showToast({
  208. // title: "购买成功",
  209. // duration: 2500
  210. // });
  211. })
  212. .catch(err => {
  213. console.log("payOrderUpdate catch", err);
  214. });
  215. },
  216. /**
  217. * 生命周期函数--监听页面初次渲染完成
  218. */
  219. onReady: function() {},
  220. /**
  221. * 生命周期函数--监听页面显示
  222. */
  223. onShow: function(options) {},
  224. /**
  225. * 生命周期函数--监听页面隐藏
  226. */
  227. onHide: function() {},
  228. /**
  229. * 生命周期函数--监听页面卸载
  230. */
  231. onUnload: function() {},
  232. /**
  233. * 页面相关事件处理函数--监听用户下拉动作
  234. */
  235. onPullDownRefresh: function() {},
  236. /**
  237. * 页面上拉触底事件的处理函数
  238. */
  239. onReachBottom: function() {},
  240. /**
  241. * 用户点击右上角分享
  242. */
  243. onShareAppMessage: function() {}
  244. });