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.

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