C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

226 řádky
6.2 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. const util = require("../../../utils/util");
  3. const config = require("../../../config/config.js");
  4. const Http = require("../../../utils/HttpBasics");
  5. let app = getApp();
  6. const imgurl = require("../../../utils/imgurl");
  7. const QR = require("../../../utils/memberqrcode.js");
  8. //券详情页面
  9. Page({
  10. data: {
  11. navigationBarHeight,
  12. code: "",
  13. topLine: imgurl.topLine.url,
  14. btomLine: imgurl.btomLine.url,
  15. lineUrl: imgurl.line.url,
  16. wm01Url: imgurl.wm01.url,
  17. wm02Url: imgurl.wm02.url,
  18. wm03Url: imgurl.wm03.url,
  19. wm04Url: imgurl.wm04.url,
  20. teljpgUrl: imgurl.teljpg.url,
  21. newUrl: imgurl.new1.url,
  22. data: {
  23. salePrice: null,
  24. price: null,
  25. usePrice: null
  26. },
  27. createDate: "",
  28. expiredTime: "",
  29. validStartDate:"",
  30. validEndDate:"",
  31. updateDate: "",
  32. //存储计时器
  33. setInter: "",
  34. staticGamedata: {},
  35. showIf: false,
  36. curHtml: '',
  37. },
  38. onUnload:function(){
  39. let that = this;
  40. clearInterval(that.data.setInter);
  41. },
  42. onHide:function(){
  43. let that = this;
  44. clearInterval(that.data.setInter);
  45. },
  46. gotogame: function () {
  47. let that = this;
  48. wx.redirectTo({
  49. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  50. })
  51. },
  52. // 获取游戏
  53. getStaticGame(token) {
  54. let _this = this;
  55. Http.get({
  56. url: config.api.getGame,
  57. data: {
  58. triggleAction: 4 // 核销触发
  59. }
  60. }).then(res => {
  61. if (res.data.id) {
  62. _this.setData({
  63. showIf: true
  64. })
  65. }
  66. _this.setData({
  67. staticGamedata: res.data
  68. })
  69. })
  70. .catch(err => {
  71. wx.showToast({
  72. title: err.errMsg,
  73. icon: 'none',
  74. duration: 2000,
  75. mask: false
  76. });
  77. })
  78. },
  79. // onShow(options) {
  80. // setTimeout(function () {
  81. // wx.setScreenBrightness({
  82. // value: 0.7,
  83. // })
  84. // }, 200)
  85. // },
  86. onLoad: function (options) {
  87. let that = this;
  88. that.setData({
  89. code: options.quancode,
  90. couponorderstatus: options.couponorderstatus
  91. });
  92. if (
  93. options.quancode &&
  94. that.data.couponorderstatus == 0
  95. ) {
  96. //aaa
  97. that.getHtml(options.quancode);
  98. }
  99. //获得优惠券的详情
  100. that.data.setInter = setInterval(function () {
  101. if (
  102. options.quancode &&
  103. that.data.couponorderstatus == 0
  104. ) {
  105. Http.get({
  106. url: config.api.couponOrderDetail,
  107. data: {
  108. couponOrderId: options.quancode
  109. }
  110. }).then(res => {
  111. that.setData({
  112. couponorderstatus: res.data.couponOrderStatus,
  113. data: res.data,
  114. });
  115. if (res.data.couponOrderStatus == 1) {
  116. /**
  117. * 动态改变上一级页面的核销状态
  118. */
  119. that.getStaticGame()
  120. var pages = getCurrentPages();
  121. var prevPage = pages[pages.length - 2]; //上一个页面
  122. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  123. prevPage.setData({
  124. mystatus: res.data.couponOrderStatus
  125. });
  126. }
  127. that.setData({
  128. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  129. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  130. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  131. });
  132. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  133. that.setData({
  134. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  135. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss")
  136. })
  137. }
  138. })
  139. .catch(err => {
  140. wx.showToast({
  141. title: err.errMsg,
  142. icon: 'none',
  143. duration: 2000,
  144. mask: false
  145. });
  146. })
  147. }
  148. }, 2000);
  149. /**
  150. * 页面需要初始渲染的效果
  151. */
  152. Http.get({
  153. url: config.api.couponOrderDetail,
  154. data: {
  155. couponOrderId: options.quancode
  156. }
  157. }).then(res => {
  158. that.setData({
  159. couponorderstatus: res.data.couponOrderStatus,
  160. data: res.data
  161. });
  162. that.setData({
  163. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  164. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  165. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  166. });
  167. if (that.data.data.validStartDate && that.data.data.validEndDate){
  168. that.setData({
  169. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  170. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss")
  171. })
  172. }
  173. let url = JSON.stringify({
  174. END:"C",
  175. TYPE:"couponorder",
  176. ID: options.quancode
  177. })
  178. // util.qrcode("qrcode", url, 350, 350);
  179. that.createQrCode(url, "qrcode", 350, 350);
  180. })
  181. .catch(err => {
  182. wx.showToast({
  183. title: err.errMsg,
  184. icon: 'none',
  185. duration: 2000,
  186. mask: false
  187. });
  188. })
  189. },
  190. getHtml(couponChannelId) {
  191. Http.get({
  192. url: config.api.couponHtmlDetailForPkg,
  193. data: {
  194. // couponChannelId: '433119630735183872'
  195. couponOrderId: couponChannelId
  196. }
  197. }).then(res => {
  198. if (res.code == 200 && res.data.html) {
  199. this.setData({
  200. curHtml: decodeURI(res.data.html)
  201. })
  202. }
  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. phone: function (e) {
  215. let that = this;
  216. if (e.currentTarget.dataset.merchantlinkphone) {
  217. wx.makePhoneCall({
  218. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  219. });
  220. }
  221. }
  222. });