C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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