C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

980 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.checkUserStatus,
  626. data: {
  627. token: app.globalData.token
  628. }
  629. }).then(res => {
  630. Http.get({
  631. url: config.api.checkPhoneStatus,
  632. data: {}
  633. })
  634. .then(res => {
  635. // 发起砍价
  636. if (discount == 'discount') {
  637. var data = {
  638. couponChannelId: "" + that.data.couponChannelId,
  639. couponId: "" + that.data.couponId,
  640. formId: "" + that.data.formId,
  641. press: true
  642. }
  643. } else if (discount == 'discount1') {
  644. var data = {
  645. couponChannelId: "" + that.data.couponChannelId,
  646. couponId: "" + that.data.couponId,
  647. formId: "" + that.data.formId,
  648. press: false
  649. }
  650. } else if (that.data.couponChannelId == null) {
  651. var data = {
  652. couponId: "" + that.data.couponId,
  653. formId: "" + that.data.formId,
  654. };
  655. } else {
  656. var data = {
  657. couponChannelId: "" + that.data.couponChannelId,
  658. couponId: "" + that.data.couponId,
  659. formId: "" + that.data.formId,
  660. }
  661. }
  662. /**
  663. * orderSave 下单
  664. */
  665. return Http.post({
  666. url: config.api.orderSave,
  667. data: data
  668. });
  669. })
  670. .catch(err => {
  671. wx.hideLoading()
  672. that.setData({
  673. showbutton: false,
  674. showbutton1: false
  675. })
  676. if (err.code == 2011) {
  677. wx.showToast({
  678. title: "商户信息没找到",
  679. image: './../../../assets/images/fail.png',
  680. duration: 2000,
  681. mask: false
  682. });
  683. } else if (err.code == 2013) {
  684. wx.showToast({
  685. title: "商户信息禁用",
  686. image: './../../../assets/images/fail.png',
  687. duration: 2000,
  688. mask: false
  689. });
  690. } else if (err.code == 3000) {
  691. wx.showToast({
  692. title: "库存不足",
  693. image: './../../../assets/images/fail.png',
  694. duration: 2000,
  695. mask: false
  696. });
  697. } else if (err.code == 3001) {
  698. wx.showToast({
  699. title: "您已超过限购",
  700. image: './../../../assets/images/fail.png',
  701. duration: 2000,
  702. mask: false
  703. });
  704. } else if (err.code == 3002) {
  705. wx.showToast({
  706. title: "订单失败",
  707. image: './../../../assets/images/fail.png',
  708. duration: 2000,
  709. mask: false
  710. });
  711. } else if (err.code == 3003) {
  712. wx.showToast({
  713. title: "订单不存在",
  714. image: './../../../assets/images/fail.png',
  715. duration: 2000,
  716. mask: false
  717. });
  718. } else if (err.code == 3004) {
  719. wx.showToast({
  720. title: "订单不存在",
  721. image: './../../../assets/images/fail.png',
  722. duration: 2000,
  723. mask: false
  724. });
  725. } else if (err.code == 4003) {
  726. wx.showToast({
  727. title: "卡券已作废",
  728. image: './../../../assets/images/fail.png',
  729. duration: 2000,
  730. mask: false
  731. });
  732. } else if (err.code == 3012) {
  733. that.getUnPaidOrder(that.data.couponId);
  734. } else if (err.code == 11005) {
  735. /**
  736. * 将值传到用户手机号授权的页面
  737. *
  738. */
  739. wx.redirectTo({
  740. url: "/pages/getphoneInfo/index?couponChannelId=" +
  741. that.data.couponChannelId
  742. });
  743. } else if (err.code == 11006) {
  744. // 用户手机已加密
  745. wx.redirectTo({
  746. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  747. that.data.couponChannelId
  748. });
  749. } else {
  750. wx.showToast({
  751. title: err.message,
  752. icon: 'none',
  753. duration: 2000,
  754. mask: false
  755. });
  756. }
  757. })
  758. .then(res => {
  759. if (discount != 'discount') {
  760. if (typeof(res) != "undefined") {
  761. let orderId = "" + res.data.id;
  762. that.setData({
  763. orderId: orderId
  764. });
  765. if (res.data.payment > 0) {
  766. // 支付金额不为0
  767. /**
  768. * 支付订单创建
  769. */
  770. Http.post({
  771. url: config.api.payOrderCreate,
  772. data: {
  773. orderId: orderId
  774. }
  775. })
  776. .then(res => {
  777. var payOrderId = "" + res.data.payOrderId;
  778. wx.hideLoading();
  779. wx.requestPayment({
  780. timeStamp: res.data.timeStamp,
  781. nonceStr: res.data.nonceStr,
  782. package: res.data.package,
  783. signType: (res.data.signType) ? res.data.signType : "MD5",
  784. paySign: res.data.paySign,
  785. success: res => {
  786. wx.showLoading({
  787. title: '订单正在处理中...',
  788. })
  789. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  790. if (res.errMsg == "requestPayment:ok") {
  791. /**
  792. * 用户支付成功以后跳转到券包列表
  793. */
  794. if (that.data.cardType == 100) {
  795. wx.setStorage({
  796. key: 'couponNum2',
  797. data: "couponNum2"
  798. })
  799. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  800. wx.setStorage({
  801. key: 'couponNum',
  802. data: "couponNum"
  803. })
  804. }
  805. }
  806. },
  807. fail: res => {
  808. wx.hideLoading();
  809. /**
  810. * 支付失败,需要更新订单的状态
  811. */
  812. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  813. that.setData({
  814. showbutton: false
  815. })
  816. return;
  817. },
  818. complete: res => {}
  819. });
  820. /// End payment --------
  821. })
  822. .catch(err => {
  823. wx.hideLoading();
  824. wx.showToast({
  825. title: err.message,
  826. icon: 'none',
  827. duration: 2000,
  828. mask: false
  829. });
  830. })
  831. } else {
  832. // 免费券
  833. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  834. if (that.data.cardType == 100) {
  835. wx.setStorage({
  836. key: 'couponNum2',
  837. data: "couponNum2"
  838. })
  839. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  840. wx.setStorage({
  841. key: 'couponNum',
  842. data: "couponNum"
  843. })
  844. }
  845. }
  846. }
  847. } else {
  848. if (res) {
  849. wx.navigateTo({
  850. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  851. })
  852. }
  853. }
  854. })
  855. }).catch(err => {
  856. console.log(err)
  857. if(err.code == 11004){
  858. wx.redirectTo({
  859. url: `/pages/getuserinfo/index?fromflag=coupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  860. })
  861. }else{
  862. wx.showToast({
  863. title: err.message,
  864. icon:"none",
  865. duration:2500
  866. })
  867. }
  868. })
  869. },
  870. // 获得未支付的订单
  871. getUnPaidOrder(couponId){
  872. let that = this;
  873. Http.get({
  874. url: config.api.getUnPaidOrder,
  875. data: {
  876. couponId: couponId
  877. }
  878. }).then(res=>{
  879. that.setData({
  880. disOrderNumber: res.data.orderNumber,
  881. })
  882. if (res.data&&res.data.pressEndDate){
  883. that.setData({
  884. dispressEndDate:true
  885. })
  886. }else{
  887. that.setData({
  888. dispressEndDate: false
  889. })
  890. }
  891. if (that.data.dispressEndDate){
  892. wx.showModal({
  893. title: '提示',
  894. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  895. confirmText:"我的砍价",
  896. success: function (res) {
  897. if (res.confirm) {
  898. wx.navigateTo({
  899. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  900. })
  901. }
  902. }
  903. })
  904. } else{
  905. wx.showModal({
  906. title: '提示',
  907. content: '您有未支付订单,请先进行支付',
  908. confirmText: "去支付",
  909. success: function (res) {
  910. if (res.confirm) {
  911. wx.navigateTo({
  912. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  913. })
  914. }
  915. }
  916. })
  917. }
  918. }).catch(error=>{
  919. wx.showToast({
  920. title: error.message,
  921. icon: "none",
  922. duration: 3000
  923. })
  924. })
  925. },
  926. onShow() {
  927. app.globalData.havePlayEd1 = true;
  928. this.setData({
  929. showbutton: false,
  930. showbutton1: false
  931. })
  932. if (this.data.end_time && this.data.activityStatus!=0) {
  933. this.countdown(this.data.end_time)
  934. }
  935. else if (this.data.begin_time && this.data.activityStatus == 0) {
  936. this.countdown(this.data.begin_time)
  937. }
  938. },
  939. onUnload: function() {
  940. let that = this;
  941. clearInterval(that.data.setInterval)
  942. },
  943. onHide: function() {
  944. let that = this;
  945. clearInterval(that.data.setInterval)
  946. },
  947. onShareAppMessage: function(options) {
  948. var that = this;
  949. console.log(options)
  950. var shareObj = {
  951. title: that.data.data.title,
  952. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  953. success: function(res) {
  954. if (res.errMsg == 'shareAppMessage:ok') {}
  955. },
  956. fail: function(error) {
  957. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  958. }
  959. };
  960. // 来自页面内的按钮的转发
  961. if (options.from == 'button') {
  962. var eData = options.target.dataset.id;
  963. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  964. }
  965. // 返回shareObj
  966. return shareObj;
  967. },
  968. // 下拉刷新
  969. onPullDownRefresh: function() {
  970. this.getDetail(this.data.couponChannelId);
  971. wx.stopPullDownRefresh()
  972. }
  973. });