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.

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