C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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