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.

1011 lines
28 KiB

  1. var config = require("../../../config/config.js");
  2. var app = getApp();
  3. const Http = require("../../../utils/HttpBasics");
  4. const util = require("../../../utils/util");
  5. const imgurl = require("../../../utils/imgurl");
  6. Page({
  7. data: {
  8. isshowposter:false,//是否显示分享弹框
  9. isshowposter1:false,//是否显示分享弹框
  10. fenxiangUrl: imgurl.fenxiang.url,
  11. clockUrl: imgurl.clock.url,
  12. teljpgUrl: imgurl.teljpg.url,
  13. closedUrl: imgurl.closed.url,
  14. quesGouUrl: imgurl.ques_gou.url,
  15. headbgUrl: imgurl.headbg.url,
  16. quesBgUrl: imgurl.ques_bg.url,
  17. close02: imgurl.close02.url,
  18. fenxiang: imgurl.fenxiang.url,
  19. fail: imgurl.fail.url,
  20. homeSelectedO: imgurl.homeSelectedO.url,
  21. wmhome: imgurl.wmhome.url,
  22. swiperCurrent: 0,
  23. hidden: "hidden",
  24. height: "",
  25. detailPicture:[],
  26. coverPicture:[],
  27. more: "点击查看更多",
  28. showMore: true,
  29. data: {
  30. title: null
  31. },
  32. showPage: false,
  33. questions1: null,
  34. questions2: null,
  35. carList: [],
  36. couponChannelId: null,
  37. orderId: "",
  38. hour: null,
  39. day: null,
  40. month: null,
  41. year: null,
  42. minute: "",
  43. tempFilePaths: null,
  44. userInfo: {},
  45. hasUserInfo: false,
  46. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  47. id: null,
  48. result: [],
  49. end_time: null,
  50. checked: false,
  51. questionnaire: {},
  52. questionId: null,
  53. widthScreen: null,
  54. moveData: null,
  55. rotateData: null,
  56. alphaData: null,
  57. scaleData: null,
  58. skewData: null,
  59. matrixData: null,
  60. opacity: 0,
  61. queueData: null,
  62. zIndex: 11,
  63. display: "none",
  64. showbutton: false,
  65. cardData: null,
  66. showCardOffer: false,
  67. isSamePeople: true,
  68. statusText: '',
  69. isReceived: false,
  70. receivedDisabled: false,
  71. clock: "结束",
  72. day: "00",
  73. hour: "00",
  74. min: "00",
  75. sec: "00",
  76. clock02: "00",
  77. day02: "00",
  78. hour02: "00",
  79. min02: "00",
  80. sec02: "00",
  81. countdown: "",
  82. showbutton1: false,
  83. limitCondition:"",
  84. minLimit:0,
  85. maxLimit:0,
  86. dispressEndDate:false
  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. showshare1: function() {
  108. this.setData({
  109. isshowposter1: true,
  110. })
  111. },
  112. /**
  113. * 隐藏砍价弹框
  114. */
  115. hidemodal1: function() {
  116. this.setData({
  117. isshowposter1: false,
  118. })
  119. },
  120. /**
  121. * 跳转到门店列表的详情页面
  122. */
  123. gotoDetail(e) {
  124. wx.navigateTo({
  125. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  126. })
  127. },
  128. /**
  129. * 显示分享海报
  130. */
  131. showPoster: function() {
  132. //跳转到海报生成页
  133. wx.navigateTo({
  134. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  135. })
  136. },
  137. swiperChange: function (e) {
  138. this.setData({
  139. swiperCurrent: e.detail.current
  140. });
  141. },
  142. phone: function(e) {
  143. let that = this;
  144. wx.makePhoneCall({
  145. phoneNumber: e.target.dataset.merchantlinkphone
  146. });
  147. },
  148. // 点击查看更多
  149. more: function() {
  150. let that = this;
  151. if (that.data.more == '点击查看更多') {
  152. this.setData({
  153. hidden: "",
  154. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  155. more: "点击收起",
  156. showMore: true
  157. })
  158. } else {
  159. this.setData({
  160. hidden: "hidden",
  161. height: 4 * 140 + 'rpx',
  162. more: "点击查看更多",
  163. showMore: true
  164. })
  165. }
  166. },
  167. //获取当前登录用户信息
  168. getUserInfo: function() {
  169. let that = this;
  170. // 获取用户信息
  171. Http.get({
  172. url: config.api.getScore,
  173. data: {}
  174. })
  175. .then(res => {
  176. console.log(res)
  177. that.getQueryCardStatus()
  178. if (that.data.cardData.cuserId != res.data.id) {
  179. console.log(2222, 6666)
  180. that.setData({
  181. isSamePeople: false
  182. })
  183. }
  184. })
  185. },
  186. //获取卡转赠状态
  187. getQueryCardStatus() {
  188. let that = this;
  189. let param = {
  190. id: this.data.cardData.couponOrderId,
  191. cUserId: this.data.cardData.cuserId,
  192. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  193. }
  194. Http.get({
  195. url: config.api.queryCardStatus,
  196. data: param
  197. })
  198. .then(res => {
  199. console.log(res, 333333333333)
  200. })
  201. .catch(err => {
  202. that.setData({
  203. isReceived: true,
  204. statusText: err.message
  205. })
  206. })
  207. },
  208. receiveCard() {
  209. let that = this;
  210. let param = {
  211. id: this.data.cardData.couponOrderId,
  212. cUserId: this.data.cardData.cuserId,
  213. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  214. }
  215. this.setData({
  216. receivedDisabled: true
  217. })
  218. Http.post({
  219. url: config.api.cardAccept,
  220. data: param
  221. })
  222. .then(res => {
  223. wx.showToast({
  224. title: '领取成功!',
  225. icon: 'none',
  226. duration: 2000,
  227. mask: false
  228. });
  229. wx.reLaunch({
  230. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  231. })
  232. })
  233. .catch(err => {
  234. wx.showToast({
  235. title: err.message,
  236. icon: 'none',
  237. duration: 2000,
  238. mask: false
  239. });
  240. that.setData({
  241. receivedDisabled: false
  242. })
  243. })
  244. },
  245. closeAlert() {
  246. this.setData({
  247. showCardOffer: false
  248. })
  249. },
  250. goback: function() {
  251. wx.switchTab({
  252. url: '/pages/main/index',
  253. })
  254. },
  255. /**
  256. * 点击提交问题单选
  257. */
  258. formSubmit: function(e) {
  259. console.log(e);
  260. let that = this;
  261. /**
  262. * 多选
  263. */
  264. if (e.currentTarget.dataset.flags == 'multi') {
  265. if (that.data.anwserId.length == 0) {
  266. var answserIs = null
  267. } else {
  268. var answserIs = that.data.anwserId.join(",");
  269. }
  270. } else if (e.currentTarget.dataset.flags == 'single') {
  271. var answserIs = e.detail.value;
  272. }
  273. console.log(answserIs)
  274. console.log(e.currentTarget.dataset.questionid)
  275. Http.post({
  276. url: config.api.answerQuestion,
  277. data: {
  278. answer: answserIs,
  279. questionId: e.currentTarget.dataset.questionid
  280. }
  281. })
  282. .then(res => {
  283. that.closeQuestion();
  284. })
  285. .catch(err => {
  286. wx.showToast({
  287. title: err.message,
  288. icon: 'none',
  289. duration: 2000,
  290. mask: false
  291. });
  292. })
  293. },
  294. /**
  295. * 多选
  296. */
  297. checkboxChange: function(e) {
  298. console.log(e)
  299. this.setData({
  300. anwserId: e.detail.value
  301. })
  302. },
  303. closeQuestion: function() {
  304. let that = this;
  305. that.setData({
  306. display: "none",
  307. zIndex: 11,
  308. opacity: 0
  309. })
  310. setTimeout(function() {
  311. that.orderFunc();
  312. }, 500)
  313. },
  314. gotopay: function(e) {
  315. let that = this;
  316. console.log(e);
  317. wx.showLoading();
  318. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50){
  319. wx.navigateTo({
  320. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  321. })
  322. }else{
  323. let formId = e.detail.formId;
  324. var discount = e.detail.target.dataset.discount;
  325. that.setData({
  326. queueData: null,
  327. showbutton: true,
  328. formId: formId
  329. })
  330. Http.get({
  331. url: config.api.getQuestion,
  332. data: {
  333. couponType: JSON.stringify(that.data.data.type)
  334. }
  335. })
  336. .then(res => {
  337. wx.hideLoading();
  338. if (res.data == undefined) {
  339. // 立即购买
  340. that.orderFunc(discount);
  341. that.setData({
  342. flag: false
  343. })
  344. } else if (res.data) {
  345. var animation = wx.createAnimation({});
  346. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  347. duration: 500
  348. })
  349. that.setData({
  350. queueData: animation.export(),
  351. zIndex: 9,
  352. opacity: 1,
  353. display: "block",
  354. questionnaire: JSON.parse(res.data.content),
  355. questionId: res.data.id
  356. });
  357. }
  358. })
  359. .catch(err => {
  360. wx.hideLoading();
  361. wx.showToast({
  362. title: err.message,
  363. icon: 'none',
  364. duration: 2000,
  365. mask: false
  366. });
  367. })
  368. }
  369. },
  370. setIntervalTime(end_time) {
  371. let that = this;
  372. var EndTime = end_time;
  373. var NowTime = new Date().getTime();
  374. var total_micro_second = EndTime - NowTime || [];
  375. // 渲染倒计时时钟
  376. let obj = that.dateformat(total_micro_second);
  377. if (total_micro_second > 0) {
  378. that.setData({
  379. clock: obj,
  380. day: obj.a1,
  381. hour: obj.b1,
  382. min: obj.c1,
  383. sec: obj.d1,
  384. })
  385. } else {
  386. that.setData({
  387. clock: "00",
  388. day: "00",
  389. hour: "00",
  390. min: "00",
  391. sec: "00",
  392. })
  393. //如果倒计时结束,需要重新查询一下券的状态
  394. // 给getDetail一个标识
  395. that.getDetail(that.data.couponChannelId, 'endclock');
  396. }
  397. total_micro_second -= 1000;
  398. },
  399. countdown: function(end_time) {
  400. let that = this;
  401. that.setIntervalTime(end_time);
  402. that.data.setInterval = setInterval(function() {
  403. that.setIntervalTime(end_time);
  404. }, 1000)
  405. },
  406. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  407. dateformat(micro_second) {
  408. // 总秒数
  409. var second = Math.floor(micro_second / 1000);
  410. // 天数
  411. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  412. // 小时
  413. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  414. // 分钟
  415. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  416. // 秒
  417. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  418. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  419. return {
  420. a1: day,
  421. b1: hr,
  422. c1: min,
  423. d1: sec
  424. }
  425. },
  426. /**
  427. * 获取用户信息
  428. */
  429. onLoad(options) {
  430. let that = this;
  431. wx.showLoading({
  432. title: "加载中..."
  433. });
  434. that.setData({
  435. onshow: false
  436. })
  437. if (options && options.couponChannelId){
  438. that.getDetail(options.couponChannelId, 'notendclock');
  439. }
  440. /**
  441. * 转赠判断
  442. */
  443. if (options.cuserId) {
  444. this.setData({
  445. showCardOffer: true,
  446. cardData: options
  447. })
  448. this.getUserInfo()
  449. }
  450. that.setData({
  451. couponChannelId: options.couponChannelId,
  452. title: that.data.data.title ? that.data.data.title : '',
  453. });
  454. if (options.cardType) {
  455. that.setData({
  456. cardType: options.cardType
  457. })
  458. }
  459. },
  460. getDetail: function(couponChannelId, flag) {
  461. let that = this;
  462. var parmer = {
  463. url: config.api.couponDetail,
  464. data: {
  465. couponChannelId: couponChannelId
  466. }
  467. };
  468. Http.get(parmer)
  469. .then(res => {
  470. that.setData({
  471. couponId: res.data.couponId
  472. })
  473. that.setData({
  474. showPage: true
  475. })
  476. if (res && res.data && res.data.detailPicture) {
  477. that.setData({
  478. detailPicture: JSON.parse(res.data.detailPicture)
  479. })
  480. }
  481. if (res && res.data && res.data.coverPicture) {
  482. that.setData({
  483. coverPicture: JSON.parse(res.data.coverPicture)
  484. })
  485. }
  486. if (res && res.data && res.data.conditions){
  487. that.setData({
  488. limitCondition: JSON.parse(res.data.conditions).type
  489. })
  490. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min==0)){
  491. that.setData({
  492. minLimit: JSON.parse(res.data.conditions).min
  493. })
  494. }
  495. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  496. that.setData({
  497. maxLimit: JSON.parse(res.data.conditions).max
  498. })
  499. }
  500. }
  501. /**
  502. * 将优惠券优惠卡的详情的BarTitle
  503. * 设置成券的名称
  504. */
  505. wx.setNavigationBarTitle({
  506. title: res.data.title
  507. })
  508. var EndTime = res.data.validStartDate;
  509. var NowTime = new Date().getTime();
  510. /**
  511. * activityStatus==0 活动未开始
  512. * activityStatus==1 活动已开始
  513. * flag == endclock 说明倒计时已经结束
  514. */
  515. if (res.data.endTime && res.data.beginTime) {
  516. that.setData({
  517. begin_time: res.data.beginTime,
  518. end_time: res.data.endTime,
  519. })
  520. if (res.data.activityStatus == 0 && flag != 'endclock') {
  521. that.countdown(res.data.beginTime);
  522. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  523. that.countdown(res.data.endTime);
  524. } else {
  525. clearInterval(that.data.setInterval)
  526. }
  527. if (res.data.activityStatus == 0) {
  528. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  529. if (util.timechuo(beginTime).indexOf('-') == 0) {
  530. that.setData({
  531. beginTime: "活动已结束",
  532. });
  533. } else {
  534. that.setData({
  535. beginTime: util.timechuo(beginTime)
  536. });
  537. }
  538. } else {
  539. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  540. if (util.timechuo(endTime).indexOf('-') == 0) {
  541. that.setData({
  542. endtime: "活动已结束",
  543. });
  544. } else {
  545. that.setData({
  546. endtime: util.timechuo(endTime)
  547. });
  548. }
  549. }
  550. }
  551. wx.hideLoading();
  552. that.setData({
  553. data: res.data
  554. });
  555. if (that.data.data.merchantVoList && that.data.data.merchantVoList.length <= 4) {
  556. that.setData({
  557. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  558. showMore: false
  559. })
  560. } else if (that.data.data.merchantVoList && that.data.data.merchantVoList.length > 4) {
  561. that.setData({
  562. height: 4 * 140 + 'rpx'
  563. })
  564. }
  565. if (res.data.validType == 1) {
  566. that.setData({
  567. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  568. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  569. });
  570. } else {
  571. if (res.data.validDays) {
  572. that.setData({
  573. validDays: res.data.validDays
  574. });
  575. }
  576. }
  577. }).catch(err => {
  578. wx.showToast({
  579. title: err.message,
  580. icon: 'none',
  581. duration: 2000,
  582. mask: false
  583. });
  584. })
  585. },
  586. /**
  587. * 邀请好友继续砍价
  588. */
  589. inviteFriend: function(e) {
  590. let that = this;
  591. let formId = e.detail.formId;
  592. that.setData({
  593. formId: formId
  594. })
  595. that.orderFunc("discount");
  596. that.setData({
  597. showbutton1: true
  598. })
  599. },
  600. /**
  601. * 支付订单更新
  602. */
  603. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  604. let that = this;
  605. // 支付成功
  606. Http.post({
  607. url: config.api.payOrderUpdate,
  608. data: {
  609. payOrderId: payOrderId,
  610. orderId: orderId,
  611. status: status,
  612. reason: reason
  613. }
  614. })
  615. .then(res => {
  616. wx.hideLoading()
  617. // 有价券
  618. if (!type && type != 'free') {
  619. wx.navigateTo({
  620. url: `/pages/order/detail/index?orderId=${
  621. orderId
  622. }&cardIf=true`
  623. });
  624. } else if (type == 'free') {
  625. wx.navigateTo({
  626. url: `/pages/order/detail/index?orderId=${
  627. orderId
  628. }`
  629. });
  630. }
  631. })
  632. .catch(err => {
  633. console.log(err);
  634. if (!type) {
  635. setTimeout(function() {
  636. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  637. }, 2000)
  638. }
  639. })
  640. },
  641. checkPhoneStatus: function() {
  642. let that = this;
  643. Http.get({
  644. url: config.api.checkPhoneStatus,
  645. data: {}
  646. })
  647. .then(res => {
  648. console.log(666, '授权成功!')
  649. that.receiveCard()
  650. })
  651. .catch(err => {
  652. if (err.code == 11005) {
  653. /**
  654. * 手机号没有授权,将值传到用户手机号授权的页面
  655. *
  656. */
  657. wx.redirectTo({
  658. 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,
  659. });
  660. } else if (err.code == 11006) {
  661. // 用户手机已加密
  662. wx.redirectTo({
  663. 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,
  664. });
  665. } else {
  666. wx.showToast({
  667. title: err.message,
  668. icon: 'none',
  669. duration: 2000,
  670. mask: false
  671. });
  672. }
  673. })
  674. },
  675. /**
  676. * 发起支付
  677. */
  678. orderFunc(discount) {
  679. let that = this;
  680. Http.get({
  681. url: config.api.checkPhoneStatus,
  682. data: {}
  683. })
  684. .then(res => {
  685. // 发起砍价
  686. if (discount == 'discount') {
  687. var data = {
  688. couponChannelId: "" + that.data.couponChannelId,
  689. couponId: "" + that.data.couponId,
  690. formId: "" + that.data.formId,
  691. press: true
  692. }
  693. } else if (discount == 'discount1') {
  694. var data = {
  695. couponChannelId: "" + that.data.couponChannelId,
  696. couponId: "" + that.data.couponId,
  697. formId: "" + that.data.formId,
  698. press: false
  699. }
  700. } else if (that.data.couponChannelId == null) {
  701. var data = {
  702. couponId: "" + that.data.couponId,
  703. formId: "" + that.data.formId,
  704. };
  705. } else {
  706. var data = {
  707. couponChannelId: "" + that.data.couponChannelId,
  708. couponId: "" + that.data.couponId,
  709. formId: "" + that.data.formId,
  710. }
  711. }
  712. /**
  713. * orderSave 下单
  714. */
  715. return Http.post({
  716. url: config.api.orderSave,
  717. data: data
  718. });
  719. })
  720. .catch(err => {
  721. wx.hideLoading()
  722. that.setData({
  723. showbutton: false,
  724. showbutton1: false
  725. })
  726. if (err.code == 2011) {
  727. wx.showToast({
  728. title: "商户信息没找到",
  729. image: './../../../assets/images/fail.png',
  730. duration: 2000,
  731. mask: false
  732. });
  733. } else if (err.code == 2013) {
  734. wx.showToast({
  735. title: "商户信息禁用",
  736. image: './../../../assets/images/fail.png',
  737. duration: 2000,
  738. mask: false
  739. });
  740. } else if (err.code == 3000) {
  741. wx.showToast({
  742. title: "库存不足",
  743. image: './../../../assets/images/fail.png',
  744. duration: 2000,
  745. mask: false
  746. });
  747. } else if (err.code == 3001) {
  748. wx.showToast({
  749. title: "您已超过限购",
  750. image: './../../../assets/images/fail.png',
  751. duration: 2000,
  752. mask: false
  753. });
  754. } else if (err.code == 3002) {
  755. wx.showToast({
  756. title: "订单失败",
  757. image: './../../../assets/images/fail.png',
  758. duration: 2000,
  759. mask: false
  760. });
  761. } else if (err.code == 3003) {
  762. wx.showToast({
  763. title: "订单不存在",
  764. image: './../../../assets/images/fail.png',
  765. duration: 2000,
  766. mask: false
  767. });
  768. } else if (err.code == 3004) {
  769. wx.showToast({
  770. title: "订单不存在",
  771. image: './../../../assets/images/fail.png',
  772. duration: 2000,
  773. mask: false
  774. });
  775. } else if (err.code == 4003) {
  776. wx.showToast({
  777. title: "卡券已作废",
  778. image: './../../../assets/images/fail.png',
  779. duration: 2000,
  780. mask: false
  781. });
  782. } else if (err.code == 3012) {
  783. that.getUnPaidOrder(that.data.couponId);
  784. } else if (err.code == 11005) {
  785. /**
  786. * 将值传到用户手机号授权的页面
  787. *
  788. */
  789. wx.redirectTo({
  790. url: "/pages/getphoneInfo/index?couponChannelId=" +
  791. that.data.couponChannelId
  792. });
  793. } else if (err.code == 11006) {
  794. // 用户手机已加密
  795. wx.redirectTo({
  796. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  797. that.data.couponChannelId
  798. });
  799. } else {
  800. wx.showToast({
  801. title: err.message,
  802. icon: 'none',
  803. duration: 2000,
  804. mask: false
  805. });
  806. }
  807. })
  808. .then(res => {
  809. if (discount != 'discount') {
  810. if (typeof(res) != "undefined") {
  811. let orderId = "" + res.data.id;
  812. that.setData({
  813. orderId: orderId
  814. });
  815. if (res.data.payment > 0) {
  816. // 支付金额不为0
  817. /**
  818. * 支付订单创建
  819. */
  820. Http.post({
  821. url: config.api.payOrderCreate,
  822. data: {
  823. orderId: orderId
  824. }
  825. })
  826. .then(res => {
  827. var payOrderId = "" + res.data.payOrderId;
  828. wx.hideLoading();
  829. wx.requestPayment({
  830. timeStamp: res.data.timeStamp,
  831. nonceStr: res.data.nonceStr,
  832. package: res.data.package,
  833. signType: (res.data.signType) ? res.data.signType : "MD5",
  834. paySign: res.data.paySign,
  835. success: res => {
  836. wx.showLoading({
  837. title: '订单正在处理中...',
  838. })
  839. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  840. if (res.errMsg == "requestPayment:ok") {
  841. /**
  842. * 用户支付成功以后跳转到券包列表
  843. */
  844. if (that.data.cardType == 100) {
  845. wx.setStorage({
  846. key: 'couponNum2',
  847. data: "couponNum2"
  848. })
  849. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  850. wx.setStorage({
  851. key: 'couponNum',
  852. data: "couponNum"
  853. })
  854. }
  855. }
  856. },
  857. fail: res => {
  858. wx.hideLoading();
  859. /**
  860. * 支付失败,需要更新订单的状态
  861. */
  862. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  863. that.setData({
  864. showbutton: false
  865. })
  866. return;
  867. },
  868. complete: res => {}
  869. });
  870. /// End payment --------
  871. })
  872. .catch(err => {
  873. wx.hideLoading();
  874. wx.showToast({
  875. title: err.message,
  876. icon: 'none',
  877. duration: 2000,
  878. mask: false
  879. });
  880. })
  881. } else {
  882. // 免费券
  883. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  884. if (that.data.cardType == 100) {
  885. wx.setStorage({
  886. key: 'couponNum2',
  887. data: "couponNum2"
  888. })
  889. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  890. wx.setStorage({
  891. key: 'couponNum',
  892. data: "couponNum"
  893. })
  894. }
  895. }
  896. }
  897. } else {
  898. if (res) {
  899. wx.navigateTo({
  900. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  901. })
  902. }
  903. }
  904. })
  905. },
  906. // 获得未支付的订单
  907. getUnPaidOrder(couponId){
  908. let that = this;
  909. Http.get({
  910. url: config.api.getUnPaidOrder,
  911. data: {
  912. couponId: couponId
  913. }
  914. }).then(res=>{
  915. that.setData({
  916. disOrderNumber: res.data.orderNumber,
  917. })
  918. if (res.data&&res.data.pressEndDate){
  919. that.setData({
  920. dispressEndDate:true
  921. })
  922. }else{
  923. that.setData({
  924. dispressEndDate: false
  925. })
  926. }
  927. if (that.data.dispressEndDate){
  928. wx.showModal({
  929. title: '提示',
  930. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  931. confirmText:"我的砍价",
  932. success: function (res) {
  933. if (res.confirm) {
  934. wx.navigateTo({
  935. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  936. })
  937. }
  938. }
  939. })
  940. } else{
  941. wx.showModal({
  942. title: '提示',
  943. content: '您有未支付订单,请先进行支付',
  944. confirmText: "去支付",
  945. success: function (res) {
  946. if (res.confirm) {
  947. wx.navigateTo({
  948. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  949. })
  950. }
  951. }
  952. })
  953. }
  954. }).catch(error=>{
  955. wx.showToast({
  956. title: error.message,
  957. icon: "none",
  958. duration: 3000
  959. })
  960. })
  961. },
  962. onShow() {
  963. this.setData({
  964. showbutton: false,
  965. showbutton1: false
  966. })
  967. if (this.data.end_time) {
  968. this.countdown(this.data.end_time)
  969. }
  970. },
  971. onUnload: function() {
  972. let that = this;
  973. clearInterval(that.data.setInterval)
  974. },
  975. onHide: function() {
  976. let that = this;
  977. clearInterval(that.data.setInterval)
  978. },
  979. onShareAppMessage: function(options) {
  980. var that = this;
  981. console.log(options)
  982. var shareObj = {
  983. title: that.data.data.title,
  984. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  985. success: function(res) {
  986. if (res.errMsg == 'shareAppMessage:ok') {}
  987. },
  988. fail: function(error) {
  989. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  990. }
  991. };
  992. // 来自页面内的按钮的转发
  993. if (options.from == 'button') {
  994. var eData = options.target.dataset.id;
  995. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  996. }
  997. // 返回shareObj
  998. return shareObj;
  999. },
  1000. // 下拉刷新
  1001. onPullDownRefresh: function() {
  1002. this.getDetail(this.data.couponChannelId);
  1003. wx.stopPullDownRefresh()
  1004. }
  1005. });