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.

287 regels
7.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. 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. upDataRqUrl: imgurl.upDataRq.url,
  20. upDataRqUrlF: imgurl.upDataRqF.url,
  21. wm04Url: imgurl.wm04.url,
  22. teljpgUrl: imgurl.teljpg.url,
  23. newUrl: imgurl.new1.url,
  24. data: {
  25. salePrice: null,
  26. price: null,
  27. usePrice: null
  28. },
  29. createDate: "",
  30. expiredTime: "",
  31. validStartDate:"",
  32. validEndDate:"",
  33. updateDate: "",
  34. //存储计时器
  35. setInter: "",
  36. staticGamedata: {},
  37. showIf: false,
  38. curHtml: '',
  39. showhieRq:false,
  40. dynamicRq:"",
  41. expiredSeconds:0,
  42. templTiem:""
  43. },
  44. onUnload:function(){
  45. let that = this;
  46. clearInterval(that.data.setInter);
  47. clearInterval(that.data.templTiem);
  48. },
  49. onHide:function(){
  50. let that = this;
  51. clearInterval(that.data.setInter);
  52. clearInterval(that.data.templTiem);
  53. },
  54. gotogame: function () {
  55. let that = this;
  56. wx.redirectTo({
  57. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  58. })
  59. },
  60. // 获取游戏
  61. getStaticGame(token) {
  62. let _this = this;
  63. Http.get({
  64. url: config.api.getGame,
  65. data: {
  66. triggleAction: 4 // 核销触发
  67. }
  68. }).then(res => {
  69. if (res.data.id) {
  70. _this.setData({
  71. showIf: true
  72. })
  73. }
  74. _this.setData({
  75. staticGamedata: res.data
  76. })
  77. })
  78. .catch(err => {
  79. wx.showToast({
  80. title: err.errMsg,
  81. icon: 'none',
  82. duration: 2000,
  83. mask: false
  84. });
  85. })
  86. },
  87. // onShow(options) {
  88. // setTimeout(function () {
  89. // wx.setScreenBrightness({
  90. // value: 0.7,
  91. // })
  92. // }, 200)
  93. // },
  94. setRq(){
  95. let _this = this
  96. _this.setData({
  97. showhieRq: false,
  98. })
  99. Http.get({//获取动态二维码
  100. url: config.api.dynamicId,
  101. data: {
  102. couponOrderId: _this.data.code
  103. }
  104. }).then(res => {
  105. console.log(res, "res")
  106. _this.setData({
  107. dynamicRq: res.data.dynamicId,
  108. expiredSeconds: res.data.expiredSeconds
  109. })
  110. let url = JSON.stringify({
  111. END: "C",
  112. TYPE: "couponorder",
  113. ID: _this.data.dynamicRq
  114. })
  115. let inre = setInterval(()=>{
  116. if(_this.data.expiredSeconds>1){
  117. _this.setData({
  118. expiredSeconds: _this.data.expiredSeconds-1
  119. })
  120. console.log("有效",_this.data.expiredSeconds)
  121. }else{
  122. console.log("无效", _this.data.expiredSeconds)
  123. clearInterval(_this.data.templTiem)
  124. _this.setData({
  125. showhieRq:true
  126. })
  127. }
  128. },1000)
  129. _this.setData({
  130. templTiem:inre
  131. })
  132. // util.qrcode("qrcode", url, 350, 350);
  133. _this.createQrCode(url, "qrcode", 350, 350);
  134. }).catch(err=>{
  135. wx.showToast({
  136. title: err.message,
  137. icon: 'none',
  138. duration: 2000,
  139. mask: false
  140. });
  141. })
  142. },
  143. onLoad: function (options) {
  144. let that = this;
  145. that.setData({
  146. code: options.quancode,
  147. couponorderstatus: options.couponorderstatus
  148. });
  149. if (
  150. options.quancode &&
  151. that.data.couponorderstatus == 0
  152. ) {
  153. //aaa
  154. that.setRq()//动态二维码 //这个方法必须在拿到 options.quancode 后调用
  155. that.getHtml(options.quancode);
  156. }
  157. //获得优惠券的详情
  158. that.data.setInter = setInterval(function () {
  159. if (
  160. options.quancode &&
  161. that.data.couponorderstatus == 0
  162. ) {
  163. Http.get({
  164. url: config.api.couponOrderDetail,
  165. data: {
  166. couponOrderId: options.quancode
  167. }
  168. }).then(res => {
  169. that.setData({
  170. couponorderstatus: res.data.couponOrderStatus,
  171. data: res.data,
  172. });
  173. if (res.data.couponOrderStatus == 1) {
  174. /**
  175. * 动态改变上一级页面的核销状态
  176. */
  177. that.getStaticGame()
  178. var pages = getCurrentPages();
  179. var prevPage = pages[pages.length - 2]; //上一个页面
  180. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  181. prevPage.setData({
  182. mystatus: res.data.couponOrderStatus
  183. });
  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. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd hh:mm:ss"),
  195. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd hh:mm:ss"),
  196. })
  197. }
  198. })
  199. .catch(err => {
  200. wx.showToast({
  201. title: err.errMsg,
  202. icon: 'none',
  203. duration: 2000,
  204. mask: false
  205. });
  206. })
  207. }
  208. }, 2000);
  209. /**
  210. * 页面需要初始渲染的效果
  211. */
  212. Http.get({
  213. url: config.api.couponOrderDetail,
  214. data: {
  215. couponOrderId: options.quancode
  216. }
  217. }).then(res => {
  218. that.setData({
  219. couponorderstatus: res.data.couponOrderStatus,
  220. data: res.data
  221. });
  222. that.setData({
  223. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  224. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  225. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  226. });
  227. if (that.data.data.validStartDate && that.data.data.validEndDate){
  228. that.setData({
  229. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  230. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss")
  231. })
  232. }
  233. })
  234. .catch(err => {
  235. wx.showToast({
  236. title: err.errMsg,
  237. icon: 'none',
  238. duration: 2000,
  239. mask: false
  240. });
  241. })
  242. },
  243. getHtml(couponChannelId) {
  244. Http.get({
  245. url: config.api.couponHtmlDetailForPkg,
  246. data: {
  247. // couponChannelId: '433119630735183872'
  248. couponOrderId: couponChannelId
  249. }
  250. }).then(res => {
  251. if (res.code == 200 && res.data.html) {
  252. this.setData({
  253. curHtml: decodeURI(res.data.html)
  254. })
  255. }
  256. })
  257. },
  258. upDataRq(){
  259. console.log(1123)
  260. },
  261. createQrCode: function (url, canvasId, cavW, cavH) {
  262. //调用插件中的draw方法,绘制二维码图片
  263. let that = this;
  264. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  265. that.setData({
  266. tempFilePath: res
  267. })
  268. });
  269. },
  270. phone: function (e) {
  271. let that = this;
  272. if (e.currentTarget.dataset.merchantlinkphone) {
  273. wx.makePhoneCall({
  274. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  275. });
  276. }
  277. }
  278. });