C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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