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.

617 líneas
14 KiB

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