C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

862 行
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. that.getDetail(options.couponChannelId, 'notendclock');
  377. /**
  378. * 转赠判断
  379. */
  380. if (options.cuserId) {
  381. this.setData({
  382. showCardOffer: true,
  383. cardData: options
  384. })
  385. this.getUserInfo()
  386. }
  387. that.setData({
  388. couponChannelId: options.couponChannelId,
  389. title: that.data.data.title ? that.data.data.title : '',
  390. });
  391. if (options.cardType) {
  392. that.setData({
  393. cardType: options.cardType
  394. })
  395. }
  396. },
  397. getDetail: function(couponChannelId, flag) {
  398. let that = this;
  399. var parmer = {
  400. url: config.api.couponDetail,
  401. data: {
  402. couponChannelId: couponChannelId
  403. }
  404. };
  405. Http.get(parmer)
  406. .then(res => {
  407. that.setData({
  408. couponId: res.data.couponId
  409. })
  410. if (res.code == 200) {
  411. that.setData({
  412. showPage: true
  413. })
  414. }
  415. if (res.data.type == 100) {
  416. wx.setNavigationBarTitle({
  417. title: "卡详情"
  418. })
  419. }
  420. var EndTime = res.data.validStartDate;
  421. var NowTime = new Date().getTime();
  422. console.log(flag);
  423. if (res.data.endTime && res.data.beginTime) {
  424. that.setData({
  425. begin_time: res.data.beginTime,
  426. end_time: res.data.endTime,
  427. })
  428. //activityStatus==0 活动未开始
  429. //activityStatus==1 活动已开始
  430. // flag == endclock 说明倒计时已经结束
  431. if (res.data.activityStatus == 0 && flag != 'endclock') {
  432. that.countdown(res.data.beginTime);
  433. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  434. that.countdown(res.data.endTime);
  435. } else {
  436. clearInterval(that.data.setInterval)
  437. }
  438. if (res.data.activityStatus == 0) {
  439. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  440. if (util.timechuo(beginTime).indexOf('-') == 0) {
  441. that.setData({
  442. beginTime: "活动已结束",
  443. });
  444. } else {
  445. that.setData({
  446. beginTime: util.timechuo(beginTime)
  447. });
  448. }
  449. } else {
  450. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  451. if (util.timechuo(endTime).indexOf('-') == 0) {
  452. that.setData({
  453. endtime: "活动已结束",
  454. });
  455. } else {
  456. that.setData({
  457. endtime: util.timechuo(endTime)
  458. });
  459. }
  460. }
  461. }
  462. wx.hideLoading();
  463. that.setData({
  464. data: res.data
  465. });
  466. if (that.data.data.merchantVoList && that.data.data.merchantVoList.length <= 4) {
  467. that.setData({
  468. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  469. showMore: false
  470. })
  471. } else if (that.data.data.merchantVoList && that.data.data.merchantVoList.length > 4) {
  472. that.setData({
  473. height: 4 * 140 + 'rpx'
  474. })
  475. }
  476. if (res.data.validType == 1) {
  477. that.setData({
  478. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  479. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  480. });
  481. } else {
  482. if (res.data.validDays) {
  483. that.setData({
  484. validDays: res.data.validDays
  485. });
  486. }
  487. }
  488. }).catch(err => {
  489. wx.showToast({
  490. title: err.message,
  491. icon: 'none',
  492. duration: 2000,
  493. mask: false
  494. });
  495. })
  496. },
  497. /**
  498. * 邀请好友继续砍价
  499. */
  500. inviteFriend: function() {
  501. let that = this;
  502. that.orderFunc("discount");
  503. that.setData({
  504. showbutton1: true
  505. })
  506. },
  507. /**
  508. * 支付订单更新
  509. */
  510. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  511. let that = this;
  512. // 支付成功
  513. Http.post({
  514. url: config.api.payOrderUpdate,
  515. data: {
  516. payOrderId: payOrderId,
  517. orderId: orderId,
  518. status: status,
  519. reason: reason
  520. }
  521. })
  522. .then(res => {
  523. wx.hideLoading()
  524. // 有价券
  525. if (!type && type != 'free') {
  526. wx.navigateTo({
  527. url: `/pages/order/detail/index?orderId=${
  528. orderId
  529. }&cardIf=true`
  530. });
  531. } else if (type == 'free') {
  532. wx.navigateTo({
  533. url: `/pages/order/detail/index?orderId=${
  534. orderId
  535. }`
  536. });
  537. }
  538. })
  539. .catch(err => {
  540. console.log(err);
  541. if (!type) {
  542. setTimeout(function() {
  543. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  544. }, 2000)
  545. }
  546. })
  547. },
  548. checkPhoneStatus: function() {
  549. let that = this;
  550. Http.get({
  551. url: config.api.checkPhoneStatus,
  552. data: {}
  553. })
  554. .then(res => {
  555. console.log(666, '授权成功!')
  556. that.receiveCard()
  557. })
  558. .catch(err => {
  559. if (err.code == 11005) {
  560. // 用户手机未授权
  561. /**
  562. * 将值传到用户手机号授权的页面
  563. *
  564. */
  565. wx.redirectTo({
  566. 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,
  567. });
  568. } else if (err.code == 11006) {
  569. // 用户手机已加密
  570. wx.redirectTo({
  571. 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,
  572. });
  573. } else {
  574. wx.showToast({
  575. title: err.message,
  576. icon: 'none',
  577. duration: 2000,
  578. mask: false
  579. });
  580. }
  581. })
  582. },
  583. /**
  584. * 发起支付
  585. */
  586. orderFunc(discount) {
  587. console.log(discount)
  588. var that = this;
  589. Http.get({
  590. url: config.api.checkPhoneStatus,
  591. data: {}
  592. })
  593. .then(res => {
  594. if (discount == 'discount') {
  595. var data = {
  596. couponChannelId: "" + that.data.couponChannelId,
  597. couponId: "" + that.data.couponId,
  598. formId: "" + that.data.formId,
  599. press: true
  600. }
  601. } else if (discount == 'discount1') {
  602. var data = {
  603. couponChannelId: "" + that.data.couponChannelId,
  604. couponId: "" + that.data.couponId,
  605. formId: "" + that.data.formId,
  606. press: false
  607. }
  608. } else if (that.data.couponChannelId == null) {
  609. var data = {
  610. couponId: "" + that.data.couponId,
  611. formId: "" + that.data.formId,
  612. };
  613. } else {
  614. var data = {
  615. couponChannelId: "" + that.data.couponChannelId,
  616. couponId: "" + that.data.couponId,
  617. formId: "" + that.data.formId,
  618. }
  619. }
  620. /**
  621. * orderSave 下单
  622. */
  623. return Http.post({
  624. url: config.api.orderSave,
  625. data: data
  626. });
  627. })
  628. .catch(err => {
  629. console.log(err);
  630. that.setData({
  631. showbutton: false,
  632. showbutton1: false
  633. })
  634. if (err.code == 2011) {
  635. wx.showToast({
  636. title: "商户信息没找到",
  637. image: './../../../assets/images/fail.png',
  638. duration: 2000,
  639. mask: false
  640. });
  641. } else if (err.code == 2013) {
  642. wx.showToast({
  643. title: "商户信息禁用",
  644. image: './../../../assets/images/fail.png',
  645. duration: 2000,
  646. mask: false
  647. });
  648. } else if (err.code == 3000) {
  649. wx.showToast({
  650. title: "库存不足",
  651. image: './../../../assets/images/fail.png',
  652. duration: 2000,
  653. mask: false
  654. });
  655. } else if (err.code == 3001) {
  656. wx.showToast({
  657. title: "超过限购条件",
  658. image: './../../../assets/images/fail.png',
  659. duration: 2000,
  660. mask: false
  661. });
  662. } else if (err.code == 3002) {
  663. wx.showToast({
  664. title: "订单失败",
  665. image: './../../../assets/images/fail.png',
  666. duration: 2000,
  667. mask: false
  668. });
  669. } else if (err.code == 3003) {
  670. wx.showToast({
  671. title: "订单不存在",
  672. image: './../../../assets/images/fail.png',
  673. duration: 2000,
  674. mask: false
  675. });
  676. } else if (err.code == 3004) {
  677. wx.showToast({
  678. title: "订单不存在",
  679. image: './../../../assets/images/fail.png',
  680. duration: 2000,
  681. mask: false
  682. });
  683. } else if (err.code == 4003) {
  684. wx.showToast({
  685. title: "卡券已作废",
  686. image: './../../../assets/images/fail.png',
  687. duration: 2000,
  688. mask: false
  689. });
  690. } else if (err.code == 11005) {
  691. /**
  692. * 将值传到用户手机号授权的页面
  693. *
  694. */
  695. wx.redirectTo({
  696. url: "/pages/getphoneInfo/index?couponChannelId=" +
  697. that.data.couponChannelId
  698. });
  699. } else if (err.code == 11006) {
  700. // 用户手机已加密
  701. wx.redirectTo({
  702. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  703. that.data.couponChannelId
  704. });
  705. } else {
  706. wx.showToast({
  707. title: err.message,
  708. icon: 'none',
  709. duration: 2000,
  710. mask: false
  711. });
  712. }
  713. })
  714. .then(res => {
  715. console.log(res)
  716. if (discount != 'discount') {
  717. if (typeof(res) != "undefined") {
  718. let orderId = "" + res.data.id;
  719. that.setData({
  720. orderId: orderId
  721. });
  722. if (res.data.payment > 0) {
  723. // 支付金额不为0
  724. /**
  725. * 支付订单创建
  726. */
  727. Http.post({
  728. url: config.api.payOrderCreate,
  729. data: {
  730. orderId: orderId
  731. }
  732. })
  733. .then(res => {
  734. var payOrderId = "" + res.data.payOrderId;
  735. wx.hideLoading();
  736. wx.requestPayment({
  737. timeStamp: res.data.timeStamp,
  738. nonceStr: res.data.nonceStr,
  739. package: res.data.package,
  740. signType: (res.data.signType) ? res.data.signType : "MD5",
  741. paySign: res.data.paySign,
  742. success: res => {
  743. wx.showLoading({
  744. title: '订单正在处理中...',
  745. })
  746. setTimeout(function() {
  747. wx.hideLoading()
  748. }, 5000)
  749. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  750. if (res.errMsg == "requestPayment:ok") {
  751. setTimeout(function() {
  752. wx.hideLoading();
  753. }, 2000);
  754. /**
  755. * 用户支付成功以后跳转到券包列表
  756. */
  757. if (that.data.cardType == 100) {
  758. wx.setStorage({
  759. key: 'couponNum2',
  760. data: "couponNum2"
  761. })
  762. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  763. wx.setStorage({
  764. key: 'couponNum',
  765. data: "couponNum"
  766. })
  767. }
  768. }
  769. },
  770. fail: res => {
  771. /**
  772. * 支付失败,需要更新订单的状态
  773. */
  774. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  775. that.setData({
  776. showbutton: false
  777. })
  778. return;
  779. },
  780. complete: res => {}
  781. });
  782. /// End payment --------
  783. })
  784. .catch(err => {
  785. wx.showToast({
  786. title: err.message,
  787. icon: 'none',
  788. duration: 2000,
  789. mask: false
  790. });
  791. })
  792. } else {
  793. // 免费券
  794. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  795. if (that.data.cardType == 100) {
  796. wx.setStorage({
  797. key: 'couponNum2',
  798. data: "couponNum2"
  799. })
  800. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  801. wx.setStorage({
  802. key: 'couponNum',
  803. data: "couponNum"
  804. })
  805. }
  806. }
  807. }
  808. } else {
  809. if (res) {
  810. wx.navigateTo({
  811. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  812. })
  813. }
  814. }
  815. })
  816. },
  817. onShow() {
  818. this.setData({
  819. showbutton: false,
  820. showbutton1: false
  821. })
  822. if (this.data.end_time) {
  823. this.countdown(this.data.end_time)
  824. }
  825. },
  826. onUnload: function() {
  827. let that = this;
  828. clearInterval(that.data.setInterval)
  829. },
  830. onHide: function() {
  831. let that = this;
  832. clearInterval(that.data.setInterval)
  833. },
  834. onShareAppMessage: function(options) {
  835. var that = this;
  836. var shareObj = {
  837. title: that.data.data.title,
  838. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  839. success: function(res) {
  840. if (res.errMsg == 'shareAppMessage:ok') {}
  841. },
  842. fail: function(error) {
  843. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  844. }
  845. };
  846. // 来自页面内的按钮的转发
  847. if (options.from == 'button') {
  848. var eData = options.target.dataset.id;
  849. shareObj.path = `/pages/index/index?couponChannelId=${eData}`;
  850. }
  851. // 返回shareObj
  852. return shareObj;
  853. },
  854. // 下拉刷新
  855. onPullDownRefresh: function() {
  856. this.getDetail(this.data.couponChannelId);
  857. wx.stopPullDownRefresh()
  858. }
  859. });