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

index.js 9.1 KiB

6 년 전
2 년 전
4 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
1 년 전
2 년 전
2 년 전
4 년 전
4 년 전
2 년 전
4 년 전
2 년 전
1 년 전
1 년 전
2 년 전
2 년 전
2 년 전
2 년 전
2 년 전
4 년 전
2 년 전
4 년 전
2 년 전
2 년 전
6 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. mallList: []
  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. console.log(options, 'options');
  171. let that = this;
  172. that.setData({
  173. code: options.quancode,
  174. codeS: options.quancode.slice(0, 4) + `******` + options.quancode.slice(14),
  175. couponorderstatus: options.couponorderstatus
  176. });
  177. if (
  178. options.quancode &&
  179. that.data.couponorderstatus == 0
  180. ) {
  181. //aaa
  182. that.setRq()//动态二维码 //这个方法必须在拿到 options.quancode 后调用
  183. that.getHtml(options.quancode);
  184. // Http.get({
  185. // url: config.api.couponMerchant,
  186. // data: {
  187. // couponChannelId: options.quancode
  188. // }
  189. // }).then(res => {
  190. // const keys = Object.keys(res.data)
  191. // const mallList = []
  192. // keys.forEach(item => {
  193. // const arr = item.split('|')
  194. // const obj = {
  195. // tenantId: arr[0],
  196. // mallName: arr[1],
  197. // merchantVoList: res.data[item],
  198. // expand: true
  199. // }
  200. // mallList.push(obj)
  201. // })
  202. // this.setData({
  203. // mallList: mallList
  204. // })
  205. // console.log(this.data.mallList, 'mallList');
  206. // })
  207. }
  208. //获得优惠券的详情
  209. that.data.setInter = setInterval(function () {
  210. if (
  211. options.quancode &&
  212. that.data.couponorderstatus == 0
  213. ) {
  214. Http.get({
  215. url: config.api.couponOrderDetail,
  216. data: {
  217. couponOrderId: options.quancode
  218. }
  219. }).then(res => {
  220. that.setData({
  221. couponorderstatus: res.data.couponOrderStatus,
  222. data: res.data,
  223. });
  224. if (res.data.couponOrderStatus == 1) {
  225. /**
  226. * 动态改变上一级页面的核销状态
  227. */
  228. that.getStaticGame()
  229. var pages = getCurrentPages();
  230. var prevPage = pages[pages.length - 2]; //上一个页面
  231. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  232. prevPage.setData({
  233. mystatus: res.data.couponOrderStatus
  234. });
  235. }
  236. that.setData({
  237. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  238. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  239. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  240. });
  241. if (that.data.data.soldStartTime && that.data.data.soldEndTime) {
  242. that.setData({
  243. soldStartTime: util.formatTime(that.data.data.soldStartTime, "yyyy-MM-dd hh:mm:ss"),
  244. soldEndTime: util.formatTime(that.data.data.soldEndTime, "yyyy-MM-dd hh:mm:ss"),
  245. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  246. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd hh:mm:ss"),
  247. })
  248. }
  249. })
  250. .catch(err => {
  251. wx.showToast({
  252. title: err.errMsg,
  253. icon: 'none',
  254. duration: 2000,
  255. mask: false
  256. });
  257. })
  258. }
  259. }, 2000);
  260. /**
  261. * 页面需要初始渲染的效果
  262. */
  263. Http.get({
  264. url: config.api.couponOrderDetail,
  265. data: {
  266. couponOrderId: options.quancode
  267. }
  268. }).then(res => {
  269. that.setData({
  270. couponorderstatus: res.data.couponOrderStatus,
  271. data: res.data
  272. });
  273. that.setData({
  274. expiredTime: util.formatTime(that.data.data.expiredTime, "yyyy-MM-dd hh:mm:ss"),
  275. updateDate: util.formatTime(that.data.data.updateDate, "yyyy-MM-dd hh:mm:ss"),
  276. createDate: util.formatTime(that.data.data.createDate, "yyyy-MM-dd hh:mm:ss")
  277. });
  278. if (that.data.data.validStartDate && that.data.data.validEndDate) {
  279. that.setData({
  280. validStartDate: util.formatTime(that.data.data.validStartDate, "yyyy-MM-dd hh:mm:ss"),
  281. validEndDate: util.formatTime(that.data.data.validEndDate, "yyyy-MM-dd hh:mm:ss")
  282. })
  283. }
  284. })
  285. .catch(err => {
  286. wx.showToast({
  287. title: err.errMsg,
  288. icon: 'none',
  289. duration: 2000,
  290. mask: false
  291. });
  292. })
  293. },
  294. getHtml(couponChannelId) {
  295. Http.get({
  296. url: config.api.couponHtmlDetailForPkg,
  297. data: {
  298. // couponChannelId: '433119630735183872'
  299. couponOrderId: couponChannelId
  300. }
  301. }).then(res => {
  302. if (res.code == 200 && res.data.html) {
  303. this.setData({
  304. curHtml: decodeURI(res.data.html),
  305. })
  306. }
  307. })
  308. },
  309. upDataRq() {
  310. console.log(1123)
  311. },
  312. createQrCode: function (url, canvasId, cavW, cavH) {
  313. //调用插件中的draw方法,绘制二维码图片
  314. let that = this;
  315. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  316. that.setData({
  317. tempFilePath: res
  318. })
  319. });
  320. },
  321. phone: function (e) {
  322. let that = this;
  323. if (e.currentTarget.dataset.merchantlinkphone) {
  324. wx.makePhoneCall({
  325. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  326. });
  327. }
  328. }
  329. });