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.

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