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.

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