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.

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