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.

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