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

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