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.

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