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.

875 rivejä
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. gotopay: function(e) {
  260. let that = this;
  261. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50){
  262. wx.navigateTo({
  263. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  264. })
  265. }else{
  266. let formId = e.detail.formId;
  267. var discount = e.currentTarget.dataset.discount;
  268. that.setData({
  269. queueData: null,
  270. showbutton: true,
  271. formId: formId
  272. })
  273. Http.get({
  274. url: config.api.getQuestion,
  275. data: {
  276. couponType: JSON.stringify(that.data.data.type)
  277. }
  278. })
  279. .then(res => {
  280. console.log(res);
  281. if (res.data == undefined) {
  282. that.orderFunc(discount);
  283. that.setData({
  284. flag: false
  285. })
  286. } else if (res.data) {
  287. var animation = wx.createAnimation({});
  288. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  289. duration: 500
  290. })
  291. that.setData({
  292. queueData: animation.export(),
  293. zIndex: 9,
  294. opacity: 1,
  295. display: "block",
  296. questionnaire: JSON.parse(res.data.content),
  297. questionId: res.data.id
  298. });
  299. }
  300. })
  301. .catch(err => {
  302. wx.showToast({
  303. title: err.message,
  304. icon: 'none',
  305. duration: 2000,
  306. mask: false
  307. });
  308. })
  309. }
  310. },
  311. setIntervalTime(end_time) {
  312. let that = this;
  313. var EndTime = end_time;
  314. var NowTime = new Date().getTime();
  315. var total_micro_second = EndTime - NowTime || [];
  316. // 渲染倒计时时钟
  317. let obj = that.dateformat(total_micro_second);
  318. if (total_micro_second > 0) {
  319. that.setData({
  320. clock: obj,
  321. day: obj.a1,
  322. hour: obj.b1,
  323. min: obj.c1,
  324. sec: obj.d1,
  325. })
  326. } else {
  327. that.setData({
  328. clock: "00",
  329. day: "00",
  330. hour: "00",
  331. min: "00",
  332. sec: "00",
  333. })
  334. //如果倒计时结束,需要重新查询一下券的状态
  335. // 给getDetail一个标识
  336. that.getDetail(that.data.couponChannelId, 'endclock');
  337. }
  338. total_micro_second -= 1000;
  339. },
  340. countdown: function(end_time) {
  341. let that = this;
  342. that.setIntervalTime(end_time);
  343. that.data.setInterval = setInterval(function() {
  344. that.setIntervalTime(end_time);
  345. }, 1000)
  346. },
  347. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  348. dateformat(micro_second) {
  349. // 总秒数
  350. var second = Math.floor(micro_second / 1000);
  351. // 天数
  352. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  353. // 小时
  354. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  355. // 分钟
  356. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  357. // 秒
  358. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  359. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  360. return {
  361. a1: day,
  362. b1: hr,
  363. c1: min,
  364. d1: sec
  365. }
  366. },
  367. /**
  368. * 获取用户信息
  369. */
  370. onLoad(options) {
  371. let that = this;
  372. wx.showLoading({
  373. title: "加载中..."
  374. });
  375. that.setData({
  376. onshow: false
  377. })
  378. if (options && options.couponChannelId){
  379. that.getDetail(options.couponChannelId, 'notendclock');
  380. }
  381. /**
  382. * 转赠判断
  383. */
  384. if (options.cuserId) {
  385. this.setData({
  386. showCardOffer: true,
  387. cardData: options
  388. })
  389. this.getUserInfo()
  390. }
  391. that.setData({
  392. couponChannelId: options.couponChannelId,
  393. title: that.data.data.title ? that.data.data.title : '',
  394. });
  395. if (options.cardType) {
  396. that.setData({
  397. cardType: options.cardType
  398. })
  399. }
  400. },
  401. getDetail: function(couponChannelId, flag) {
  402. let that = this;
  403. var parmer = {
  404. url: config.api.couponDetail,
  405. data: {
  406. couponChannelId: couponChannelId
  407. }
  408. };
  409. Http.get(parmer)
  410. .then(res => {
  411. that.setData({
  412. couponId: res.data.couponId
  413. })
  414. if (res.code == 200) {
  415. that.setData({
  416. showPage: true
  417. })
  418. }
  419. /**
  420. * 将优惠券优惠卡的详情的BarTitle
  421. * 设置成券的名称
  422. */
  423. wx.setNavigationBarTitle({
  424. title: res.data.title
  425. })
  426. var EndTime = res.data.validStartDate;
  427. var NowTime = new Date().getTime();
  428. /**
  429. * activityStatus==0 活动未开始
  430. * activityStatus==1 活动已开始
  431. * flag == endclock 说明倒计时已经结束
  432. */
  433. if (res.data.endTime && res.data.beginTime) {
  434. that.setData({
  435. begin_time: res.data.beginTime,
  436. end_time: res.data.endTime,
  437. })
  438. if (res.data.activityStatus == 0 && flag != 'endclock') {
  439. that.countdown(res.data.beginTime);
  440. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  441. that.countdown(res.data.endTime);
  442. } else {
  443. clearInterval(that.data.setInterval)
  444. }
  445. if (res.data.activityStatus == 0) {
  446. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  447. if (util.timechuo(beginTime).indexOf('-') == 0) {
  448. that.setData({
  449. beginTime: "活动已结束",
  450. });
  451. } else {
  452. that.setData({
  453. beginTime: util.timechuo(beginTime)
  454. });
  455. }
  456. } else {
  457. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  458. if (util.timechuo(endTime).indexOf('-') == 0) {
  459. that.setData({
  460. endtime: "活动已结束",
  461. });
  462. } else {
  463. that.setData({
  464. endtime: util.timechuo(endTime)
  465. });
  466. }
  467. }
  468. }
  469. wx.hideLoading();
  470. that.setData({
  471. data: res.data
  472. });
  473. if (that.data.data.merchantVoList && that.data.data.merchantVoList.length <= 4) {
  474. that.setData({
  475. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  476. showMore: false
  477. })
  478. } else if (that.data.data.merchantVoList && that.data.data.merchantVoList.length > 4) {
  479. that.setData({
  480. height: 4 * 140 + 'rpx'
  481. })
  482. }
  483. if (res.data.validType == 1) {
  484. that.setData({
  485. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  486. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  487. });
  488. } else {
  489. if (res.data.validDays) {
  490. that.setData({
  491. validDays: res.data.validDays
  492. });
  493. }
  494. }
  495. }).catch(err => {
  496. wx.showToast({
  497. title: err.message,
  498. icon: 'none',
  499. duration: 2000,
  500. mask: false
  501. });
  502. })
  503. },
  504. /**
  505. * 邀请好友继续砍价
  506. */
  507. inviteFriend: function() {
  508. let that = this;
  509. that.orderFunc("discount");
  510. that.setData({
  511. showbutton1: true
  512. })
  513. },
  514. /**
  515. * 支付订单更新
  516. */
  517. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  518. let that = this;
  519. // 支付成功
  520. Http.post({
  521. url: config.api.payOrderUpdate,
  522. data: {
  523. payOrderId: payOrderId,
  524. orderId: orderId,
  525. status: status,
  526. reason: reason
  527. }
  528. })
  529. .then(res => {
  530. wx.hideLoading()
  531. // 有价券
  532. if (!type && type != 'free') {
  533. wx.navigateTo({
  534. url: `/pages/order/detail/index?orderId=${
  535. orderId
  536. }&cardIf=true`
  537. });
  538. } else if (type == 'free') {
  539. wx.navigateTo({
  540. url: `/pages/order/detail/index?orderId=${
  541. orderId
  542. }`
  543. });
  544. }
  545. })
  546. .catch(err => {
  547. console.log(err);
  548. if (!type) {
  549. setTimeout(function() {
  550. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  551. }, 2000)
  552. }
  553. })
  554. },
  555. checkPhoneStatus: function() {
  556. let that = this;
  557. Http.get({
  558. url: config.api.checkPhoneStatus,
  559. data: {}
  560. })
  561. .then(res => {
  562. console.log(666, '授权成功!')
  563. that.receiveCard()
  564. })
  565. .catch(err => {
  566. if (err.code == 11005) {
  567. /**
  568. * 手机号没有授权,将值传到用户手机号授权的页面
  569. *
  570. */
  571. wx.redirectTo({
  572. 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,
  573. });
  574. } else if (err.code == 11006) {
  575. // 用户手机已加密
  576. wx.redirectTo({
  577. 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,
  578. });
  579. } else {
  580. wx.showToast({
  581. title: err.message,
  582. icon: 'none',
  583. duration: 2000,
  584. mask: false
  585. });
  586. }
  587. })
  588. },
  589. /**
  590. * 发起支付
  591. */
  592. orderFunc(discount) {
  593. let that = this;
  594. Http.get({
  595. url: config.api.checkPhoneStatus,
  596. data: {}
  597. })
  598. .then(res => {
  599. if (discount == 'discount') {
  600. var data = {
  601. couponChannelId: "" + that.data.couponChannelId,
  602. couponId: "" + that.data.couponId,
  603. formId: "" + that.data.formId,
  604. press: true
  605. }
  606. } else if (discount == 'discount1') {
  607. var data = {
  608. couponChannelId: "" + that.data.couponChannelId,
  609. couponId: "" + that.data.couponId,
  610. formId: "" + that.data.formId,
  611. press: false
  612. }
  613. } else if (that.data.couponChannelId == null) {
  614. var data = {
  615. couponId: "" + that.data.couponId,
  616. formId: "" + that.data.formId,
  617. };
  618. } else {
  619. var data = {
  620. couponChannelId: "" + that.data.couponChannelId,
  621. couponId: "" + that.data.couponId,
  622. formId: "" + that.data.formId,
  623. }
  624. }
  625. /**
  626. * orderSave 下单
  627. */
  628. return Http.post({
  629. url: config.api.orderSave,
  630. data: data
  631. });
  632. })
  633. .catch(err => {
  634. console.log(err);
  635. that.setData({
  636. showbutton: false,
  637. showbutton1: false
  638. })
  639. if (err.code == 2011) {
  640. wx.showToast({
  641. title: "商户信息没找到",
  642. image: './../../../assets/images/fail.png',
  643. duration: 2000,
  644. mask: false
  645. });
  646. } else if (err.code == 2013) {
  647. wx.showToast({
  648. title: "商户信息禁用",
  649. image: './../../../assets/images/fail.png',
  650. duration: 2000,
  651. mask: false
  652. });
  653. } else if (err.code == 3000) {
  654. wx.showToast({
  655. title: "库存不足",
  656. image: './../../../assets/images/fail.png',
  657. duration: 2000,
  658. mask: false
  659. });
  660. } else if (err.code == 3001) {
  661. wx.showToast({
  662. title: "您已超过限购",
  663. image: './../../../assets/images/fail.png',
  664. duration: 2000,
  665. mask: false
  666. });
  667. } else if (err.code == 3002) {
  668. wx.showToast({
  669. title: "订单失败",
  670. image: './../../../assets/images/fail.png',
  671. duration: 2000,
  672. mask: false
  673. });
  674. } else if (err.code == 3003) {
  675. wx.showToast({
  676. title: "订单不存在",
  677. image: './../../../assets/images/fail.png',
  678. duration: 2000,
  679. mask: false
  680. });
  681. } else if (err.code == 3004) {
  682. wx.showToast({
  683. title: "订单不存在",
  684. image: './../../../assets/images/fail.png',
  685. duration: 2000,
  686. mask: false
  687. });
  688. } else if (err.code == 4003) {
  689. wx.showToast({
  690. title: "卡券已作废",
  691. image: './../../../assets/images/fail.png',
  692. duration: 2000,
  693. mask: false
  694. });
  695. } else if (err.code == 3012) {
  696. wx.showToast({
  697. title: "您有未支付订单",
  698. image: './../../../assets/images/fail.png',
  699. duration: 2000,
  700. mask: false
  701. });
  702. } else if (err.code == 11005) {
  703. /**
  704. * 将值传到用户手机号授权的页面
  705. *
  706. */
  707. wx.redirectTo({
  708. url: "/pages/getphoneInfo/index?couponChannelId=" +
  709. that.data.couponChannelId
  710. });
  711. } else if (err.code == 11006) {
  712. // 用户手机已加密
  713. wx.redirectTo({
  714. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  715. that.data.couponChannelId
  716. });
  717. } else {
  718. wx.showToast({
  719. title: err.message,
  720. icon: 'none',
  721. duration: 2000,
  722. mask: false
  723. });
  724. }
  725. })
  726. .then(res => {
  727. if (discount != 'discount') {
  728. if (typeof(res) != "undefined") {
  729. let orderId = "" + res.data.id;
  730. that.setData({
  731. orderId: orderId
  732. });
  733. if (res.data.payment > 0) {
  734. // 支付金额不为0
  735. /**
  736. * 支付订单创建
  737. */
  738. Http.post({
  739. url: config.api.payOrderCreate,
  740. data: {
  741. orderId: orderId
  742. }
  743. })
  744. .then(res => {
  745. var payOrderId = "" + res.data.payOrderId;
  746. wx.hideLoading();
  747. wx.requestPayment({
  748. timeStamp: res.data.timeStamp,
  749. nonceStr: res.data.nonceStr,
  750. package: res.data.package,
  751. signType: (res.data.signType) ? res.data.signType : "MD5",
  752. paySign: res.data.paySign,
  753. success: res => {
  754. wx.showLoading({
  755. title: '订单正在处理中...',
  756. })
  757. setTimeout(function() {
  758. wx.hideLoading()
  759. }, 5000)
  760. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  761. if (res.errMsg == "requestPayment:ok") {
  762. setTimeout(function() {
  763. wx.hideLoading();
  764. }, 2000);
  765. /**
  766. * 用户支付成功以后跳转到券包列表
  767. */
  768. if (that.data.cardType == 100) {
  769. wx.setStorage({
  770. key: 'couponNum2',
  771. data: "couponNum2"
  772. })
  773. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  774. wx.setStorage({
  775. key: 'couponNum',
  776. data: "couponNum"
  777. })
  778. }
  779. }
  780. },
  781. fail: res => {
  782. /**
  783. * 支付失败,需要更新订单的状态
  784. */
  785. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  786. that.setData({
  787. showbutton: false
  788. })
  789. return;
  790. },
  791. complete: res => {}
  792. });
  793. /// End payment --------
  794. })
  795. .catch(err => {
  796. wx.showToast({
  797. title: err.message,
  798. icon: 'none',
  799. duration: 2000,
  800. mask: false
  801. });
  802. })
  803. } else {
  804. // 免费券
  805. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  806. if (that.data.cardType == 100) {
  807. wx.setStorage({
  808. key: 'couponNum2',
  809. data: "couponNum2"
  810. })
  811. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  812. wx.setStorage({
  813. key: 'couponNum',
  814. data: "couponNum"
  815. })
  816. }
  817. }
  818. }
  819. } else {
  820. if (res) {
  821. wx.navigateTo({
  822. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  823. })
  824. }
  825. }
  826. })
  827. },
  828. onShow() {
  829. this.setData({
  830. showbutton: false,
  831. showbutton1: false
  832. })
  833. if (this.data.end_time) {
  834. this.countdown(this.data.end_time)
  835. }
  836. },
  837. onUnload: function() {
  838. let that = this;
  839. clearInterval(that.data.setInterval)
  840. },
  841. onHide: function() {
  842. let that = this;
  843. clearInterval(that.data.setInterval)
  844. },
  845. onShareAppMessage: function(options) {
  846. var that = this;
  847. var shareObj = {
  848. title: that.data.data.title,
  849. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  850. success: function(res) {
  851. if (res.errMsg == 'shareAppMessage:ok') {}
  852. },
  853. fail: function(error) {
  854. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  855. }
  856. };
  857. // 来自页面内的按钮的转发
  858. if (options.from == 'button') {
  859. var eData = options.target.dataset.id;
  860. shareObj.path = `/pages/index/index?couponChannelId=${eData}`;
  861. }
  862. // 返回shareObj
  863. return shareObj;
  864. },
  865. // 下拉刷新
  866. onPullDownRefresh: function() {
  867. this.getDetail(this.data.couponChannelId);
  868. wx.stopPullDownRefresh()
  869. }
  870. });