C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

739 líneas
17 KiB

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