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.

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