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

818 рядки
19 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  2. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  3. let app = getApp();
  4. const format = require("../utils/util.js");
  5. let config = require("../config/config.js");
  6. let Http = require("../utils/HttpBasics");
  7. let Util = require("../utils/util");
  8. const imgurl = require("../utils/imgurl");
  9. Page({
  10. data: {
  11. navigationBarHeight,
  12. jianUrl: imgurl.jian.url,
  13. jiaofeiwm: imgurl.jiaofeiwm.url,
  14. parkUrl: imgurl.park.url,
  15. guanliHr: imgurl.guanliHr.url,
  16. qidaiUrl: imgurl.qidai.url,
  17. addUrl: imgurl.add.url,
  18. tingcheHr: imgurl.tingcheHr.url,
  19. cheUrl: imgurl.che.url,
  20. jiaofei: imgurl.jiaofei.url,
  21. wentiHr: imgurl.wentiHr.url,
  22. park: null,
  23. carList: [],
  24. payList: [],
  25. addCar: null,
  26. tcq: 2,
  27. flag: "",
  28. extraData: {},
  29. desc: '',
  30. title: '',
  31. indicatorDots: true,
  32. autoplay: false,
  33. interval: 5000,
  34. duration: 1000,
  35. current: 0,
  36. stopFees: {},
  37. scroll: true,
  38. ifHaveCarModular: "",
  39. canIUse: wx.canIUse("navigator"),
  40. showTicketModal: false,
  41. ticketList: [],
  42. noCoupon:imgurl.noCoupon.url,
  43. loadingUrl: imgurl.loading.url,
  44. allow_load: true,
  45. curPageNum: 1,
  46. curPageSize: 15,
  47. curTotalpageNum: 0,
  48. quantitle: '',
  49. quanid: '',
  50. gouHr: imgurl.gouHr.url,
  51. totalTicketNum: 0,
  52. },
  53. getMoreList(e) {
  54. let totalNum = this.data.ticketList.length;
  55. if (this.data.curPageNum < this.data.curTotalpageNum) {
  56. this.setData({
  57. curPageNum: this.data.curPageNum+1
  58. })
  59. this.getTicketList(0 ,this.data.curPageNum);
  60. }
  61. },
  62. /**
  63. * 选择使用的优惠券
  64. */
  65. choicecoupon: function(e) {
  66. /* wx.navigateBack();
  67. var pages = getCurrentPages();
  68. var prevPage = pages[pages.length - 2] //上一个页面 */
  69. var that = this;
  70. var quantitle = e.currentTarget.dataset.title;
  71. var quanid = e.currentTarget.dataset.id;
  72. this.setData({
  73. quantitle: quantitle,
  74. quanid: quanid,
  75. showTicketModal: false,
  76. });
  77. that.bindCoupon(that.data.quanid);
  78. /* wx.setStorage({
  79. key: 'chosed',
  80. data: 'chosed',
  81. }) */
  82. },
  83. /*
  84. */
  85. getTicketList(key, pageNum) {
  86. var that = this;
  87. if (that.data.allow_load) {
  88. wx.showLoading({
  89. title: "加载中"
  90. });
  91. Http.get({
  92. url: config.api.couponOrderCarList,
  93. data: {
  94. pageNum: pageNum,
  95. pageSize: 15,
  96. couponOrderStatus: key
  97. }
  98. }).then(res => {
  99. that.setData({
  100. curTotalpageNum: res.data.pages,
  101. curPageNum: res.data.pageNum,
  102. totalTicketNum: res.data.total
  103. })
  104. res.data.list.map(file => {
  105. file.expiredTime = format.formatTime(
  106. file.expiredTime,
  107. "yyyy-MM-dd hh:mm:ss"
  108. );
  109. });
  110. setTimeout(function () {
  111. wx.hideLoading();
  112. }, 1200);
  113. if (pageNum >= res.data.pages) {
  114. that.setData({
  115. allow_load: false
  116. });
  117. }
  118. /**
  119. * 先赋值后渲染页面
  120. * concat 不会改变原数组值
  121. * push 会改变原数组值,但不会一条一条插入,而是整个数组插入
  122. */
  123. if (pageNum == 1) {
  124. that.setData({
  125. ticketList: res.data.list,
  126. curPageNum: pageNum
  127. });
  128. } else {
  129. that.setData({
  130. ticketList: that.data.ticketList.concat(res.data.list)
  131. });
  132. }
  133. // that.data.ticketList = that.data.ticketList.concat(res.data.list);
  134. this.hideLoading();
  135. })
  136. .catch(err => {
  137. setTimeout(function () {
  138. wx.hideLoading();
  139. }, 1200);
  140. wx.showToast({
  141. title: err.errMsg,
  142. icon: 'none',
  143. duration: 2000,
  144. mask: false
  145. });
  146. })
  147. } else {
  148. }
  149. },
  150. //点击跳转到券详情页面
  151. gotouse: function (e) {
  152. wx.navigateTo({
  153. url: `/pages/passCar/couponDetail/couponDetail?quancode=${
  154. e.currentTarget.dataset.quancode
  155. }`,
  156. success: function (res) {
  157. // success
  158. },
  159. fail: function () {
  160. // fail
  161. },
  162. complete: function () {
  163. // complete
  164. }
  165. });
  166. },
  167. /**
  168. * 车牌轮播滑动
  169. */
  170. onSlideChangeEnd: function (e) {
  171. var that = this;
  172. /**
  173. * 获得当前的车牌号码
  174. */
  175. var listCardNum = (that.data.carList)[e.detail.current].carNumber;
  176. that.setData({
  177. listCardNum: listCardNum
  178. });
  179. /**
  180. * 获得停车费用
  181. */
  182. if (that.data.scroll) {
  183. that.getStopFee(listCardNum);
  184. }
  185. },
  186. //停车费用为0
  187. paySuccess: function () {
  188. wx.showModal({
  189. title: '支付成功',
  190. content: '请尽快离场',
  191. showCancel: false
  192. })
  193. },
  194. gotomange: function () {
  195. wx.navigateTo({
  196. url: '/pages/managelicenseplate/managelicenseplate',
  197. })
  198. },
  199. bindfail: function (res) {
  200. console.log(res)
  201. },
  202. gotoetcp: function (e) {
  203. // etcp parkVendor1
  204. // 泊链停车 parkVendor5
  205. if (e.target.dataset.flag == 'parkVendor1'){
  206. wx.navigateToMiniProgram({
  207. appId: this.data.etcpAppId,
  208. extraData: this.data.extraData,
  209. envVersion: 'release',
  210. path: "pages/pay/order-pay-open/main",
  211. })
  212. } else if (e.target.dataset.flag == 'parkVendor5'){
  213. wx.navigateToMiniProgram({
  214. appId: 'wxbd08b4baa10fcc1d',
  215. extraData: this.data.extraData,
  216. envVersion: 'release',
  217. path: "pages/park/park",
  218. })
  219. }
  220. },
  221. showquan: function () {
  222. wx.navigateTo({
  223. url: '/pages/passCar/couponList/couponList',
  224. })
  225. },
  226. gotodetail: function (e) {
  227. wx.showModal({
  228. title: '缴费规则',
  229. content: e.target.dataset.rule,
  230. showCancel: false,
  231. })
  232. },
  233. onShow: function (options) {
  234. if (typeof this.getTabBar === 'function' &&
  235. this.getTabBar()) {
  236. this.getTabBar().setData({
  237. selected: 2
  238. })
  239. }
  240. var that = this;
  241. that.setData({
  242. etcpAppId: extConfig.attr.etcpAppId,
  243. etcpVersion: extConfig.attr.etcpVersion,
  244. etcpCallbackUrl: extConfig.attr.etcpCallbackUrl,
  245. ifHaveCarModular: extConfig.attr.ifHaveCarModular
  246. })
  247. if (app.globalData.token) {
  248. that.getList();
  249. that.init();
  250. } else {
  251. that.init();
  252. }
  253. /**
  254. * 只有用户选择了优惠券
  255. * 才会进行券和车牌的绑定
  256. */
  257. /* if (wx.getStorageSync("chosed") && that.data.quanid) {
  258. that.getStopFee(that.data.listCardNum);
  259. that.bindCoupon(that.data.quanid);
  260. wx.setStorage({
  261. key: 'chosed',
  262. data: '',
  263. })
  264. }; */
  265. if (app.globalData.token) {
  266. // that.initUsrCarList();
  267. that.initUsrCarList("flags");
  268. that.setData({
  269. current: 0
  270. })
  271. }
  272. if (that.data.addCar) {
  273. // 绑车牌
  274. if (app.globalData.carLogin) {
  275. that.bindCar(that.data.addCar);
  276. } else {
  277. that.bindCar(that.data.addCar);
  278. }
  279. that.setData({
  280. addCar: null
  281. });
  282. }
  283. this.getTicketList(0, 1);
  284. },
  285. cancelMove: function() {
  286. console.log(111)
  287. return false;
  288. },
  289. onHide: function () {
  290. this.setData({
  291. allow_load: true,
  292. showTicketModal: false,
  293. curPageNum: 1,
  294. ticketList: []
  295. })
  296. },
  297. onLoad: function (options) {
  298. var that = this;
  299. /**
  300. * 获得分享小程序的
  301. * title
  302. * desc
  303. */
  304. Http.get({
  305. url: config.api.getWeapNote,
  306. data: {
  307. appId: config.weapp.AppId,
  308. }
  309. })
  310. .then(res => {
  311. let weapNote = JSON.parse(res.data.weapNote);
  312. that.setData({
  313. desc: weapNote.carpage.desc,
  314. title: weapNote.carpage.title
  315. })
  316. })
  317. .catch(err => {
  318. console.log(err);
  319. })
  320. // 登录
  321. var scene = decodeURIComponent(options.scene);
  322. that.setData({
  323. scene: scene
  324. });
  325. if (app.globalData.token) { } else {
  326. // app.getLocation();
  327. that.userLogin()
  328. }
  329. },
  330. /**
  331. * 用户登录
  332. */
  333. userLogin: function () {
  334. var that = this;
  335. // 登录
  336. wx.login({
  337. success: ({
  338. code
  339. }) => {
  340. wx.getSystemInfo({
  341. success: function (res) {
  342. that.setData({
  343. systemInfo: JSON.stringify(res)
  344. })
  345. }
  346. })
  347. var usrdata = {
  348. appId: config.weapp.AppId,
  349. code: code,
  350. sceneAddress: app.globalData.sceneAddress,
  351. scene: that.data.scene,
  352. systemInfo: that.data.systemInfo
  353. };
  354. if (app.globalData.locationInfo) {
  355. usrdata = {
  356. appId: config.weapp.AppId,
  357. code: code,
  358. sceneAddress: app.globalData.sceneAddress,
  359. latitude: "" + app.globalData.locationInfo.latitude,
  360. longitude: "" + app.globalData.locationInfo.longitude,
  361. scene: that.data.scene,
  362. systemInfo: that.data.systemInfo
  363. };
  364. }
  365. Http.post({
  366. url: config.api.login,
  367. data: usrdata
  368. })
  369. .then(res => {
  370. app.globalData.token = res.data.token;
  371. Http.setToken(res.data.token);
  372. that.checkUserCarStatus();
  373. that.getList();
  374. that.init();
  375. that.initUsrCarList();
  376. return Http.get({
  377. url: config.api.checkUserStatus,
  378. data: {}
  379. });
  380. })
  381. .then(res => { })
  382. .catch(err => {
  383. if (err.code == 11004) {
  384. // 用户昵称未授权
  385. wx.redirectTo({
  386. url: "/pages/getuserinfo/index"
  387. });
  388. } else {
  389. wx.showModal({
  390. title: '提示',
  391. content: err.errMsg,
  392. showCancel: false
  393. })
  394. }
  395. });
  396. }
  397. });
  398. },
  399. /**
  400. * 检查用户是否有车
  401. */
  402. checkUserCarStatus: function () {
  403. var that = this;
  404. Http.get({
  405. url: config.api.userCarCount,
  406. data: {}
  407. }).then(res => {
  408. if (res.data > 0) {
  409. // 用户名下有车
  410. app.globalData.phone = res.data.phone;
  411. app.globalData.supportCar = true;
  412. // 共同登录
  413. that.userCarLogin();
  414. }
  415. })
  416. .catch(err => { })
  417. },
  418. jumpToAdd: function () {
  419. wx.navigateTo({
  420. url: `/pages/addPark/addPark?flags=managepalte`
  421. });
  422. },
  423. passc: function () {
  424. wx.navigateTo({
  425. url: '/pages/ques/ques',
  426. })
  427. },
  428. /**
  429. * 券绑定车牌
  430. */
  431. bindCoupon: function (quanid) {
  432. var that = this;
  433. /**
  434. * etcp
  435. */
  436. var etcpData = {
  437. etcpToken: app.globalData.etcpToken,
  438. carNumber: that.data.listCardNum,
  439. couponOrderId: quanid
  440. };
  441. /**
  442. * 停简单
  443. */
  444. var tjdData = {
  445. carNumber: that.data.listCardNum
  446. };
  447. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  448. if (app.globalData.parkVendor == 4){
  449. postCouponData = {
  450. carNumber: that.data.listCardNum,
  451. couponOrderId: quanid
  452. }
  453. }
  454. Http.post({
  455. url: config.api.getCarCoupon,
  456. data: postCouponData
  457. })
  458. .then(res => {
  459. that.getStopFee(that.data.listCardNum);
  460. that.initUsrCarList();
  461. })
  462. .catch(err => {
  463. if (err.message!=undefined) {
  464. wx.showToast({
  465. title: err.message,
  466. icon: 'none',
  467. duration: 2000,
  468. mask: false
  469. });
  470. }
  471. })
  472. },
  473. /**
  474. * 选择优惠券
  475. */
  476. // gotoquan: function () {
  477. // let that = this;
  478. // if (that.data.quanid) {
  479. // wx.navigateTo({
  480. // url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  481. // })
  482. // } else {
  483. // wx.navigateTo({
  484. // url: '/pages/passCar/choicecoupon/choicecoupon',
  485. // })
  486. // }
  487. // },
  488. closeTicketModal: function () {
  489. this.setData({
  490. showTicketModal: false
  491. })
  492. },
  493. /**
  494. * 停车券 弹框
  495. */
  496. openTicketModal: function () {
  497. this.setData({
  498. showTicketModal: true,
  499. allow_load: true,
  500. ticketList: [],
  501. curPageNum: 1,
  502. })
  503. this.getTicketList(0, 1);
  504. /* if (!this.data.ticketList.length){
  505. this.getTicketList(0, 1);
  506. } */
  507. },
  508. //获取名下停车券列表
  509. getList() {
  510. var that = this;
  511. Http.get({
  512. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  513. data: {
  514. pageNum: 1,
  515. pageSize: 15,
  516. couponOrderStatus: 0
  517. }
  518. }).then(res => {
  519. that.setData({
  520. couponList: res.data.list
  521. });
  522. })
  523. .catch(err => {
  524. console.log(err)
  525. })
  526. },
  527. /**
  528. * 共同登录
  529. */
  530. init: function (carNumber) {
  531. var that = this;
  532. app.parkInitCallback = token => {
  533. that.initPark();
  534. that.getParkStatus();
  535. if (!app.globalData.carLogin) {
  536. /**
  537. * 判断是否授权手机号
  538. */
  539. Http.get({
  540. url: config.api.checkPhoneStatus,
  541. data: {}
  542. })
  543. .then(res => {
  544. Http.post({
  545. url: config.api.carInit,
  546. data: {
  547. phone: app.globalData.phone
  548. }
  549. }).then(res => {
  550. app.globalData.carLogin = true;
  551. app.globalData.parkVendor = res.data.vendor;
  552. if (res.data.token) {
  553. app.globalData.etcpToken = res.data.token;
  554. }
  555. /**
  556. * 获得停车费用
  557. */
  558. that.initUsrCarList("flags");
  559. });
  560. })
  561. .catch(err => {
  562. if (err.code == 11005) {
  563. // 用户手机未授权
  564. /**
  565. * 将值传到用户手机号授权的页面
  566. *
  567. */
  568. wx.redirectTo({
  569. url: "/pages/getphoneInfo/index"
  570. });
  571. } else if (err.code == 11006) {
  572. // 用户手机已加密
  573. wx.redirectTo({
  574. url: "/pages/phoneinput/phoneinput"
  575. });
  576. } else {
  577. wx.showToast({
  578. title: err.errMsg,
  579. icon: 'none',
  580. duration: 2000,
  581. mask: false
  582. });
  583. }
  584. })
  585. }
  586. };
  587. if (app.globalData.token && app.globalData.token != null) {
  588. app.parkInitCallback(app.globalData.token);
  589. }
  590. },
  591. bindCar: function (carNum) {
  592. var that = this;
  593. // ETCP
  594. var etcpData = {
  595. etcpToken: app.globalData.etcpToken,
  596. carNumber: carNum
  597. };
  598. var tjdData = {
  599. carNumber: carNum
  600. };
  601. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  602. Http.post({
  603. url: config.api.bindCar,
  604. data: postData
  605. })
  606. .then(res => {
  607. that.setData({
  608. addCar: null
  609. });
  610. that.initUsrCarList();
  611. wx.showModal({
  612. title: "提示",
  613. showCancel: false,
  614. content: "绑车牌成功!",
  615. success: function () { }
  616. });
  617. })
  618. .catch(error => {
  619. wx.showModal({
  620. title: "提示",
  621. showCancel: false,
  622. content: error.data.message,
  623. success: function () { }
  624. });
  625. });
  626. },
  627. /**
  628. * 车场信息获取
  629. */
  630. initPark: function () {
  631. var that = this;
  632. Http.get({
  633. url: config.api.getParkInfo,
  634. data: {}
  635. })
  636. .then(res => {
  637. that.setData({
  638. park: res.data
  639. })
  640. if (res.data){
  641. app.globalData.parkVendor = res.data.vendorType;
  642. }
  643. })
  644. .catch(err => {
  645. console.log(err);
  646. // wx.showToast({
  647. // title: err.message,
  648. // icon: 'none',
  649. // duration: 2000,
  650. // mask: false
  651. // });
  652. })
  653. },
  654. /**
  655. * 车场状态获取
  656. */
  657. getParkStatus: function () {
  658. var that = this;
  659. Http.get({
  660. url: config.api.getParkStatus,
  661. })
  662. .then(res => {
  663. console.log(res)
  664. })
  665. .catch(err => {
  666. console.log(err)
  667. // wx.showToast({
  668. // title: err.message,
  669. // icon:"none"
  670. // })
  671. })
  672. },
  673. /**
  674. * 绑定车获取
  675. */
  676. initUsrCarList: function (flag) {
  677. var that = this;
  678. Http.get({
  679. url: config.api.getUserCarList,
  680. data: {}
  681. }).then(res => {
  682. that.setData({
  683. carList: res.data
  684. });
  685. /**
  686. * flag ==flags
  687. * 表示从首页onShow进来的
  688. */
  689. if (flag == "flags" && res.data.length > 0) {
  690. var listCardNum = res.data[0].carNumber;
  691. that.setData({
  692. listCardNum: listCardNum
  693. })
  694. /**
  695. * 获得停车费用
  696. */
  697. that.getStopFee(listCardNum);
  698. }
  699. })
  700. .catch(err => {
  701. wx.showToast({
  702. title: err.message,
  703. icon: 'none',
  704. duration: 2000,
  705. mask: false
  706. });
  707. })
  708. },
  709. /**
  710. * 获得停车费用修改
  711. */
  712. getStopFee: function (carNumber) {
  713. let that = this;
  714. let postData =
  715. app.globalData.parkVendor == 1 ? {
  716. etcpToken: app.globalData.etcpToken,
  717. carNumber: carNumber
  718. } : {
  719. carNumber: carNumber
  720. };
  721. Http.post({
  722. url: config.api.getCarStopFee,
  723. data: postData
  724. })
  725. .then(res => {
  726. console.log(res)
  727. if(app.globalData.parkVendor != 5){
  728. var extraDataStr = {
  729. params: {
  730. token: app.globalData.etcpToken,
  731. syncId: res.data.orderId,
  732. payType: 6, // 小程序支付
  733. CarNumber: carNumber,
  734. returnUrl: that.data.etcpCallbackUrl,
  735. source: "FUMAO-001",
  736. actionId: "1" //操作ID,1:小程序支付
  737. }
  738. }
  739. that.setData({
  740. extraData: extraDataStr,
  741. stopFees: res.data,
  742. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  743. });
  744. } else if (app.globalData.parkVendor == 5) {
  745. var extraDataStr = {
  746. params: {
  747. union_id: '200389',
  748. order_id: res.data.order_id,
  749. park_id: "30536",
  750. plate_number: res.data.plate_number,
  751. money: res.data.money,
  752. park_name: res.data.park_name
  753. }
  754. }
  755. that.setData({
  756. extraData: extraDataStr,
  757. stopFees: {
  758. orderId: res.data.order_id,
  759. entranceTime: res.data.start_time,
  760. remainingFee: res.data.money
  761. },
  762. timecha: res.data.duration
  763. });
  764. }
  765. that.setData({
  766. scroll: true
  767. })
  768. })
  769. .catch(error => {
  770. that.setData({
  771. stopFees: {},
  772. scroll: true
  773. })
  774. });
  775. },
  776. /**
  777. * 下拉刷新
  778. */
  779. onPullDownRefresh: function (e) {
  780. let that = this;
  781. that.initUsrCarList("flags");
  782. that.setData({
  783. current:0
  784. })
  785. wx.stopPullDownRefresh();
  786. }
  787. });