C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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