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.

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