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.

992 line
28 KiB

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