C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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