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.

618 regels
15 KiB

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