C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

604 lignes
14 KiB

  1. let config = require("../../config/config.js");
  2. let Http = require("../../utils/HttpBasics");
  3. let Util = require("../../utils/util");
  4. let app = getApp();
  5. Page({
  6. data: {
  7. park: null,
  8. carList: [],
  9. payList: [],
  10. addCar: null,
  11. tcq: 2,
  12. flag: "",
  13. extraData: {},
  14. desc: '',
  15. title: '',
  16. indicatorDots: true,
  17. autoplay: false,
  18. interval: 5000,
  19. duration: 1000,
  20. current: 0,
  21. stopFees: {},
  22. canIUse: wx.canIUse("navigator")
  23. },
  24. /**
  25. * 车牌轮播滑动
  26. */
  27. onSlideChangeEnd: function(e) {
  28. var that = this;
  29. /**
  30. * 获得当前的车牌号码
  31. */
  32. var listCardNum = (that.data.carList)[e.detail.current].carNumber;
  33. that.setData({
  34. listCardNum: listCardNum
  35. });
  36. /**
  37. * 获得停车费用
  38. */
  39. that.getStopFee(listCardNum);
  40. },
  41. gotomange: function() {
  42. wx.navigateTo({
  43. url: '/pages/managelicenseplate/managelicenseplate',
  44. })
  45. },
  46. gotoetcp:function(){
  47. wx.navigateToMiniProgram({
  48. appId:'wx192b7d2e8dcbefd0',
  49. extraData: this.data.extraData,
  50. envVersion:'release'
  51. })
  52. // wx.navigateToMiniProgram({
  53. // appId:'wxc07f9d67923d676d',
  54. // extraData: this.data.extraData,
  55. // envVersion:'release'
  56. // })
  57. },
  58. showquan: function() {
  59. wx.navigateTo({
  60. url: '/pages/passCar/couponList/couponList',
  61. })
  62. },
  63. gotodetail: function(e) {
  64. wx.showModal({
  65. title: '缴费规则',
  66. content: e.target.dataset.rule,
  67. showCancel: false,
  68. })
  69. },
  70. onShow: function(options) {
  71. var that = this;
  72. if (app.globalData.token) {
  73. that.getList();
  74. that.init();
  75. }
  76. /**
  77. * 只有用户选择了优惠券
  78. * 才会进行券和车牌的绑定
  79. */
  80. if (wx.getStorageSync("chosed") && that.data.quanid) {
  81. that.bindCoupon(that.data.quanid);
  82. wx.setStorage({
  83. key: 'chosed',
  84. data: '',
  85. })
  86. };
  87. if (app.globalData.token) {
  88. that.initUsrCarList();
  89. }
  90. if (that.data.addCar) {
  91. // 绑车牌
  92. if (app.globalData.carLogin) {
  93. that.bindCar(that.data.addCar);
  94. } else {
  95. that.bindCar(that.data.addCar);
  96. }
  97. that.setData({
  98. addCar: null
  99. });
  100. }
  101. },
  102. onLoad: function(options) {
  103. var that = this;
  104. /**
  105. * 获得分享小程序的
  106. * title
  107. * desc
  108. */
  109. Http.get({
  110. url: config.api.getWeapNote,
  111. data: {
  112. appId: config.weapp.AppId,
  113. }
  114. })
  115. .then(res => {
  116. let weapNote = JSON.parse(res.data.weapNote);
  117. that.setData({
  118. desc: weapNote.carpage.desc,
  119. title: weapNote.carpage.title
  120. })
  121. })
  122. .catch(err => {
  123. wx.showToast({
  124. title: err.errMsg,
  125. icon: 'none',
  126. duration: 2000,
  127. mask: false
  128. });
  129. })
  130. // 登录
  131. var scene = decodeURIComponent(options.scene);
  132. that.setData({
  133. scene: scene
  134. });
  135. if (app.globalData.token){}else{
  136. app.getLocation();
  137. that.userLogin()
  138. }
  139. },
  140. /**
  141. * 用户登录
  142. */
  143. userLogin: function () {
  144. var that = this;
  145. // 登录
  146. wx.login({
  147. success: ({
  148. code
  149. }) => {
  150. wx.getSystemInfo({
  151. success: function (res) {
  152. that.setData({
  153. systemInfo: JSON.stringify(res)
  154. })
  155. }
  156. })
  157. var usrdata = {
  158. appId: config.weapp.AppId,
  159. code: code,
  160. sceneAddress: app.globalData.sceneAddress,
  161. scene: that.data.scene,
  162. systemInfo: that.data.systemInfo
  163. };
  164. if (app.globalData.locationInfo) {
  165. usrdata = {
  166. appId: config.weapp.AppId,
  167. code: code,
  168. sceneAddress: app.globalData.sceneAddress,
  169. latitude: "" + app.globalData.locationInfo.latitude,
  170. longitude: "" + app.globalData.locationInfo.longitude,
  171. scene: that.data.scene,
  172. systemInfo: that.data.systemInfo
  173. };
  174. }
  175. Http.post({
  176. url: config.api.login,
  177. data: usrdata
  178. })
  179. .then(res => {
  180. app.globalData.token = res.data.token;
  181. Http.setToken(res.data.token);
  182. that.checkUserCarStatus();
  183. that.getUserInfo();
  184. that.getList();
  185. that.init();
  186. that.initUsrCarList();
  187. return Http.post({
  188. url: config.api.checkUserStatus,
  189. data: {}
  190. });
  191. })
  192. .then(res => {
  193. })
  194. .catch(err => {
  195. if (err.code == 11004) {
  196. // 用户昵称未授权
  197. wx.redirectTo({
  198. url: "/pages/getuserinfo/index"
  199. });
  200. }else{
  201. wx.showToast({
  202. title: err.errMsg,
  203. icon: 'none',
  204. duration: 2000,
  205. mask: false
  206. });
  207. }
  208. });
  209. }
  210. });
  211. },
  212. /**
  213. * 检查用户是否有车
  214. */
  215. checkUserCarStatus: function () {
  216. var that = this;
  217. Http.get({
  218. url: config.api.userCarCount,
  219. data: {}
  220. }).then(res => {
  221. if (res.data > 0) {
  222. // 用户名下有车
  223. app.globalData.phone = res.data.phone;
  224. app.globalData.supportCar = true;
  225. // 共同登录
  226. that.userCarLogin();
  227. }
  228. })
  229. .catch(err => {
  230. wx.showToast({
  231. title: err.errMsg,
  232. icon: 'none',
  233. duration: 2000,
  234. mask: false
  235. });
  236. })
  237. },
  238. /**
  239. * 获取用户信息
  240. */
  241. getUserInfo: function () {
  242. // 获取用户信息
  243. wx.getSetting({
  244. success: res => {
  245. if (res.authSetting["scope.userInfo"]) {
  246. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  247. wx.getUserInfo({
  248. success: res => {
  249. // 可以将 res 发送给后台解码出 unionId
  250. }
  251. });
  252. }
  253. }
  254. })
  255. },
  256. jumpToAdd: function() {
  257. wx.navigateTo({
  258. url: `/pages/addPark/addPark?flags=managepalte`
  259. });
  260. },
  261. passc: function() {
  262. wx.navigateTo({
  263. url: '/pages/ques/ques',
  264. })
  265. },
  266. /**
  267. * 券绑定车牌
  268. */
  269. bindCoupon: function(quanid) {
  270. var that = this;
  271. /**
  272. * etcp
  273. */
  274. var etcpData = {
  275. etcpToken: app.globalData.etcpToken,
  276. carNumber: that.data.listCardNum,
  277. couponOrderId: quanid
  278. };
  279. /**
  280. * 停简单
  281. */
  282. var tjdData = {
  283. carNumber: that.data.listCardNum
  284. };
  285. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  286. Http.post({
  287. url: config.api.getCarCoupon,
  288. data: postCouponData
  289. })
  290. .then(res => {
  291. that.initUsrCarList();
  292. })
  293. .catch(err => {
  294. wx.showToast({
  295. title: err.errMsg,
  296. icon: 'none',
  297. duration: 2000,
  298. mask: false
  299. });
  300. })
  301. },
  302. /**
  303. * 选择优惠券
  304. */
  305. gotoquan: function() {
  306. let that = this;
  307. if (that.data.quanid) {
  308. wx.navigateTo({
  309. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  310. })
  311. } else {
  312. wx.navigateTo({
  313. url: '/pages/passCar/choicecoupon/choicecoupon',
  314. })
  315. }
  316. },
  317. //获取名下停车券列表
  318. getList() {
  319. var that = this;
  320. Http.get({
  321. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  322. data: {
  323. pageNum: 1,
  324. pageSize: 8,
  325. couponOrderStatus: 0
  326. }
  327. }).then(res => {
  328. that.setData({
  329. couponList: res.data.list
  330. });
  331. })
  332. .catch(err => {
  333. wx.showToast({
  334. title: err.errMsg,
  335. icon: 'none',
  336. duration: 2000,
  337. mask: false
  338. });
  339. })
  340. },
  341. /**
  342. * 共同登录
  343. */
  344. init: function(carNumber) {
  345. var that = this;
  346. app.parkInitCallback = token => {
  347. that.initPark();
  348. that.getParkStatus();
  349. if (!app.globalData.carLogin) {
  350. /**
  351. * 判断是否授权手机号
  352. */
  353. Http.post({
  354. url: config.api.checkPhoneStatus,
  355. data: {}
  356. })
  357. .then(res => {
  358. Http.post({
  359. url: config.api.carInit,
  360. data: {
  361. phone: app.globalData.phone
  362. }
  363. }).then(res => {
  364. app.globalData.carLogin = true;
  365. app.globalData.parkVendor = res.data.vendor;
  366. if (res.data.token) {
  367. app.globalData.etcpToken = res.data.token;
  368. }
  369. /**
  370. * 获得停车费用
  371. */
  372. that.initUsrCarList("flags");
  373. });
  374. })
  375. .catch(err => {
  376. if (err.code == 11005) {
  377. // 用户手机未授权
  378. /**
  379. * 将值传到用户手机号授权的页面
  380. *
  381. */
  382. wx.redirectTo({
  383. url: "/pages/getphoneInfo/index"
  384. });
  385. } else if (err.code == 11006) {
  386. // 用户手机已加密
  387. wx.redirectTo({
  388. url: "/pages/phoneinput/phoneinput"
  389. });
  390. }else{
  391. wx.showToast({
  392. title: err.errMsg,
  393. icon: 'none',
  394. duration: 2000,
  395. mask: false
  396. });
  397. }
  398. })
  399. }
  400. };
  401. if (app.globalData.token && app.globalData.token != null) {
  402. app.parkInitCallback(app.globalData.token);
  403. }
  404. },
  405. bindCar: function (carNum) {
  406. var that = this;
  407. // ETCP
  408. var etcpData = {
  409. etcpToken: app.globalData.etcpToken,
  410. carNumber: carNum
  411. };
  412. var tjdData = {
  413. carNumber: carNum
  414. };
  415. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  416. Http.post({
  417. url: config.api.bindCar,
  418. data: postData
  419. })
  420. .then(res => {
  421. that.setData({
  422. addCar: null
  423. });
  424. that.initUsrCarList();
  425. wx.showModal({
  426. title: "提示",
  427. showCancel: false,
  428. content: "绑车牌成功!",
  429. success: function () { }
  430. });
  431. })
  432. .catch(error => {
  433. wx.showModal({
  434. title: "提示",
  435. showCancel: false,
  436. content: error.data.message,
  437. success: function () { }
  438. });
  439. });
  440. },
  441. /**
  442. * 车场信息获取
  443. */
  444. initPark: function() {
  445. var that = this;
  446. Http.get({
  447. url: config.api.getParkInfo,
  448. data: {}
  449. })
  450. .then(res => {
  451. that.setData({
  452. park: res.data
  453. })
  454. })
  455. .catch(err => {
  456. wx.showToast({
  457. title: err.errMsg,
  458. icon: 'none',
  459. duration: 2000,
  460. mask: false
  461. });
  462. })
  463. },
  464. /**
  465. * 车场状态获取
  466. */
  467. getParkStatus: function() {
  468. var that = this;
  469. Http.get({
  470. url: config.api.getParkStatus,
  471. })
  472. .then(res => {
  473. })
  474. .catch(err => {
  475. wx.showToast({
  476. title: err.errMsg,
  477. icon: 'none',
  478. duration: 2000,
  479. mask: false
  480. });
  481. })
  482. },
  483. /**
  484. * 绑定车获取
  485. */
  486. initUsrCarList: function(flag) {
  487. var that = this;
  488. Http.get({
  489. url: config.api.getUserCarList,
  490. data: {}
  491. }).then(res => {
  492. that.setData({
  493. carList: res.data
  494. });
  495. /**
  496. * flag ==flags
  497. * 表示从首页onShow进来的
  498. */
  499. if (flag == "flags" && res.data.length > 0) {
  500. var listCardNum = res.data[0].carNumber;
  501. that.setData({
  502. listCardNum: listCardNum
  503. })
  504. /**
  505. * 获得停车费用
  506. */
  507. that.getStopFee(listCardNum);
  508. }
  509. })
  510. .catch(err => {
  511. wx.showToast({
  512. title: err.errMsg,
  513. icon: 'none',
  514. duration: 2000,
  515. mask: false
  516. });
  517. })
  518. },
  519. /**
  520. * 获得停车费用修改
  521. */
  522. getStopFee: function(carNumber) {
  523. var that = this;
  524. var postData =
  525. app.globalData.parkVendor == 1 ? {
  526. etcpToken: app.globalData.etcpToken,
  527. carNumber: carNumber
  528. } : {
  529. carNumber: carNumber,
  530. outCarId: outCarId
  531. };
  532. Http.post({
  533. url: config.api.getCarStopFee,
  534. data: postData
  535. })
  536. .then(res => {
  537. var extraDataStr = {
  538. params: {
  539. token: app.globalData.etcpToken,
  540. syncId: res.data.orderId,
  541. payType: 6, // 小程序支付
  542. CarNumber: carNumber,
  543. returnUrl: "https://admin.malls.iformall.com/api/carCallback/etcpPaidCallback",
  544. source: "FUMAO-001",
  545. actionId: "1" //操作ID,1:小程序支付
  546. }
  547. };
  548. that.setData({
  549. extraData: extraDataStr
  550. });
  551. that.setData({
  552. stopFees: res.data
  553. })
  554. that.setData({
  555. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  556. })
  557. })
  558. .catch(error => {
  559. wx.showModal({
  560. title: '提示',
  561. content: error.message,
  562. showCancel: false
  563. })
  564. that.setData({
  565. stopFees: {}
  566. })
  567. });
  568. },
  569. /**
  570. * 下拉刷新
  571. */
  572. onPullDownRefresh: function(e) {
  573. let that = this;
  574. that.initUsrCarList("flags");
  575. wx.stopPullDownRefresh();
  576. },
  577. // 用户点击右上角分享
  578. onShareAppMessage: function() {
  579. return {
  580. title: this.data.title,
  581. desc: this.data.desc,
  582. success: function(res) {
  583. wx.showToast({
  584. title: "分享成功",
  585. duration: 1000,
  586. icon: "success"
  587. });
  588. }
  589. }
  590. }
  591. });