C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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