C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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