抖音小程序C端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

237 lignes
6.1 KiB

  1. // let util = require("../../utils/util");
  2. const navigationBarHeight = (getApp().statusBarHeight + 50) + '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. upDataRqUrl: imgurl.upDataRq.url,
  19. upDataRqUrlF: imgurl.upDataRqF.url,
  20. code: "",
  21. //存储计时器
  22. setInter: "",
  23. staticGamedata: {},
  24. showIf: false,
  25. curHtml: '',
  26. contentType: 0,
  27. showhieRq: false,
  28. dynamicRq: "",
  29. expiredSeconds: 0,
  30. templTiem: ""
  31. },
  32. gotogame: function () {
  33. let that = this;
  34. tt.navigateTo({
  35. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  36. })
  37. },
  38. // 获取游戏
  39. getStaticGame(token) {
  40. let _this = this;
  41. Http.get({
  42. url: config.api.getGame,
  43. data: {
  44. triggleAction: 4 // 核销触发
  45. }
  46. }).then(res => {
  47. if (res.data.id) {
  48. _this.setData({
  49. showIf: true
  50. })
  51. }
  52. _this.setData({
  53. staticGamedata: res.data
  54. })
  55. })
  56. .catch(err => {
  57. tt.showToast({
  58. title: err.errMsg,
  59. icon: 'none',
  60. duration: 2000,
  61. mask: false
  62. });
  63. })
  64. },
  65. setRq() {
  66. let _this = this
  67. _this.setData({
  68. showhieRq: false,
  69. })
  70. Http.get({//获取动态二维码
  71. url: config.api.dynamicId,
  72. data: {
  73. couponOrderId: _this.data.code
  74. }
  75. }).then(res => {
  76. console.log(res, "res")
  77. _this.setData({
  78. dynamicRq: res.data.dynamicId,
  79. expiredSeconds: res.data.expiredSeconds
  80. })
  81. let url = JSON.stringify({
  82. END: "C",
  83. TYPE: "couponorder",
  84. ID: _this.data.dynamicRq
  85. })
  86. let inre = setInterval(() => {
  87. if (_this.data.expiredSeconds > 1) {
  88. _this.setData({
  89. expiredSeconds: _this.data.expiredSeconds - 1
  90. })
  91. console.log("有效", _this.data.expiredSeconds)
  92. } else {
  93. console.log("无效", _this.data.expiredSeconds)
  94. clearInterval(_this.data.templTiem)
  95. _this.setData({
  96. showhieRq: true
  97. })
  98. }
  99. }, 1000)
  100. _this.setData({
  101. templTiem: inre
  102. })
  103. // util.qrcode("qrcode", url, 350, 350);
  104. _this.createQrCode(url, "qrcode", 350, 350);
  105. }).catch(err => {
  106. tt.showToast({
  107. title: err.message,
  108. icon: 'none',
  109. duration: 2000,
  110. mask: false
  111. });
  112. })
  113. },
  114. onLoad: function (options) { //quancode
  115. console.log(options)
  116. console.log(app.globalData.curHtml)
  117. let that = this;
  118. // let value = JSON.stringify({ END: "C", TYPE: "couponorder", ID: options.quancode})
  119. // that.createQrCode(value, "qrcode", 350, 350);
  120. that.setData({
  121. code: options.quancode,
  122. title: options.title,
  123. subtitle: options.subtitle,
  124. remark: options.remark,
  125. couponorderstatus: options.couponorderstatus,
  126. validStatus: options.validstatus,
  127. contentType: options.contentType
  128. });
  129. if (options.couponorderstatus==0){
  130. that.setRq()//动态获取二维码 这个方法必须在拿到 options.quancode 后调用
  131. }
  132. if (options.contentType != undefined && options.contentType==1) {
  133. this.setData({
  134. curHtml: app.globalData.curHtml
  135. })
  136. }
  137. /**
  138. * 如果没有核销
  139. */
  140. that.data.setInter = setInterval(function () {
  141. if (that.data.couponorderstatus == 0) {
  142. Http.get({
  143. url: config.api.getStatus,
  144. data: {
  145. couponOrderId: options.quancode
  146. }
  147. }).then(res => {
  148. console.log(res);
  149. that.setData({
  150. couponorderstatus: res.data.CouponOrderStatus
  151. });
  152. if (res.data.CouponOrderStatus == 1) {
  153. /**
  154. * 动态改变上一级页面的核销状态
  155. */
  156. that.getStaticGame()
  157. var pages = getCurrentPages();
  158. var prevPage = pages[pages.length - 2]; //上一个页面
  159. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  160. prevPage.setData({
  161. mystatus: res.data.CouponOrderStatus
  162. });
  163. }
  164. })
  165. .catch(err => {
  166. tt.showToast({
  167. title: err.errMsg,
  168. icon: 'none',
  169. duration: 2000,
  170. mask: false
  171. });
  172. })
  173. }
  174. }, 2000);
  175. if (that.data.couponorderstatus == 1) {
  176. /**
  177. * 如果已经核销
  178. * 不需要循环
  179. */
  180. Http.get({
  181. url: config.api.getStatus,
  182. data: {
  183. couponOrderId: options.quancode
  184. }
  185. }).then(res => {
  186. that.setData({
  187. couponorderstatus: res.data.CouponOrderStatus
  188. });
  189. })
  190. .catch(err => {
  191. tt.showToast({
  192. title: err.errMsg,
  193. icon: 'none',
  194. duration: 2000,
  195. mask: false
  196. });
  197. })
  198. }
  199. /**
  200. * couponorderstatus
  201. * 0 没有核销
  202. * 1 已经核销成功
  203. */
  204. },
  205. createQrCode: function (url, canvasId, cavW, cavH) {
  206. //调用插件中的draw方法,绘制二维码图片
  207. let that = this;
  208. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  209. that.setData({
  210. tempFilePath: res
  211. })
  212. });
  213. },
  214. onUnload: function () {
  215. let that = this;
  216. clearInterval(that.data.setInter);
  217. clearInterval(that.data.templTiem);
  218. },
  219. onHide: function () {
  220. let that = this;
  221. clearInterval(that.data.setInter);
  222. clearInterval(that.data.templTiem);
  223. },
  224. // onHide:function(){
  225. // console.log(app.globalData.sight)
  226. // tt.setScreenBrightness({
  227. // value: app.globalData.sight,
  228. // })
  229. // }
  230. });