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.

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