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.

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