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.

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