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.

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