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.

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