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.

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