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.

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