C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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