C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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