C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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