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.

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