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.

1000 regels
28 KiB

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