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.

1003 regels
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. fenxiang: imgurl.fenxiang1.url,
  13. fenxiangUrl: imgurl.fenxiang.url,
  14. clockUrl: imgurl.clock.url,
  15. teljpgUrl: imgurl.teljpg.url,
  16. closedUrl: imgurl.closed.url,
  17. quesGouUrl: imgurl.ques_gou.url,
  18. headbgUrl: imgurl.headbg.url,
  19. quesBgUrl: imgurl.ques_bg.url,
  20. close02: imgurl.close02.url,
  21. share01: imgurl.share01.url,
  22. fail: imgurl.fail.url,
  23. wmhome: imgurl.wmhome.url,
  24. swiperCurrent: 0,
  25. 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. activityStatus:""
  91. },
  92. /**
  93. * 显示分享弹框
  94. */
  95. showshare: function() {
  96. this.setData({
  97. isshowposter: true,
  98. })
  99. },
  100. /**
  101. * 隐藏分享弹框
  102. */
  103. hidemodal: function() {
  104. this.setData({
  105. isshowposter: false,
  106. })
  107. },
  108. /**
  109. * 跳转到门店列表的详情页面
  110. */
  111. gotoDetail(e) {
  112. wx.navigateTo({
  113. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  114. })
  115. },
  116. /**
  117. * 显示分享海报
  118. */
  119. showPoster: function() {
  120. //跳转到海报生成页
  121. wx.navigateTo({
  122. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  123. })
  124. },
  125. swiperChange: function (e) {
  126. this.setData({
  127. swiperCurrent: e.detail.current
  128. });
  129. },
  130. phone: function(e) {
  131. let that = this;
  132. wx.makePhoneCall({
  133. phoneNumber: e.target.dataset.merchantlinkphone
  134. });
  135. },
  136. // 点击查看更多
  137. more: function() {
  138. let that = this;
  139. if (that.data.more == '点击查看更多') {
  140. this.setData({
  141. hidden: "",
  142. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  143. more: "点击收起",
  144. showMore: true
  145. })
  146. } else {
  147. this.setData({
  148. hidden: "hidden",
  149. height: 4 * 140 + 'rpx',
  150. more: "点击查看更多",
  151. showMore: true
  152. })
  153. }
  154. },
  155. //获取当前登录用户信息
  156. getUserInfo: function() {
  157. let that = this;
  158. // 获取用户信息
  159. Http.get({
  160. url: config.api.getScore,
  161. data: {}
  162. })
  163. .then(res => {
  164. console.log(res)
  165. that.getQueryCardStatus()
  166. if (that.data.cardData.cuserId != res.data.id) {
  167. console.log(2222, 6666)
  168. that.setData({
  169. isSamePeople: false
  170. })
  171. }
  172. })
  173. },
  174. //获取卡转赠状态
  175. getQueryCardStatus() {
  176. let that = this;
  177. let param = {
  178. id: this.data.cardData.couponOrderId,
  179. cUserId: this.data.cardData.cuserId,
  180. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  181. }
  182. Http.get({
  183. url: config.api.queryCardStatus,
  184. data: param
  185. })
  186. .then(res => {
  187. console.log(res, 333333333333)
  188. })
  189. .catch(err => {
  190. that.setData({
  191. isReceived: true,
  192. statusText: err.message
  193. })
  194. })
  195. },
  196. receiveCard() {
  197. let that = this;
  198. let param = {
  199. id: this.data.cardData.couponOrderId,
  200. cUserId: this.data.cardData.cuserId,
  201. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  202. }
  203. this.setData({
  204. receivedDisabled: true
  205. })
  206. Http.post({
  207. url: config.api.cardAccept,
  208. data: param
  209. })
  210. .then(res => {
  211. wx.showToast({
  212. title: '领取成功!',
  213. icon: 'none',
  214. duration: 2000,
  215. mask: false
  216. });
  217. wx.reLaunch({
  218. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  219. })
  220. })
  221. .catch(err => {
  222. wx.showToast({
  223. title: err.message,
  224. icon: 'none',
  225. duration: 2000,
  226. mask: false
  227. });
  228. that.setData({
  229. receivedDisabled: false
  230. })
  231. })
  232. },
  233. closeAlert() {
  234. this.setData({
  235. showCardOffer: false
  236. })
  237. },
  238. goback: function() {
  239. wx.switchTab({
  240. url: '/pages/main/index',
  241. })
  242. },
  243. /**
  244. * 点击提交问题单选
  245. */
  246. formSubmit: function(e) {
  247. console.log(e);
  248. let that = this;
  249. /**
  250. * 多选
  251. */
  252. if (e.currentTarget.dataset.flags == 'multi') {
  253. if (that.data.anwserId.length == 0) {
  254. var answserIs = null
  255. } else {
  256. var answserIs = that.data.anwserId.join(",");
  257. }
  258. } else if (e.currentTarget.dataset.flags == 'single') {
  259. var answserIs = e.detail.value;
  260. }
  261. console.log(answserIs)
  262. console.log(e.currentTarget.dataset.questionid)
  263. Http.post({
  264. url: config.api.answerQuestion,
  265. data: {
  266. answer: answserIs,
  267. questionId: e.currentTarget.dataset.questionid
  268. }
  269. })
  270. .then(res => {
  271. that.closeQuestion();
  272. })
  273. .catch(err => {
  274. wx.showToast({
  275. title: err.message,
  276. icon: 'none',
  277. duration: 2000,
  278. mask: false
  279. });
  280. })
  281. },
  282. /**
  283. * 多选
  284. */
  285. checkboxChange: function(e) {
  286. console.log(e)
  287. this.setData({
  288. anwserId: e.detail.value
  289. })
  290. },
  291. closeQuestion: function() {
  292. let that = this;
  293. that.setData({
  294. display: "none",
  295. zIndex: 11,
  296. opacity: 0
  297. })
  298. setTimeout(function() {
  299. that.orderFunc();
  300. }, 500)
  301. },
  302. gotopay: function(e) {
  303. let that = this;
  304. console.log(e);
  305. wx.showLoading();
  306. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50){
  307. wx.navigateTo({
  308. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  309. })
  310. }else{
  311. let formId = e.detail.formId;
  312. var discount = e.detail.target.dataset.discount;
  313. that.setData({
  314. queueData: null,
  315. showbutton: true,
  316. formId: formId
  317. })
  318. Http.get({
  319. url: config.api.getQuestion,
  320. data: {
  321. couponType: JSON.stringify(that.data.data.type)
  322. }
  323. })
  324. .then(res => {
  325. wx.hideLoading();
  326. if (res.data == undefined) {
  327. // 立即购买
  328. that.orderFunc(discount);
  329. that.setData({
  330. flag: false
  331. })
  332. } else if (res.data) {
  333. var animation = wx.createAnimation({});
  334. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  335. duration: 500
  336. })
  337. that.setData({
  338. queueData: animation.export(),
  339. zIndex: 9,
  340. opacity: 1,
  341. display: "block",
  342. questionnaire: JSON.parse(res.data.content),
  343. questionId: res.data.id
  344. });
  345. }
  346. })
  347. .catch(err => {
  348. wx.hideLoading();
  349. wx.showToast({
  350. title: err.message,
  351. icon: 'none',
  352. duration: 2000,
  353. mask: false
  354. });
  355. })
  356. }
  357. },
  358. setIntervalTime(end_time) {
  359. let that = this;
  360. var EndTime = end_time;
  361. var NowTime = new Date().getTime();
  362. var total_micro_second = EndTime - NowTime || [];
  363. // 渲染倒计时时钟
  364. let obj = that.dateformat(total_micro_second);
  365. if (total_micro_second > 0) {
  366. that.setData({
  367. clock: obj,
  368. day: obj.a1,
  369. hour: obj.b1,
  370. min: obj.c1,
  371. sec: obj.d1,
  372. })
  373. } else {
  374. that.setData({
  375. clock: "00",
  376. day: "00",
  377. hour: "00",
  378. min: "00",
  379. sec: "00",
  380. })
  381. //如果倒计时结束,需要重新查询一下券的状态
  382. // 给getDetail一个标识
  383. that.getDetail(that.data.couponChannelId, 'endclock');
  384. }
  385. total_micro_second -= 1000;
  386. },
  387. countdown: function(end_time) {
  388. let that = this;
  389. that.setIntervalTime(end_time);
  390. that.data.setInterval = setInterval(function() {
  391. that.setIntervalTime(end_time);
  392. }, 1000)
  393. },
  394. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  395. dateformat(micro_second) {
  396. // 总秒数
  397. var second = Math.floor(micro_second / 1000);
  398. // 天数
  399. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  400. // 小时
  401. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  402. // 分钟
  403. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  404. // 秒
  405. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  406. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  407. return {
  408. a1: day,
  409. b1: hr,
  410. c1: min,
  411. d1: sec
  412. }
  413. },
  414. /**
  415. * 获取用户信息
  416. */
  417. onLoad(options) {
  418. let that = this;
  419. wx.showLoading({
  420. title: "加载中..."
  421. });
  422. that.setData({
  423. onshow: false
  424. })
  425. if (options && options.couponChannelId){
  426. that.getDetail(options.couponChannelId, 'notendclock');
  427. }
  428. /**
  429. * 转赠判断
  430. */
  431. if (options.cuserId) {
  432. this.setData({
  433. showCardOffer: true,
  434. cardData: options
  435. })
  436. this.getUserInfo()
  437. }
  438. that.setData({
  439. couponChannelId: options.couponChannelId,
  440. title: that.data.data.title ? that.data.data.title : '',
  441. });
  442. if (options.cardType) {
  443. that.setData({
  444. cardType: options.cardType
  445. })
  446. }
  447. },
  448. getDetail: function(couponChannelId, flag) {
  449. let that = this;
  450. var parmer = {
  451. url: config.api.couponDetail,
  452. data: {
  453. couponChannelId: couponChannelId
  454. }
  455. };
  456. Http.get(parmer)
  457. .then(res => {
  458. that.setData({
  459. couponId: res.data.couponId
  460. })
  461. that.setData({
  462. showPage: true
  463. })
  464. if (res && res.data && res.data.detailPicture) {
  465. that.setData({
  466. detailPicture: JSON.parse(res.data.detailPicture)
  467. })
  468. }
  469. if (res && res.data && res.data.coverPicture) {
  470. that.setData({
  471. coverPicture: JSON.parse(res.data.coverPicture)
  472. })
  473. }
  474. if (res && res.data && res.data.conditions){
  475. that.setData({
  476. limitCondition: JSON.parse(res.data.conditions).type
  477. })
  478. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min==0)){
  479. that.setData({
  480. minLimit: JSON.parse(res.data.conditions).min
  481. })
  482. }
  483. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  484. that.setData({
  485. maxLimit: JSON.parse(res.data.conditions).max
  486. })
  487. }
  488. }
  489. /**
  490. * 将优惠券优惠卡的详情的BarTitle
  491. * 设置成券的名称
  492. */
  493. // wx.setNavigationBarTitle({
  494. // title: res.data.title
  495. // })
  496. that.setData({
  497. barTitle: res.data.title
  498. })
  499. var EndTime = res.data.validStartDate;
  500. var NowTime = new Date().getTime();
  501. /**
  502. * activityStatus==0 活动未开始
  503. * activityStatus==1 活动已开始
  504. * flag == endclock 说明倒计时已经结束
  505. */
  506. if (res.data.endTime && res.data.beginTime) {
  507. that.setData({
  508. begin_time: res.data.beginTime,
  509. end_time: res.data.endTime,
  510. activityStatus: res.data.activityStatus
  511. })
  512. if (res.data.activityStatus == 0 && flag != 'endclock') {
  513. that.countdown(res.data.beginTime);
  514. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  515. that.countdown(res.data.endTime);
  516. } else {
  517. clearInterval(that.data.setInterval)
  518. }
  519. if (res.data.activityStatus == 0) {
  520. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  521. if (util.timechuo(beginTime).indexOf('-') == 0) {
  522. that.setData({
  523. beginTime: "活动已结束",
  524. });
  525. } else {
  526. that.setData({
  527. beginTime: util.timechuo(beginTime)
  528. });
  529. }
  530. } else {
  531. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  532. if (util.timechuo(endTime).indexOf('-') == 0) {
  533. that.setData({
  534. endtime: "活动已结束",
  535. });
  536. } else {
  537. that.setData({
  538. endtime: util.timechuo(endTime)
  539. });
  540. }
  541. }
  542. }
  543. wx.hideLoading();
  544. that.setData({
  545. data: res.data
  546. });
  547. if (that.data.data.merchantVoList && that.data.data.merchantVoList.length <= 4) {
  548. that.setData({
  549. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  550. showMore: false
  551. })
  552. } else if (that.data.data.merchantVoList && that.data.data.merchantVoList.length > 4) {
  553. that.setData({
  554. height: 4 * 140 + 'rpx'
  555. })
  556. }
  557. if (res.data.validType == 1) {
  558. that.setData({
  559. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  560. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  561. });
  562. } else {
  563. if (res.data.validDays) {
  564. that.setData({
  565. validDays: res.data.validDays
  566. });
  567. }
  568. }
  569. }).catch(err => {
  570. wx.showToast({
  571. title: err.message,
  572. icon: 'none',
  573. duration: 2000,
  574. mask: false
  575. });
  576. })
  577. },
  578. /**
  579. * 邀请好友继续砍价
  580. */
  581. inviteFriend: function(e) {
  582. let that = this;
  583. let formId = e.detail.formId;
  584. that.setData({
  585. formId: formId,
  586. showbutton1: true
  587. })
  588. that.orderFunc("discount");
  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 && this.data.activityStatus!=0) {
  958. this.countdown(this.data.end_time)
  959. }
  960. else if (this.data.begin_time && this.data.activityStatus == 0) {
  961. this.countdown(this.data.begin_time)
  962. }
  963. },
  964. onUnload: function() {
  965. let that = this;
  966. clearInterval(that.data.setInterval)
  967. },
  968. onHide: function() {
  969. let that = this;
  970. clearInterval(that.data.setInterval)
  971. },
  972. onShareAppMessage: function(options) {
  973. var that = this;
  974. console.log(options)
  975. var shareObj = {
  976. title: that.data.data.title,
  977. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  978. success: function(res) {
  979. if (res.errMsg == 'shareAppMessage:ok') {}
  980. },
  981. fail: function(error) {
  982. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  983. }
  984. };
  985. // 来自页面内的按钮的转发
  986. if (options.from == 'button') {
  987. var eData = options.target.dataset.id;
  988. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  989. }
  990. // 返回shareObj
  991. return shareObj;
  992. },
  993. // 下拉刷新
  994. onPullDownRefresh: function() {
  995. this.getDetail(this.data.couponChannelId);
  996. wx.stopPullDownRefresh()
  997. }
  998. });