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.

960 lines
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. 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. checkPhoneStatus: function() {
  586. let that = this;
  587. Http.get({
  588. url: config.api.checkPhoneStatus,
  589. data: {}
  590. })
  591. .then(res => {
  592. console.log(666, '授权成功!')
  593. that.receiveCard()
  594. })
  595. .catch(err => {
  596. if (err.code == 11005) {
  597. /**
  598. * 手机号没有授权,将值传到用户手机号授权的页面
  599. *
  600. */
  601. wx.redirectTo({
  602. 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,
  603. });
  604. } else if (err.code == 11006) {
  605. // 用户手机已加密
  606. wx.redirectTo({
  607. 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,
  608. });
  609. } else {
  610. wx.showToast({
  611. title: err.message,
  612. icon: 'none',
  613. duration: 2000,
  614. mask: false
  615. });
  616. }
  617. })
  618. },
  619. /**
  620. * 发起支付
  621. */
  622. orderFunc(discount) {
  623. let that = this;
  624. Http.get({
  625. url: config.api.checkPhoneStatus,
  626. data: {}
  627. })
  628. .then(res => {
  629. // 发起砍价
  630. if (discount == 'discount') {
  631. var data = {
  632. couponChannelId: "" + that.data.couponChannelId,
  633. couponId: "" + that.data.couponId,
  634. formId: "" + that.data.formId,
  635. press: true
  636. }
  637. } else if (discount == 'discount1') {
  638. var data = {
  639. couponChannelId: "" + that.data.couponChannelId,
  640. couponId: "" + that.data.couponId,
  641. formId: "" + that.data.formId,
  642. press: false
  643. }
  644. } else if (that.data.couponChannelId == null) {
  645. var data = {
  646. couponId: "" + that.data.couponId,
  647. formId: "" + that.data.formId,
  648. };
  649. } else {
  650. var data = {
  651. couponChannelId: "" + that.data.couponChannelId,
  652. couponId: "" + that.data.couponId,
  653. formId: "" + that.data.formId,
  654. }
  655. }
  656. /**
  657. * orderSave 下单
  658. */
  659. return Http.post({
  660. url: config.api.orderSave,
  661. data: data
  662. });
  663. })
  664. .catch(err => {
  665. wx.hideLoading()
  666. that.setData({
  667. showbutton: false,
  668. showbutton1: false
  669. })
  670. if (err.code == 2011) {
  671. wx.showToast({
  672. title: "商户信息没找到",
  673. image: './../../../assets/images/fail.png',
  674. duration: 2000,
  675. mask: false
  676. });
  677. } else if (err.code == 2013) {
  678. wx.showToast({
  679. title: "商户信息禁用",
  680. image: './../../../assets/images/fail.png',
  681. duration: 2000,
  682. mask: false
  683. });
  684. } else if (err.code == 3000) {
  685. wx.showToast({
  686. title: "库存不足",
  687. image: './../../../assets/images/fail.png',
  688. duration: 2000,
  689. mask: false
  690. });
  691. } else if (err.code == 3001) {
  692. wx.showToast({
  693. title: "您已超过限购",
  694. image: './../../../assets/images/fail.png',
  695. duration: 2000,
  696. mask: false
  697. });
  698. } else if (err.code == 3002) {
  699. wx.showToast({
  700. title: "订单失败",
  701. image: './../../../assets/images/fail.png',
  702. duration: 2000,
  703. mask: false
  704. });
  705. } else if (err.code == 3003) {
  706. wx.showToast({
  707. title: "订单不存在",
  708. image: './../../../assets/images/fail.png',
  709. duration: 2000,
  710. mask: false
  711. });
  712. } else if (err.code == 3004) {
  713. wx.showToast({
  714. title: "订单不存在",
  715. image: './../../../assets/images/fail.png',
  716. duration: 2000,
  717. mask: false
  718. });
  719. } else if (err.code == 4003) {
  720. wx.showToast({
  721. title: "卡券已作废",
  722. image: './../../../assets/images/fail.png',
  723. duration: 2000,
  724. mask: false
  725. });
  726. } else if (err.code == 3012) {
  727. that.getUnPaidOrder(that.data.couponId);
  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. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  784. if (res.errMsg == "requestPayment:ok") {
  785. /**
  786. * 用户支付成功以后跳转到券包列表
  787. */
  788. if (that.data.cardType == 100) {
  789. wx.setStorage({
  790. key: 'couponNum2',
  791. data: "couponNum2"
  792. })
  793. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  794. wx.setStorage({
  795. key: 'couponNum',
  796. data: "couponNum"
  797. })
  798. }
  799. }
  800. },
  801. fail: res => {
  802. wx.hideLoading();
  803. /**
  804. * 支付失败,需要更新订单的状态
  805. */
  806. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  807. that.setData({
  808. showbutton: false
  809. })
  810. return;
  811. },
  812. complete: res => {}
  813. });
  814. /// End payment --------
  815. })
  816. .catch(err => {
  817. wx.hideLoading();
  818. wx.showToast({
  819. title: err.message,
  820. icon: 'none',
  821. duration: 2000,
  822. mask: false
  823. });
  824. })
  825. } else {
  826. // 免费券
  827. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  828. if (that.data.cardType == 100) {
  829. wx.setStorage({
  830. key: 'couponNum2',
  831. data: "couponNum2"
  832. })
  833. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  834. wx.setStorage({
  835. key: 'couponNum',
  836. data: "couponNum"
  837. })
  838. }
  839. }
  840. }
  841. } else {
  842. if (res) {
  843. wx.navigateTo({
  844. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  845. })
  846. }
  847. }
  848. })
  849. },
  850. // 获得未支付的订单
  851. getUnPaidOrder(couponId){
  852. let that = this;
  853. Http.get({
  854. url: config.api.getUnPaidOrder,
  855. data: {
  856. couponId: couponId
  857. }
  858. }).then(res=>{
  859. that.setData({
  860. disOrderNumber: res.data.orderNumber,
  861. })
  862. if (res.data&&res.data.pressEndDate){
  863. that.setData({
  864. dispressEndDate:true
  865. })
  866. }else{
  867. that.setData({
  868. dispressEndDate: false
  869. })
  870. }
  871. if (that.data.dispressEndDate){
  872. wx.showModal({
  873. title: '提示',
  874. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  875. confirmText:"我的砍价",
  876. success: function (res) {
  877. if (res.confirm) {
  878. wx.navigateTo({
  879. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  880. })
  881. }
  882. }
  883. })
  884. } else{
  885. wx.showModal({
  886. title: '提示',
  887. content: '您有未支付订单,请先进行支付',
  888. confirmText: "去支付",
  889. success: function (res) {
  890. if (res.confirm) {
  891. wx.navigateTo({
  892. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  893. })
  894. }
  895. }
  896. })
  897. }
  898. }).catch(error=>{
  899. wx.showToast({
  900. title: error.message,
  901. icon: "none",
  902. duration: 3000
  903. })
  904. })
  905. },
  906. onShow() {
  907. this.setData({
  908. showbutton: false,
  909. showbutton1: false
  910. })
  911. if (this.data.end_time && this.data.activityStatus!=0) {
  912. this.countdown(this.data.end_time)
  913. }
  914. else if (this.data.begin_time && this.data.activityStatus == 0) {
  915. this.countdown(this.data.begin_time)
  916. }
  917. },
  918. onUnload: function() {
  919. let that = this;
  920. clearInterval(that.data.setInterval)
  921. },
  922. onHide: function() {
  923. let that = this;
  924. clearInterval(that.data.setInterval)
  925. },
  926. onShareAppMessage: function(options) {
  927. var that = this;
  928. console.log(options)
  929. var shareObj = {
  930. title: that.data.data.title,
  931. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  932. success: function(res) {
  933. if (res.errMsg == 'shareAppMessage:ok') {}
  934. },
  935. fail: function(error) {
  936. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  937. }
  938. };
  939. // 来自页面内的按钮的转发
  940. if (options.from == 'button') {
  941. var eData = options.target.dataset.id;
  942. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  943. }
  944. // 返回shareObj
  945. return shareObj;
  946. },
  947. // 下拉刷新
  948. onPullDownRefresh: function() {
  949. this.getDetail(this.data.couponChannelId);
  950. wx.stopPullDownRefresh()
  951. }
  952. });