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.

561 line
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. 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. if (app.globalData.token){}else{
  128. app.getLocation();
  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. bindCar: function (carNum) {
  375. var that = this;
  376. // ETCP
  377. var etcpData = {
  378. etcpToken: app.globalData.etcpToken,
  379. carNumber: carNum
  380. };
  381. var tjdData = {
  382. carNumber: carNum
  383. };
  384. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  385. Http.post({
  386. url: config.api.bindCar,
  387. data: postData
  388. })
  389. .then(res => {
  390. console.log(res);
  391. that.setData({
  392. addCar: null
  393. });
  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.data.message,
  408. success: function () { }
  409. });
  410. });
  411. },
  412. /**
  413. * 车场信息获取
  414. */
  415. initPark: function() {
  416. var that = this;
  417. Http.get({
  418. url: config.api.getParkInfo,
  419. data: {}
  420. })
  421. .then(res => {
  422. that.setData({
  423. park: res.data
  424. })
  425. })
  426. .catch(error=>{
  427. console.log(error)
  428. })
  429. },
  430. /**
  431. * 车场状态获取
  432. */
  433. getParkStatus: function() {
  434. var that = this;
  435. Http.get({
  436. url: config.api.getParkStatus,
  437. })
  438. .then(res => {
  439. console.log(res);
  440. })
  441. .catch(error=>{
  442. console.log(error)
  443. })
  444. },
  445. /**
  446. * 绑定车获取
  447. */
  448. initUsrCarList: function(flag) {
  449. console.log(flag);
  450. var that = this;
  451. Http.get({
  452. url: config.api.getUserCarList,
  453. data: {}
  454. }).then(res => {
  455. console.log(res)
  456. that.setData({
  457. carList: res.data
  458. });
  459. /**
  460. * flag ==flags
  461. * 表示从首页onShow进来的
  462. */
  463. if (flag == "flags" && res.data.length > 0) {
  464. var listCardNum = res.data[0].carNumber;
  465. console.log(listCardNum);
  466. that.setData({
  467. listCardNum: listCardNum
  468. })
  469. /**
  470. * 获得停车费用
  471. */
  472. that.getStopFee(listCardNum);
  473. }
  474. })
  475. },
  476. /**
  477. * 获得停车费用修改
  478. */
  479. getStopFee: function(carNumber) {
  480. var that = this;
  481. var postData =
  482. app.globalData.parkVendor == 1 ? {
  483. etcpToken: app.globalData.etcpToken,
  484. carNumber: carNumber
  485. } : {
  486. carNumber: carNumber,
  487. outCarId: outCarId
  488. };
  489. Http.post({
  490. url: config.api.getCarStopFee,
  491. data: postData
  492. })
  493. .then(res => {
  494. var extraDataStr = {
  495. params: {
  496. token: app.globalData.etcpToken,
  497. syncId: res.data.orderId,
  498. payType: 6, // 小程序支付
  499. CarNumber: carNumber,
  500. returnUrl: "https://admin.malls.iformall.com/api/carCallback/etcpPaidCallback",
  501. source: "FUMAO-001",
  502. actionId: "1" //操作ID,1:小程序支付
  503. }
  504. };
  505. that.setData({
  506. extraData: extraDataStr
  507. });
  508. that.setData({
  509. stopFees: res.data
  510. })
  511. that.setData({
  512. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  513. })
  514. })
  515. .catch(error => {
  516. console.log(error);
  517. wx.showModal({
  518. title: '提示',
  519. content: error.message,
  520. showCancel: false
  521. })
  522. that.setData({
  523. stopFees: {}
  524. })
  525. });
  526. },
  527. /**
  528. * 下拉刷新
  529. */
  530. onPullDownRefresh: function(e) {
  531. let that = this;
  532. that.initUsrCarList("flags");
  533. wx.stopPullDownRefresh();
  534. },
  535. // 用户点击右上角分享
  536. onShareAppMessage: function() {
  537. return {
  538. title: this.data.title,
  539. desc: this.data.desc,
  540. success: function(res) {
  541. wx.showToast({
  542. title: "分享成功",
  543. duration: 1000,
  544. icon: "success"
  545. });
  546. }
  547. }
  548. }
  549. });