C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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