农经大屏
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.

402 line
14 KiB

  1. import { getConfigKey } from "@/api/system/config";
  2. import { getInfo } from "@/api/login";
  3. import { treeselect, treeselectByDeptId } from "@/api/system/dept";
  4. import GisUtils from '@/utils/gis.js';
  5. import {
  6. assetsStatistics,
  7. deptFundStatistics,
  8. financeSummary, financeSummaryOverview, incomeBookRank, incomeMonthStatistics, incomeTownRank,
  9. resourceAssetsStatistics
  10. } from "@/api/dataScreen/bigDataMonitoring2/stockCooperative.js";
  11. import { comps } from './data.js'
  12. import {
  13. fromLonLat
  14. } from 'ol/proj'
  15. let gis = null;
  16. const DEPT_CHANGED = 1;
  17. const YEAR_CHANGED = 1 << 1;
  18. const ALL_CHANGED = ~(1 << 31);
  19. export default {
  20. components: {
  21. },
  22. watch: {
  23. 'queryParams.deptId': {
  24. handler: function () {
  25. this.commitDept(this.queryParams.deptId);
  26. },
  27. immediate: true, // 立即执行
  28. }
  29. },
  30. data () {
  31. return {
  32. financeSummary: {
  33. funds: 0, // 资金
  34. totalAssets: 0, // 资产
  35. totalResource: 0, // 资源
  36. income: 0, // 经营收入
  37. outcome: 0, // 经营支出
  38. overhead: 0, // 管理费用
  39. revenue: 0, // 发包收入
  40. otherIncome: 0, // 其他收入
  41. otherOutcome: 0, // 其他支出
  42. },
  43. financeSummaryOverview: {
  44. zeroIncomeBook: 0, // 0收入组织
  45. areaTotalIncome: 0, // 区收入总和
  46. townAvgIncome: 0, // 镇平均收入
  47. bookAvgIncome: 0, // 组织平均收入
  48. },
  49. //搜索栏参数
  50. centerYear: new Date().getFullYear(),
  51. yearList: [
  52. new Date().getFullYear(),
  53. new Date().getFullYear() - 1,
  54. new Date().getFullYear() - 2,
  55. new Date().getFullYear() - 3,
  56. new Date().getFullYear() - 4,
  57. ],
  58. addrText: [100,],
  59. deptTreeProps: {
  60. checkStrictly: true,
  61. },
  62. queryParams: {
  63. year: new Date().getFullYear(),
  64. deptId: 100,
  65. },
  66. yellowIcon: require('./icon/yellow.png'),
  67. comps,
  68. map: "", // 地图
  69. mapGeoServerUrl: "", // geoserver地址
  70. mapBorder: "", // 地图边界
  71. deptLayer: "", // 坐标点图层
  72. countyBorderLayerName: "", // 区县边界图层名称
  73. townBorderLayerName: "", // 乡镇边界图层名称
  74. villageBorderLayerName: "", // 村边界图层名称
  75. groupBorderLayerName: "", // 组边界图层名称
  76. addrOptions: []
  77. };
  78. },
  79. computed: {
  80. currentComp: function () {
  81. return this.comps[this.tab]
  82. }
  83. },
  84. created () {
  85. },
  86. mounted () {
  87. this.commitYear(this.centerYear);
  88. // 获取geoserver的地址
  89. this.getGeoServerUrl();
  90. getInfo().then(res => {
  91. // this.getData();
  92. treeselectByDeptId({ deptId: res.user.deptId }).then((resp) => {
  93. this.addrOptions = resp.data;
  94. // 初始化地图
  95. this.initMap();
  96. });
  97. });
  98. },
  99. methods: {
  100. /**
  101. * 提交dept
  102. * @param {*} deptId
  103. */
  104. commitDept (deptId) {
  105. this.$store.commit('SET_DEPTID', deptId);
  106. },
  107. commitYear (year) {
  108. this.$store.commit('SET_YEAR', year);
  109. },
  110. //切换年份
  111. yearDropdown (item) {
  112. this.queryParams.year = item;
  113. this.centerYear = item;
  114. this.getData(YEAR_CHANGED);
  115. this.commitYear(item);
  116. },
  117. // 绘制地图
  118. drawMap (node, isLocated) { // isLocated 控制地图是否跳转
  119. const dept = node.data;
  120. gis.getMapContainer().removeLayer(this.mapBorder);
  121. this.mapBorder = '';
  122. gis.getMapContainer().removeLayer(this.deptLayer);
  123. this.deptLayer = '';
  124. if (dept.deptLevel === '5') {
  125. this.cityId = dept.id;
  126. this.currentDeptLevel = '5';
  127. if (dept.children && dept.children.length > 0) {
  128. // 添加区县边界
  129. this.addCountyBorder(dept.children.map(item => item.id));
  130. // 添加坐标点图层
  131. this.addDeptLayer(dept.children, 'yellow.png');
  132. }
  133. if (isLocated) {
  134. gis.getMapContainer().getView().setZoom(9);
  135. gis.getMapContainer().getView().setCenter(fromLonLat([dept.lng, dept.lat]));
  136. }
  137. } else if (dept.deptLevel === '4') {
  138. this.countyId = dept.id;
  139. this.currentDeptLevel = '4';
  140. if (dept.children && dept.children.length > 0) {
  141. // 添加乡镇边界
  142. this.addTownBorder(dept.children.map(item => item.id));
  143. // 添加坐标点图层
  144. this.addDeptLayer(dept.children, 'yellow.png');
  145. }
  146. if (isLocated) {
  147. gis.getMapContainer().getView().setZoom(11);
  148. gis.getMapContainer().getView().setCenter(fromLonLat([dept.lng, dept.lat]));
  149. }
  150. // this.villageIds = this.findLeafNodeIds(dept);
  151. } else if (dept.deptLevel === '3') {
  152. this.townId = dept.id;
  153. this.countyId = node.path.slice(-2)[0];
  154. this.currentDeptLevel = '3';
  155. if (dept.children && dept.children.length > 0) {
  156. // 添加村边界
  157. this.addVillageBorder(dept.children.map(item => item.id));
  158. // 添加坐标点图层
  159. this.addDeptLayer(dept.children, 'yellow.png');
  160. }
  161. if (isLocated) {
  162. gis.getMapContainer().getView().setZoom(13);
  163. gis.getMapContainer().getView().setCenter(fromLonLat([dept.lng, dept.lat]));
  164. }
  165. // this.villageIds = this.findLeafNodeIds(dept);
  166. } else if (dept.deptLevel === '2') {
  167. this.ruralId = dept.id;
  168. this.townId = node.path.slice(-2)[0];
  169. this.countyId = node.path.slice(-3)[0];
  170. this.currentDeptLevel = '2';
  171. if (dept.children && dept.children.length > 0) {
  172. const groupIds = dept.children.map(item => item.id);
  173. // 添加组边界
  174. this.addGroupBorder(groupIds);
  175. // 添加组的坐标点图层,并且跳转到图层的中心点位置
  176. this.addGroupPointLayer(groupIds, isLocated);
  177. } else {
  178. // 添加村边界
  179. this.addVillageBorder(dept.id);
  180. // 添加坐标点图层
  181. let deptList = [];
  182. deptList.push(dept);
  183. this.addDeptLayer(deptList, 'yellow.png');
  184. if (isLocated) {
  185. gis.getMapContainer().getView().setCenter(fromLonLat([dept.lng, dept.lat]));
  186. }
  187. }
  188. if (isLocated) {
  189. gis.getMapContainer().getView().setZoom(15);
  190. }
  191. // this.villageIds = this.findLeafNodeIds(dept);
  192. } else if (dept.deptLevel === '1') {
  193. this.ruralId = node.path.slice(-2)[0];
  194. this.townId = node.path.slice(-3)[0];
  195. this.countyId = node.path.slice(-4)[0];
  196. this.currentDeptLevel = '1';
  197. // 添加组边界
  198. this.addGroupBorder(dept.id);
  199. // 添加组的坐标点图层,并且跳转到图层的中心点位置
  200. this.addGroupPointLayer(dept.id, isLocated);
  201. if (isLocated) {
  202. gis.getMapContainer().getView().setZoom(17);
  203. }
  204. // this.villageIds = this.findLeafNodeIds(dept);
  205. }
  206. // this.changeLayerByDept();
  207. },
  208. tabChange (info) {
  209. this.tab = info.id;
  210. },
  211. // 初始化地图
  212. initMap () {
  213. let dept = this.addrOptions[0];
  214. let mapCenterLocation;
  215. if (dept.lng && dept.lat) {
  216. mapCenterLocation = [dept.lng, dept.lat];
  217. } else {
  218. mapCenterLocation = [116.391461, 39.902359];
  219. }
  220. gis = new GisUtils('map22222')
  221. gis.addTianDiTuLayer()
  222. gis.addAnnotationLayer()
  223. if (dept.deptLevel === '5') {
  224. // 登录身份为市级领导
  225. this.userRole = 'cityLeader';
  226. this.cityId = dept.id;
  227. this.currentDeptLevel = '5';
  228. // 添加区县边界
  229. this.addCountyBorder(dept.children.map(item => item.id));
  230. } else if (dept.deptLevel === '4') {
  231. // 登录身份为县级领导
  232. this.userRole = 'countyLeader';
  233. this.countyId = dept.id;
  234. this.currentDeptLevel = '4';
  235. // 添加乡镇边界
  236. this.addTownBorder(dept.children.map(item => item.id));
  237. gis.getView().setZoom(11);
  238. } else if (dept.deptLevel === '3') {
  239. // 登录身份为镇级领导
  240. this.userRole = 'townLeader';
  241. this.townId = dept.id;
  242. this.currentDeptLevel = '3';
  243. // 添加村边界
  244. this.addVillageBorder(dept.children.map(item => item.id));
  245. gis.getView().setZoom(13);
  246. }
  247. // 添加坐标点图层
  248. if (dept.children) {
  249. this.addDeptLayer(dept.children);
  250. }
  251. gis.getView().setCenter(fromLonLat(mapCenterLocation))
  252. // 地图点击事件
  253. gis.getMapContainer().on("click", (evt) => {
  254. let feature = gis.getMapContainer().forEachFeatureAtPixel(
  255. evt.pixel,
  256. (feature) => feature
  257. );
  258. if (feature) {
  259. // 镇级:加载村级坐标点
  260. if (feature.get('level') === 'deptPoint') {
  261. let parentIds = [];
  262. this.findParentNodeIds(this.addrOptions, feature.get('deptId'), parentIds);
  263. this.addrText = parentIds;
  264. this.selectAddress(parentIds);
  265. }
  266. }
  267. });
  268. },
  269. getData (mask) {
  270. if (!mask)
  271. mask = ALL_CHANGED;
  272. financeSummary(this.queryParams).then((resp) => {
  273. let data = resp;
  274. this.financeSummary.funds = data.funds;
  275. this.financeSummary.totalAssets = data.totalAssets;
  276. this.financeSummary.totalResource = data.totalResource;
  277. this.financeSummary.income = data.income;
  278. this.financeSummary.outcome = data.outcome;
  279. this.financeSummary.overhead = data.overhead;
  280. this.financeSummary.revenue = data.revenue;
  281. this.financeSummary.otherIncome = data.otherIncome;
  282. this.financeSummary.otherOutcome = data.otherOutcome;
  283. });
  284. deptFundStatistics(this.queryParams).then((resp) => {
  285. let data = resp.data;
  286. // this.leftTopEchart(this.genChartData(data));
  287. this.fundAmountTotal = data.extras.total;
  288. });
  289. resourceAssetsStatistics(this.queryParams).then((resp) => {
  290. // this.leftBottomEchart(this.genChartData(resp.data));
  291. });
  292. assetsStatistics(this.queryParams).then((resp) => {
  293. // let data = this.genChartData(resp.data);
  294. // this.leftCenterEchart(data);
  295. // this.assetStatistics = data.xAxis.data.map((x, i) => {
  296. // return {
  297. // name: x,
  298. // value: data.series[0].data[i],
  299. // };
  300. // });
  301. });
  302. incomeMonthStatistics(this.queryParams).then((resp) => {
  303. // this.rightTopEchart(this.genChartData(resp.data));
  304. });
  305. incomeBookRank(this.queryParams).then((resp) => {
  306. this.incomeBookRankList = resp.data;
  307. });
  308. if (mask & YEAR_CHANGED) {
  309. incomeTownRank(this.queryParams).then((resp) => {
  310. this.incomeTownRankList = resp.data;
  311. });
  312. financeSummaryOverview(this.queryParams).then((resp) => {
  313. let data = resp.data;
  314. this.financeSummaryOverview.zeroIncomeBook = data.zeroIncomeBook;
  315. this.financeSummaryOverview.areaTotalIncome = data.areaTotalIncome;
  316. this.financeSummaryOverview.townAvgIncome = data.townAvgIncome;
  317. this.financeSummaryOverview.bookAvgIncome = data.bookAvgIncome;
  318. // this.dashboardZeroincome();
  319. // this.dashboardZeroincome2();
  320. // this.dashboardZeroincome3();
  321. // this.dashboardZeroincome4();
  322. });
  323. }
  324. },
  325. selectAddress (value, isLocated = true) { // isLocated 控制地图是否跳转
  326. this.queryParams.deptId = value[value.length - 1];
  327. this.getData(DEPT_CHANGED);
  328. let node = this.$refs["cascader2"].panel.getNodeByValue(value);
  329. this.drawMap(node, isLocated);
  330. },
  331. // 查找指定deptId的所有父节点id
  332. findParentNodeIds (tree, deptId, result) {
  333. for (let node of tree) {
  334. if (node.id === deptId) {
  335. result.unshift(node.id);
  336. return true;
  337. }
  338. if (node.children && node.children.length > 0) {
  339. let isFind = this.findParentNodeIds(node.children, deptId, result);
  340. if (isFind) {
  341. result.unshift(node.id);
  342. return true;
  343. }
  344. }
  345. }
  346. return false;
  347. },
  348. // 添加坐标点图层
  349. addDeptLayer (nextDeptSet) {
  350. let features = [];
  351. nextDeptSet.forEach(item => {
  352. let fs = gis.getFeature(item, this.yellowIcon)
  353. features.push(fs);
  354. });
  355. gis.getVectorLayerByFs(features)
  356. gis.mapSetFit(features)
  357. },
  358. // 添加区县边界
  359. addCountyBorder (deptIds) {
  360. gis.addImageLayer(this.mapGeoServerUrl, this.countyBorderLayerName, deptIds)
  361. },
  362. // 添加乡镇边界
  363. addTownBorder (deptIds) {
  364. gis.addImageLayer(this.mapGeoServerUrl, this.townBorderLayerName, deptIds)
  365. },
  366. // 添加村边界
  367. addVillageBorder (deptIds) {
  368. gis.addImageLayer(this.mapGeoServerUrl, this.villageBorderLayerName, deptIds)
  369. },
  370. // 获取geoserver的地址
  371. getGeoServerUrl () {
  372. // 获取geoserver的地址
  373. getConfigKey("system.geoServer.url").then(response => {
  374. this.mapGeoServerUrl = response.msg;
  375. });
  376. // 获取区县边界图层名称
  377. getConfigKey("geoserver.layer.countyBorder").then(response => {
  378. this.countyBorderLayerName = response.msg;
  379. });
  380. // 获取乡镇边界的图层名称
  381. getConfigKey("geoserver.layer.townBorder").then(response => {
  382. this.townBorderLayerName = response.msg;
  383. });
  384. // 获取村边界的图层名称
  385. getConfigKey("geoserver.layer.villageBorder").then(response => {
  386. this.villageBorderLayerName = response.msg;
  387. });
  388. // 获取组边界的图层名称
  389. getConfigKey("geoserver.layer.groupBorder").then(response => {
  390. this.groupBorderLayerName = response.msg;
  391. });
  392. }
  393. }
  394. };