C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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