C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

228 行
6.4 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. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  137. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  138. })
  139. }
  140. })
  141. .catch(err => {
  142. wx.showToast({
  143. title: err.errMsg,
  144. icon: 'none',
  145. duration: 2000,
  146. mask: false
  147. });
  148. })
  149. }
  150. }, 2000);
  151. /**
  152. * 页面需要初始渲染的效果
  153. */
  154. Http.get({
  155. url: config.api.couponOrderDetail,
  156. data: {
  157. couponOrderId: options.quancode
  158. }
  159. }).then(res => {
  160. that.setData({
  161. couponorderstatus: res.data.couponOrderStatus,
  162. data: res.data
  163. });
  164. that.setData({
  165. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  166. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  167. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  168. });
  169. if (that.data.data.validStartDate && that.data.data.validEndDate){
  170. that.setData({
  171. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  172. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss")
  173. })
  174. }
  175. let url = JSON.stringify({
  176. END:"C",
  177. TYPE:"couponorder",
  178. ID: options.quancode
  179. })
  180. // util.qrcode("qrcode", url, 350, 350);
  181. that.createQrCode(url, "qrcode", 350, 350);
  182. })
  183. .catch(err => {
  184. wx.showToast({
  185. title: err.errMsg,
  186. icon: 'none',
  187. duration: 2000,
  188. mask: false
  189. });
  190. })
  191. },
  192. getHtml(couponChannelId) {
  193. Http.get({
  194. url: config.api.couponHtmlDetailForPkg,
  195. data: {
  196. // couponChannelId: '433119630735183872'
  197. couponOrderId: couponChannelId
  198. }
  199. }).then(res => {
  200. if (res.code == 200 && res.data.html) {
  201. this.setData({
  202. curHtml: decodeURI(res.data.html)
  203. })
  204. }
  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. phone: function (e) {
  217. let that = this;
  218. if (e.currentTarget.dataset.merchantlinkphone) {
  219. wx.makePhoneCall({
  220. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  221. });
  222. }
  223. }
  224. });