C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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