C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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