C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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