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

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