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 lines
27 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. console.log(e)
  107. wx.navigateTo({
  108. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  109. })
  110. },
  111. /**
  112. * 显示分享海报
  113. */
  114. showPoster: function() {
  115. //跳转到海报生成页
  116. wx.navigateTo({
  117. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  118. })
  119. },
  120. swiperChange: function (e) {
  121. this.setData({
  122. swiperCurrent: e.detail.current
  123. });
  124. },
  125. phone: function(e) {
  126. let that = this;
  127. wx.makePhoneCall({
  128. phoneNumber: e.target.dataset.merchantlinkphone
  129. });
  130. },
  131. // 点击查看更多
  132. more: function() {
  133. let that = this;
  134. if (that.data.more == '点击查看更多') {
  135. this.setData({
  136. hidden: "",
  137. height: that.data.data.merchantVoList.length * 140 + 'rpx',
  138. more: "点击收起",
  139. showMore: true
  140. })
  141. } else {
  142. this.setData({
  143. hidden: "hidden",
  144. height: 4 * 140 + 'rpx',
  145. more: "点击查看更多",
  146. showMore: true
  147. })
  148. }
  149. },
  150. //获取当前登录用户信息
  151. getUserInfo: function() {
  152. let that = this;
  153. // 获取用户信息
  154. Http.get({
  155. url: config.api.getScore,
  156. data: {}
  157. })
  158. .then(res => {
  159. console.log(res)
  160. that.getQueryCardStatus()
  161. if (that.data.cardData.cuserId != res.data.id) {
  162. console.log(2222, 6666)
  163. that.setData({
  164. isSamePeople: false
  165. })
  166. }
  167. })
  168. },
  169. //获取卡转赠状态
  170. getQueryCardStatus() {
  171. let that = this;
  172. let param = {
  173. id: this.data.cardData.couponOrderId,
  174. cUserId: this.data.cardData.cuserId,
  175. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  176. }
  177. Http.get({
  178. url: config.api.queryCardStatus,
  179. data: param
  180. })
  181. .then(res => {
  182. console.log(res, 333333333333)
  183. })
  184. .catch(err => {
  185. that.setData({
  186. isReceived: true,
  187. statusText: err.message
  188. })
  189. })
  190. },
  191. receiveCard() {
  192. let that = this;
  193. let param = {
  194. id: this.data.cardData.couponOrderId,
  195. cUserId: this.data.cardData.cuserId,
  196. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  197. }
  198. this.setData({
  199. receivedDisabled: true
  200. })
  201. Http.post({
  202. url: config.api.cardAccept,
  203. data: param
  204. })
  205. .then(res => {
  206. wx.showToast({
  207. title: '领取成功!',
  208. icon: 'none',
  209. duration: 2000,
  210. mask: false
  211. });
  212. wx.reLaunch({
  213. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  214. })
  215. })
  216. .catch(err => {
  217. wx.showToast({
  218. title: err.message,
  219. icon: 'none',
  220. duration: 2000,
  221. mask: false
  222. });
  223. that.setData({
  224. receivedDisabled: false
  225. })
  226. })
  227. },
  228. closeAlert() {
  229. this.setData({
  230. showCardOffer: false
  231. })
  232. },
  233. goback: function() {
  234. wx.switchTab({
  235. url: '/pages/main/index',
  236. })
  237. },
  238. /**
  239. * 点击提交问题单选
  240. */
  241. formSubmit: function(e) {
  242. console.log(e);
  243. let that = this;
  244. /**
  245. * 多选
  246. */
  247. if (e.currentTarget.dataset.flags == 'multi') {
  248. if (that.data.anwserId.length == 0) {
  249. var answserIs = null
  250. } else {
  251. var answserIs = that.data.anwserId.join(",");
  252. }
  253. } else if (e.currentTarget.dataset.flags == 'single') {
  254. var answserIs = e.detail.value;
  255. }
  256. console.log(answserIs)
  257. console.log(e.currentTarget.dataset.questionid)
  258. Http.post({
  259. url: config.api.answerQuestion,
  260. data: {
  261. answer: answserIs,
  262. questionId: e.currentTarget.dataset.questionid
  263. }
  264. })
  265. .then(res => {
  266. that.closeQuestion();
  267. })
  268. .catch(err => {
  269. wx.showToast({
  270. title: err.message,
  271. icon: 'none',
  272. duration: 2000,
  273. mask: false
  274. });
  275. })
  276. },
  277. /**
  278. * 多选
  279. */
  280. checkboxChange: function(e) {
  281. console.log(e)
  282. this.setData({
  283. anwserId: e.detail.value
  284. })
  285. },
  286. closeQuestion: function() {
  287. let that = this;
  288. that.setData({
  289. display: "none",
  290. zIndex: 11,
  291. opacity: 0
  292. })
  293. setTimeout(function() {
  294. that.orderFunc();
  295. }, 500)
  296. },
  297. gotopay: function(e) {
  298. let that = this;
  299. console.log(e);
  300. wx.showLoading();
  301. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50){
  302. wx.navigateTo({
  303. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  304. })
  305. }else{
  306. let formId = e.detail.formId;
  307. var discount = e.detail.target.dataset.discount;
  308. that.setData({
  309. queueData: null,
  310. showbutton: true,
  311. formId: formId
  312. })
  313. Http.get({
  314. url: config.api.getQuestion,
  315. data: {
  316. couponType: JSON.stringify(that.data.data.type)
  317. }
  318. })
  319. .then(res => {
  320. wx.hideLoading();
  321. if (res.data == undefined) {
  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. if (discount == 'discount') {
  668. var data = {
  669. couponChannelId: "" + that.data.couponChannelId,
  670. couponId: "" + that.data.couponId,
  671. formId: "" + that.data.formId,
  672. press: true
  673. }
  674. } else if (discount == 'discount1') {
  675. var data = {
  676. couponChannelId: "" + that.data.couponChannelId,
  677. couponId: "" + that.data.couponId,
  678. formId: "" + that.data.formId,
  679. press: false
  680. }
  681. } else if (that.data.couponChannelId == null) {
  682. var data = {
  683. couponId: "" + that.data.couponId,
  684. formId: "" + that.data.formId,
  685. };
  686. } else {
  687. var data = {
  688. couponChannelId: "" + that.data.couponChannelId,
  689. couponId: "" + that.data.couponId,
  690. formId: "" + that.data.formId,
  691. }
  692. }
  693. /**
  694. * orderSave 下单
  695. */
  696. return Http.post({
  697. url: config.api.orderSave,
  698. data: data
  699. });
  700. })
  701. .catch(err => {
  702. wx.hideLoading()
  703. that.setData({
  704. showbutton: false,
  705. showbutton1: false
  706. })
  707. if (err.code == 2011) {
  708. wx.showToast({
  709. title: "商户信息没找到",
  710. image: './../../../assets/images/fail.png',
  711. duration: 2000,
  712. mask: false
  713. });
  714. } else if (err.code == 2013) {
  715. wx.showToast({
  716. title: "商户信息禁用",
  717. image: './../../../assets/images/fail.png',
  718. duration: 2000,
  719. mask: false
  720. });
  721. } else if (err.code == 3000) {
  722. wx.showToast({
  723. title: "库存不足",
  724. image: './../../../assets/images/fail.png',
  725. duration: 2000,
  726. mask: false
  727. });
  728. } else if (err.code == 3001) {
  729. wx.showToast({
  730. title: "您已超过限购",
  731. image: './../../../assets/images/fail.png',
  732. duration: 2000,
  733. mask: false
  734. });
  735. } else if (err.code == 3002) {
  736. wx.showToast({
  737. title: "订单失败",
  738. image: './../../../assets/images/fail.png',
  739. duration: 2000,
  740. mask: false
  741. });
  742. } else if (err.code == 3003) {
  743. wx.showToast({
  744. title: "订单不存在",
  745. image: './../../../assets/images/fail.png',
  746. duration: 2000,
  747. mask: false
  748. });
  749. } else if (err.code == 3004) {
  750. wx.showToast({
  751. title: "订单不存在",
  752. image: './../../../assets/images/fail.png',
  753. duration: 2000,
  754. mask: false
  755. });
  756. } else if (err.code == 4003) {
  757. wx.showToast({
  758. title: "卡券已作废",
  759. image: './../../../assets/images/fail.png',
  760. duration: 2000,
  761. mask: false
  762. });
  763. } else if (err.code == 3012) {
  764. that.getUnPaidOrder(that.data.couponId);
  765. } else if (err.code == 11005) {
  766. /**
  767. * 将值传到用户手机号授权的页面
  768. *
  769. */
  770. wx.redirectTo({
  771. url: "/pages/getphoneInfo/index?couponChannelId=" +
  772. that.data.couponChannelId
  773. });
  774. } else if (err.code == 11006) {
  775. // 用户手机已加密
  776. wx.redirectTo({
  777. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  778. that.data.couponChannelId
  779. });
  780. } else {
  781. wx.showToast({
  782. title: err.message,
  783. icon: 'none',
  784. duration: 2000,
  785. mask: false
  786. });
  787. }
  788. })
  789. .then(res => {
  790. if (discount != 'discount') {
  791. if (typeof(res) != "undefined") {
  792. let orderId = "" + res.data.id;
  793. that.setData({
  794. orderId: orderId
  795. });
  796. if (res.data.payment > 0) {
  797. // 支付金额不为0
  798. /**
  799. * 支付订单创建
  800. */
  801. Http.post({
  802. url: config.api.payOrderCreate,
  803. data: {
  804. orderId: orderId
  805. }
  806. })
  807. .then(res => {
  808. var payOrderId = "" + res.data.payOrderId;
  809. wx.hideLoading();
  810. wx.requestPayment({
  811. timeStamp: res.data.timeStamp,
  812. nonceStr: res.data.nonceStr,
  813. package: res.data.package,
  814. signType: (res.data.signType) ? res.data.signType : "MD5",
  815. paySign: res.data.paySign,
  816. success: res => {
  817. wx.showLoading({
  818. title: '订单正在处理中...',
  819. })
  820. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  821. if (res.errMsg == "requestPayment:ok") {
  822. /**
  823. * 用户支付成功以后跳转到券包列表
  824. */
  825. if (that.data.cardType == 100) {
  826. wx.setStorage({
  827. key: 'couponNum2',
  828. data: "couponNum2"
  829. })
  830. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  831. wx.setStorage({
  832. key: 'couponNum',
  833. data: "couponNum"
  834. })
  835. }
  836. }
  837. },
  838. fail: res => {
  839. wx.hideLoading();
  840. /**
  841. * 支付失败,需要更新订单的状态
  842. */
  843. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  844. that.setData({
  845. showbutton: false
  846. })
  847. return;
  848. },
  849. complete: res => {}
  850. });
  851. /// End payment --------
  852. })
  853. .catch(err => {
  854. wx.hideLoading();
  855. wx.showToast({
  856. title: err.message,
  857. icon: 'none',
  858. duration: 2000,
  859. mask: false
  860. });
  861. })
  862. } else {
  863. // 免费券
  864. that.payOrderUpdate(orderId, "0", 1, '', 'free');
  865. if (that.data.cardType == 100) {
  866. wx.setStorage({
  867. key: 'couponNum2',
  868. data: "couponNum2"
  869. })
  870. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  871. wx.setStorage({
  872. key: 'couponNum',
  873. data: "couponNum"
  874. })
  875. }
  876. }
  877. }
  878. } else {
  879. if (res) {
  880. wx.navigateTo({
  881. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  882. })
  883. }
  884. }
  885. })
  886. },
  887. // 获得未支付的订单
  888. getUnPaidOrder(couponId){
  889. let that = this;
  890. Http.get({
  891. url: config.api.getUnPaidOrder,
  892. data: {
  893. couponId: couponId
  894. }
  895. }).then(res=>{
  896. that.setData({
  897. disOrderNumber: res.data.orderNumber,
  898. })
  899. if (res.data&&res.data.pressEndDate){
  900. that.setData({
  901. dispressEndDate:true
  902. })
  903. }else{
  904. that.setData({
  905. dispressEndDate: false
  906. })
  907. }
  908. if (that.data.dispressEndDate){
  909. wx.showModal({
  910. title: '提示',
  911. content: "您有未支付砍价订单,请先进行支付",
  912. confirmText:"去支付",
  913. success: function (res) {
  914. if (res.confirm) {
  915. wx.navigateTo({
  916. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  917. })
  918. }
  919. }
  920. })
  921. } else{
  922. wx.showModal({
  923. title: '提示',
  924. content: '您有未支付订单,请先进行支付',
  925. confirmText: "去支付",
  926. success: function (res) {
  927. if (res.confirm) {
  928. wx.navigateTo({
  929. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  930. })
  931. }
  932. }
  933. })
  934. }
  935. }).catch(error=>{
  936. wx.showToast({
  937. title: error.message,
  938. icon: "none",
  939. duration: 3000
  940. })
  941. })
  942. },
  943. onShow() {
  944. this.setData({
  945. showbutton: false,
  946. showbutton1: false
  947. })
  948. if (this.data.end_time) {
  949. this.countdown(this.data.end_time)
  950. }
  951. },
  952. onUnload: function() {
  953. let that = this;
  954. clearInterval(that.data.setInterval)
  955. },
  956. onHide: function() {
  957. let that = this;
  958. clearInterval(that.data.setInterval)
  959. },
  960. onShareAppMessage: function(options) {
  961. var that = this;
  962. console.log(options)
  963. var shareObj = {
  964. title: that.data.data.title,
  965. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  966. success: function(res) {
  967. if (res.errMsg == 'shareAppMessage:ok') {}
  968. },
  969. fail: function(error) {
  970. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  971. }
  972. };
  973. // 来自页面内的按钮的转发
  974. if (options.from == 'button') {
  975. var eData = options.target.dataset.id;
  976. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  977. }
  978. // 返回shareObj
  979. return shareObj;
  980. },
  981. // 下拉刷新
  982. onPullDownRefresh: function() {
  983. this.getDetail(this.data.couponChannelId);
  984. wx.stopPullDownRefresh()
  985. }
  986. });