C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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