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