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.

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