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.

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