抖音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.

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