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.

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