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.

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