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.

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