C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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