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.

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