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.

612 rivejä
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. console.log(err)
  202. wx.showToast({
  203. title: err.errMsg,
  204. icon: 'none',
  205. duration: 2000,
  206. mask: false
  207. });
  208. }
  209. });
  210. }
  211. });
  212. },
  213. /**
  214. * 检查用户是否有车
  215. */
  216. checkUserCarStatus: function () {
  217. var that = this;
  218. Http.get({
  219. url: config.api.userCarCount,
  220. data: {}
  221. }).then(res => {
  222. if (res.data > 0) {
  223. // 用户名下有车
  224. app.globalData.phone = res.data.phone;
  225. app.globalData.supportCar = true;
  226. // 共同登录
  227. that.userCarLogin();
  228. }
  229. })
  230. .catch(err => {
  231. console.log(err)
  232. wx.showToast({
  233. title: err.errMsg,
  234. icon: 'none',
  235. duration: 2000,
  236. mask: false
  237. });
  238. })
  239. },
  240. /**
  241. * 获取用户信息
  242. */
  243. getUserInfo: function () {
  244. // 获取用户信息
  245. wx.getSetting({
  246. success: res => {
  247. if (res.authSetting["scope.userInfo"]) {
  248. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  249. wx.getUserInfo({
  250. success: res => {
  251. // 可以将 res 发送给后台解码出 unionId
  252. }
  253. });
  254. }
  255. }
  256. })
  257. },
  258. jumpToAdd: function() {
  259. wx.navigateTo({
  260. url: `/pages/addPark/addPark?flags=managepalte`
  261. });
  262. },
  263. passc: function() {
  264. wx.navigateTo({
  265. url: '/pages/ques/ques',
  266. })
  267. },
  268. /**
  269. * 券绑定车牌
  270. */
  271. bindCoupon: function(quanid) {
  272. var that = this;
  273. /**
  274. * etcp
  275. */
  276. var etcpData = {
  277. etcpToken: app.globalData.etcpToken,
  278. carNumber: that.data.listCardNum,
  279. couponOrderId: quanid
  280. };
  281. /**
  282. * 停简单
  283. */
  284. var tjdData = {
  285. carNumber: that.data.listCardNum
  286. };
  287. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  288. Http.post({
  289. url: config.api.getCarCoupon,
  290. data: postCouponData
  291. })
  292. .then(res => {
  293. that.initUsrCarList();
  294. })
  295. .catch(err => {
  296. console.log(err)
  297. wx.showToast({
  298. title: err.errMsg,
  299. icon: 'none',
  300. duration: 2000,
  301. mask: false
  302. });
  303. })
  304. },
  305. /**
  306. * 选择优惠券
  307. */
  308. gotoquan: function() {
  309. let that = this;
  310. if (that.data.quanid) {
  311. wx.navigateTo({
  312. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  313. })
  314. } else {
  315. wx.navigateTo({
  316. url: '/pages/passCar/choicecoupon/choicecoupon',
  317. })
  318. }
  319. },
  320. //获取名下停车券列表
  321. getList() {
  322. var that = this;
  323. Http.get({
  324. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  325. data: {
  326. pageNum: 1,
  327. pageSize: 8,
  328. couponOrderStatus: 0
  329. }
  330. }).then(res => {
  331. that.setData({
  332. couponList: res.data.list
  333. });
  334. })
  335. .catch(err => {
  336. console.log(err)
  337. wx.showToast({
  338. title: err.errMsg,
  339. icon: 'none',
  340. duration: 2000,
  341. mask: false
  342. });
  343. })
  344. },
  345. /**
  346. * 共同登录
  347. */
  348. init: function(carNumber) {
  349. var that = this;
  350. app.parkInitCallback = token => {
  351. that.initPark();
  352. that.getParkStatus();
  353. if (!app.globalData.carLogin) {
  354. /**
  355. * 判断是否授权手机号
  356. */
  357. Http.post({
  358. url: config.api.checkPhoneStatus,
  359. data: {}
  360. })
  361. .then(res => {
  362. Http.post({
  363. url: config.api.carInit,
  364. data: {
  365. phone: app.globalData.phone
  366. }
  367. }).then(res => {
  368. app.globalData.carLogin = true;
  369. app.globalData.parkVendor = res.data.vendor;
  370. if (res.data.token) {
  371. app.globalData.etcpToken = res.data.token;
  372. }
  373. /**
  374. * 获得停车费用
  375. */
  376. that.initUsrCarList("flags");
  377. });
  378. })
  379. .catch(err => {
  380. if (err.code == 11005) {
  381. // 用户手机未授权
  382. /**
  383. * 将值传到用户手机号授权的页面
  384. *
  385. */
  386. wx.redirectTo({
  387. url: "/pages/getphoneInfo/index"
  388. });
  389. } else if (err.code == 11006) {
  390. // 用户手机已加密
  391. wx.redirectTo({
  392. url: "/pages/phoneinput/phoneinput"
  393. });
  394. }else{
  395. console.log(err)
  396. wx.showToast({
  397. title: err.errMsg,
  398. icon: 'none',
  399. duration: 2000,
  400. mask: false
  401. });
  402. }
  403. })
  404. }
  405. };
  406. if (app.globalData.token && app.globalData.token != null) {
  407. app.parkInitCallback(app.globalData.token);
  408. }
  409. },
  410. bindCar: function (carNum) {
  411. var that = this;
  412. // ETCP
  413. var etcpData = {
  414. etcpToken: app.globalData.etcpToken,
  415. carNumber: carNum
  416. };
  417. var tjdData = {
  418. carNumber: carNum
  419. };
  420. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  421. Http.post({
  422. url: config.api.bindCar,
  423. data: postData
  424. })
  425. .then(res => {
  426. that.setData({
  427. addCar: null
  428. });
  429. that.initUsrCarList();
  430. wx.showModal({
  431. title: "提示",
  432. showCancel: false,
  433. content: "绑车牌成功!",
  434. success: function () { }
  435. });
  436. })
  437. .catch(error => {
  438. console.log(error)
  439. wx.showModal({
  440. title: "提示",
  441. showCancel: false,
  442. content: error.data.message,
  443. success: function () { }
  444. });
  445. });
  446. },
  447. /**
  448. * 车场信息获取
  449. */
  450. initPark: function() {
  451. var that = this;
  452. Http.get({
  453. url: config.api.getParkInfo,
  454. data: {}
  455. })
  456. .then(res => {
  457. that.setData({
  458. park: res.data
  459. })
  460. })
  461. .catch(err => {
  462. console.log(err)
  463. wx.showToast({
  464. title: err.errMsg,
  465. icon: 'none',
  466. duration: 2000,
  467. mask: false
  468. });
  469. })
  470. },
  471. /**
  472. * 车场状态获取
  473. */
  474. getParkStatus: function() {
  475. var that = this;
  476. Http.get({
  477. url: config.api.getParkStatus,
  478. })
  479. .then(res => {
  480. })
  481. .catch(err => {
  482. console.log(err)
  483. wx.showToast({
  484. title: err.message,
  485. icon: 'none',
  486. duration: 2000,
  487. mask: false
  488. });
  489. })
  490. },
  491. /**
  492. * 绑定车获取
  493. */
  494. initUsrCarList: function(flag) {
  495. var that = this;
  496. Http.get({
  497. url: config.api.getUserCarList,
  498. data: {}
  499. }).then(res => {
  500. that.setData({
  501. carList: res.data
  502. });
  503. /**
  504. * flag ==flags
  505. * 表示从首页onShow进来的
  506. */
  507. if (flag == "flags" && res.data.length > 0) {
  508. var listCardNum = res.data[0].carNumber;
  509. that.setData({
  510. listCardNum: listCardNum
  511. })
  512. /**
  513. * 获得停车费用
  514. */
  515. that.getStopFee(listCardNum);
  516. }
  517. })
  518. .catch(err => {
  519. wx.showToast({
  520. title: err.errMsg,
  521. icon: 'none',
  522. duration: 2000,
  523. mask: false
  524. });
  525. })
  526. },
  527. /**
  528. * 获得停车费用修改
  529. */
  530. getStopFee: function(carNumber) {
  531. var that = this;
  532. var postData =
  533. app.globalData.parkVendor == 1 ? {
  534. etcpToken: app.globalData.etcpToken,
  535. carNumber: carNumber
  536. } : {
  537. carNumber: carNumber,
  538. outCarId: outCarId
  539. };
  540. Http.post({
  541. url: config.api.getCarStopFee,
  542. data: postData
  543. })
  544. .then(res => {
  545. var extraDataStr = {
  546. params: {
  547. token: app.globalData.etcpToken,
  548. syncId: res.data.orderId,
  549. payType: 6, // 小程序支付
  550. CarNumber: carNumber,
  551. returnUrl: "https://admin.malls.iformall.com/api/carCallback/etcpPaidCallback",
  552. source: "FUMAO-001",
  553. actionId: "1" //操作ID,1:小程序支付
  554. }
  555. };
  556. that.setData({
  557. extraData: extraDataStr
  558. });
  559. that.setData({
  560. stopFees: res.data
  561. })
  562. that.setData({
  563. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  564. })
  565. })
  566. .catch(error => {
  567. wx.showModal({
  568. title: '提示',
  569. content: error.message,
  570. showCancel: false
  571. })
  572. that.setData({
  573. stopFees: {}
  574. })
  575. });
  576. },
  577. /**
  578. * 下拉刷新
  579. */
  580. onPullDownRefresh: function(e) {
  581. let that = this;
  582. that.initUsrCarList("flags");
  583. wx.stopPullDownRefresh();
  584. },
  585. // 用户点击右上角分享
  586. onShareAppMessage: function() {
  587. return {
  588. title: this.data.title,
  589. desc: this.data.desc,
  590. success: function(res) {
  591. wx.showToast({
  592. title: "分享成功",
  593. duration: 1000,
  594. icon: "success"
  595. });
  596. }
  597. }
  598. }
  599. });