C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

208 righe
5.8 KiB

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