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.

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