C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

774 行
18 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 () {
  203. wx.navigateToMiniProgram({
  204. appId: that.data.etcpAppId,
  205. extraData: this.data.extraData,
  206. envVersion: 'release',
  207. path: "pages/main/main",
  208. })
  209. },
  210. showquan: function () {
  211. wx.navigateTo({
  212. url: '/pages/passCar/couponList/couponList',
  213. })
  214. },
  215. gotodetail: function (e) {
  216. wx.showModal({
  217. title: '缴费规则',
  218. content: e.target.dataset.rule,
  219. showCancel: false,
  220. })
  221. },
  222. onShow: function (options) {
  223. if (typeof this.getTabBar === 'function' &&
  224. this.getTabBar()) {
  225. this.getTabBar().setData({
  226. selected: 2
  227. })
  228. }
  229. var that = this;
  230. that.setData({
  231. etcpAppId: extConfig.attr.etcpAppId,
  232. etcpVersion: extConfig.attr.etcpVersion,
  233. etcpCallbackUrl: extConfig.attr.etcpCallbackUrl,
  234. ifHaveCarModular: extConfig.attr.ifHaveCarModular
  235. })
  236. if (app.globalData.token) {
  237. that.getList();
  238. that.init();
  239. } else {
  240. that.init();
  241. }
  242. /**
  243. * 只有用户选择了优惠券
  244. * 才会进行券和车牌的绑定
  245. */
  246. /* if (wx.getStorageSync("chosed") && that.data.quanid) {
  247. that.getStopFee(that.data.listCardNum);
  248. that.bindCoupon(that.data.quanid);
  249. wx.setStorage({
  250. key: 'chosed',
  251. data: '',
  252. })
  253. }; */
  254. if (app.globalData.token) {
  255. // that.initUsrCarList();
  256. that.initUsrCarList("flags");
  257. that.setData({
  258. current: 0
  259. })
  260. }
  261. if (that.data.addCar) {
  262. // 绑车牌
  263. if (app.globalData.carLogin) {
  264. that.bindCar(that.data.addCar);
  265. } else {
  266. that.bindCar(that.data.addCar);
  267. }
  268. that.setData({
  269. addCar: null
  270. });
  271. }
  272. this.getTicketList(0, 1);
  273. },
  274. cancelMove: function() {
  275. console.log(111)
  276. return false;
  277. },
  278. onHide: function () {
  279. this.setData({
  280. allow_load: true,
  281. showTicketModal: false,
  282. curPageNum: 1,
  283. ticketList: []
  284. })
  285. },
  286. onLoad: function (options) {
  287. var that = this;
  288. /**
  289. * 获得分享小程序的
  290. * title
  291. * desc
  292. */
  293. Http.get({
  294. url: config.api.getWeapNote,
  295. data: {
  296. appId: config.weapp.AppId,
  297. }
  298. })
  299. .then(res => {
  300. let weapNote = JSON.parse(res.data.weapNote);
  301. that.setData({
  302. desc: weapNote.carpage.desc,
  303. title: weapNote.carpage.title
  304. })
  305. })
  306. .catch(err => {
  307. console.log(err);
  308. })
  309. // 登录
  310. var scene = decodeURIComponent(options.scene);
  311. that.setData({
  312. scene: scene
  313. });
  314. if (app.globalData.token) { } else {
  315. // app.getLocation();
  316. that.userLogin()
  317. }
  318. },
  319. /**
  320. * 用户登录
  321. */
  322. userLogin: function () {
  323. var that = this;
  324. // 登录
  325. wx.login({
  326. success: ({
  327. code
  328. }) => {
  329. wx.getSystemInfo({
  330. success: function (res) {
  331. that.setData({
  332. systemInfo: JSON.stringify(res)
  333. })
  334. }
  335. })
  336. var usrdata = {
  337. appId: config.weapp.AppId,
  338. code: code,
  339. sceneAddress: app.globalData.sceneAddress,
  340. scene: that.data.scene,
  341. systemInfo: that.data.systemInfo
  342. };
  343. if (app.globalData.locationInfo) {
  344. usrdata = {
  345. appId: config.weapp.AppId,
  346. code: code,
  347. sceneAddress: app.globalData.sceneAddress,
  348. latitude: "" + app.globalData.locationInfo.latitude,
  349. longitude: "" + app.globalData.locationInfo.longitude,
  350. scene: that.data.scene,
  351. systemInfo: that.data.systemInfo
  352. };
  353. }
  354. Http.post({
  355. url: config.api.login,
  356. data: usrdata
  357. })
  358. .then(res => {
  359. app.globalData.token = res.data.token;
  360. Http.setToken(res.data.token);
  361. that.checkUserCarStatus();
  362. that.getList();
  363. that.init();
  364. that.initUsrCarList();
  365. return Http.get({
  366. url: config.api.checkUserStatus,
  367. data: {}
  368. });
  369. })
  370. .then(res => { })
  371. .catch(err => {
  372. if (err.code == 11004) {
  373. // 用户昵称未授权
  374. wx.redirectTo({
  375. url: "/pages/getuserinfo/index"
  376. });
  377. } else {
  378. wx.showModal({
  379. title: '提示',
  380. content: err.errMsg,
  381. showCancel: false
  382. })
  383. }
  384. });
  385. }
  386. });
  387. },
  388. /**
  389. * 检查用户是否有车
  390. */
  391. checkUserCarStatus: function () {
  392. var that = this;
  393. Http.get({
  394. url: config.api.userCarCount,
  395. data: {}
  396. }).then(res => {
  397. if (res.data > 0) {
  398. // 用户名下有车
  399. app.globalData.phone = res.data.phone;
  400. app.globalData.supportCar = true;
  401. // 共同登录
  402. that.userCarLogin();
  403. }
  404. })
  405. .catch(err => { })
  406. },
  407. jumpToAdd: function () {
  408. wx.navigateTo({
  409. url: `/pages/addPark/addPark?flags=managepalte`
  410. });
  411. },
  412. passc: function () {
  413. wx.navigateTo({
  414. url: '/pages/ques/ques',
  415. })
  416. },
  417. /**
  418. * 券绑定车牌
  419. */
  420. bindCoupon: function (quanid) {
  421. var that = this;
  422. /**
  423. * etcp
  424. */
  425. var etcpData = {
  426. etcpToken: app.globalData.etcpToken,
  427. carNumber: that.data.listCardNum,
  428. couponOrderId: quanid
  429. };
  430. /**
  431. * 停简单
  432. */
  433. var tjdData = {
  434. carNumber: that.data.listCardNum
  435. };
  436. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  437. Http.post({
  438. url: config.api.getCarCoupon,
  439. data: postCouponData
  440. })
  441. .then(res => {
  442. that.getStopFee(that.data.listCardNum);
  443. that.initUsrCarList();
  444. })
  445. .catch(err => {
  446. if (err.message!=undefined) {
  447. wx.showToast({
  448. title: err.message,
  449. icon: 'none',
  450. duration: 2000,
  451. mask: false
  452. });
  453. }
  454. })
  455. },
  456. /**
  457. * 选择优惠券
  458. */
  459. // gotoquan: function () {
  460. // let that = this;
  461. // if (that.data.quanid) {
  462. // wx.navigateTo({
  463. // url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  464. // })
  465. // } else {
  466. // wx.navigateTo({
  467. // url: '/pages/passCar/choicecoupon/choicecoupon',
  468. // })
  469. // }
  470. // },
  471. closeTicketModal: function () {
  472. this.setData({
  473. showTicketModal: false
  474. })
  475. },
  476. /**
  477. * 停车券 弹框
  478. */
  479. openTicketModal: function () {
  480. this.setData({
  481. showTicketModal: true,
  482. allow_load: true,
  483. ticketList: [],
  484. curPageNum: 1,
  485. })
  486. this.getTicketList(0, 1);
  487. /* if (!this.data.ticketList.length){
  488. this.getTicketList(0, 1);
  489. } */
  490. },
  491. //获取名下停车券列表
  492. getList() {
  493. var that = this;
  494. Http.get({
  495. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  496. data: {
  497. pageNum: 1,
  498. pageSize: 15,
  499. couponOrderStatus: 0
  500. }
  501. }).then(res => {
  502. that.setData({
  503. couponList: res.data.list
  504. });
  505. })
  506. .catch(err => {
  507. console.log(err)
  508. })
  509. },
  510. /**
  511. * 共同登录
  512. */
  513. init: function (carNumber) {
  514. var that = this;
  515. app.parkInitCallback = token => {
  516. that.initPark();
  517. that.getParkStatus();
  518. if (!app.globalData.carLogin) {
  519. /**
  520. * 判断是否授权手机号
  521. */
  522. Http.get({
  523. url: config.api.checkPhoneStatus,
  524. data: {}
  525. })
  526. .then(res => {
  527. Http.post({
  528. url: config.api.carInit,
  529. data: {
  530. phone: app.globalData.phone
  531. }
  532. }).then(res => {
  533. app.globalData.carLogin = true;
  534. app.globalData.parkVendor = res.data.vendor;
  535. if (res.data.token) {
  536. app.globalData.etcpToken = res.data.token;
  537. }
  538. /**
  539. * 获得停车费用
  540. */
  541. that.initUsrCarList("flags");
  542. });
  543. })
  544. .catch(err => {
  545. if (err.code == 11005) {
  546. // 用户手机未授权
  547. /**
  548. * 将值传到用户手机号授权的页面
  549. *
  550. */
  551. wx.redirectTo({
  552. url: "/pages/getphoneInfo/index"
  553. });
  554. } else if (err.code == 11006) {
  555. // 用户手机已加密
  556. wx.redirectTo({
  557. url: "/pages/phoneinput/phoneinput"
  558. });
  559. } else {
  560. wx.showToast({
  561. title: err.errMsg,
  562. icon: 'none',
  563. duration: 2000,
  564. mask: false
  565. });
  566. }
  567. })
  568. }
  569. };
  570. if (app.globalData.token && app.globalData.token != null) {
  571. app.parkInitCallback(app.globalData.token);
  572. }
  573. },
  574. bindCar: function (carNum) {
  575. var that = this;
  576. // ETCP
  577. var etcpData = {
  578. etcpToken: app.globalData.etcpToken,
  579. carNumber: carNum
  580. };
  581. var tjdData = {
  582. carNumber: carNum
  583. };
  584. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  585. Http.post({
  586. url: config.api.bindCar,
  587. data: postData
  588. })
  589. .then(res => {
  590. that.setData({
  591. addCar: null
  592. });
  593. that.initUsrCarList();
  594. wx.showModal({
  595. title: "提示",
  596. showCancel: false,
  597. content: "绑车牌成功!",
  598. success: function () { }
  599. });
  600. })
  601. .catch(error => {
  602. wx.showModal({
  603. title: "提示",
  604. showCancel: false,
  605. content: error.data.message,
  606. success: function () { }
  607. });
  608. });
  609. },
  610. /**
  611. * 车场信息获取
  612. */
  613. initPark: function () {
  614. var that = this;
  615. Http.get({
  616. url: config.api.getParkInfo,
  617. data: {}
  618. })
  619. .then(res => {
  620. that.setData({
  621. park: res.data
  622. })
  623. })
  624. .catch(err => {
  625. console.log(err);
  626. // wx.showToast({
  627. // title: err.message,
  628. // icon: 'none',
  629. // duration: 2000,
  630. // mask: false
  631. // });
  632. })
  633. },
  634. /**
  635. * 车场状态获取
  636. */
  637. getParkStatus: function () {
  638. var that = this;
  639. Http.get({
  640. url: config.api.getParkStatus,
  641. })
  642. .then(res => {
  643. console.log(res)
  644. })
  645. .catch(err => {
  646. console.log(err)
  647. // wx.showToast({
  648. // title: err.message,
  649. // icon:"none"
  650. // })
  651. })
  652. },
  653. /**
  654. * 绑定车获取
  655. */
  656. initUsrCarList: function (flag) {
  657. var that = this;
  658. Http.get({
  659. url: config.api.getUserCarList,
  660. data: {}
  661. }).then(res => {
  662. that.setData({
  663. carList: res.data
  664. });
  665. /**
  666. * flag ==flags
  667. * 表示从首页onShow进来的
  668. */
  669. if (flag == "flags" && res.data.length > 0) {
  670. var listCardNum = res.data[0].carNumber;
  671. that.setData({
  672. listCardNum: listCardNum
  673. })
  674. /**
  675. * 获得停车费用
  676. */
  677. that.getStopFee(listCardNum);
  678. }
  679. })
  680. .catch(err => {
  681. wx.showToast({
  682. title: err.message,
  683. icon: 'none',
  684. duration: 2000,
  685. mask: false
  686. });
  687. })
  688. },
  689. /**
  690. * 获得停车费用修改
  691. */
  692. getStopFee: function (carNumber) {
  693. let that = this;
  694. let postData =
  695. app.globalData.parkVendor == 1 ? {
  696. etcpToken: app.globalData.etcpToken,
  697. carNumber: carNumber
  698. } : {
  699. carNumber: carNumber,
  700. outCarId: outCarId
  701. };
  702. Http.post({
  703. url: config.api.getCarStopFee,
  704. data: postData
  705. })
  706. .then(res => {
  707. console.log(res)
  708. var extraDataStr = {
  709. params: {
  710. token: app.globalData.etcpToken,
  711. syncId: res.data.orderId,
  712. payType: 6, // 小程序支付
  713. CarNumber: carNumber,
  714. returnUrl: that.data.etcpCallbackUrl,
  715. source: "FUMAO-001",
  716. actionId: "1" //操作ID,1:小程序支付
  717. }
  718. };
  719. that.setData({
  720. extraData: extraDataStr,
  721. stopFees: res.data,
  722. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  723. });
  724. that.setData({
  725. scroll: true
  726. })
  727. })
  728. .catch(error => {
  729. that.setData({
  730. stopFees: {},
  731. scroll: true
  732. })
  733. });
  734. },
  735. /**
  736. * 下拉刷新
  737. */
  738. onPullDownRefresh: function (e) {
  739. let that = this;
  740. that.initUsrCarList("flags");
  741. that.setData({
  742. current:0
  743. })
  744. wx.stopPullDownRefresh();
  745. }
  746. });