C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

603 line
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. wx.showToast({
  302. title: err.message,
  303. icon: 'none',
  304. duration: 2000,
  305. mask: false
  306. });
  307. })
  308. },
  309. /**
  310. * 选择优惠券
  311. */
  312. gotoquan: function() {
  313. let that = this;
  314. if (that.data.quanid) {
  315. wx.navigateTo({
  316. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  317. })
  318. } else {
  319. wx.navigateTo({
  320. url: '/pages/passCar/choicecoupon/choicecoupon',
  321. })
  322. }
  323. },
  324. //获取名下停车券列表
  325. getList() {
  326. var that = this;
  327. Http.get({
  328. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  329. data: {
  330. pageNum: 1,
  331. pageSize: 8,
  332. couponOrderStatus: 0
  333. }
  334. }).then(res => {
  335. that.setData({
  336. couponList: res.data.list
  337. });
  338. })
  339. .catch(err => {
  340. console.log(err)
  341. })
  342. },
  343. /**
  344. * 共同登录
  345. */
  346. init: function(carNumber) {
  347. var that = this;
  348. app.parkInitCallback = token => {
  349. that.initPark();
  350. that.getParkStatus();
  351. if (!app.globalData.carLogin) {
  352. /**
  353. * 判断是否授权手机号
  354. */
  355. Http.post({
  356. url: config.api.checkPhoneStatus,
  357. data: {}
  358. })
  359. .then(res => {
  360. Http.post({
  361. url: config.api.carInit,
  362. data: {
  363. phone: app.globalData.phone
  364. }
  365. }).then(res => {
  366. app.globalData.carLogin = true;
  367. app.globalData.parkVendor = res.data.vendor;
  368. if (res.data.token) {
  369. app.globalData.etcpToken = res.data.token;
  370. }
  371. /**
  372. * 获得停车费用
  373. */
  374. that.initUsrCarList("flags");
  375. });
  376. })
  377. .catch(err => {
  378. if (err.code == 11005) {
  379. // 用户手机未授权
  380. /**
  381. * 将值传到用户手机号授权的页面
  382. *
  383. */
  384. wx.redirectTo({
  385. url: "/pages/getphoneInfo/index"
  386. });
  387. } else if (err.code == 11006) {
  388. // 用户手机已加密
  389. wx.redirectTo({
  390. url: "/pages/phoneinput/phoneinput"
  391. });
  392. }else{
  393. wx.showToast({
  394. title: err.errMsg,
  395. icon: 'none',
  396. duration: 2000,
  397. mask: false
  398. });
  399. }
  400. })
  401. }
  402. };
  403. if (app.globalData.token && app.globalData.token != null) {
  404. app.parkInitCallback(app.globalData.token);
  405. }
  406. },
  407. bindCar: function (carNum) {
  408. var that = this;
  409. // ETCP
  410. var etcpData = {
  411. etcpToken: app.globalData.etcpToken,
  412. carNumber: carNum
  413. };
  414. var tjdData = {
  415. carNumber: carNum
  416. };
  417. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  418. Http.post({
  419. url: config.api.bindCar,
  420. data: postData
  421. })
  422. .then(res => {
  423. that.setData({
  424. addCar: null
  425. });
  426. that.initUsrCarList();
  427. wx.showModal({
  428. title: "提示",
  429. showCancel: false,
  430. content: "绑车牌成功!",
  431. success: function () { }
  432. });
  433. })
  434. .catch(error => {
  435. wx.showModal({
  436. title: "提示",
  437. showCancel: false,
  438. content: error.data.message,
  439. success: function () { }
  440. });
  441. });
  442. },
  443. /**
  444. * 车场信息获取
  445. */
  446. initPark: function() {
  447. var that = this;
  448. Http.get({
  449. url: config.api.getParkInfo,
  450. data: {}
  451. })
  452. .then(res => {
  453. that.setData({
  454. park: res.data
  455. })
  456. })
  457. .catch(err => {
  458. console.log(err);
  459. // wx.showToast({
  460. // title: err.message,
  461. // icon: 'none',
  462. // duration: 2000,
  463. // mask: false
  464. // });
  465. })
  466. },
  467. /**
  468. * 车场状态获取
  469. */
  470. getParkStatus: function() {
  471. var that = this;
  472. Http.get({
  473. url: config.api.getParkStatus,
  474. })
  475. .then(res => {
  476. })
  477. .catch(err => {
  478. })
  479. },
  480. /**
  481. * 绑定车获取
  482. */
  483. initUsrCarList: function(flag) {
  484. var that = this;
  485. Http.get({
  486. url: config.api.getUserCarList,
  487. data: {}
  488. }).then(res => {
  489. that.setData({
  490. carList: res.data
  491. });
  492. /**
  493. * flag ==flags
  494. * 表示从首页onShow进来的
  495. */
  496. if (flag == "flags" && res.data.length > 0) {
  497. var listCardNum = res.data[0].carNumber;
  498. that.setData({
  499. listCardNum: listCardNum
  500. })
  501. /**
  502. * 获得停车费用
  503. */
  504. that.getStopFee(listCardNum);
  505. }
  506. })
  507. .catch(err => {
  508. wx.showToast({
  509. title: err.message,
  510. icon: 'none',
  511. duration: 2000,
  512. mask: false
  513. });
  514. })
  515. },
  516. /**
  517. * 获得停车费用修改
  518. */
  519. getStopFee: function(carNumber) {
  520. let that = this;
  521. let postData =
  522. app.globalData.parkVendor == 1 ? {
  523. etcpToken: app.globalData.etcpToken,
  524. carNumber: carNumber
  525. } : {
  526. carNumber: carNumber,
  527. outCarId: outCarId
  528. };
  529. console.log(postData)
  530. Http.post({
  531. url: config.api.getCarStopFee,
  532. data: postData
  533. })
  534. .then(res => {
  535. var extraDataStr = {
  536. params: {
  537. token: app.globalData.etcpToken,
  538. syncId: res.data.orderId,
  539. payType: 6, // 小程序支付
  540. CarNumber: carNumber,
  541. returnUrl: "https://admintest.malls.iformall.com/api/carCallback/etcpPaidCallback",
  542. source: "FUMAO-001",
  543. actionId: "1" //操作ID,1:小程序支付
  544. }
  545. };
  546. that.setData({
  547. extraData: extraDataStr,
  548. stopFees: res.data,
  549. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  550. });
  551. that.setData({
  552. scroll:true
  553. })
  554. })
  555. .catch(error => {
  556. console.log(error)
  557. wx.showModal({
  558. title: '提示',
  559. content: error.message,
  560. showCancel: false
  561. })
  562. that.setData({
  563. stopFees: {},
  564. scroll: true
  565. })
  566. });
  567. },
  568. /**
  569. * 下拉刷新
  570. */
  571. onPullDownRefresh: function(e) {
  572. let that = this;
  573. that.initUsrCarList("flags");
  574. wx.stopPullDownRefresh();
  575. },
  576. // 用户点击右上角分享
  577. onShareAppMessage: function() {
  578. return {
  579. title: this.data.title,
  580. desc: this.data.desc,
  581. success: function(res) {
  582. wx.showToast({
  583. title: "分享成功",
  584. duration: 1000,
  585. icon: "success"
  586. });
  587. }
  588. }
  589. }
  590. });