抖音c端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

240 satır
6.3 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. if (res.data.expiredSeconds == 0) {
  87. } else {
  88. let inre = setInterval(() => {
  89. if (_this.data.expiredSeconds > 1) {
  90. _this.setData({
  91. expiredSeconds: _this.data.expiredSeconds - 1
  92. })
  93. console.log("有效", _this.data.expiredSeconds)
  94. } else {
  95. console.log("无效", _this.data.expiredSeconds)
  96. clearInterval(_this.data.templTiem)
  97. _this.setData({
  98. showhieRq: true
  99. })
  100. }
  101. }, 1000)
  102. _this.setData({
  103. templTiem: inre
  104. })
  105. }
  106. // util.qrcode("qrcode", url, 350, 350);
  107. _this.createQrCode(url, "qrcode", 350, 350);
  108. }).catch(err => {
  109. tt.showToast({
  110. title: err.message,
  111. icon: 'none',
  112. duration: 2000,
  113. mask: false
  114. });
  115. })
  116. },
  117. onLoad: function (options) { //quancode
  118. console.log(options)
  119. console.log(app.globalData.curHtml)
  120. let that = this;
  121. // let value = JSON.stringify({ END: "C", TYPE: "couponorder", ID: options.quancode})
  122. // that.createQrCode(value, "qrcode", 350, 350);
  123. that.setData({
  124. code: options.quancode,
  125. title: options.title,
  126. subtitle: options.subtitle,
  127. remark: options.remark,
  128. couponorderstatus: options.couponorderstatus,
  129. validStatus: options.validstatus,
  130. contentType: options.contentType
  131. });
  132. if (options.couponorderstatus == 0) {
  133. that.setRq() //动态获取二维码 这个方法必须在拿到 options.quancode 后调用
  134. }
  135. if (options.contentType != undefined && options.contentType == 1) {
  136. this.setData({
  137. curHtml: app.globalData.curHtml
  138. })
  139. }
  140. /**
  141. * 如果没有核销
  142. */
  143. that.data.setInter = setInterval(function () {
  144. if (that.data.couponorderstatus == 0) {
  145. Http.get({
  146. url: config.api.getStatus,
  147. data: {
  148. couponOrderId: options.quancode
  149. }
  150. }).then(res => {
  151. console.log(res);
  152. that.setData({
  153. couponorderstatus: res.data.CouponOrderStatus
  154. });
  155. if (res.data.CouponOrderStatus == 1) {
  156. /**
  157. * 动态改变上一级页面的核销状态
  158. */
  159. that.getStaticGame()
  160. var pages = getCurrentPages();
  161. var prevPage = pages[pages.length - 2]; //上一个页面
  162. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  163. prevPage.setData({
  164. mystatus: res.data.CouponOrderStatus
  165. });
  166. }
  167. })
  168. .catch(err => {
  169. tt.showToast({
  170. title: err.errMsg,
  171. icon: 'none',
  172. duration: 2000,
  173. mask: false
  174. });
  175. })
  176. }
  177. }, 2000);
  178. if (that.data.couponorderstatus == 1) {
  179. /**
  180. * 如果已经核销
  181. * 不需要循环
  182. */
  183. Http.get({
  184. url: config.api.getStatus,
  185. data: {
  186. couponOrderId: options.quancode
  187. }
  188. }).then(res => {
  189. that.setData({
  190. couponorderstatus: res.data.CouponOrderStatus
  191. });
  192. })
  193. .catch(err => {
  194. tt.showToast({
  195. title: err.errMsg,
  196. icon: 'none',
  197. duration: 2000,
  198. mask: false
  199. });
  200. })
  201. }
  202. /**
  203. * couponorderstatus
  204. * 0 没有核销
  205. * 1 已经核销成功
  206. */
  207. },
  208. createQrCode: function (url, canvasId, cavW, cavH) {
  209. //调用插件中的draw方法,绘制二维码图片
  210. let that = this;
  211. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  212. that.setData({
  213. tempFilePath: res
  214. })
  215. });
  216. },
  217. onUnload: function () {
  218. let that = this;
  219. clearInterval(that.data.setInter);
  220. clearInterval(that.data.templTiem);
  221. },
  222. onHide: function () {
  223. let that = this;
  224. clearInterval(that.data.setInter);
  225. clearInterval(that.data.templTiem);
  226. },
  227. // onHide:function(){
  228. // console.log(app.globalData.sight)
  229. // tt.setScreenBrightness({
  230. // value: app.globalData.sight,
  231. // })
  232. // }
  233. });