C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

604 строки
14 KiB

  1. let config = require("../../config/config.js");
  2. let Http = require("../../utils/HttpBasics");
  3. let Util = require("../../utils/util");
  4. let app = getApp();
  5. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. data: {
  8. parkUrl: imgurl.park.url,
  9. jianUrl: imgurl.jian.url,
  10. addUrl: imgurl.add.url,
  11. quanUrl: imgurl.quan.url,
  12. cheUrl: imgurl.che.url,
  13. ruleUrl: imgurl.rule.url,
  14. wentiUrl: imgurl.wenti.url,
  15. park: null,
  16. carList: [],
  17. payList: [],
  18. addCar: null,
  19. tcq: 2,
  20. flag: "",
  21. extraData: {},
  22. desc: '',
  23. title: '',
  24. indicatorDots: true,
  25. autoplay: false,
  26. interval: 5000,
  27. duration: 1000,
  28. current: 0,
  29. stopFees: {},
  30. scroll:true,
  31. canIUse: wx.canIUse("navigator")
  32. },
  33. /**
  34. * 车牌轮播滑动
  35. */
  36. onSlideChangeEnd: function(e) {
  37. var that = this;
  38. /**
  39. * 获得当前的车牌号码
  40. */
  41. var listCardNum = (that.data.carList)[e.detail.current].carNumber;
  42. that.setData({
  43. listCardNum: listCardNum
  44. });
  45. /**
  46. * 获得停车费用
  47. */
  48. if(that.data.scroll){
  49. that.getStopFee(listCardNum);
  50. }
  51. },
  52. gotomange: function() {
  53. wx.navigateTo({
  54. url: '/pages/managelicenseplate/managelicenseplate',
  55. })
  56. },
  57. bindfail:function(res){
  58. console.log(res)
  59. },
  60. gotoetcp:function(){
  61. console.log(this.data.extraData)
  62. wx.navigateToMiniProgram({
  63. appId:'wx192b7d2e8dcbefd0',
  64. extraData: this.data.extraData,
  65. envVersion:'release',
  66. path:"pages/main/main",
  67. })
  68. },
  69. showquan: function() {
  70. wx.navigateTo({
  71. url: '/pages/passCar/couponList/couponList',
  72. })
  73. },
  74. gotodetail: function(e) {
  75. wx.showModal({
  76. title: '缴费规则',
  77. content: e.target.dataset.rule,
  78. showCancel: false,
  79. })
  80. },
  81. onShow: function(options) {
  82. var that = this;
  83. if (app.globalData.token) {
  84. that.getList();
  85. that.init();
  86. }else{
  87. that.init();
  88. }
  89. /**
  90. * 只有用户选择了优惠券
  91. * 才会进行券和车牌的绑定
  92. */
  93. if (wx.getStorageSync("chosed") && that.data.quanid) {
  94. that.bindCoupon(that.data.quanid);
  95. wx.setStorage({
  96. key: 'chosed',
  97. data: '',
  98. })
  99. };
  100. if (app.globalData.token) {
  101. that.initUsrCarList();
  102. }
  103. if (that.data.addCar) {
  104. // 绑车牌
  105. if (app.globalData.carLogin) {
  106. that.bindCar(that.data.addCar);
  107. } else {
  108. that.bindCar(that.data.addCar);
  109. }
  110. that.setData({
  111. addCar: null
  112. });
  113. }
  114. },
  115. onLoad: function(options) {
  116. var that = this;
  117. /**
  118. * 获得分享小程序的
  119. * title
  120. * desc
  121. */
  122. Http.get({
  123. url: config.api.getWeapNote,
  124. data: {
  125. appId: config.weapp.AppId,
  126. }
  127. })
  128. .then(res => {
  129. let weapNote = JSON.parse(res.data.weapNote);
  130. that.setData({
  131. desc: weapNote.carpage.desc,
  132. title: weapNote.carpage.title
  133. })
  134. })
  135. .catch(err => {
  136. console.log(err);
  137. })
  138. // 登录
  139. var scene = decodeURIComponent(options.scene);
  140. that.setData({
  141. scene: scene
  142. });
  143. if (app.globalData.token){}else{
  144. app.getLocation();
  145. that.userLogin()
  146. }
  147. },
  148. /**
  149. * 用户登录
  150. */
  151. userLogin: function () {
  152. var that = this;
  153. // 登录
  154. wx.login({
  155. success: ({
  156. code
  157. }) => {
  158. wx.getSystemInfo({
  159. success: function (res) {
  160. that.setData({
  161. systemInfo: JSON.stringify(res)
  162. })
  163. }
  164. })
  165. var usrdata = {
  166. appId: config.weapp.AppId,
  167. code: code,
  168. sceneAddress: app.globalData.sceneAddress,
  169. scene: that.data.scene,
  170. systemInfo: that.data.systemInfo
  171. };
  172. if (app.globalData.locationInfo) {
  173. usrdata = {
  174. appId: config.weapp.AppId,
  175. code: code,
  176. sceneAddress: app.globalData.sceneAddress,
  177. latitude: "" + app.globalData.locationInfo.latitude,
  178. longitude: "" + app.globalData.locationInfo.longitude,
  179. scene: that.data.scene,
  180. systemInfo: that.data.systemInfo
  181. };
  182. }
  183. Http.post({
  184. url: config.api.login,
  185. data: usrdata
  186. })
  187. .then(res => {
  188. app.globalData.token = res.data.token;
  189. Http.setToken(res.data.token);
  190. that.checkUserCarStatus();
  191. that.getUserInfo();
  192. that.getList();
  193. that.init();
  194. that.initUsrCarList();
  195. return Http.post({
  196. url: config.api.checkUserStatus,
  197. data: {}
  198. });
  199. })
  200. .then(res => {
  201. })
  202. .catch(err => {
  203. if (err.code == 11004) {
  204. // 用户昵称未授权
  205. wx.redirectTo({
  206. url: "/pages/getuserinfo/index"
  207. });
  208. }else{
  209. wx.showModal({
  210. title: '提示',
  211. content: err.errMsg,
  212. showCancel:false
  213. })
  214. }
  215. });
  216. }
  217. });
  218. },
  219. /**
  220. * 检查用户是否有车
  221. */
  222. checkUserCarStatus: function () {
  223. var that = this;
  224. Http.get({
  225. url: config.api.userCarCount,
  226. data: {}
  227. }).then(res => {
  228. if (res.data > 0) {
  229. // 用户名下有车
  230. app.globalData.phone = res.data.phone;
  231. app.globalData.supportCar = true;
  232. // 共同登录
  233. that.userCarLogin();
  234. }
  235. })
  236. .catch(err => {
  237. })
  238. },
  239. /**
  240. * 获取用户信息
  241. */
  242. getUserInfo: function () {
  243. // 获取用户信息
  244. wx.getSetting({
  245. success: res => {
  246. if (res.authSetting["scope.userInfo"]) {
  247. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  248. wx.getUserInfo({
  249. success: res => {
  250. // 可以将 res 发送给后台解码出 unionId
  251. }
  252. });
  253. }
  254. }
  255. })
  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.post({
  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. console.log(postData)
  531. Http.post({
  532. url: config.api.getCarStopFee,
  533. data: postData
  534. })
  535. .then(res => {
  536. var extraDataStr = {
  537. params: {
  538. token: app.globalData.etcpToken,
  539. syncId: res.data.orderId,
  540. payType: 6, // 小程序支付
  541. CarNumber: carNumber,
  542. returnUrl: "https://admintest.malls.iformall.com/api/carCallback/etcpPaidCallback",
  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. console.log(error)
  558. wx.showModal({
  559. title: '提示',
  560. content: error.message,
  561. showCancel: false
  562. })
  563. that.setData({
  564. stopFees: {},
  565. scroll: true
  566. })
  567. });
  568. },
  569. /**
  570. * 下拉刷新
  571. */
  572. onPullDownRefresh: function(e) {
  573. let that = this;
  574. that.initUsrCarList("flags");
  575. wx.stopPullDownRefresh();
  576. },
  577. // 用户点击右上角分享
  578. onShareAppMessage: function() {
  579. return {
  580. title: this.data.title,
  581. desc: this.data.desc,
  582. success: function(res) {
  583. wx.showToast({
  584. title: "分享成功",
  585. duration: 1000,
  586. icon: "success"
  587. });
  588. }
  589. }
  590. }
  591. });