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.

611 líneas
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. bindfail:function(res){
  47. console.log(res)
  48. },
  49. gotoetcp:function(){
  50. wx.navigateToMiniProgram({
  51. appId:'wx192b7d2e8dcbefd0',
  52. extraData: this.data.extraData,
  53. envVersion:'trial'
  54. })
  55. // wx.navigateToMiniProgram({
  56. // appId:'wxc07f9d67923d676d',
  57. // extraData: this.data.extraData,
  58. // envVersion:'release'
  59. // })
  60. },
  61. showquan: function() {
  62. wx.navigateTo({
  63. url: '/pages/passCar/couponList/couponList',
  64. })
  65. },
  66. gotodetail: function(e) {
  67. wx.showModal({
  68. title: '缴费规则',
  69. content: e.target.dataset.rule,
  70. showCancel: false,
  71. })
  72. },
  73. onShow: function(options) {
  74. var that = this;
  75. if (app.globalData.token) {
  76. that.getList();
  77. that.init();
  78. }
  79. /**
  80. * 只有用户选择了优惠券
  81. * 才会进行券和车牌的绑定
  82. */
  83. if (wx.getStorageSync("chosed") && that.data.quanid) {
  84. that.bindCoupon(that.data.quanid);
  85. wx.setStorage({
  86. key: 'chosed',
  87. data: '',
  88. })
  89. };
  90. if (app.globalData.token) {
  91. that.initUsrCarList();
  92. }
  93. if (that.data.addCar) {
  94. // 绑车牌
  95. if (app.globalData.carLogin) {
  96. that.bindCar(that.data.addCar);
  97. } else {
  98. that.bindCar(that.data.addCar);
  99. }
  100. that.setData({
  101. addCar: null
  102. });
  103. }
  104. },
  105. onLoad: function(options) {
  106. var that = this;
  107. /**
  108. * 获得分享小程序的
  109. * title
  110. * desc
  111. */
  112. Http.get({
  113. url: config.api.getWeapNote,
  114. data: {
  115. appId: config.weapp.AppId,
  116. }
  117. })
  118. .then(res => {
  119. let weapNote = JSON.parse(res.data.weapNote);
  120. that.setData({
  121. desc: weapNote.carpage.desc,
  122. title: weapNote.carpage.title
  123. })
  124. })
  125. .catch(err => {
  126. console.log(err);
  127. wx.showToast({
  128. title: err.errMsg,
  129. icon: 'none',
  130. duration: 2000,
  131. mask: false
  132. });
  133. })
  134. // 登录
  135. var scene = decodeURIComponent(options.scene);
  136. that.setData({
  137. scene: scene
  138. });
  139. if (app.globalData.token){}else{
  140. app.getLocation();
  141. that.userLogin()
  142. }
  143. },
  144. /**
  145. * 用户登录
  146. */
  147. userLogin: function () {
  148. var that = this;
  149. // 登录
  150. wx.login({
  151. success: ({
  152. code
  153. }) => {
  154. wx.getSystemInfo({
  155. success: function (res) {
  156. that.setData({
  157. systemInfo: JSON.stringify(res)
  158. })
  159. }
  160. })
  161. var usrdata = {
  162. appId: config.weapp.AppId,
  163. code: code,
  164. sceneAddress: app.globalData.sceneAddress,
  165. scene: that.data.scene,
  166. systemInfo: that.data.systemInfo
  167. };
  168. if (app.globalData.locationInfo) {
  169. usrdata = {
  170. appId: config.weapp.AppId,
  171. code: code,
  172. sceneAddress: app.globalData.sceneAddress,
  173. latitude: "" + app.globalData.locationInfo.latitude,
  174. longitude: "" + app.globalData.locationInfo.longitude,
  175. scene: that.data.scene,
  176. systemInfo: that.data.systemInfo
  177. };
  178. }
  179. Http.post({
  180. url: config.api.login,
  181. data: usrdata
  182. })
  183. .then(res => {
  184. app.globalData.token = res.data.token;
  185. Http.setToken(res.data.token);
  186. that.checkUserCarStatus();
  187. that.getUserInfo();
  188. that.getList();
  189. that.init();
  190. that.initUsrCarList();
  191. return Http.post({
  192. url: config.api.checkUserStatus,
  193. data: {}
  194. });
  195. })
  196. .then(res => {
  197. })
  198. .catch(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. }
  255. });
  256. }
  257. }
  258. })
  259. },
  260. jumpToAdd: function() {
  261. wx.navigateTo({
  262. url: `/pages/addPark/addPark?flags=managepalte`
  263. });
  264. },
  265. passc: function() {
  266. wx.navigateTo({
  267. url: '/pages/ques/ques',
  268. })
  269. },
  270. /**
  271. * 券绑定车牌
  272. */
  273. bindCoupon: function(quanid) {
  274. var that = this;
  275. /**
  276. * etcp
  277. */
  278. var etcpData = {
  279. etcpToken: app.globalData.etcpToken,
  280. carNumber: that.data.listCardNum,
  281. couponOrderId: quanid
  282. };
  283. /**
  284. * 停简单
  285. */
  286. var tjdData = {
  287. carNumber: that.data.listCardNum
  288. };
  289. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  290. Http.post({
  291. url: config.api.getCarCoupon,
  292. data: postCouponData
  293. })
  294. .then(res => {
  295. that.initUsrCarList();
  296. })
  297. .catch(err => {
  298. wx.showToast({
  299. title: err.errMsg,
  300. icon: 'none',
  301. duration: 2000,
  302. mask: false
  303. });
  304. })
  305. },
  306. /**
  307. * 选择优惠券
  308. */
  309. gotoquan: function() {
  310. let that = this;
  311. if (that.data.quanid) {
  312. wx.navigateTo({
  313. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  314. })
  315. } else {
  316. wx.navigateTo({
  317. url: '/pages/passCar/choicecoupon/choicecoupon',
  318. })
  319. }
  320. },
  321. //获取名下停车券列表
  322. getList() {
  323. var that = this;
  324. Http.get({
  325. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  326. data: {
  327. pageNum: 1,
  328. pageSize: 8,
  329. couponOrderStatus: 0
  330. }
  331. }).then(res => {
  332. that.setData({
  333. couponList: res.data.list
  334. });
  335. })
  336. .catch(err => {
  337. console.log(err)
  338. wx.showToast({
  339. title: err.errMsg,
  340. icon: 'none',
  341. duration: 2000,
  342. mask: false
  343. });
  344. })
  345. },
  346. /**
  347. * 共同登录
  348. */
  349. init: function(carNumber) {
  350. var that = this;
  351. app.parkInitCallback = token => {
  352. that.initPark();
  353. that.getParkStatus();
  354. if (!app.globalData.carLogin) {
  355. /**
  356. * 判断是否授权手机号
  357. */
  358. Http.post({
  359. url: config.api.checkPhoneStatus,
  360. data: {}
  361. })
  362. .then(res => {
  363. Http.post({
  364. url: config.api.carInit,
  365. data: {
  366. phone: app.globalData.phone
  367. }
  368. }).then(res => {
  369. app.globalData.carLogin = true;
  370. app.globalData.parkVendor = res.data.vendor;
  371. if (res.data.token) {
  372. app.globalData.etcpToken = res.data.token;
  373. }
  374. /**
  375. * 获得停车费用
  376. */
  377. that.initUsrCarList("flags");
  378. });
  379. })
  380. .catch(err => {
  381. if (err.code == 11005) {
  382. // 用户手机未授权
  383. /**
  384. * 将值传到用户手机号授权的页面
  385. *
  386. */
  387. wx.redirectTo({
  388. url: "/pages/getphoneInfo/index"
  389. });
  390. } else if (err.code == 11006) {
  391. // 用户手机已加密
  392. wx.redirectTo({
  393. url: "/pages/phoneinput/phoneinput"
  394. });
  395. }else{
  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. wx.showModal({
  439. title: "提示",
  440. showCancel: false,
  441. content: error.data.message,
  442. success: function () { }
  443. });
  444. });
  445. },
  446. /**
  447. * 车场信息获取
  448. */
  449. initPark: function() {
  450. var that = this;
  451. Http.get({
  452. url: config.api.getParkInfo,
  453. data: {}
  454. })
  455. .then(res => {
  456. that.setData({
  457. park: res.data
  458. })
  459. })
  460. .catch(err => {
  461. console.log(err);
  462. wx.showToast({
  463. title: err.errMsg,
  464. icon: 'none',
  465. duration: 2000,
  466. mask: false
  467. });
  468. })
  469. },
  470. /**
  471. * 车场状态获取
  472. */
  473. getParkStatus: function() {
  474. var that = this;
  475. Http.get({
  476. url: config.api.getParkStatus,
  477. })
  478. .then(res => {
  479. })
  480. .catch(err => {
  481. wx.showToast({
  482. title: err.message,
  483. icon: 'none',
  484. duration: 2000,
  485. mask: false
  486. });
  487. })
  488. },
  489. /**
  490. * 绑定车获取
  491. */
  492. initUsrCarList: function(flag) {
  493. var that = this;
  494. Http.get({
  495. url: config.api.getUserCarList,
  496. data: {}
  497. }).then(res => {
  498. that.setData({
  499. carList: res.data
  500. });
  501. /**
  502. * flag ==flags
  503. * 表示从首页onShow进来的
  504. */
  505. if (flag == "flags" && res.data.length > 0) {
  506. var listCardNum = res.data[0].carNumber;
  507. that.setData({
  508. listCardNum: listCardNum
  509. })
  510. /**
  511. * 获得停车费用
  512. */
  513. that.getStopFee(listCardNum);
  514. }
  515. })
  516. .catch(err => {
  517. wx.showToast({
  518. title: err.errMsg,
  519. icon: 'none',
  520. duration: 2000,
  521. mask: false
  522. });
  523. })
  524. },
  525. /**
  526. * 获得停车费用修改
  527. */
  528. getStopFee: function(carNumber) {
  529. var that = this;
  530. var postData =
  531. app.globalData.parkVendor == 1 ? {
  532. etcpToken: app.globalData.etcpToken,
  533. carNumber: carNumber
  534. } : {
  535. carNumber: carNumber,
  536. outCarId: outCarId
  537. };
  538. Http.post({
  539. url: config.api.getCarStopFee,
  540. data: postData
  541. })
  542. .then(res => {
  543. var extraDataStr = {
  544. params: {
  545. token: app.globalData.etcpToken,
  546. syncId: res.data.orderId,
  547. payType: 6, // 小程序支付
  548. CarNumber: carNumber,
  549. returnUrl: "https://mall.youlane.cn/api/carCallback/etcpPaidCallback",
  550. source: "FUMAO-001",
  551. actionId: "1" //操作ID,1:小程序支付
  552. }
  553. };
  554. that.setData({
  555. extraData: extraDataStr
  556. });
  557. that.setData({
  558. stopFees: res.data
  559. })
  560. that.setData({
  561. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  562. })
  563. })
  564. .catch(error => {
  565. wx.showModal({
  566. title: '提示',
  567. content: error.message,
  568. showCancel: false
  569. })
  570. that.setData({
  571. stopFees: {}
  572. })
  573. });
  574. console.log(that.data.extraData)
  575. },
  576. /**
  577. * 下拉刷新
  578. */
  579. onPullDownRefresh: function(e) {
  580. let that = this;
  581. that.initUsrCarList("flags");
  582. wx.stopPullDownRefresh();
  583. },
  584. // 用户点击右上角分享
  585. onShareAppMessage: function() {
  586. return {
  587. title: this.data.title,
  588. desc: this.data.desc,
  589. success: function(res) {
  590. wx.showToast({
  591. title: "分享成功",
  592. duration: 1000,
  593. icon: "success"
  594. });
  595. }
  596. }
  597. }
  598. });