C端小程序

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