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.

778 line
18 KiB

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