C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1257 рядки
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. this.setData({
  506. mouldType: app.globalData.mouldType,
  507. })
  508. let that = this;
  509. if (options.g) {
  510. app.globalData.havePlayEd1 = true;
  511. }
  512. wx.showLoading({
  513. title: "加载中..."
  514. });
  515. that.setData({
  516. onshow: false
  517. })
  518. if (options && (options.couponChannelId || options.couponIds)) {
  519. if (options.couponIds) {
  520. this.setData({
  521. couponIds: options.couponIds
  522. })
  523. that.getDetail(options.couponIds, 'notendclock');
  524. } else {
  525. that.getDetail(options.couponChannelId, 'notendclock');
  526. }
  527. }
  528. /**
  529. * 转赠判断
  530. */
  531. if (options.cuserId) {
  532. this.setData({
  533. showCardOffer: true,
  534. cardData: options
  535. })
  536. this.getUserInfo()
  537. }
  538. that.setData({
  539. couponChannelId: options.couponChannelId,
  540. title: that.data.data.title ? that.data.data.title : '',
  541. });
  542. if (options.cardType) {
  543. that.setData({
  544. cardType: options.cardType
  545. })
  546. }
  547. },
  548. getHtml(couponChannelId) {
  549. Http.get({
  550. url: config.api.couponHtmlDetail,
  551. data: {
  552. couponChannelId: couponChannelId
  553. }
  554. }).then(res => {
  555. console.log(res)
  556. if (res.code == 200 && res.data.html) {
  557. this.setData({
  558. curHtml: decodeURI(res.data.html),
  559. type: res.data.type
  560. })
  561. app.globalData.curHtml = this.data.curHtml;
  562. console.log(app.globalData.curHtml)
  563. }
  564. })
  565. },
  566. getCouponPriceAndStock(couponChannelId) {//获取券价格与库存
  567. Http.get({
  568. url: config.api.couponPriceAndStock,
  569. data: {
  570. couponChannelId
  571. }
  572. }).then(res => {
  573. let tempBoj = JSON.parse(res.data)
  574. console.log(tempBoj, "$");
  575. this.setData({
  576. priceAndStockObj: tempBoj
  577. })
  578. })
  579. },
  580. getCouponMerchant(couponChannelId) {//获取适用门店
  581. Http.get({
  582. url: config.api.couponMerchant,
  583. data: {
  584. couponChannelId: couponChannelId
  585. }
  586. }).then(res => {
  587. const keys = Object.keys(res.data)
  588. const mallList = []
  589. keys.forEach(item => {
  590. const arr = item.split('|')
  591. const obj = {
  592. tenantId: arr[0],
  593. mallName: arr[1],
  594. merchantVoList: res.data[item],
  595. expand: true
  596. }
  597. mallList.push(obj)
  598. })
  599. this.setData({
  600. mallList: mallList
  601. })
  602. console.log(this.data.mallList, 'mallList');
  603. })
  604. },
  605. getDetail: function (couponChannelId, flag) {
  606. let that = this;
  607. let data = {};
  608. that.getCouponMerchant(couponChannelId);//获取适用门店
  609. that.getCouponPriceAndStock(couponChannelId);//获取券价格和库存
  610. if (that.data.couponIds) {
  611. data.couponId = couponChannelId
  612. } else {
  613. data.couponChannelId = couponChannelId
  614. }
  615. var parmer = {
  616. url: config.api.couponDetail,
  617. data: data
  618. };
  619. Http.get(parmer)
  620. .then(res => {
  621. //aaa
  622. if (res.data.contentType != undefined && res.data.contentType == 1) {
  623. //获取图文展示详情html
  624. this.setData({
  625. contentType: res.data.contentType
  626. })
  627. this.getHtml(couponChannelId);
  628. }
  629. that.setData({
  630. couponId: res.data.couponId
  631. })
  632. that.setData({
  633. showPage: true
  634. })
  635. if (res && res.data && res.data.detailPicture) {
  636. that.setData({
  637. detailPicture: JSON.parse(res.data.detailPicture)
  638. })
  639. }
  640. if (res && res.data && res.data.coverPicture) {
  641. that.setData({
  642. coverPicture: JSON.parse(res.data.coverPicture)
  643. })
  644. }
  645. if (res && res.data && res.data.conditions) {
  646. that.setData({
  647. limitCondition: JSON.parse(res.data.conditions).type
  648. })
  649. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  650. that.setData({
  651. minLimit: JSON.parse(res.data.conditions).min
  652. })
  653. }
  654. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  655. that.setData({
  656. maxLimit: JSON.parse(res.data.conditions).max
  657. })
  658. }
  659. }
  660. /**
  661. * 将优惠券优惠卡的详情的BarTitle
  662. * 设置成券的名称
  663. */
  664. // wx.setNavigationBarTitle({
  665. // title: res.data.title
  666. // })
  667. that.setData({
  668. barTitle: res.data.title
  669. })
  670. var EndTime = res.data.validStartDate;
  671. var NowTime = new Date().getTime();
  672. /**
  673. * activityStatus==0 活动未开始
  674. * activityStatus==1 活动已开始
  675. * flag == endclock 说明倒计时已经结束
  676. */
  677. if (res.data.endTime && res.data.beginTime) {
  678. that.setData({
  679. begin_time: res.data.beginTime,
  680. end_time: res.data.endTime,
  681. activityStatus: res.data.activityStatus ? res.data.activityStatus : ''
  682. })
  683. if (res.data.activityStatus == 0 && flag != 'endclock') {
  684. that.countdown(res.data.beginTime);
  685. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  686. that.countdown(res.data.endTime);
  687. } else {
  688. clearInterval(that.data.setInterval)
  689. that.countdown(res.data.endTime);
  690. }
  691. if (res.data.activityStatus == 0) {
  692. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  693. if (util.timechuo(beginTime).indexOf('-') == 0) {
  694. that.setData({
  695. beginTime: "活动已结束",
  696. });
  697. } else {
  698. that.setData({
  699. beginTime: util.timechuo(beginTime)
  700. });
  701. }
  702. } else {
  703. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  704. if (util.timechuo(endTime).indexOf('-') == 0) {
  705. that.setData({
  706. endtime: "活动已结束",
  707. });
  708. } else {
  709. that.setData({
  710. endtime: util.timechuo(endTime)
  711. });
  712. }
  713. }
  714. }
  715. wx.hideLoading();
  716. that.setData({
  717. data: res.data,
  718. });
  719. if (res.data.type == 10) {
  720. that.setData({
  721. salePriceStr: res.data.salePriceStr,
  722. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  723. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  724. priceStr: res.data.priceStr,
  725. tailPriceStr: res.data.tailPriceStr,
  726. origPriceStr: res.data.origPriceStr
  727. })
  728. }
  729. if (res.data.validType == 1) {
  730. that.setData({
  731. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  732. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  733. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  734. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  735. });
  736. } else {
  737. if (res.data.validDays) {
  738. that.setData({
  739. validDays: res.data.validDays
  740. });
  741. }
  742. }
  743. }).catch(err => {
  744. wx.showToast({
  745. title: err.message,
  746. icon: 'none',
  747. duration: 2000,
  748. mask: false
  749. });
  750. })
  751. },
  752. /**
  753. * 邀请好友继续砍价
  754. */
  755. inviteFriend: function (e) {
  756. let that = this;
  757. let formId = e.detail.formId;
  758. that.setData({
  759. formId: formId,
  760. showbutton1: true
  761. })
  762. that.orderFunc("discount");
  763. },
  764. /**
  765. * 支付订单更新
  766. */
  767. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this, composeOrderType) => {
  768. let that = this;
  769. // 支付成功
  770. Http.post({
  771. url: config.api.payOrderUpdate,
  772. data: {
  773. payOrderId: payOrderId,
  774. composeOrderId: orderId,
  775. status: status,
  776. reason: reason
  777. }
  778. })
  779. .then(res => {
  780. wx.hideLoading()
  781. // 有价券
  782. if (!type && type != 'free') {
  783. wx.navigateTo({
  784. url: `/pages/order/detail/index?orderId=${orderId
  785. }&cardIf=true&contentType=${_this.data.contentType}&composeOrderType=${composeOrderType}`
  786. });
  787. } else if (type == 'free') {
  788. wx.navigateTo({
  789. url: `/pages/order/detail/index?orderId=${orderId
  790. }&contentType=${_this.data.contentType}&composeOrderType=${composeOrderType}`
  791. });
  792. }
  793. })
  794. .catch(err => {
  795. console.log(err);
  796. if (!type) {
  797. setTimeout(function () {
  798. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  799. }, 2000)
  800. }
  801. })
  802. },
  803. checkPhoneStatus: function () {
  804. let that = this;
  805. Http.get({
  806. url: config.api.checkPhoneStatus,
  807. data: {}
  808. })
  809. .then(res => {
  810. console.log(666, '授权成功!')
  811. that.receiveCard()
  812. })
  813. .catch(err => {
  814. if (err.code == 11005) {
  815. /**
  816. * 手机号没有授权,将值传到用户手机号授权的页面
  817. *
  818. */
  819. wx.redirectTo({
  820. 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,
  821. });
  822. } else if (err.code == 11006) {
  823. // 用户手机已加密
  824. wx.redirectTo({
  825. 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,
  826. });
  827. } else {
  828. wx.showToast({
  829. title: err.message,
  830. icon: 'none',
  831. duration: 2000,
  832. mask: false
  833. });
  834. }
  835. })
  836. },
  837. // 券包支付
  838. /**
  839. * 发起支付
  840. */
  841. orderFunc(discount) {
  842. let that = this;
  843. Http.get({
  844. url: config.api.checkUserStatus,
  845. data: {
  846. token: app.globalData.token
  847. }
  848. }).then(res => {
  849. Http.get({
  850. url: config.api.checkPhoneStatus,
  851. data: {}
  852. })
  853. .then(res => {
  854. // 发起砍价
  855. if (discount == 'discount') {
  856. var data = {
  857. couponChannelId: "" + that.data.couponChannelId,
  858. couponId: "" + that.data.couponId,
  859. formId: "" + that.data.formId,
  860. press: true
  861. }
  862. } else if (discount == 'discount1') {
  863. var data = {
  864. couponChannelId: "" + that.data.couponChannelId,
  865. couponId: "" + that.data.couponId,
  866. formId: "" + that.data.formId,
  867. press: false
  868. }
  869. } else if (that.data.couponChannelId == null) {
  870. var data = {
  871. couponId: "" + that.data.couponId,
  872. formId: "" + that.data.formId,
  873. };
  874. } else {
  875. var data = {
  876. couponChannelId: "" + that.data.couponChannelId,
  877. couponId: "" + that.data.couponId,
  878. formId: "" + that.data.formId,
  879. }
  880. }
  881. console.log(data, "data")
  882. let url = ""
  883. let tempObj;
  884. let tempArr = []
  885. if (that.data.data.type == 12) {
  886. url = config.api.couponPackageSave
  887. tempObj = {
  888. signleOrder: {
  889. couponChannelId: "" + that.data.couponChannelId,
  890. couponId: "" + that.data.couponId,
  891. formId: "" + that.data.formId,
  892. },
  893. count: "1"
  894. }
  895. tempArr.push(tempObj)
  896. } else {
  897. url = config.api.orderSave
  898. }
  899. /**
  900. * orderSave 下单
  901. */
  902. return Http.post({
  903. url: url,
  904. data: that.data.data.type == 12 ? JSON.stringify(tempArr) : data
  905. });
  906. })
  907. .catch(err => {
  908. wx.hideLoading()
  909. that.setData({
  910. showbutton: false,
  911. showbutton1: false
  912. })
  913. if (err.code == 2011) {
  914. wx.showToast({
  915. title: "商户信息没找到",
  916. image: './../../../assets/images/fail.png',
  917. duration: 2000,
  918. mask: false
  919. });
  920. } else if (err.code == 2013) {
  921. wx.showToast({
  922. title: "商户信息禁用",
  923. image: './../../../assets/images/fail.png',
  924. duration: 2000,
  925. mask: false
  926. });
  927. } else if (err.code == 3000) {
  928. wx.showToast({
  929. title: "库存不足",
  930. image: './../../../assets/images/fail.png',
  931. duration: 2000,
  932. mask: false
  933. });
  934. } else if (err.code == 3001) {
  935. wx.showToast({
  936. title: "您已超过限购",
  937. image: './../../../assets/images/fail.png',
  938. duration: 2000,
  939. mask: false
  940. });
  941. } else if (err.code == 3002) {
  942. wx.showToast({
  943. title: "订单失败",
  944. image: './../../../assets/images/fail.png',
  945. duration: 2000,
  946. mask: false
  947. });
  948. } else if (err.code == 3003) {
  949. wx.showToast({
  950. title: "订单不存在",
  951. image: './../../../assets/images/fail.png',
  952. duration: 2000,
  953. mask: false
  954. });
  955. } else if (err.code == 3004) {
  956. wx.showToast({
  957. title: "订单不存在",
  958. image: './../../../assets/images/fail.png',
  959. duration: 2000,
  960. mask: false
  961. });
  962. } else if (err.code == 4003) {
  963. wx.showToast({
  964. title: "卡券已作废",
  965. image: './../../../assets/images/fail.png',
  966. duration: 2000,
  967. mask: false
  968. });
  969. } else if (err.code == 3012) {
  970. that.getUnPaidOrder(that.data.couponId);
  971. } else if (err.code == 11005) {
  972. /**
  973. * 将值传到用户手机号授权的页面
  974. *
  975. */
  976. wx.redirectTo({
  977. url: "/pages/getphoneInfo/index?couponChannelId=" +
  978. that.data.couponChannelId
  979. });
  980. } else if (err.code == 11006) {
  981. // 用户手机已加密
  982. wx.redirectTo({
  983. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  984. that.data.couponChannelId
  985. });
  986. } else {
  987. wx.showToast({
  988. title: err.message,
  989. icon: 'none',
  990. duration: 2000,
  991. mask: false
  992. });
  993. }
  994. })
  995. .then(res => {
  996. console.log(res, "res123")
  997. if (discount != 'discount') {
  998. if (typeof (res) != "undefined") {
  999. let orderId = "" + res.data.mainOrderId;
  1000. that.setData({
  1001. orderId: orderId,
  1002. composeOrderType: res.data.composeOrderType
  1003. });
  1004. if (res.data.payment > 0) {
  1005. // 支付金额不为0
  1006. /**
  1007. * 支付订单创建
  1008. */
  1009. Http.post({
  1010. url: config.api.payOrderCreate,
  1011. data: {
  1012. orderId: orderId,
  1013. composeOrderType: res.data.composeOrderType
  1014. }
  1015. })
  1016. .then(res => {
  1017. var payOrderId = "" + res.data.payOrderId;
  1018. wx.hideLoading();
  1019. wx.requestPayment({
  1020. timeStamp: res.data.timeStamp,
  1021. nonceStr: res.data.nonceStr,
  1022. package: res.data.package,
  1023. signType: (res.data.signType) ? res.data.signType : "MD5",
  1024. paySign: res.data.paySign,
  1025. success: res => {
  1026. wx.showLoading({
  1027. title: '订单正在处理中...',
  1028. })
  1029. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that, that.data.composeOrderType);
  1030. if (res.errMsg == "requestPayment:ok") {
  1031. /**
  1032. * 用户支付成功以后跳转到券包列表
  1033. */
  1034. if (that.data.cardType == 100) {
  1035. wx.setStorage({
  1036. key: 'couponNum2',
  1037. data: "couponNum2"
  1038. })
  1039. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  1040. wx.setStorage({
  1041. key: 'couponNum',
  1042. data: "couponNum"
  1043. })
  1044. }
  1045. }
  1046. },
  1047. fail: res => {
  1048. wx.hideLoading();
  1049. /**
  1050. * 支付失败,需要更新订单的状态
  1051. */
  1052. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that, that.data.composeOrderType);
  1053. that.setData({
  1054. showbutton: false
  1055. })
  1056. return;
  1057. },
  1058. complete: res => { }
  1059. });
  1060. /// End payment --------
  1061. })
  1062. .catch(err => {
  1063. wx.hideLoading();
  1064. wx.showToast({
  1065. title: err.message,
  1066. icon: 'none',
  1067. duration: 2000,
  1068. mask: false
  1069. });
  1070. })
  1071. } else {
  1072. // 免费券
  1073. that.payOrderUpdate(orderId, "0", 1, '', 'free', that, that.data.composeOrderType);
  1074. if (that.data.cardType == 100) {
  1075. wx.setStorage({
  1076. key: 'couponNum2',
  1077. data: "couponNum2"
  1078. })
  1079. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  1080. wx.setStorage({
  1081. key: 'couponNum',
  1082. data: "couponNum"
  1083. })
  1084. }
  1085. }
  1086. }
  1087. } else {
  1088. if (res) {
  1089. wx.navigateTo({
  1090. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.singleOrder.id}&composeOrderType=${res.data.composeOrderType}`,
  1091. })
  1092. }
  1093. }
  1094. })
  1095. }).catch(err => {
  1096. console.log(err)
  1097. if (err.code == 11004) {
  1098. wx.redirectTo({
  1099. url: `/pages/getuserinfo/index?fromflag=coupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  1100. })
  1101. } else {
  1102. wx.showToast({
  1103. title: err.message,
  1104. icon: "none",
  1105. duration: 2500
  1106. })
  1107. }
  1108. })
  1109. },
  1110. // 获得未支付的订单
  1111. getUnPaidOrder(couponId) {
  1112. let that = this;
  1113. Http.get({
  1114. url: config.api.getUnPaidOrder,
  1115. data: {
  1116. couponId: couponId
  1117. }
  1118. }).then(res => {
  1119. that.setData({
  1120. disOrderNumber: res.data.orderNumber,
  1121. composeOrderType: res.data.composeOrderType
  1122. })
  1123. if (res.data && res.data.pressEndDate) {
  1124. that.setData({
  1125. dispressEndDate: true
  1126. })
  1127. } else {
  1128. that.setData({
  1129. dispressEndDate: false
  1130. })
  1131. }
  1132. if (that.data.dispressEndDate) {
  1133. wx.showModal({
  1134. title: '提示',
  1135. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  1136. confirmText: "我的砍价",
  1137. success: function (res) {
  1138. if (res.confirm) {
  1139. wx.navigateTo({
  1140. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  1141. })
  1142. }
  1143. }
  1144. })
  1145. } else {
  1146. wx.showModal({
  1147. title: '提示',
  1148. content: '您有未支付订单,请先进行支付',
  1149. confirmText: "去支付",
  1150. success: function (res1) {
  1151. if (res1.confirm) {
  1152. if (that.data.composeOrderType > 0) {//券包
  1153. wx.navigateTo({
  1154. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&contentType=${that.data.contentType}&composeOrderType=${that.data.composeOrderType}`,
  1155. })
  1156. } else {
  1157. wx.navigateTo({
  1158. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&contentType=${that.data.contentType}&composeOrderType=${that.data.composeOrderType}`,
  1159. })
  1160. }
  1161. }
  1162. }
  1163. })
  1164. }
  1165. }).catch(error => {
  1166. wx.showToast({
  1167. title: error.message,
  1168. icon: "none",
  1169. duration: 3000
  1170. })
  1171. })
  1172. },
  1173. onShow() {
  1174. this.setData({
  1175. mouldConfig: app.globalData.mouldConfig,
  1176. mouldType: app.globalData.mouldType,
  1177. showbutton: false,
  1178. showbutton1: false,
  1179. goHomeUrl: app.globalData.goHomeUrl
  1180. })
  1181. if (this.data.end_time && this.data.activityStatus != 0) {
  1182. this.countdown(this.data.end_time)
  1183. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  1184. this.countdown(this.data.begin_time)
  1185. }
  1186. },
  1187. onUnload: function () {
  1188. let that = this;
  1189. clearInterval(that.data.setInterval)
  1190. },
  1191. onHide: function () {
  1192. let that = this;
  1193. clearInterval(that.data.setInterval)
  1194. },
  1195. onShareAppMessage: function (options) {
  1196. app.globalData.previewFlag = true
  1197. var that = this;
  1198. console.log(options)
  1199. var shareObj = {
  1200. title: that.data.data.title,
  1201. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  1202. success: function (res) {
  1203. if (res.errMsg == 'shareAppMessage:ok') { }
  1204. },
  1205. fail: function (error) {
  1206. if (res.errMsg == 'shareAppMessage:fail cancel') { } else if (res.errMsg == 'shareAppMessage:fail') { }
  1207. }
  1208. };
  1209. // 来自页面内的按钮的转发
  1210. if (options.from == 'button') {
  1211. var eData = options.target.dataset.id;
  1212. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  1213. }
  1214. console.log(shareObj)
  1215. // 返回shareObj
  1216. return shareObj;
  1217. },
  1218. // 下拉刷新
  1219. onPullDownRefresh: function () {
  1220. this.getDetail(this.data.couponChannelId);
  1221. wx.stopPullDownRefresh()
  1222. },
  1223. onReachBottom: function () {
  1224. this.setData({
  1225. page: this.data.page + 1
  1226. })
  1227. if (this.data.idList.length > 0) {
  1228. this.getCouponList(this.data.idList)
  1229. }
  1230. }
  1231. });