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

742 行
18 KiB

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