C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

162 rader
4.2 KiB

  1. // let util = require("../../utils/util");
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  3. let Http = require("../../utils/HttpBasics");
  4. let config = require("../../config/config.js");
  5. let app = getApp();
  6. const imgurl = require("../../utils/imgurl");
  7. const QR = require("../../utils/memberqrcode.js");
  8. Page({
  9. data: {
  10. navigationBarHeight,
  11. btomLineUrl: imgurl.btomLine.url,
  12. topLineUrl: imgurl.topLine.url,
  13. lineUrl: imgurl.line.url,
  14. wm01Url: imgurl.wm01.url,
  15. wm02Url: imgurl.wm02.url,
  16. wm03Url: imgurl.wm03.url,
  17. wm04Url: imgurl.wm04.url,
  18. code: "",
  19. //存储计时器
  20. setInter: "",
  21. staticGamedata: {},
  22. showIf: false,
  23. },
  24. gotogame: function () {
  25. let that = this;
  26. wx.navigateTo({
  27. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  28. })
  29. },
  30. // 获取游戏
  31. getStaticGame(token) {
  32. let _this = this;
  33. Http.get({
  34. url: config.api.getGame,
  35. data: {
  36. triggleAction: 4 // 核销触发
  37. }
  38. }).then(res => {
  39. if (res.data.id) {
  40. _this.setData({
  41. showIf: true
  42. })
  43. }
  44. _this.setData({
  45. staticGamedata: res.data
  46. })
  47. })
  48. .catch(err => {
  49. wx.showToast({
  50. title: err.errMsg,
  51. icon: 'none',
  52. duration: 2000,
  53. mask: false
  54. });
  55. })
  56. },
  57. onLoad: function (options) {
  58. let that = this;
  59. let value = JSON.stringify({ END: "C", TYPE: "couponorder", ID: options.quancode})
  60. that.createQrCode(value, "qrcode", 350, 350);
  61. that.setData({
  62. code: options.quancode,
  63. title: options.title,
  64. subtitle: options.subtitle,
  65. remark: options.remark,
  66. couponorderstatus: options.couponorderstatus,
  67. validStatus: options.validstatus
  68. });
  69. /**
  70. * 如果没有核销
  71. */
  72. that.data.setInter = setInterval(function () {
  73. if (that.data.couponorderstatus == 0) {
  74. Http.get({
  75. url: config.api.getStatus,
  76. data: {
  77. couponOrderId: options.quancode
  78. }
  79. }).then(res => {
  80. console.log(res);
  81. that.setData({
  82. couponorderstatus: res.data.CouponOrderStatus
  83. });
  84. if (res.data.CouponOrderStatus == 1) {
  85. /**
  86. * 动态改变上一级页面的核销状态
  87. */
  88. that.getStaticGame()
  89. var pages = getCurrentPages();
  90. var prevPage = pages[pages.length - 2]; //上一个页面
  91. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  92. prevPage.setData({
  93. mystatus: res.data.CouponOrderStatus
  94. });
  95. }
  96. })
  97. .catch(err => {
  98. wx.showToast({
  99. title: err.errMsg,
  100. icon: 'none',
  101. duration: 2000,
  102. mask: false
  103. });
  104. })
  105. }
  106. }, 2000);
  107. if (that.data.couponorderstatus == 1) {
  108. /**
  109. * 如果已经核销
  110. * 不需要循环
  111. */
  112. Http.get({
  113. url: config.api.getStatus,
  114. data: {
  115. couponOrderId: options.quancode
  116. }
  117. }).then(res => {
  118. that.setData({
  119. couponorderstatus: res.data.CouponOrderStatus
  120. });
  121. })
  122. .catch(err => {
  123. wx.showToast({
  124. title: err.errMsg,
  125. icon: 'none',
  126. duration: 2000,
  127. mask: false
  128. });
  129. })
  130. }
  131. /**
  132. * couponorderstatus
  133. * 0 没有核销
  134. * 1 已经核销成功
  135. */
  136. },
  137. createQrCode: function (url, canvasId, cavW, cavH) {
  138. //调用插件中的draw方法,绘制二维码图片
  139. let that = this;
  140. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  141. that.setData({
  142. tempFilePath: res
  143. })
  144. });
  145. },
  146. onUnload: function () {
  147. let that = this;
  148. clearInterval(that.data.setInter);
  149. },
  150. onHide: function () {
  151. let that = this;
  152. clearInterval(that.data.setInter);
  153. },
  154. // onHide:function(){
  155. // console.log(app.globalData.sight)
  156. // wx.setScreenBrightness({
  157. // value: app.globalData.sight,
  158. // })
  159. // }
  160. });