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

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