C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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