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.

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