C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

998 行
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. },
  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. showbutton1: true
  585. })
  586. that.orderFunc("discount");
  587. },
  588. /**
  589. * 支付订单更新
  590. */
  591. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  592. let that = this;
  593. // 支付成功
  594. Http.post({
  595. url: config.api.payOrderUpdate,
  596. data: {
  597. payOrderId: payOrderId,
  598. orderId: orderId,
  599. status: status,
  600. reason: reason
  601. }
  602. })
  603. .then(res => {
  604. wx.hideLoading()
  605. // 有价券
  606. if (!type && type != 'free') {
  607. wx.navigateTo({
  608. url: `/pages/order/detail/index?orderId=${
  609. orderId
  610. }&cardIf=true`
  611. });
  612. } else if (type == 'free') {
  613. wx.navigateTo({
  614. url: `/pages/order/detail/index?orderId=${
  615. orderId
  616. }`
  617. });
  618. }
  619. })
  620. .catch(err => {
  621. console.log(err);
  622. if (!type) {
  623. setTimeout(function() {
  624. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  625. }, 2000)
  626. }
  627. })
  628. },
  629. checkPhoneStatus: function() {
  630. let that = this;
  631. Http.get({
  632. url: config.api.checkPhoneStatus,
  633. data: {}
  634. })
  635. .then(res => {
  636. console.log(666, '授权成功!')
  637. that.receiveCard()
  638. })
  639. .catch(err => {
  640. if (err.code == 11005) {
  641. /**
  642. * 手机号没有授权,将值传到用户手机号授权的页面
  643. *
  644. */
  645. wx.redirectTo({
  646. 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,
  647. });
  648. } else if (err.code == 11006) {
  649. // 用户手机已加密
  650. wx.redirectTo({
  651. 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,
  652. });
  653. } else {
  654. wx.showToast({
  655. title: err.message,
  656. icon: 'none',
  657. duration: 2000,
  658. mask: false
  659. });
  660. }
  661. })
  662. },
  663. /**
  664. * 发起支付
  665. */
  666. orderFunc(discount) {
  667. let that = this;
  668. Http.get({
  669. url: config.api.checkPhoneStatus,
  670. data: {}
  671. })
  672. .then(res => {
  673. // 发起砍价
  674. if (discount == 'discount') {
  675. var data = {
  676. couponChannelId: "" + that.data.couponChannelId,
  677. couponId: "" + that.data.couponId,
  678. formId: "" + that.data.formId,
  679. press: true
  680. }
  681. } else if (discount == 'discount1') {
  682. var data = {
  683. couponChannelId: "" + that.data.couponChannelId,
  684. couponId: "" + that.data.couponId,
  685. formId: "" + that.data.formId,
  686. press: false
  687. }
  688. } else if (that.data.couponChannelId == null) {
  689. var data = {
  690. couponId: "" + that.data.couponId,
  691. formId: "" + that.data.formId,
  692. };
  693. } else {
  694. var data = {
  695. couponChannelId: "" + that.data.couponChannelId,
  696. couponId: "" + that.data.couponId,
  697. formId: "" + that.data.formId,
  698. }
  699. }
  700. /**
  701. * orderSave 下单
  702. */
  703. return Http.post({
  704. url: config.api.orderSave,
  705. data: data
  706. });
  707. })
  708. .catch(err => {
  709. wx.hideLoading()
  710. that.setData({
  711. showbutton: false,
  712. showbutton1: false
  713. })
  714. if (err.code == 2011) {
  715. wx.showToast({
  716. title: "商户信息没找到",
  717. image: './../../../assets/images/fail.png',
  718. duration: 2000,
  719. mask: false
  720. });
  721. } else if (err.code == 2013) {
  722. wx.showToast({
  723. title: "商户信息禁用",
  724. image: './../../../assets/images/fail.png',
  725. duration: 2000,
  726. mask: false
  727. });
  728. } else if (err.code == 3000) {
  729. wx.showToast({
  730. title: "库存不足",
  731. image: './../../../assets/images/fail.png',
  732. duration: 2000,
  733. mask: false
  734. });
  735. } else if (err.code == 3001) {
  736. wx.showToast({
  737. title: "您已超过限购",
  738. image: './../../../assets/images/fail.png',
  739. duration: 2000,
  740. mask: false
  741. });
  742. } else if (err.code == 3002) {
  743. wx.showToast({
  744. title: "订单失败",
  745. image: './../../../assets/images/fail.png',
  746. duration: 2000,
  747. mask: false
  748. });
  749. } else if (err.code == 3003) {
  750. wx.showToast({
  751. title: "订单不存在",
  752. image: './../../../assets/images/fail.png',
  753. duration: 2000,
  754. mask: false
  755. });
  756. } else if (err.code == 3004) {
  757. wx.showToast({
  758. title: "订单不存在",
  759. image: './../../../assets/images/fail.png',
  760. duration: 2000,
  761. mask: false
  762. });
  763. } else if (err.code == 4003) {
  764. wx.showToast({
  765. title: "卡券已作废",
  766. image: './../../../assets/images/fail.png',
  767. duration: 2000,
  768. mask: false
  769. });
  770. } else if (err.code == 3012) {
  771. that.getUnPaidOrder(that.data.couponId);
  772. } else if (err.code == 11005) {
  773. /**
  774. * 将值传到用户手机号授权的页面
  775. *
  776. */
  777. wx.redirectTo({
  778. url: "/pages/getphoneInfo/index?couponChannelId=" +
  779. that.data.couponChannelId
  780. });
  781. } else if (err.code == 11006) {
  782. // 用户手机已加密
  783. wx.redirectTo({
  784. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  785. that.data.couponChannelId
  786. });
  787. } else {
  788. wx.showToast({
  789. title: err.message,
  790. icon: 'none',
  791. duration: 2000,
  792. mask: false
  793. });
  794. }
  795. })
  796. .then(res => {
  797. if (discount != 'discount') {
  798. if (typeof(res) != "undefined") {
  799. let orderId = "" + res.data.id;
  800. that.setData({
  801. orderId: orderId
  802. });
  803. if (res.data.payment > 0) {
  804. // 支付金额不为0
  805. /**
  806. * 支付订单创建
  807. */
  808. Http.post({
  809. url: config.api.payOrderCreate,
  810. data: {
  811. orderId: orderId
  812. }
  813. })
  814. .then(res => {
  815. var payOrderId = "" + res.data.payOrderId;
  816. wx.hideLoading();
  817. wx.requestPayment({
  818. timeStamp: res.data.timeStamp,
  819. nonceStr: res.data.nonceStr,
  820. package: res.data.package,
  821. signType: (res.data.signType) ? res.data.signType : "MD5",
  822. paySign: res.data.paySign,
  823. success: res => {
  824. wx.showLoading({
  825. title: '订单正在处理中...',
  826. })
  827. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  828. if (res.errMsg == "requestPayment:ok") {
  829. /**
  830. * 用户支付成功以后跳转到券包列表
  831. */
  832. if (that.data.cardType == 100) {
  833. wx.setStorage({
  834. key: 'couponNum2',
  835. data: "couponNum2"
  836. })
  837. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  838. wx.setStorage({
  839. key: 'couponNum',
  840. data: "couponNum"
  841. })
  842. }
  843. }
  844. },
  845. fail: res => {
  846. wx.hideLoading();
  847. /**
  848. * 支付失败,需要更新订单的状态
  849. */
  850. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  851. that.setData({
  852. showbutton: false
  853. })
  854. return;
  855. },
  856. complete: res => {}
  857. });
  858. /// End payment --------
  859. })
  860. .catch(err => {
  861. wx.hideLoading();
  862. wx.showToast({
  863. title: err.message,
  864. icon: 'none',
  865. duration: 2000,
  866. mask: false
  867. });
  868. })
  869. } else {
  870. // 免费券
  871. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  872. if (that.data.cardType == 100) {
  873. wx.setStorage({
  874. key: 'couponNum2',
  875. data: "couponNum2"
  876. })
  877. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  878. wx.setStorage({
  879. key: 'couponNum',
  880. data: "couponNum"
  881. })
  882. }
  883. }
  884. }
  885. } else {
  886. if (res) {
  887. wx.navigateTo({
  888. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  889. })
  890. }
  891. }
  892. })
  893. },
  894. // 获得未支付的订单
  895. getUnPaidOrder(couponId){
  896. let that = this;
  897. Http.get({
  898. url: config.api.getUnPaidOrder,
  899. data: {
  900. couponId: couponId
  901. }
  902. }).then(res=>{
  903. that.setData({
  904. disOrderNumber: res.data.orderNumber,
  905. })
  906. if (res.data&&res.data.pressEndDate){
  907. that.setData({
  908. dispressEndDate:true
  909. })
  910. }else{
  911. that.setData({
  912. dispressEndDate: false
  913. })
  914. }
  915. if (that.data.dispressEndDate){
  916. wx.showModal({
  917. title: '提示',
  918. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  919. confirmText:"我的砍价",
  920. success: function (res) {
  921. if (res.confirm) {
  922. wx.navigateTo({
  923. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  924. })
  925. }
  926. }
  927. })
  928. } else{
  929. wx.showModal({
  930. title: '提示',
  931. content: '您有未支付订单,请先进行支付',
  932. confirmText: "去支付",
  933. success: function (res) {
  934. if (res.confirm) {
  935. wx.navigateTo({
  936. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  937. })
  938. }
  939. }
  940. })
  941. }
  942. }).catch(error=>{
  943. wx.showToast({
  944. title: error.message,
  945. icon: "none",
  946. duration: 3000
  947. })
  948. })
  949. },
  950. onShow() {
  951. this.setData({
  952. showbutton: false,
  953. showbutton1: false
  954. })
  955. if (this.data.end_time) {
  956. this.countdown(this.data.end_time)
  957. }
  958. },
  959. onUnload: function() {
  960. let that = this;
  961. clearInterval(that.data.setInterval)
  962. },
  963. onHide: function() {
  964. let that = this;
  965. clearInterval(that.data.setInterval)
  966. },
  967. onShareAppMessage: function(options) {
  968. var that = this;
  969. console.log(options)
  970. var shareObj = {
  971. title: that.data.data.title,
  972. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  973. success: function(res) {
  974. if (res.errMsg == 'shareAppMessage:ok') {}
  975. },
  976. fail: function(error) {
  977. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  978. }
  979. };
  980. // 来自页面内的按钮的转发
  981. if (options.from == 'button') {
  982. var eData = options.target.dataset.id;
  983. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  984. }
  985. // 返回shareObj
  986. return shareObj;
  987. },
  988. // 下拉刷新
  989. onPullDownRefresh: function() {
  990. this.getDetail(this.data.couponChannelId);
  991. wx.stopPullDownRefresh()
  992. }
  993. });