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.

596 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) {
  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. that.getStopFee(that.data.listCardNum);
  111. that.bindCoupon(that.data.quanid);
  112. wx.setStorage({
  113. key: 'chosed',
  114. data: '',
  115. })
  116. };
  117. if (app.globalData.token) {
  118. that.initUsrCarList();
  119. }
  120. if (that.data.addCar) {
  121. // 绑车牌
  122. if (app.globalData.carLogin) {
  123. that.bindCar(that.data.addCar);
  124. } else {
  125. that.bindCar(that.data.addCar);
  126. }
  127. that.setData({
  128. addCar: null
  129. });
  130. }
  131. },
  132. onLoad: function(options) {
  133. var that = this;
  134. /**
  135. * 获得分享小程序的
  136. * title
  137. * desc
  138. */
  139. Http.get({
  140. url: config.api.getWeapNote,
  141. data: {
  142. appId: config.weapp.AppId,
  143. }
  144. })
  145. .then(res => {
  146. let weapNote = JSON.parse(res.data.weapNote);
  147. that.setData({
  148. desc: weapNote.carpage.desc,
  149. title: weapNote.carpage.title
  150. })
  151. })
  152. .catch(err => {
  153. console.log(err);
  154. })
  155. // 登录
  156. var scene = decodeURIComponent(options.scene);
  157. that.setData({
  158. scene: scene
  159. });
  160. if (app.globalData.token) {} else {
  161. // app.getLocation();
  162. that.userLogin()
  163. }
  164. },
  165. /**
  166. * 用户登录
  167. */
  168. userLogin: function() {
  169. var that = this;
  170. // 登录
  171. wx.login({
  172. success: ({
  173. code
  174. }) => {
  175. wx.getSystemInfo({
  176. success: function(res) {
  177. that.setData({
  178. systemInfo: JSON.stringify(res)
  179. })
  180. }
  181. })
  182. var usrdata = {
  183. appId: config.weapp.AppId,
  184. code: code,
  185. sceneAddress: app.globalData.sceneAddress,
  186. scene: that.data.scene,
  187. systemInfo: that.data.systemInfo
  188. };
  189. if (app.globalData.locationInfo) {
  190. usrdata = {
  191. appId: config.weapp.AppId,
  192. code: code,
  193. sceneAddress: app.globalData.sceneAddress,
  194. latitude: "" + app.globalData.locationInfo.latitude,
  195. longitude: "" + app.globalData.locationInfo.longitude,
  196. scene: that.data.scene,
  197. systemInfo: that.data.systemInfo
  198. };
  199. }
  200. Http.post({
  201. url: config.api.login,
  202. data: usrdata
  203. })
  204. .then(res => {
  205. app.globalData.token = res.data.token;
  206. Http.setToken(res.data.token);
  207. that.checkUserCarStatus();
  208. that.getList();
  209. that.init();
  210. that.initUsrCarList();
  211. return Http.get({
  212. url: config.api.checkUserStatus,
  213. data: {}
  214. });
  215. })
  216. .then(res => {})
  217. .catch(err => {
  218. if (err.code == 11004) {
  219. // 用户昵称未授权
  220. wx.redirectTo({
  221. url: "/pages/getuserinfo/index"
  222. });
  223. } else {
  224. wx.showModal({
  225. title: '提示',
  226. content: err.errMsg,
  227. showCancel: false
  228. })
  229. }
  230. });
  231. }
  232. });
  233. },
  234. /**
  235. * 检查用户是否有车
  236. */
  237. checkUserCarStatus: function() {
  238. var that = this;
  239. Http.get({
  240. url: config.api.userCarCount,
  241. data: {}
  242. }).then(res => {
  243. if (res.data > 0) {
  244. // 用户名下有车
  245. app.globalData.phone = res.data.phone;
  246. app.globalData.supportCar = true;
  247. // 共同登录
  248. that.userCarLogin();
  249. }
  250. })
  251. .catch(err => {})
  252. },
  253. jumpToAdd: function() {
  254. wx.navigateTo({
  255. url: `/pages/addPark/addPark?flags=managepalte`
  256. });
  257. },
  258. passc: function() {
  259. wx.navigateTo({
  260. url: '/pages/ques/ques',
  261. })
  262. },
  263. /**
  264. * 券绑定车牌
  265. */
  266. bindCoupon: function(quanid) {
  267. var that = this;
  268. /**
  269. * etcp
  270. */
  271. var etcpData = {
  272. etcpToken: app.globalData.etcpToken,
  273. carNumber: that.data.listCardNum,
  274. couponOrderId: quanid
  275. };
  276. /**
  277. * 停简单
  278. */
  279. var tjdData = {
  280. carNumber: that.data.listCardNum
  281. };
  282. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  283. Http.post({
  284. url: config.api.getCarCoupon,
  285. data: postCouponData
  286. })
  287. .then(res => {
  288. that.initUsrCarList();
  289. })
  290. .catch(err => {
  291. console.log(err)
  292. wx.showToast({
  293. title: err.message,
  294. icon: 'none',
  295. duration: 2000,
  296. mask: false
  297. });
  298. })
  299. },
  300. /**
  301. * 选择优惠券
  302. */
  303. gotoquan: function() {
  304. let that = this;
  305. if (that.data.quanid) {
  306. wx.navigateTo({
  307. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  308. })
  309. } else {
  310. wx.navigateTo({
  311. url: '/pages/passCar/choicecoupon/choicecoupon',
  312. })
  313. }
  314. },
  315. //获取名下停车券列表
  316. getList() {
  317. var that = this;
  318. Http.get({
  319. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  320. data: {
  321. pageNum: 1,
  322. pageSize: 8,
  323. couponOrderStatus: 0
  324. }
  325. }).then(res => {
  326. that.setData({
  327. couponList: res.data.list
  328. });
  329. })
  330. .catch(err => {
  331. console.log(err)
  332. })
  333. },
  334. /**
  335. * 共同登录
  336. */
  337. init: function(carNumber) {
  338. var that = this;
  339. app.parkInitCallback = token => {
  340. that.initPark();
  341. that.getParkStatus();
  342. if (!app.globalData.carLogin) {
  343. /**
  344. * 判断是否授权手机号
  345. */
  346. Http.get({
  347. url: config.api.checkPhoneStatus,
  348. data: {}
  349. })
  350. .then(res => {
  351. Http.post({
  352. url: config.api.carInit,
  353. data: {
  354. phone: app.globalData.phone
  355. }
  356. }).then(res => {
  357. app.globalData.carLogin = true;
  358. app.globalData.parkVendor = res.data.vendor;
  359. if (res.data.token) {
  360. app.globalData.etcpToken = res.data.token;
  361. }
  362. /**
  363. * 获得停车费用
  364. */
  365. that.initUsrCarList("flags");
  366. });
  367. })
  368. .catch(err => {
  369. if (err.code == 11005) {
  370. // 用户手机未授权
  371. /**
  372. * 将值传到用户手机号授权的页面
  373. *
  374. */
  375. wx.redirectTo({
  376. url: "/pages/getphoneInfo/index"
  377. });
  378. } else if (err.code == 11006) {
  379. // 用户手机已加密
  380. wx.redirectTo({
  381. url: "/pages/phoneinput/phoneinput"
  382. });
  383. } else {
  384. wx.showToast({
  385. title: err.errMsg,
  386. icon: 'none',
  387. duration: 2000,
  388. mask: false
  389. });
  390. }
  391. })
  392. }
  393. };
  394. if (app.globalData.token && app.globalData.token != null) {
  395. app.parkInitCallback(app.globalData.token);
  396. }
  397. },
  398. bindCar: function(carNum) {
  399. var that = this;
  400. // ETCP
  401. var etcpData = {
  402. etcpToken: app.globalData.etcpToken,
  403. carNumber: carNum
  404. };
  405. var tjdData = {
  406. carNumber: carNum
  407. };
  408. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  409. Http.post({
  410. url: config.api.bindCar,
  411. data: postData
  412. })
  413. .then(res => {
  414. that.setData({
  415. addCar: null
  416. });
  417. that.initUsrCarList();
  418. wx.showModal({
  419. title: "提示",
  420. showCancel: false,
  421. content: "绑车牌成功!",
  422. success: function() {}
  423. });
  424. })
  425. .catch(error => {
  426. wx.showModal({
  427. title: "提示",
  428. showCancel: false,
  429. content: error.data.message,
  430. success: function() {}
  431. });
  432. });
  433. },
  434. /**
  435. * 车场信息获取
  436. */
  437. initPark: function() {
  438. var that = this;
  439. Http.get({
  440. url: config.api.getParkInfo,
  441. data: {}
  442. })
  443. .then(res => {
  444. that.setData({
  445. park: res.data
  446. })
  447. })
  448. .catch(err => {
  449. console.log(err);
  450. // wx.showToast({
  451. // title: err.message,
  452. // icon: 'none',
  453. // duration: 2000,
  454. // mask: false
  455. // });
  456. })
  457. },
  458. /**
  459. * 车场状态获取
  460. */
  461. getParkStatus: function() {
  462. var that = this;
  463. Http.get({
  464. url: config.api.getParkStatus,
  465. })
  466. .then(res => {
  467. console.log(res)
  468. })
  469. .catch(err => {
  470. console.log(err)
  471. // wx.showToast({
  472. // title: err.message,
  473. // icon:"none"
  474. // })
  475. })
  476. },
  477. /**
  478. * 绑定车获取
  479. */
  480. initUsrCarList: function(flag) {
  481. var that = this;
  482. Http.get({
  483. url: config.api.getUserCarList,
  484. data: {}
  485. }).then(res => {
  486. that.setData({
  487. carList: res.data
  488. });
  489. /**
  490. * flag ==flags
  491. * 表示从首页onShow进来的
  492. */
  493. if (flag == "flags" && res.data.length > 0) {
  494. var listCardNum = res.data[0].carNumber;
  495. that.setData({
  496. listCardNum: listCardNum
  497. })
  498. /**
  499. * 获得停车费用
  500. */
  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. // 用户点击右上角分享
  568. onShareAppMessage: function() {
  569. return {
  570. title: this.data.title,
  571. desc: this.data.desc,
  572. success: function(res) {
  573. wx.showToast({
  574. title: "分享成功",
  575. duration: 1000,
  576. icon: "success"
  577. })
  578. }
  579. }
  580. }
  581. });