historyAnalysis.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div class="history-analysis-container">
  3. <!-- 搜索区域 -->
  4. <div class="search-area">
  5. <el-form :inline="true" :model="searchForm" class="demo-form-inline">
  6. <el-form-item label="项目名称">
  7. <el-input
  8. v-model="searchForm.projectName"
  9. placeholder="请输入"
  10. style="width: 200px"
  11. ></el-input>
  12. </el-form-item>
  13. <el-form-item label="被监审单位">
  14. <el-input
  15. v-model="searchForm.auditedUnit"
  16. placeholder="请输入"
  17. style="width: 200px"
  18. ></el-input>
  19. </el-form-item>
  20. <el-form-item label="监审期间">
  21. <el-date-picker
  22. v-model="searchForm.startYear"
  23. type="year"
  24. placeholder="选择开始年份"
  25. format="yyyy年"
  26. value-format="yyyy"
  27. style="width: 120px; margin-right: 10px"
  28. ></el-date-picker>
  29. <span>-</span>
  30. <el-date-picker
  31. v-model="searchForm.endYear"
  32. type="year"
  33. placeholder="选择结束年份"
  34. format="yyyy年"
  35. value-format="yyyy"
  36. style="width: 120px; margin-left: 10px"
  37. ></el-date-picker>
  38. </el-form-item>
  39. <el-form-item>
  40. <el-button type="primary" icon="el-icon-search" @click="handleQuery">
  41. 查询
  42. </el-button>
  43. <el-button icon="el-icon-refresh" @click="handleReset">
  44. 重置
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. </div>
  49. <!-- 主内容区域 -->
  50. <div class="main-content">
  51. <!-- 左侧指标选择列表 -->
  52. <div class="indicator-list">
  53. <div class="list-title">请选择数据项后查看分析:</div>
  54. <el-tree
  55. v-model="selectedIndicators"
  56. class="indicator-tree"
  57. :data="indicatorData"
  58. show-checkbox
  59. node-key="id"
  60. default-expand-all
  61. :expand-on-click-node="false"
  62. @check-change="handleCheckChange"
  63. ></el-tree>
  64. </div>
  65. <!-- 右侧图表展示区域 -->
  66. <div class="chart-area">
  67. <div class="chart-title">成本分析</div>
  68. <div class="charts-wrapper">
  69. <!-- 成本变化趋势分析图表 -->
  70. <div class="chart-item">
  71. <div class="sub-title">成本变化趋势分析</div>
  72. <div id="trendChart" style="height: 300px"></div>
  73. </div>
  74. <!-- 成本构成分析图表 -->
  75. <div class="chart-item">
  76. <div class="sub-title">成本构成分析</div>
  77. <div id="compositionChart" style="height: 300px"></div>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. import * as echarts from 'echarts'
  86. export default {
  87. name: 'HistoryAnalysis',
  88. data() {
  89. return {
  90. // 搜索表单
  91. searchForm: {
  92. projectName: '',
  93. auditedUnit: '',
  94. startYear: '2022',
  95. endYear: '2024',
  96. },
  97. // 指标树数据
  98. indicatorData: [
  99. {
  100. id: '1',
  101. label: '一、污水处治理成本',
  102. children: [
  103. { id: '1-1', label: '1.1 污水处理成本' },
  104. { id: '1-2', label: '1.2 污泥处理成本' },
  105. { id: '1-3', label: '1.3 税金及附加费用' },
  106. ],
  107. },
  108. {
  109. id: '2',
  110. label: '二、垃圾处理成本',
  111. children: [
  112. { id: '2-1', label: '2.1 垃圾处理总成本' },
  113. { id: '2-2', label: '2.2 单位垃圾处理成本' },
  114. ],
  115. },
  116. {
  117. id: '3',
  118. label: '三、分析类指标',
  119. children: [
  120. { id: '3-1', label: '3.1 实际处理水量' },
  121. { id: '3-2', label: '3.2 实际垃圾处理量' },
  122. { id: '3-3', label: '3.3 政府购买服务价格' },
  123. ],
  124. },
  125. ],
  126. // 选中的指标
  127. selectedIndicators: ['1-3'], // 默认选中"税金及附加费用"
  128. // 图表实例
  129. trendChart: null,
  130. compositionChart: null,
  131. }
  132. },
  133. mounted() {
  134. // 初始化图表
  135. this.initCharts()
  136. // 监听窗口大小变化,自动调整图表大小
  137. window.addEventListener('resize', this.handleResize)
  138. },
  139. beforeDestroy() {
  140. // 销毁图表实例,防止内存泄漏
  141. if (this.trendChart) {
  142. this.trendChart.dispose()
  143. }
  144. if (this.compositionChart) {
  145. this.compositionChart.dispose()
  146. }
  147. // 移除窗口大小变化监听
  148. window.removeEventListener('resize', this.handleResize)
  149. },
  150. methods: {
  151. // 初始化图表
  152. initCharts() {
  153. // 成本变化趋势分析图表
  154. const trendChartDom = document.getElementById('trendChart')
  155. this.trendChart = echarts.init(trendChartDom)
  156. this.trendChart.setOption(this.getTrendChartOption())
  157. // 成本构成分析图表
  158. const compositionChartDom = document.getElementById('compositionChart')
  159. this.compositionChart = echarts.init(compositionChartDom)
  160. this.compositionChart.setOption(this.getCompositionChartOption())
  161. },
  162. // 获取趋势图表配置
  163. getTrendChartOption() {
  164. return {
  165. tooltip: {
  166. trigger: 'axis',
  167. axisPointer: {
  168. type: 'cross',
  169. },
  170. },
  171. legend: {
  172. data: ['指标1', '指标2'],
  173. bottom: 0,
  174. },
  175. grid: {
  176. left: '3%',
  177. right: '4%',
  178. bottom: '10%',
  179. containLabel: true,
  180. },
  181. xAxis: {
  182. type: 'category',
  183. boundaryGap: false,
  184. data: ['2022年', '2023年', '2024年'],
  185. },
  186. yAxis: {
  187. type: 'value',
  188. min: 3,
  189. max: 10,
  190. },
  191. series: [
  192. {
  193. name: '指标1',
  194. type: 'line',
  195. data: [7.5, 7.2, 9.5],
  196. symbolSize: 10,
  197. smooth: true,
  198. lineStyle: {
  199. width: 3,
  200. color: '#0066FF',
  201. },
  202. itemStyle: {
  203. color: '#0066FF',
  204. },
  205. },
  206. {
  207. name: '指标2',
  208. type: 'line',
  209. data: [4.2, 4.5, 6.2],
  210. symbolSize: 10,
  211. smooth: true,
  212. lineStyle: {
  213. width: 3,
  214. color: '#52C41A',
  215. },
  216. itemStyle: {
  217. color: '#52C41A',
  218. },
  219. },
  220. ],
  221. }
  222. },
  223. // 获取构成图表配置
  224. getCompositionChartOption() {
  225. return {
  226. tooltip: {
  227. trigger: 'item',
  228. formatter: '{a} <br/>{b}: {c} ({d}%)',
  229. },
  230. legend: {
  231. orient: 'vertical',
  232. right: 10,
  233. top: 'center',
  234. data: [
  235. '职工薪酬',
  236. '材料费',
  237. '动力费',
  238. '固定资产折旧',
  239. '无形资产摊销',
  240. '修理费',
  241. '其他费用',
  242. ],
  243. formatter: function (name) {
  244. return name.split('-').join('\n')
  245. },
  246. },
  247. series: [
  248. {
  249. name: '成本构成',
  250. type: 'pie',
  251. radius: ['40%', '70%'],
  252. avoidLabelOverlap: false,
  253. itemStyle: {
  254. borderRadius: 0,
  255. borderColor: '#fff',
  256. borderWidth: 0,
  257. },
  258. label: {
  259. show: false,
  260. position: 'center',
  261. },
  262. emphasis: {
  263. label: {
  264. show: true,
  265. fontSize: '18',
  266. fontWeight: 'bold',
  267. },
  268. },
  269. labelLine: {
  270. show: false,
  271. },
  272. data: [
  273. {
  274. value: 35,
  275. name: '职工薪酬',
  276. itemStyle: { color: '#FF6B6B' },
  277. },
  278. {
  279. value: 20,
  280. name: '材料费',
  281. itemStyle: { color: '#4ECDC4' },
  282. },
  283. {
  284. value: 15,
  285. name: '动力费',
  286. itemStyle: { color: '#FFD166' },
  287. },
  288. {
  289. value: 10,
  290. name: '固定资产折旧',
  291. itemStyle: { color: '#6A0572' },
  292. },
  293. {
  294. value: 8,
  295. name: '无形资产摊销',
  296. itemStyle: { color: '#AB83A1' },
  297. },
  298. {
  299. value: 7,
  300. name: '修理费',
  301. itemStyle: { color: '#FC5185' },
  302. },
  303. {
  304. value: 5,
  305. name: '其他费用',
  306. itemStyle: { color: '#36A2EB' },
  307. },
  308. ],
  309. },
  310. ],
  311. }
  312. },
  313. // 处理查询
  314. handleQuery() {
  315. console.log('查询条件:', this.searchForm)
  316. this.updateChartData()
  317. },
  318. // 处理重置
  319. handleReset() {
  320. this.searchForm = {
  321. projectName: '',
  322. auditedUnit: '',
  323. startYear: '2022',
  324. endYear: '2024',
  325. }
  326. this.selectedIndicators = ['1-3']
  327. this.updateChartData()
  328. },
  329. // 处理指标选择变化
  330. handleCheckChange(data, checked, indeterminate) {
  331. console.log('选择的指标:', this.selectedIndicators)
  332. this.updateChartData()
  333. },
  334. // 更新图表数据
  335. updateChartData() {
  336. // 这里可以根据实际业务需求,基于搜索条件和选中的指标重新获取数据并更新图表
  337. // 目前使用的是模拟数据
  338. if (this.trendChart) {
  339. this.trendChart.setOption(this.getTrendChartOption())
  340. }
  341. if (this.compositionChart) {
  342. this.compositionChart.setOption(this.getCompositionChartOption())
  343. }
  344. },
  345. // 处理窗口大小变化
  346. handleResize() {
  347. if (this.trendChart) {
  348. this.trendChart.resize()
  349. }
  350. if (this.compositionChart) {
  351. this.compositionChart.resize()
  352. }
  353. },
  354. },
  355. }
  356. </script>
  357. <style scoped lang="scss">
  358. .history-analysis-container {
  359. padding: 20px;
  360. }
  361. .main-content {
  362. display: flex;
  363. gap: 20px;
  364. height: 100%;
  365. }
  366. .indicator-list {
  367. width: 300px;
  368. height: 100%;
  369. overflow-y: auto;
  370. }
  371. .indicator-tree {
  372. border: 1px solid #e8e8e8;
  373. height: 100%;
  374. }
  375. .list-title {
  376. font-size: 16px;
  377. margin-bottom: 10px;
  378. color: #333;
  379. }
  380. .chart-area {
  381. flex: 1;
  382. }
  383. .charts-wrapper {
  384. border: 1px solid #e8e8e8;
  385. padding: 20px;
  386. }
  387. .chart-title {
  388. width: 80px;
  389. text-align: center;
  390. color: #fff;
  391. padding: 6px 10px;
  392. background-color: #8400ff;
  393. }
  394. .charts-wrapper {
  395. display: flex;
  396. gap: 20px;
  397. }
  398. .chart-item {
  399. flex: 1;
  400. }
  401. .sub-title {
  402. font-size: 14px;
  403. font-weight: 500;
  404. margin-bottom: 15px;
  405. color: #666;
  406. }
  407. // 适配不同屏幕尺寸
  408. @media (max-width: 1200px) {
  409. .main-content {
  410. flex-direction: column;
  411. }
  412. .indicator-list {
  413. width: 100%;
  414. }
  415. .charts-wrapper {
  416. flex-direction: column;
  417. }
  418. }
  419. </style>