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.

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