C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

665 wiersze
16 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. wx.getSetting({
  163. success: (res) => {
  164. console.log(res)
  165. if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {//非初始化进入该页面,且未授权
  166. wx.showModal({
  167. title: '是否授权当前位置',
  168. content: '需要获取您的地理位置,请确认授权,否则无法获取您所需数据',
  169. success: function (res) {
  170. debugger;
  171. if (res.cancel) {
  172. wx.showToast({
  173. title: '授权失败',
  174. icon: 'success',
  175. duration: 1000
  176. })
  177. } else if (res.confirm) {
  178. wx.openSetting({
  179. success: function (dataAu) {
  180. if (dataAu.authSetting["scope.userLocation"] == true) {
  181. wx.showToast({
  182. title: '授权成功',
  183. icon: 'success',
  184. duration: 1000
  185. })
  186. //再次授权,调用getLocationt的API
  187. app.getLocation();
  188. } else {
  189. wx.showToast({
  190. title: '授权失败',
  191. icon: 'success',
  192. duration: 1000
  193. })
  194. }
  195. }
  196. })
  197. }
  198. }
  199. })
  200. } else if (res.authSetting['scope.userLocation'] == undefined) {
  201. //初始化进入
  202. app.getLocation();
  203. }
  204. else {
  205. //授权后默认加载
  206. app.getLocation();
  207. }
  208. }
  209. })
  210. that.userLogin()
  211. }
  212. },
  213. /**
  214. * 用户登录
  215. */
  216. userLogin: function () {
  217. var that = this;
  218. // 登录
  219. wx.login({
  220. success: ({
  221. code
  222. }) => {
  223. wx.getSystemInfo({
  224. success: function (res) {
  225. that.setData({
  226. systemInfo: JSON.stringify(res)
  227. })
  228. }
  229. })
  230. var usrdata = {
  231. appId: config.weapp.AppId,
  232. code: code,
  233. sceneAddress: app.globalData.sceneAddress,
  234. scene: that.data.scene,
  235. systemInfo: that.data.systemInfo
  236. };
  237. if (app.globalData.locationInfo) {
  238. usrdata = {
  239. appId: config.weapp.AppId,
  240. code: code,
  241. sceneAddress: app.globalData.sceneAddress,
  242. latitude: "" + app.globalData.locationInfo.latitude,
  243. longitude: "" + app.globalData.locationInfo.longitude,
  244. scene: that.data.scene,
  245. systemInfo: that.data.systemInfo
  246. };
  247. }
  248. Http.post({
  249. url: config.api.login,
  250. data: usrdata
  251. })
  252. .then(res => {
  253. app.globalData.token = res.data.token;
  254. Http.setToken(res.data.token);
  255. that.checkUserCarStatus();
  256. that.getUserInfo();
  257. that.getList();
  258. that.init();
  259. that.initUsrCarList();
  260. return Http.get({
  261. url: config.api.checkUserStatus,
  262. data: {}
  263. });
  264. })
  265. .then(res => {
  266. })
  267. .catch(err => {
  268. if (err.code == 11004) {
  269. // 用户昵称未授权
  270. wx.redirectTo({
  271. url: "/pages/getuserinfo/index"
  272. });
  273. } else {
  274. wx.showModal({
  275. title: '提示',
  276. content: err.errMsg,
  277. showCancel: false
  278. })
  279. }
  280. });
  281. }
  282. });
  283. },
  284. /**
  285. * 检查用户是否有车
  286. */
  287. checkUserCarStatus: function () {
  288. var that = this;
  289. Http.get({
  290. url: config.api.userCarCount,
  291. data: {}
  292. }).then(res => {
  293. if (res.data > 0) {
  294. // 用户名下有车
  295. app.globalData.phone = res.data.phone;
  296. app.globalData.supportCar = true;
  297. // 共同登录
  298. that.userCarLogin();
  299. }
  300. })
  301. .catch(err => {
  302. })
  303. },
  304. /**
  305. * 获取用户信息
  306. */
  307. getUserInfo: function () {
  308. // 获取用户信息
  309. wx.getSetting({
  310. success: res => {
  311. if (res.authSetting["scope.userInfo"]) {
  312. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  313. wx.getUserInfo({
  314. success: res => {
  315. // 可以将 res 发送给后台解码出 unionId
  316. }
  317. });
  318. }
  319. }
  320. })
  321. },
  322. jumpToAdd: function () {
  323. wx.navigateTo({
  324. url: `/pages/addPark/addPark?flags=managepalte`
  325. });
  326. },
  327. passc: function () {
  328. wx.navigateTo({
  329. url: '/pages/ques/ques',
  330. })
  331. },
  332. /**
  333. * 券绑定车牌
  334. */
  335. bindCoupon: function (quanid) {
  336. var that = this;
  337. /**
  338. * etcp
  339. */
  340. var etcpData = {
  341. etcpToken: app.globalData.etcpToken,
  342. carNumber: that.data.listCardNum,
  343. couponOrderId: quanid
  344. };
  345. /**
  346. * 停简单
  347. */
  348. var tjdData = {
  349. carNumber: that.data.listCardNum
  350. };
  351. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  352. Http.post({
  353. url: config.api.getCarCoupon,
  354. data: postCouponData
  355. })
  356. .then(res => {
  357. that.initUsrCarList();
  358. })
  359. .catch(err => {
  360. console.log(err)
  361. wx.showToast({
  362. title: err.message,
  363. icon: 'none',
  364. duration: 2000,
  365. mask: false
  366. });
  367. })
  368. },
  369. /**
  370. * 选择优惠券
  371. */
  372. gotoquan: function () {
  373. let that = this;
  374. if (that.data.quanid) {
  375. wx.navigateTo({
  376. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  377. })
  378. } else {
  379. wx.navigateTo({
  380. url: '/pages/passCar/choicecoupon/choicecoupon',
  381. })
  382. }
  383. },
  384. //获取名下停车券列表
  385. getList() {
  386. var that = this;
  387. Http.get({
  388. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  389. data: {
  390. pageNum: 1,
  391. pageSize: 8,
  392. couponOrderStatus: 0
  393. }
  394. }).then(res => {
  395. that.setData({
  396. couponList: res.data.list
  397. });
  398. })
  399. .catch(err => {
  400. console.log(err)
  401. })
  402. },
  403. /**
  404. * 共同登录
  405. */
  406. init: function (carNumber) {
  407. var that = this;
  408. app.parkInitCallback = token => {
  409. that.initPark();
  410. that.getParkStatus();
  411. if (!app.globalData.carLogin) {
  412. /**
  413. * 判断是否授权手机号
  414. */
  415. Http.get({
  416. url: config.api.checkPhoneStatus,
  417. data: {}
  418. })
  419. .then(res => {
  420. Http.post({
  421. url: config.api.carInit,
  422. data: {
  423. phone: app.globalData.phone
  424. }
  425. }).then(res => {
  426. app.globalData.carLogin = true;
  427. app.globalData.parkVendor = res.data.vendor;
  428. if (res.data.token) {
  429. app.globalData.etcpToken = res.data.token;
  430. }
  431. /**
  432. * 获得停车费用
  433. */
  434. that.initUsrCarList("flags");
  435. });
  436. })
  437. .catch(err => {
  438. if (err.code == 11005) {
  439. // 用户手机未授权
  440. /**
  441. * 将值传到用户手机号授权的页面
  442. *
  443. */
  444. wx.redirectTo({
  445. url: "/pages/getphoneInfo/index"
  446. });
  447. } else if (err.code == 11006) {
  448. // 用户手机已加密
  449. wx.redirectTo({
  450. url: "/pages/phoneinput/phoneinput"
  451. });
  452. } else {
  453. wx.showToast({
  454. title: err.errMsg,
  455. icon: 'none',
  456. duration: 2000,
  457. mask: false
  458. });
  459. }
  460. })
  461. }
  462. };
  463. if (app.globalData.token && app.globalData.token != null) {
  464. app.parkInitCallback(app.globalData.token);
  465. }
  466. },
  467. bindCar: function (carNum) {
  468. var that = this;
  469. // ETCP
  470. var etcpData = {
  471. etcpToken: app.globalData.etcpToken,
  472. carNumber: carNum
  473. };
  474. var tjdData = {
  475. carNumber: carNum
  476. };
  477. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  478. Http.post({
  479. url: config.api.bindCar,
  480. data: postData
  481. })
  482. .then(res => {
  483. that.setData({
  484. addCar: null
  485. });
  486. that.initUsrCarList();
  487. wx.showModal({
  488. title: "提示",
  489. showCancel: false,
  490. content: "绑车牌成功!",
  491. success: function () { }
  492. });
  493. })
  494. .catch(error => {
  495. wx.showModal({
  496. title: "提示",
  497. showCancel: false,
  498. content: error.data.message,
  499. success: function () { }
  500. });
  501. });
  502. },
  503. /**
  504. * 车场信息获取
  505. */
  506. initPark: function () {
  507. var that = this;
  508. Http.get({
  509. url: config.api.getParkInfo,
  510. data: {}
  511. })
  512. .then(res => {
  513. that.setData({
  514. park: res.data
  515. })
  516. })
  517. .catch(err => {
  518. console.log(err);
  519. // wx.showToast({
  520. // title: err.message,
  521. // icon: 'none',
  522. // duration: 2000,
  523. // mask: false
  524. // });
  525. })
  526. },
  527. /**
  528. * 车场状态获取
  529. */
  530. getParkStatus: function () {
  531. var that = this;
  532. Http.get({
  533. url: config.api.getParkStatus,
  534. })
  535. .then(res => {
  536. console.log(res)
  537. })
  538. .catch(err => {
  539. console.log(err)
  540. // wx.showToast({
  541. // title: err.message,
  542. // icon:"none"
  543. // })
  544. })
  545. },
  546. /**
  547. * 绑定车获取
  548. */
  549. initUsrCarList: function (flag) {
  550. var that = this;
  551. Http.get({
  552. url: config.api.getUserCarList,
  553. data: {}
  554. }).then(res => {
  555. that.setData({
  556. carList: res.data
  557. });
  558. /**
  559. * flag ==flags
  560. * 表示从首页onShow进来的
  561. */
  562. if (flag == "flags" && res.data.length > 0) {
  563. var listCardNum = res.data[0].carNumber;
  564. that.setData({
  565. listCardNum: listCardNum
  566. })
  567. /**
  568. * 获得停车费用
  569. */
  570. that.getStopFee(listCardNum);
  571. }
  572. })
  573. .catch(err => {
  574. wx.showToast({
  575. title: err.message,
  576. icon: 'none',
  577. duration: 2000,
  578. mask: false
  579. });
  580. })
  581. },
  582. /**
  583. * 获得停车费用修改
  584. */
  585. getStopFee: function (carNumber) {
  586. let that = this;
  587. let postData =
  588. app.globalData.parkVendor == 1 ? {
  589. etcpToken: app.globalData.etcpToken,
  590. carNumber: carNumber
  591. } : {
  592. carNumber: carNumber,
  593. outCarId: outCarId
  594. };
  595. Http.post({
  596. url: config.api.getCarStopFee,
  597. data: postData
  598. })
  599. .then(res => {
  600. console.log(res)
  601. var extraDataStr = {
  602. params: {
  603. token: app.globalData.etcpToken,
  604. syncId: res.data.orderId,
  605. payType: 6, // 小程序支付
  606. CarNumber: carNumber,
  607. returnUrl: that.data.etcpCallbackUrl,
  608. source: "FUMAO-001",
  609. actionId: "1" //操作ID,1:小程序支付
  610. }
  611. };
  612. that.setData({
  613. extraData: extraDataStr,
  614. stopFees: res.data,
  615. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  616. });
  617. that.setData({
  618. scroll: true
  619. })
  620. })
  621. .catch(error => {
  622. that.setData({
  623. stopFees: {},
  624. scroll: true
  625. })
  626. });
  627. },
  628. /**
  629. * 下拉刷新
  630. */
  631. onPullDownRefresh: function (e) {
  632. let that = this;
  633. that.initUsrCarList("flags");
  634. wx.stopPullDownRefresh();
  635. },
  636. // 用户点击右上角分享
  637. onShareAppMessage: function () {
  638. return {
  639. title: this.data.title,
  640. desc: this.data.desc,
  641. success: function (res) {
  642. wx.showToast({
  643. title: "分享成功",
  644. duration: 1000,
  645. icon: "success"
  646. });
  647. }
  648. }
  649. }
  650. });