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.

866 line
24 KiB

  1. var config = require("../../../config/config.js");
  2. var app = getApp();
  3. const Http = require("../../../utils/HttpBasics");
  4. const util = require("../../../utils/util");
  5. const imgurl = require("../../../utils/imgurl");
  6. Page({
  7. data: {
  8. fenxiangUrl: imgurl.fenxiang.url,
  9. clockUrl: imgurl.clock.url,
  10. teljpgUrl: imgurl.teljpg.url,
  11. closedUrl: imgurl.closed.url,
  12. quesGouUrl: imgurl.ques_gou.url,
  13. headbgUrl: imgurl.headbg.url,
  14. quesBgUrl: imgurl.ques_bg.url,
  15. close02: imgurl.close02.url,
  16. share01: imgurl.share01.url,
  17. fail: imgurl.fail.url,
  18. share01: imgurl.share01.url,
  19. wmhome: imgurl.wmhome.url,
  20. hidden: "hidden",
  21. height: "",
  22. more: "点击查看更多",
  23. showMore: true,
  24. data: {
  25. title: null
  26. },
  27. showPage: false,
  28. questions1: null,
  29. questions2: null,
  30. carList: [],
  31. couponChannelId: null,
  32. orderId: "",
  33. hour: null,
  34. day: null,
  35. month: null,
  36. year: null,
  37. minute: "",
  38. tempFilePaths: null,
  39. userInfo: {},
  40. hasUserInfo: false,
  41. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  42. id: null,
  43. result: [],
  44. end_time: null,
  45. checked: false,
  46. questionnaire: {},
  47. questionId: null,
  48. widthScreen: null,
  49. moveData: null,
  50. rotateData: null,
  51. alphaData: null,
  52. scaleData: null,
  53. skewData: null,
  54. matrixData: null,
  55. opacity: 0,
  56. queueData: null,
  57. zIndex: 11,
  58. display: "none",
  59. showbutton: false,
  60. cardData: null,
  61. showCardOffer: false,
  62. isSamePeople: true,
  63. statusText: '',
  64. isReceived: false,
  65. receivedDisabled: false,
  66. clock: "结束",
  67. day: "00",
  68. hour: "00",
  69. min: "00",
  70. sec: "00",
  71. clock02: "00",
  72. day02: "00",
  73. hour02: "00",
  74. min02: "00",
  75. sec02: "00",
  76. countdown: "",
  77. showbutton1: false
  78. },
  79. /**
  80. * 跳转到门店列表的详情页面
  81. */
  82. gotoDetail(e) {
  83. wx.navigateTo({
  84. url: `/pages/index/detail/index?id=${e.currentTarget.dataset.id}`
  85. })
  86. },
  87. phone: function(e) {
  88. let that = this;
  89. wx.makePhoneCall({
  90. phoneNumber: e.target.dataset.merchantlinkphone
  91. });
  92. },
  93. // 点击查看更多
  94. more: function() {
  95. let that = this;
  96. if (that.data.more == '点击查看更多') {
  97. this.setData({
  98. hidden: "",
  99. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  100. more: "点击收起",
  101. showMore: true
  102. })
  103. } else {
  104. this.setData({
  105. hidden: "hidden",
  106. height: 4 * 140 + 'rpx',
  107. more: "点击查看更多",
  108. showMore: true
  109. })
  110. }
  111. },
  112. //获取当前登录用户信息
  113. getUserInfo: function() {
  114. let that = this;
  115. // 获取用户信息
  116. Http.get({
  117. url: config.api.getScore,
  118. data: {}
  119. })
  120. .then(res => {
  121. console.log(res)
  122. that.getQueryCardStatus()
  123. if (that.data.cardData.cuserId != res.data.id) {
  124. console.log(2222, 6666)
  125. that.setData({
  126. isSamePeople: false
  127. })
  128. }
  129. })
  130. },
  131. //获取卡转赠状态
  132. getQueryCardStatus() {
  133. let that = this;
  134. let param = {
  135. id: this.data.cardData.couponOrderId,
  136. cUserId: this.data.cardData.cuserId,
  137. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  138. }
  139. Http.get({
  140. url: config.api.queryCardStatus,
  141. data: param
  142. })
  143. .then(res => {
  144. console.log(res, 333333333333)
  145. })
  146. .catch(err => {
  147. that.setData({
  148. isReceived: true,
  149. statusText: err.message
  150. })
  151. })
  152. },
  153. receiveCard() {
  154. let that = this;
  155. let param = {
  156. id: this.data.cardData.couponOrderId,
  157. cUserId: this.data.cardData.cuserId,
  158. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  159. }
  160. this.setData({
  161. receivedDisabled: true
  162. })
  163. Http.post({
  164. url: config.api.cardAccept,
  165. data: param
  166. })
  167. .then(res => {
  168. wx.showToast({
  169. title: '领取成功!',
  170. icon: 'none',
  171. duration: 2000,
  172. mask: false
  173. });
  174. wx.reLaunch({
  175. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  176. })
  177. })
  178. .catch(err => {
  179. wx.showToast({
  180. title: err.message,
  181. icon: 'none',
  182. duration: 2000,
  183. mask: false
  184. });
  185. that.setData({
  186. receivedDisabled: false
  187. })
  188. })
  189. },
  190. closeAlert() {
  191. this.setData({
  192. showCardOffer: false
  193. })
  194. },
  195. goback: function() {
  196. wx.switchTab({
  197. url: '/pages/main/index',
  198. })
  199. },
  200. /**
  201. * 点击提交问题单选
  202. */
  203. formSubmit: function(e) {
  204. console.log(e);
  205. let that = this;
  206. /**
  207. * 多选
  208. */
  209. if (e.currentTarget.dataset.flags == 'multi') {
  210. if (that.data.anwserId.length == 0) {
  211. var answserIs = null
  212. } else {
  213. var answserIs = that.data.anwserId.join(",");
  214. }
  215. } else if (e.currentTarget.dataset.flags == 'single') {
  216. var answserIs = e.detail.value;
  217. }
  218. console.log(answserIs)
  219. console.log(e.currentTarget.dataset.questionid)
  220. Http.post({
  221. url: config.api.answerQuestion,
  222. data: {
  223. answer: answserIs,
  224. questionId: e.currentTarget.dataset.questionid
  225. }
  226. })
  227. .then(res => {
  228. that.closeQuestion();
  229. })
  230. .catch(err => {
  231. wx.showToast({
  232. title: err.message,
  233. icon: 'none',
  234. duration: 2000,
  235. mask: false
  236. });
  237. })
  238. },
  239. /**
  240. * 多选
  241. */
  242. checkboxChange: function(e) {
  243. console.log(e)
  244. this.setData({
  245. anwserId: e.detail.value
  246. })
  247. },
  248. closeQuestion: function() {
  249. let that = this;
  250. that.setData({
  251. display: "none",
  252. zIndex: 11,
  253. opacity: 0
  254. })
  255. setTimeout(function() {
  256. that.orderFunc();
  257. }, 500)
  258. },
  259. /**
  260. * gotopay
  261. */
  262. gotopay: function(e) {
  263. let that = this;
  264. console.log(e)
  265. let formId = e.detail.formId;
  266. var discount = e.currentTarget.dataset.discount;
  267. that.setData({
  268. queueData: null,
  269. showbutton: true,
  270. formId: formId
  271. })
  272. Http.get({
  273. url: config.api.getQuestion,
  274. data: {
  275. couponType: JSON.stringify(that.data.data.type)
  276. }
  277. })
  278. .then(res => {
  279. console.log(res);
  280. if (res.data == undefined) {
  281. that.orderFunc(discount);
  282. that.setData({
  283. flag: false
  284. })
  285. } else if (res.data) {
  286. var animation = wx.createAnimation({});
  287. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  288. duration: 500
  289. })
  290. that.setData({
  291. queueData: animation.export(),
  292. zIndex: 9,
  293. opacity: 1,
  294. display: "block",
  295. questionnaire: JSON.parse(res.data.content),
  296. questionId: res.data.id
  297. });
  298. }
  299. })
  300. .catch(err => {
  301. wx.showToast({
  302. title: err.message,
  303. icon: 'none',
  304. duration: 2000,
  305. mask: false
  306. });
  307. })
  308. },
  309. setIntervalTime(end_time) {
  310. let that = this;
  311. var EndTime = end_time;
  312. var NowTime = new Date().getTime();
  313. var total_micro_second = EndTime - NowTime || [];
  314. // 渲染倒计时时钟
  315. let obj = that.dateformat(total_micro_second);
  316. if (total_micro_second > 0) {
  317. that.setData({
  318. clock: obj,
  319. day: obj.a1,
  320. hour: obj.b1,
  321. min: obj.c1,
  322. sec: obj.d1,
  323. })
  324. } else {
  325. that.setData({
  326. clock: "00",
  327. day: "00",
  328. hour: "00",
  329. min: "00",
  330. sec: "00",
  331. })
  332. //如果倒计时结束,需要重新查询一下券的状态
  333. // 给getDetail一个标识
  334. that.getDetail(that.data.couponChannelId, 'endclock');
  335. }
  336. total_micro_second -= 1000;
  337. },
  338. countdown: function(end_time) {
  339. let that = this;
  340. that.setIntervalTime(end_time);
  341. that.data.setInterval = setInterval(function() {
  342. that.setIntervalTime(end_time);
  343. }, 1000)
  344. },
  345. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  346. dateformat(micro_second) {
  347. // 总秒数
  348. var second = Math.floor(micro_second / 1000);
  349. // 天数
  350. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  351. // 小时
  352. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  353. // 分钟
  354. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  355. // 秒
  356. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  357. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  358. return {
  359. a1: day,
  360. b1: hr,
  361. c1: min,
  362. d1: sec
  363. }
  364. },
  365. /**
  366. * 获取用户信息
  367. */
  368. onLoad(options) {
  369. let that = this;
  370. wx.showLoading({
  371. title: "加载中..."
  372. });
  373. that.setData({
  374. onshow: false
  375. })
  376. if (options && options.couponChannelId){
  377. that.getDetail(options.couponChannelId, 'notendclock');
  378. }
  379. /**
  380. * 转赠判断
  381. */
  382. if (options.cuserId) {
  383. this.setData({
  384. showCardOffer: true,
  385. cardData: options
  386. })
  387. this.getUserInfo()
  388. }
  389. that.setData({
  390. couponChannelId: options.couponChannelId,
  391. title: that.data.data.title ? that.data.data.title : '',
  392. });
  393. if (options.cardType) {
  394. that.setData({
  395. cardType: options.cardType
  396. })
  397. }
  398. },
  399. getDetail: function(couponChannelId, flag) {
  400. let that = this;
  401. var parmer = {
  402. url: config.api.couponDetail,
  403. data: {
  404. couponChannelId: couponChannelId
  405. }
  406. };
  407. Http.get(parmer)
  408. .then(res => {
  409. that.setData({
  410. couponId: res.data.couponId
  411. })
  412. if (res.code == 200) {
  413. that.setData({
  414. showPage: true
  415. })
  416. }
  417. /**
  418. * 将优惠券优惠卡的详情的BarTitle
  419. * 设置成券的名称
  420. */
  421. wx.setNavigationBarTitle({
  422. title: res.data.title
  423. })
  424. var EndTime = res.data.validStartDate;
  425. var NowTime = new Date().getTime();
  426. /**
  427. * activityStatus==0 活动未开始
  428. * activityStatus==1 活动已开始
  429. * flag == endclock 说明倒计时已经结束
  430. */
  431. if (res.data.endTime && res.data.beginTime) {
  432. that.setData({
  433. begin_time: res.data.beginTime,
  434. end_time: res.data.endTime,
  435. })
  436. if (res.data.activityStatus == 0 && flag != 'endclock') {
  437. that.countdown(res.data.beginTime);
  438. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  439. that.countdown(res.data.endTime);
  440. } else {
  441. clearInterval(that.data.setInterval)
  442. }
  443. if (res.data.activityStatus == 0) {
  444. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  445. if (util.timechuo(beginTime).indexOf('-') == 0) {
  446. that.setData({
  447. beginTime: "活动已结束",
  448. });
  449. } else {
  450. that.setData({
  451. beginTime: util.timechuo(beginTime)
  452. });
  453. }
  454. } else {
  455. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  456. if (util.timechuo(endTime).indexOf('-') == 0) {
  457. that.setData({
  458. endtime: "活动已结束",
  459. });
  460. } else {
  461. that.setData({
  462. endtime: util.timechuo(endTime)
  463. });
  464. }
  465. }
  466. }
  467. wx.hideLoading();
  468. that.setData({
  469. data: res.data
  470. });
  471. if (that.data.data.merchantVoList && that.data.data.merchantVoList.length <= 4) {
  472. that.setData({
  473. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  474. showMore: false
  475. })
  476. } else if (that.data.data.merchantVoList && that.data.data.merchantVoList.length > 4) {
  477. that.setData({
  478. height: 4 * 140 + 'rpx'
  479. })
  480. }
  481. if (res.data.validType == 1) {
  482. that.setData({
  483. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  484. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  485. });
  486. } else {
  487. if (res.data.validDays) {
  488. that.setData({
  489. validDays: res.data.validDays
  490. });
  491. }
  492. }
  493. }).catch(err => {
  494. wx.showToast({
  495. title: err.message,
  496. icon: 'none',
  497. duration: 2000,
  498. mask: false
  499. });
  500. })
  501. },
  502. /**
  503. * 邀请好友继续砍价
  504. */
  505. inviteFriend: function() {
  506. let that = this;
  507. that.orderFunc("discount");
  508. that.setData({
  509. showbutton1: true
  510. })
  511. },
  512. /**
  513. * 支付订单更新
  514. */
  515. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  516. let that = this;
  517. // 支付成功
  518. Http.post({
  519. url: config.api.payOrderUpdate,
  520. data: {
  521. payOrderId: payOrderId,
  522. orderId: orderId,
  523. status: status,
  524. reason: reason
  525. }
  526. })
  527. .then(res => {
  528. wx.hideLoading()
  529. // 有价券
  530. if (!type && type != 'free') {
  531. wx.navigateTo({
  532. url: `/pages/order/detail/index?orderId=${
  533. orderId
  534. }&cardIf=true`
  535. });
  536. } else if (type == 'free') {
  537. wx.navigateTo({
  538. url: `/pages/order/detail/index?orderId=${
  539. orderId
  540. }`
  541. });
  542. }
  543. })
  544. .catch(err => {
  545. console.log(err);
  546. if (!type) {
  547. setTimeout(function() {
  548. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  549. }, 2000)
  550. }
  551. })
  552. },
  553. checkPhoneStatus: function() {
  554. let that = this;
  555. Http.get({
  556. url: config.api.checkPhoneStatus,
  557. data: {}
  558. })
  559. .then(res => {
  560. console.log(666, '授权成功!')
  561. that.receiveCard()
  562. })
  563. .catch(err => {
  564. if (err.code == 11005) {
  565. /**
  566. * 手机号没有授权,将值传到用户手机号授权的页面
  567. *
  568. */
  569. wx.redirectTo({
  570. url: "/pages/getphoneInfo/index?path=index&cuserId=" + that.data.cardData.cuserId + "&couponChannelId=" + that.data.cardData.couponChannelId + "&userName=" + that.data.cardData.userName + "&coverImg=" + that.data.cardData.coverImg + "&avatarUrl=" + that.data.cardData.avatarUrl + "&couponOrderId=" + that.data.cardData.couponOrderId + "&updateDate=" + that.data.cardData.updateDate,
  571. });
  572. } else if (err.code == 11006) {
  573. // 用户手机已加密
  574. wx.redirectTo({
  575. url: "/pages/phoneinput/phoneinput?path=index&cuserId=" + that.data.cardData.cuserId + "&couponChannelId=" + that.data.cardData.couponChannelId + "&userName=" + that.data.cardData.userName + "&coverImg=" + that.data.cardData.coverImg + "&avatarUrl=" + that.data.cardData.avatarUrl + "&couponOrderId=" + that.data.cardData.couponOrderId + "&updateDate=" + that.data.cardData.updateDate,
  576. });
  577. } else {
  578. wx.showToast({
  579. title: err.message,
  580. icon: 'none',
  581. duration: 2000,
  582. mask: false
  583. });
  584. }
  585. })
  586. },
  587. /**
  588. * 发起支付
  589. */
  590. orderFunc(discount) {
  591. let that = this;
  592. Http.get({
  593. url: config.api.checkPhoneStatus,
  594. data: {}
  595. })
  596. .then(res => {
  597. if (discount == 'discount') {
  598. var data = {
  599. couponChannelId: "" + that.data.couponChannelId,
  600. couponId: "" + that.data.couponId,
  601. formId: "" + that.data.formId,
  602. press: true
  603. }
  604. } else if (discount == 'discount1') {
  605. var data = {
  606. couponChannelId: "" + that.data.couponChannelId,
  607. couponId: "" + that.data.couponId,
  608. formId: "" + that.data.formId,
  609. press: false
  610. }
  611. } else if (that.data.couponChannelId == null) {
  612. var data = {
  613. couponId: "" + that.data.couponId,
  614. formId: "" + that.data.formId,
  615. };
  616. } else {
  617. var data = {
  618. couponChannelId: "" + that.data.couponChannelId,
  619. couponId: "" + that.data.couponId,
  620. formId: "" + that.data.formId,
  621. }
  622. }
  623. /**
  624. * orderSave 下单
  625. */
  626. return Http.post({
  627. url: config.api.orderSave,
  628. data: data
  629. });
  630. })
  631. .catch(err => {
  632. console.log(err);
  633. that.setData({
  634. showbutton: false,
  635. showbutton1: false
  636. })
  637. if (err.code == 2011) {
  638. wx.showToast({
  639. title: "商户信息没找到",
  640. image: './../../../assets/images/fail.png',
  641. duration: 2000,
  642. mask: false
  643. });
  644. } else if (err.code == 2013) {
  645. wx.showToast({
  646. title: "商户信息禁用",
  647. image: './../../../assets/images/fail.png',
  648. duration: 2000,
  649. mask: false
  650. });
  651. } else if (err.code == 3000) {
  652. wx.showToast({
  653. title: "库存不足",
  654. image: './../../../assets/images/fail.png',
  655. duration: 2000,
  656. mask: false
  657. });
  658. } else if (err.code == 3001) {
  659. wx.showToast({
  660. title: "超过限购条件",
  661. image: './../../../assets/images/fail.png',
  662. duration: 2000,
  663. mask: false
  664. });
  665. } else if (err.code == 3002) {
  666. wx.showToast({
  667. title: "订单失败",
  668. image: './../../../assets/images/fail.png',
  669. duration: 2000,
  670. mask: false
  671. });
  672. } else if (err.code == 3003) {
  673. wx.showToast({
  674. title: "订单不存在",
  675. image: './../../../assets/images/fail.png',
  676. duration: 2000,
  677. mask: false
  678. });
  679. } else if (err.code == 3004) {
  680. wx.showToast({
  681. title: "订单不存在",
  682. image: './../../../assets/images/fail.png',
  683. duration: 2000,
  684. mask: false
  685. });
  686. } else if (err.code == 4003) {
  687. wx.showToast({
  688. title: "卡券已作废",
  689. image: './../../../assets/images/fail.png',
  690. duration: 2000,
  691. mask: false
  692. });
  693. } else if (err.code == 11005) {
  694. /**
  695. * 将值传到用户手机号授权的页面
  696. *
  697. */
  698. wx.redirectTo({
  699. url: "/pages/getphoneInfo/index?couponChannelId=" +
  700. that.data.couponChannelId
  701. });
  702. } else if (err.code == 11006) {
  703. // 用户手机已加密
  704. wx.redirectTo({
  705. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  706. that.data.couponChannelId
  707. });
  708. } else {
  709. wx.showToast({
  710. title: err.message,
  711. icon: 'none',
  712. duration: 2000,
  713. mask: false
  714. });
  715. }
  716. })
  717. .then(res => {
  718. if (discount != 'discount') {
  719. if (typeof(res) != "undefined") {
  720. let orderId = "" + res.data.id;
  721. that.setData({
  722. orderId: orderId
  723. });
  724. if (res.data.payment > 0) {
  725. // 支付金额不为0
  726. /**
  727. * 支付订单创建
  728. */
  729. Http.post({
  730. url: config.api.payOrderCreate,
  731. data: {
  732. orderId: orderId
  733. }
  734. })
  735. .then(res => {
  736. var payOrderId = "" + res.data.payOrderId;
  737. wx.hideLoading();
  738. wx.requestPayment({
  739. timeStamp: res.data.timeStamp,
  740. nonceStr: res.data.nonceStr,
  741. package: res.data.package,
  742. signType: (res.data.signType) ? res.data.signType : "MD5",
  743. paySign: res.data.paySign,
  744. success: res => {
  745. wx.showLoading({
  746. title: '订单正在处理中...',
  747. })
  748. setTimeout(function() {
  749. wx.hideLoading()
  750. }, 5000)
  751. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  752. if (res.errMsg == "requestPayment:ok") {
  753. setTimeout(function() {
  754. wx.hideLoading();
  755. }, 2000);
  756. /**
  757. * 用户支付成功以后跳转到券包列表
  758. */
  759. if (that.data.cardType == 100) {
  760. wx.setStorage({
  761. key: 'couponNum2',
  762. data: "couponNum2"
  763. })
  764. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  765. wx.setStorage({
  766. key: 'couponNum',
  767. data: "couponNum"
  768. })
  769. }
  770. }
  771. },
  772. fail: res => {
  773. /**
  774. * 支付失败,需要更新订单的状态
  775. */
  776. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  777. that.setData({
  778. showbutton: false
  779. })
  780. return;
  781. },
  782. complete: res => {}
  783. });
  784. /// End payment --------
  785. })
  786. .catch(err => {
  787. wx.showToast({
  788. title: err.message,
  789. icon: 'none',
  790. duration: 2000,
  791. mask: false
  792. });
  793. })
  794. } else {
  795. // 免费券
  796. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  797. if (that.data.cardType == 100) {
  798. wx.setStorage({
  799. key: 'couponNum2',
  800. data: "couponNum2"
  801. })
  802. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  803. wx.setStorage({
  804. key: 'couponNum',
  805. data: "couponNum"
  806. })
  807. }
  808. }
  809. }
  810. } else {
  811. if (res) {
  812. wx.navigateTo({
  813. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  814. })
  815. }
  816. }
  817. })
  818. },
  819. onShow() {
  820. this.setData({
  821. showbutton: false,
  822. showbutton1: false
  823. })
  824. if (this.data.end_time) {
  825. this.countdown(this.data.end_time)
  826. }
  827. },
  828. onUnload: function() {
  829. let that = this;
  830. clearInterval(that.data.setInterval)
  831. },
  832. onHide: function() {
  833. let that = this;
  834. clearInterval(that.data.setInterval)
  835. },
  836. onShareAppMessage: function(options) {
  837. var that = this;
  838. var shareObj = {
  839. title: that.data.data.title,
  840. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  841. success: function(res) {
  842. if (res.errMsg == 'shareAppMessage:ok') {}
  843. },
  844. fail: function(error) {
  845. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  846. }
  847. };
  848. // 来自页面内的按钮的转发
  849. if (options.from == 'button') {
  850. var eData = options.target.dataset.id;
  851. shareObj.path = `/pages/index/index?couponChannelId=${eData}`;
  852. }
  853. // 返回shareObj
  854. return shareObj;
  855. },
  856. // 下拉刷新
  857. onPullDownRefresh: function() {
  858. this.getDetail(this.data.couponChannelId);
  859. wx.stopPullDownRefresh()
  860. }
  861. });