C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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