C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

982 行
27 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. var config = require("../../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../../utils/HttpBasics");
  5. const util = require("../../../utils/util");
  6. const imgurl = require("../../../utils/imgurl");
  7. Page({
  8. data: {
  9. navigationBarHeight,
  10. homeSelectedO: imgurl.homeSelectedO.url,
  11. isshowposter:false,//是否显示分享弹框
  12. fenxiang: imgurl.fenxiang1.url,
  13. fenxiangUrl: imgurl.fenxiang.url,
  14. clockUrl: imgurl.clock.url,
  15. teljpgUrl: imgurl.teljpg.url,
  16. closedUrl: imgurl.closed.url,
  17. quesGouUrl: imgurl.ques_gou.url,
  18. headbgUrl: imgurl.headbg.url,
  19. quesBgUrl: imgurl.ques_bg.url,
  20. close02: imgurl.close02.url,
  21. share01: imgurl.share01.url,
  22. fail: imgurl.fail.url,
  23. wmhome: imgurl.wmhome.url,
  24. swiperCurrent: 0,
  25. detailPicture:[],
  26. coverPicture:[],
  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. limitCondition:"",
  82. minLimit:0,
  83. maxLimit:0,
  84. dispressEndDate:false,
  85. barTitle:"",
  86. activityStatus:""
  87. },
  88. /**
  89. * 显示分享弹框
  90. */
  91. showshare: function() {
  92. this.setData({
  93. isshowposter: true,
  94. })
  95. },
  96. /**
  97. * 隐藏分享弹框
  98. */
  99. hidemodal: function() {
  100. this.setData({
  101. isshowposter: false,
  102. })
  103. },
  104. /**
  105. * 显示分享海报
  106. */
  107. showPoster: function() {
  108. //跳转到海报生成页
  109. wx.navigateTo({
  110. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  111. })
  112. },
  113. swiperChange: function (e) {
  114. this.setData({
  115. swiperCurrent: e.detail.current
  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: '/index/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. console.log(e);
  268. wx.showLoading();
  269. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50){
  270. wx.navigateTo({
  271. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  272. })
  273. }else{
  274. let formId = e.detail.formId;
  275. var discount = e.detail.target.dataset.discount;
  276. that.setData({
  277. queueData: null,
  278. showbutton: true,
  279. formId: formId
  280. })
  281. Http.get({
  282. url: config.api.getQuestion,
  283. data: {
  284. couponType: JSON.stringify(that.data.data.type)
  285. }
  286. })
  287. .then(res => {
  288. wx.hideLoading();
  289. if (res.data == undefined) {
  290. // 立即购买
  291. that.orderFunc(discount);
  292. that.setData({
  293. flag: false
  294. })
  295. } else if (res.data) {
  296. var animation = wx.createAnimation({});
  297. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  298. duration: 500
  299. })
  300. that.setData({
  301. queueData: animation.export(),
  302. zIndex: 9,
  303. opacity: 1,
  304. display: "block",
  305. questionnaire: JSON.parse(res.data.content),
  306. questionId: res.data.id
  307. });
  308. }
  309. })
  310. .catch(err => {
  311. wx.hideLoading();
  312. wx.showToast({
  313. title: err.message,
  314. icon: 'none',
  315. duration: 2000,
  316. mask: false
  317. });
  318. })
  319. }
  320. },
  321. setIntervalTime(end_time) {
  322. let that = this;
  323. var EndTime = end_time;
  324. var NowTime = new Date().getTime();
  325. var total_micro_second = EndTime - NowTime || [];
  326. // 渲染倒计时时钟
  327. let obj = that.dateformat(total_micro_second);
  328. if (total_micro_second > 0) {
  329. that.setData({
  330. clock: obj,
  331. day: obj.a1,
  332. hour: obj.b1,
  333. min: obj.c1,
  334. sec: obj.d1,
  335. })
  336. } else {
  337. that.setData({
  338. clock: "00",
  339. day: "00",
  340. hour: "00",
  341. min: "00",
  342. sec: "00",
  343. })
  344. //如果倒计时结束,需要重新查询一下券的状态
  345. // 给getDetail一个标识
  346. that.getDetail(that.data.couponChannelId, 'endclock');
  347. }
  348. total_micro_second -= 1000;
  349. },
  350. countdown: function(end_time) {
  351. let that = this;
  352. that.setIntervalTime(end_time);
  353. that.data.setInterval = setInterval(function() {
  354. that.setIntervalTime(end_time);
  355. }, 1000)
  356. },
  357. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  358. dateformat(micro_second) {
  359. // 总秒数
  360. var second = Math.floor(micro_second / 1000);
  361. // 天数
  362. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  363. // 小时
  364. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  365. // 分钟
  366. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  367. // 秒
  368. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  369. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  370. return {
  371. a1: day,
  372. b1: hr,
  373. c1: min,
  374. d1: sec
  375. }
  376. },
  377. /**
  378. * 获取用户信息
  379. */
  380. onLoad(options) {
  381. let that = this;
  382. if (options.g){
  383. app.globalData.havePlayEd1 = true;
  384. }
  385. wx.showLoading({
  386. title: "加载中..."
  387. });
  388. that.setData({
  389. onshow: false
  390. })
  391. if (options && options.couponChannelId){
  392. that.getDetail(options.couponChannelId, 'notendclock');
  393. }
  394. /**
  395. * 转赠判断
  396. */
  397. if (options.cuserId) {
  398. this.setData({
  399. showCardOffer: true,
  400. cardData: options
  401. })
  402. this.getUserInfo()
  403. }
  404. that.setData({
  405. couponChannelId: options.couponChannelId,
  406. title: that.data.data.title ? that.data.data.title : '',
  407. });
  408. if (options.cardType) {
  409. that.setData({
  410. cardType: options.cardType
  411. })
  412. }
  413. },
  414. getDetail: function(couponChannelId, flag) {
  415. let that = this;
  416. var parmer = {
  417. url: config.api.couponDetail,
  418. data: {
  419. couponChannelId: couponChannelId
  420. }
  421. };
  422. Http.get(parmer)
  423. .then(res => {
  424. that.setData({
  425. couponId: res.data.couponId
  426. })
  427. that.setData({
  428. showPage: true
  429. })
  430. if (res && res.data && res.data.detailPicture) {
  431. that.setData({
  432. detailPicture: JSON.parse(res.data.detailPicture)
  433. })
  434. }
  435. if (res && res.data && res.data.coverPicture) {
  436. that.setData({
  437. coverPicture: JSON.parse(res.data.coverPicture)
  438. })
  439. }
  440. if (res && res.data && res.data.conditions){
  441. that.setData({
  442. limitCondition: JSON.parse(res.data.conditions).type
  443. })
  444. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min==0)){
  445. that.setData({
  446. minLimit: JSON.parse(res.data.conditions).min
  447. })
  448. }
  449. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  450. that.setData({
  451. maxLimit: JSON.parse(res.data.conditions).max
  452. })
  453. }
  454. }
  455. /**
  456. * 将优惠券优惠卡的详情的BarTitle
  457. * 设置成券的名称
  458. */
  459. // wx.setNavigationBarTitle({
  460. // title: res.data.title
  461. // })
  462. that.setData({
  463. barTitle: res.data.title
  464. })
  465. var EndTime = res.data.validStartDate;
  466. var NowTime = new Date().getTime();
  467. /**
  468. * activityStatus==0 活动未开始
  469. * activityStatus==1 活动已开始
  470. * flag == endclock 说明倒计时已经结束
  471. */
  472. if (res.data.endTime && res.data.beginTime) {
  473. that.setData({
  474. begin_time: res.data.beginTime,
  475. end_time: res.data.endTime,
  476. activityStatus: res.data.activityStatus ? res.data.activityStatus:''
  477. })
  478. if (res.data.activityStatus == 0 && flag != 'endclock') {
  479. that.countdown(res.data.beginTime);
  480. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  481. that.countdown(res.data.endTime);
  482. } else {
  483. clearInterval(that.data.setInterval)
  484. }
  485. if (res.data.activityStatus == 0) {
  486. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  487. if (util.timechuo(beginTime).indexOf('-') == 0) {
  488. that.setData({
  489. beginTime: "活动已结束",
  490. });
  491. } else {
  492. that.setData({
  493. beginTime: util.timechuo(beginTime)
  494. });
  495. }
  496. } else {
  497. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  498. if (util.timechuo(endTime).indexOf('-') == 0) {
  499. that.setData({
  500. endtime: "活动已结束",
  501. });
  502. } else {
  503. that.setData({
  504. endtime: util.timechuo(endTime)
  505. });
  506. }
  507. }
  508. }
  509. wx.hideLoading();
  510. that.setData({
  511. data: res.data,
  512. merchantVoList: res.data.merchantVoList
  513. });
  514. if (res.data.validType == 1) {
  515. that.setData({
  516. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  517. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  518. });
  519. } else {
  520. if (res.data.validDays) {
  521. that.setData({
  522. validDays: res.data.validDays
  523. });
  524. }
  525. }
  526. }).catch(err => {
  527. wx.showToast({
  528. title: err.message,
  529. icon: 'none',
  530. duration: 2000,
  531. mask: false
  532. });
  533. })
  534. },
  535. /**
  536. * 邀请好友继续砍价
  537. */
  538. inviteFriend: function(e) {
  539. let that = this;
  540. let formId = e.detail.formId;
  541. that.setData({
  542. formId: formId,
  543. showbutton1: true
  544. })
  545. that.orderFunc("discount");
  546. },
  547. /**
  548. * 支付订单更新
  549. */
  550. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  551. let that = this;
  552. // 支付成功
  553. Http.post({
  554. url: config.api.payOrderUpdate,
  555. data: {
  556. payOrderId: payOrderId,
  557. orderId: orderId,
  558. status: status,
  559. reason: reason
  560. }
  561. })
  562. .then(res => {
  563. wx.hideLoading()
  564. // 有价券
  565. if (!type && type != 'free') {
  566. wx.navigateTo({
  567. url: `/pages/order/detail/index?orderId=${
  568. orderId
  569. }&cardIf=true`
  570. });
  571. } else if (type == 'free') {
  572. wx.navigateTo({
  573. url: `/pages/order/detail/index?orderId=${
  574. orderId
  575. }`
  576. });
  577. }
  578. })
  579. .catch(err => {
  580. console.log(err);
  581. if (!type) {
  582. setTimeout(function() {
  583. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  584. }, 2000)
  585. }
  586. })
  587. },
  588. checkPhoneStatus: function () {
  589. let that = this;
  590. Http.get({
  591. url: config.api.checkPhoneStatus,
  592. data: {}
  593. })
  594. .then(res => {
  595. console.log(666, '授权成功!')
  596. that.receiveCard()
  597. })
  598. .catch(err => {
  599. if (err.code == 11005) {
  600. /**
  601. * 手机号没有授权,将值传到用户手机号授权的页面
  602. *
  603. */
  604. wx.redirectTo({
  605. 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,
  606. });
  607. } else if (err.code == 11006) {
  608. // 用户手机已加密
  609. wx.redirectTo({
  610. 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,
  611. });
  612. } else {
  613. wx.showToast({
  614. title: err.message,
  615. icon: 'none',
  616. duration: 2000,
  617. mask: false
  618. });
  619. }
  620. })
  621. },
  622. /**
  623. * 发起支付
  624. */
  625. orderFunc(discount) {
  626. let that = this;
  627. Http.get({
  628. url: config.api.checkUserStatus,
  629. data: {
  630. token: app.globalData.token
  631. }
  632. }).then(res => {
  633. Http.get({
  634. url: config.api.checkPhoneStatus,
  635. data: {}
  636. })
  637. .then(res => {
  638. // 发起砍价
  639. if (discount == 'discount') {
  640. var data = {
  641. couponChannelId: "" + that.data.couponChannelId,
  642. couponId: "" + that.data.couponId,
  643. formId: "" + that.data.formId,
  644. press: true
  645. }
  646. } else if (discount == 'discount1') {
  647. var data = {
  648. couponChannelId: "" + that.data.couponChannelId,
  649. couponId: "" + that.data.couponId,
  650. formId: "" + that.data.formId,
  651. press: false
  652. }
  653. } else if (that.data.couponChannelId == null) {
  654. var data = {
  655. couponId: "" + that.data.couponId,
  656. formId: "" + that.data.formId,
  657. };
  658. } else {
  659. var data = {
  660. couponChannelId: "" + that.data.couponChannelId,
  661. couponId: "" + that.data.couponId,
  662. formId: "" + that.data.formId,
  663. }
  664. }
  665. /**
  666. * orderSave 下单
  667. */
  668. return Http.post({
  669. url: config.api.orderSave,
  670. data: data
  671. });
  672. })
  673. .catch(err => {
  674. wx.hideLoading()
  675. that.setData({
  676. showbutton: false,
  677. showbutton1: false
  678. })
  679. if (err.code == 2011) {
  680. wx.showToast({
  681. title: "商户信息没找到",
  682. image: './../../../assets/images/fail.png',
  683. duration: 2000,
  684. mask: false
  685. });
  686. } else if (err.code == 2013) {
  687. wx.showToast({
  688. title: "商户信息禁用",
  689. image: './../../../assets/images/fail.png',
  690. duration: 2000,
  691. mask: false
  692. });
  693. } else if (err.code == 3000) {
  694. wx.showToast({
  695. title: "库存不足",
  696. image: './../../../assets/images/fail.png',
  697. duration: 2000,
  698. mask: false
  699. });
  700. } else if (err.code == 3001) {
  701. wx.showToast({
  702. title: "您已超过限购",
  703. image: './../../../assets/images/fail.png',
  704. duration: 2000,
  705. mask: false
  706. });
  707. } else if (err.code == 3002) {
  708. wx.showToast({
  709. title: "订单失败",
  710. image: './../../../assets/images/fail.png',
  711. duration: 2000,
  712. mask: false
  713. });
  714. } else if (err.code == 3003) {
  715. wx.showToast({
  716. title: "订单不存在",
  717. image: './../../../assets/images/fail.png',
  718. duration: 2000,
  719. mask: false
  720. });
  721. } else if (err.code == 3004) {
  722. wx.showToast({
  723. title: "订单不存在",
  724. image: './../../../assets/images/fail.png',
  725. duration: 2000,
  726. mask: false
  727. });
  728. } else if (err.code == 4003) {
  729. wx.showToast({
  730. title: "卡券已作废",
  731. image: './../../../assets/images/fail.png',
  732. duration: 2000,
  733. mask: false
  734. });
  735. } else if (err.code == 3012) {
  736. that.getUnPaidOrder(that.data.couponId);
  737. } else if (err.code == 11005) {
  738. /**
  739. * 将值传到用户手机号授权的页面
  740. *
  741. */
  742. wx.redirectTo({
  743. url: "/pages/getphoneInfo/index?couponChannelId=" +
  744. that.data.couponChannelId
  745. });
  746. } else if (err.code == 11006) {
  747. // 用户手机已加密
  748. wx.redirectTo({
  749. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  750. that.data.couponChannelId
  751. });
  752. } else {
  753. wx.showToast({
  754. title: err.message,
  755. icon: 'none',
  756. duration: 2000,
  757. mask: false
  758. });
  759. }
  760. })
  761. .then(res => {
  762. if (discount != 'discount') {
  763. if (typeof(res) != "undefined") {
  764. let orderId = "" + res.data.id;
  765. that.setData({
  766. orderId: orderId
  767. });
  768. if (res.data.payment > 0) {
  769. // 支付金额不为0
  770. /**
  771. * 支付订单创建
  772. */
  773. Http.post({
  774. url: config.api.payOrderCreate,
  775. data: {
  776. orderId: orderId
  777. }
  778. })
  779. .then(res => {
  780. var payOrderId = "" + res.data.payOrderId;
  781. wx.hideLoading();
  782. wx.requestPayment({
  783. timeStamp: res.data.timeStamp,
  784. nonceStr: res.data.nonceStr,
  785. package: res.data.package,
  786. signType: (res.data.signType) ? res.data.signType : "MD5",
  787. paySign: res.data.paySign,
  788. success: res => {
  789. wx.showLoading({
  790. title: '订单正在处理中...',
  791. })
  792. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  793. if (res.errMsg == "requestPayment:ok") {
  794. /**
  795. * 用户支付成功以后跳转到券包列表
  796. */
  797. if (that.data.cardType == 100) {
  798. wx.setStorage({
  799. key: 'couponNum2',
  800. data: "couponNum2"
  801. })
  802. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  803. wx.setStorage({
  804. key: 'couponNum',
  805. data: "couponNum"
  806. })
  807. }
  808. }
  809. },
  810. fail: res => {
  811. wx.hideLoading();
  812. /**
  813. * 支付失败,需要更新订单的状态
  814. */
  815. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  816. that.setData({
  817. showbutton: false
  818. })
  819. return;
  820. },
  821. complete: res => {}
  822. });
  823. /// End payment --------
  824. })
  825. .catch(err => {
  826. wx.hideLoading();
  827. wx.showToast({
  828. title: err.message,
  829. icon: 'none',
  830. duration: 2000,
  831. mask: false
  832. });
  833. })
  834. } else {
  835. // 免费券
  836. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  837. if (that.data.cardType == 100) {
  838. wx.setStorage({
  839. key: 'couponNum2',
  840. data: "couponNum2"
  841. })
  842. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  843. wx.setStorage({
  844. key: 'couponNum',
  845. data: "couponNum"
  846. })
  847. }
  848. }
  849. }
  850. } else {
  851. if (res) {
  852. wx.navigateTo({
  853. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  854. })
  855. }
  856. }
  857. })
  858. }).catch(err => {
  859. console.log(err)
  860. if(err.code == 11004){
  861. wx.redirectTo({
  862. url: `/pages/getuserinfo/index?fromflag=coupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  863. })
  864. }else{
  865. wx.showToast({
  866. title: err.message,
  867. icon:"none",
  868. duration:2500
  869. })
  870. }
  871. })
  872. },
  873. // 获得未支付的订单
  874. getUnPaidOrder(couponId){
  875. let that = this;
  876. Http.get({
  877. url: config.api.getUnPaidOrder,
  878. data: {
  879. couponId: couponId
  880. }
  881. }).then(res=>{
  882. that.setData({
  883. disOrderNumber: res.data.orderNumber,
  884. })
  885. if (res.data&&res.data.pressEndDate){
  886. that.setData({
  887. dispressEndDate:true
  888. })
  889. }else{
  890. that.setData({
  891. dispressEndDate: false
  892. })
  893. }
  894. if (that.data.dispressEndDate){
  895. wx.showModal({
  896. title: '提示',
  897. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  898. confirmText:"我的砍价",
  899. success: function (res) {
  900. if (res.confirm) {
  901. wx.navigateTo({
  902. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  903. })
  904. }
  905. }
  906. })
  907. } else{
  908. wx.showModal({
  909. title: '提示',
  910. content: '您有未支付订单,请先进行支付',
  911. confirmText: "去支付",
  912. success: function (res) {
  913. if (res.confirm) {
  914. wx.navigateTo({
  915. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  916. })
  917. }
  918. }
  919. })
  920. }
  921. }).catch(error=>{
  922. wx.showToast({
  923. title: error.message,
  924. icon: "none",
  925. duration: 3000
  926. })
  927. })
  928. },
  929. onShow() {
  930. this.setData({
  931. showbutton: false,
  932. showbutton1: false
  933. })
  934. if (this.data.end_time && this.data.activityStatus!=0) {
  935. this.countdown(this.data.end_time)
  936. }
  937. else if (this.data.begin_time && this.data.activityStatus == 0) {
  938. this.countdown(this.data.begin_time)
  939. }
  940. },
  941. onUnload: function() {
  942. let that = this;
  943. clearInterval(that.data.setInterval)
  944. },
  945. onHide: function() {
  946. let that = this;
  947. clearInterval(that.data.setInterval)
  948. },
  949. onShareAppMessage: function(options) {
  950. var that = this;
  951. console.log(options)
  952. var shareObj = {
  953. title: that.data.data.title,
  954. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  955. success: function(res) {
  956. if (res.errMsg == 'shareAppMessage:ok') {}
  957. },
  958. fail: function(error) {
  959. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  960. }
  961. };
  962. // 来自页面内的按钮的转发
  963. if (options.from == 'button') {
  964. var eData = options.target.dataset.id;
  965. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  966. }
  967. // 返回shareObj
  968. return shareObj;
  969. },
  970. // 下拉刷新
  971. onPullDownRefresh: function() {
  972. this.getDetail(this.data.couponChannelId);
  973. wx.stopPullDownRefresh()
  974. }
  975. });