C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

160 righe
4.1 KiB

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