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.

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