collectionList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <div class="energy-monitoring">
  3. <el-card shadow="never" class="monitoring-card">
  4. <!-- 主内容区 -->
  5. <ele-split-layout
  6. width="220px"
  7. allow-collapse
  8. :right-style="{ overflow: 'hidden' }"
  9. >
  10. <!-- 左侧树形菜单 -->
  11. <div class="left-sidebar">
  12. <el-tabs
  13. v-model="activeTab"
  14. type="border-card"
  15. @tab-click="activeTabChange"
  16. >
  17. <el-tab-pane label="设备类型" name="org">
  18. <el-tree
  19. :data="orgTreeData"
  20. :props="treeProps"
  21. node-key="id"
  22. highlight-current
  23. @node-click="handleNodeClick"
  24. style="height: calc(100vh - 180px)"
  25. ref="treeRef"
  26. ></el-tree>
  27. </el-tab-pane>
  28. <el-tab-pane label="用能分区" name="energy">
  29. <el-tree
  30. :data="treeData"
  31. :props="treeProps"
  32. node-key="id"
  33. default-expand-all
  34. ref="treeRef1"
  35. highlight-current
  36. @node-click="handleNodeClick"
  37. ></el-tree>
  38. </el-tab-pane>
  39. </el-tabs>
  40. </div>
  41. <!-- 右侧内容区 -->
  42. <template v-slot:content>
  43. <div class="right-content">
  44. <!-- 搜索区域 -->
  45. <div class="search-area card-mode">
  46. <!-- 搜索框 -->
  47. <div class="search-input-wrapper">
  48. <el-form label-width="90px" :inline="true">
  49. <el-form-item label="表计名称:">
  50. <el-input
  51. v-model="where.keyWord"
  52. placeholder=" "
  53. prefix-icon="el-icon-search"
  54. clearable
  55. @keyup.enter.native="handleSearch"
  56. style="width: 250px"
  57. >
  58. </el-input>
  59. </el-form-item>
  60. <el-form-item label="用能分类:">
  61. <el-select
  62. clearable
  63. v-model="where.energyClassificationCode"
  64. style="width: 250px"
  65. >
  66. <el-option
  67. v-for="(op, i) in energyConsumingUnitList"
  68. :label="op.label"
  69. :value="op.value"
  70. :key="i"
  71. ></el-option>
  72. </el-select>
  73. </el-form-item>
  74. <el-form-item
  75. v-if="pageName != 'fullYearCollection'"
  76. :label="
  77. pageName == 'dailyCollection'
  78. ? '查询日期:'
  79. : pageName == 'monthlyCollection'
  80. ? '查询月份:'
  81. : pageName == 'yearlyCollection'
  82. ? '查询年度:'
  83. : ''
  84. "
  85. >
  86. <el-date-picker
  87. v-model="queryDate"
  88. @change="handleDateChange"
  89. :type="
  90. pageName == 'dailyCollection'
  91. ? 'date'
  92. : pageName == 'monthlyCollection'
  93. ? 'month'
  94. : pageName == 'yearlyCollection'
  95. ? 'year'
  96. : ''
  97. "
  98. :format="
  99. pageName == 'dailyCollection'
  100. ? 'yyyy-MM-dd'
  101. : pageName == 'monthlyCollection'
  102. ? 'yyyy-MM'
  103. : pageName == 'yearlyCollection'
  104. ? 'yyyy'
  105. : ''
  106. "
  107. :value-format="
  108. pageName == 'dailyCollection'
  109. ? 'yyyy-MM-dd'
  110. : pageName == 'monthlyCollection'
  111. ? 'yyyy-MM'
  112. : pageName == 'yearlyCollection'
  113. ? 'yyyy'
  114. : 'yyyy-MM-dd'
  115. "
  116. placeholder="选择"
  117. style="width: 200px"
  118. >
  119. </el-date-picker>
  120. </el-form-item>
  121. <el-form-item
  122. v-if="pageName == 'fullYearCollection'"
  123. label="查询年度:"
  124. >
  125. <el-date-picker
  126. v-model="where.startYear"
  127. @change="handleYearRangeChange"
  128. type="year"
  129. format="yyyy"
  130. value-format="yyyy"
  131. placeholder="选择"
  132. style="width: 200px"
  133. >
  134. </el-date-picker>
  135. 至
  136. <el-date-picker
  137. v-model="where.endYear"
  138. @change="handleYearRangeChange"
  139. type="year"
  140. format="yyyy"
  141. value-format="yyyy"
  142. placeholder="选择"
  143. style="width: 200px"
  144. >
  145. </el-date-picker>
  146. </el-form-item>
  147. </el-form>
  148. </div>
  149. <div>
  150. <el-button type="primary" @click="handleSearch">搜索</el-button>
  151. <el-button @click="handleReset">重置</el-button></div
  152. >
  153. </div>
  154. <!-- 列表视图 -->
  155. <div class="list-view">
  156. <ele-pro-table
  157. ref="table"
  158. row-key="id"
  159. :columns="columns"
  160. @columns-change="handleColumnChange"
  161. :datasource="datasource"
  162. :cache-key="cacheKeyUrl"
  163. autoAmendPage
  164. height="calc(100vh - 300px)"
  165. >
  166. </ele-pro-table>
  167. </div>
  168. </div>
  169. </template>
  170. </ele-split-layout>
  171. </el-card>
  172. </div>
  173. </template>
  174. <script>
  175. import dictMixins from '@/mixins/dictMixins';
  176. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  177. import { getTreeByPid } from '@/api/classifyManage';
  178. import { basicAreaPageAPI } from '@/api/factoryModel';
  179. import {
  180. statByDay,
  181. statByMonth,
  182. statByYear,
  183. statByYearRange
  184. } from '@/api/centralizedMeterReading/index.js';
  185. import dayjs from 'dayjs';
  186. import { energyConsumingUnitList } from '@/enum/dict.js';
  187. export default {
  188. mixins: [dictMixins, tableColumnsMixin],
  189. components: {},
  190. props: {
  191. pageName: ''
  192. },
  193. data() {
  194. return {
  195. activeTab: 'org',
  196. // 更新时间
  197. updateTime: dayjs().format('YYYY-M-D HH:mm:ss'),
  198. // 树形数据
  199. treeData: [],
  200. orgTreeData: [],
  201. treeProps: {
  202. children: 'children',
  203. label: 'name'
  204. },
  205. areaId: '',
  206. categoryLevelId: '',
  207. // 表格列配置
  208. cacheKeyUrl: ` ems-collectionList-${this.pageName}-list`,
  209. energyConsumingUnitList,
  210. queryDate: '',
  211. where: {
  212. keyWord: '',
  213. energyClassificationCode: '',
  214. queryDate: '',
  215. queryMonth: '',
  216. queryYear: '',
  217. startYear: '',
  218. endYear: ''
  219. }
  220. };
  221. },
  222. created() {
  223. // 设置默认日期
  224. this.initDefaultDate();
  225. getTreeByPid('29').then((res) => {
  226. this.orgTreeData = res.data;
  227. if (this.orgTreeData.length) {
  228. this.handleNodeClick(this.orgTreeData[0]);
  229. this.$nextTick(() => {
  230. this.$refs.treeRef.setCurrentKey(this.orgTreeData[0].id);
  231. });
  232. }
  233. });
  234. /* 获取区域集合 */
  235. basicAreaPageAPI({
  236. pageNum: 1,
  237. size: 9999
  238. }).then((res) => {
  239. this.treeData = this.$util.toTreeData({
  240. data: res,
  241. idField: 'id',
  242. parentIdField: 'parentId'
  243. });
  244. });
  245. },
  246. computed: {
  247. columns() {
  248. let arr = [
  249. {
  250. columnKey: 'index',
  251. label: '序号',
  252. type: 'index',
  253. width: 55,
  254. align: 'center',
  255. fixed: 'left'
  256. },
  257. {
  258. prop: 'substanceName',
  259. label: '表计',
  260. align: 'center',
  261. minWidth: 130,
  262. showOverflowTooltip: true
  263. },
  264. {
  265. prop: 'energyClassificationName',
  266. label: '用能分类',
  267. align: 'center',
  268. minWidth: 130,
  269. showOverflowTooltip: true
  270. }
  271. ];
  272. // 日采集 - 1-24时
  273. if (this.pageName == 'dailyCollection') {
  274. for (let i = 1; i <= 24; i++) {
  275. arr.push({
  276. prop: i < 10 ? 'hour0' + i : 'hour' + i,
  277. label: i + '时',
  278. align: 'center',
  279. minWidth: 90,
  280. showOverflowTooltip: true
  281. });
  282. }
  283. }
  284. // 月采集 - 1-31日(根据选择的月份天数)
  285. if (this.pageName == 'monthlyCollection') {
  286. // 获取选择月份的天数,默认为当前月
  287. const queryMonth = this.where.queryMonth || dayjs().format('YYYY-MM');
  288. const daysInMonth = dayjs(queryMonth).daysInMonth();
  289. for (let i = 1; i <= daysInMonth; i++) {
  290. arr.push({
  291. prop: i < 10 ? 'day0' + i : 'day' + i,
  292. label: i + '日',
  293. align: 'center',
  294. minWidth: 90,
  295. showOverflowTooltip: true
  296. });
  297. }
  298. }
  299. // 年采集 - 1-12月
  300. if (this.pageName == 'yearlyCollection') {
  301. for (let i = 1; i <= 12; i++) {
  302. arr.push({
  303. prop: i < 10 ? 'month0' + i : 'month' + i,
  304. label: i + '月',
  305. align: 'center',
  306. minWidth: 100,
  307. showOverflowTooltip: true
  308. });
  309. }
  310. }
  311. // 全年采集 - 根据startYear和endYear生成年度列
  312. if (this.pageName == 'fullYearCollection') {
  313. const startYear = parseInt(this.where.startYear) || dayjs().year();
  314. const endYear = parseInt(this.where.endYear) || dayjs().year();
  315. for (let year = startYear; year <= endYear; year++) {
  316. arr.push({
  317. prop: year + '',
  318. label: year + '年',
  319. align: 'center',
  320. minWidth: 100,
  321. showOverflowTooltip: true
  322. });
  323. }
  324. }
  325. return arr;
  326. }
  327. },
  328. methods: {
  329. // 初始化默认日期
  330. initDefaultDate() {
  331. const today = dayjs();
  332. if (this.pageName == 'dailyCollection') {
  333. this.queryDate = today.format('YYYY-MM-DD');
  334. } else if (this.pageName == 'monthlyCollection') {
  335. this.queryDate = today.format('YYYY-MM');
  336. } else if (this.pageName == 'yearlyCollection') {
  337. this.queryDate = today.format('YYYY');
  338. } else if (this.pageName == 'fullYearCollection') {
  339. const currentYear = today.format('YYYY');
  340. this.where.startYear = currentYear;
  341. this.where.endYear = currentYear;
  342. }
  343. },
  344. // 日期变化处理
  345. handleDateChange(val) {
  346. // 校验不能为空
  347. if (!val && this.pageName != 'fullYearCollection') {
  348. this.$message.warning('查询日期不能为空');
  349. this.initDefaultDate();
  350. return;
  351. }
  352. // 日期变化后重新加载表格
  353. this.$nextTick(() => {
  354. this.$refs.table.reload({ page: 1 });
  355. });
  356. },
  357. // 年度范围变化处理
  358. handleYearRangeChange() {
  359. // 校验不能为空
  360. if (!this.where.startYear || !this.where.endYear) {
  361. this.$message.warning('开始年度和结束年度不能为空');
  362. return;
  363. }
  364. // 校验 startYear 不能大于 endYear
  365. if (parseInt(this.where.startYear) > parseInt(this.where.endYear)) {
  366. this.$message.warning('开始年度不能大于结束年度');
  367. // 交换两个值
  368. const temp = this.where.startYear;
  369. this.where.startYear = this.where.endYear;
  370. this.where.endYear = temp;
  371. }
  372. this.where.startDate = this.where.startYear;
  373. this.where.endDate = this.where.endYear;
  374. // 年度范围变化后重新加载表格
  375. this.$nextTick(() => {
  376. this.$refs.table.reload({ page: 1 });
  377. });
  378. },
  379. // Tab切换
  380. activeTabChange() {
  381. this.categoryLevelId = '';
  382. this.areaId = '';
  383. if (this.activeTab == 'org') {
  384. this.categoryLevelId = this.orgTreeData[0].id;
  385. this.$nextTick(() => {
  386. this.$refs.treeRef &&
  387. this.$refs.treeRef.setCurrentKey(this.orgTreeData[0].id);
  388. });
  389. } else {
  390. this.areaId = this.treeData[0] ? this.treeData[0].id : '';
  391. this.$nextTick(() => {
  392. this.$refs.treeRef1 &&
  393. this.$refs.treeRef1.setCurrentKey(this.treeData[0].id);
  394. });
  395. }
  396. this.$refs.table.reload({ page: 1 });
  397. },
  398. // 搜索
  399. handleSearch() {
  400. // 校验日期不能为空
  401. if (this.pageName == 'fullYearCollection') {
  402. if (!this.where.startYear || !this.where.endYear) {
  403. this.$message.warning('开始年度和结束年度不能为空');
  404. return;
  405. }
  406. if (parseInt(this.where.startYear) > parseInt(this.where.endYear)) {
  407. this.$message.warning('开始年度不能大于结束年度');
  408. return;
  409. }
  410. } else {
  411. if (!this.queryDate) {
  412. this.$message.warning('查询日期不能为空');
  413. return;
  414. }
  415. }
  416. this.$refs.table.reload({ page: 1 });
  417. },
  418. // 重置
  419. handleReset() {
  420. this.where = {
  421. keyWord: '',
  422. energyClassificationCode: '',
  423. startDate: '',
  424. endDate: '',
  425. queryDate: '',
  426. queryMonth: '',
  427. queryYear: '',
  428. startYear: '',
  429. endYear: ''
  430. };
  431. this.initDefaultDate();
  432. this.$refs.table.reload({ page: 1 });
  433. },
  434. // 树节点点击
  435. handleNodeClick(data) {
  436. this.categoryLevelId = '';
  437. this.areaId = '';
  438. if (this.activeTab == 'org') {
  439. this.categoryLevelId = data.id;
  440. } else {
  441. this.areaId = data.id;
  442. }
  443. this.$refs.table.reload({ page: 1 });
  444. },
  445. // 表格数据源
  446. async datasource({ page, limit }) {
  447. let api = statByYearRange;
  448. if (this.pageName == 'dailyCollection') {
  449. this.where.queryDate = this.queryDate;
  450. api = statByDay;
  451. } else if (this.pageName == 'monthlyCollection') {
  452. this.where.queryMonth = this.queryDate;
  453. api = statByMonth;
  454. } else if (this.pageName == 'yearlyCollection') {
  455. this.where.queryYear = this.queryDate;
  456. api = statByYear;
  457. }
  458. let res = await api({
  459. pageNum: page,
  460. size: limit,
  461. ...this.where,
  462. areaId: this.areaId,
  463. categoryLevelId: this.categoryLevelId
  464. });
  465. if (this.pageName == 'fullYearCollection') {
  466. if (res.list.length) {
  467. res.list = res.list[0].dataList.map((item) => {
  468. let data = {
  469. substanceName: item.substanceName,
  470. energyClassificationName: item.energyClassificationName
  471. };
  472. for (let key in item.yearDataMap) {
  473. data[key] = item.yearDataMap[key] || '';
  474. }
  475. return data;
  476. });
  477. }
  478. }
  479. console.log(res, 'res');
  480. return res;
  481. },
  482. // 刷新表格
  483. reloadTable() {
  484. this.$refs.table.reload();
  485. }
  486. }
  487. };
  488. </script>
  489. <style lang="scss" scoped>
  490. .energy-monitoring {
  491. .monitoring-card {
  492. height: calc(100vh - 100px);
  493. ::v-deep .el-card__body {
  494. height: 100%;
  495. padding: 15px;
  496. }
  497. }
  498. ::v-deep .ele-split-layout {
  499. .ele-split-layout-left {
  500. padding: 0;
  501. background: transparent;
  502. border: none;
  503. }
  504. .ele-split-layout-right {
  505. padding: 0;
  506. }
  507. .ele-split-layout-trigger {
  508. width: 8px;
  509. background: #f0f0f0;
  510. border-left: 1px solid #e0e0e0;
  511. border-right: 1px solid #e0e0e0;
  512. &:hover {
  513. background: #d0d0d0;
  514. }
  515. .ele-split-layout-trigger-icon {
  516. color: #909399;
  517. }
  518. }
  519. }
  520. .left-sidebar {
  521. height: 100%;
  522. ::v-deep .el-tabs--border-card {
  523. box-shadow: none;
  524. border: 1px solid #ebeef5;
  525. height: 100%;
  526. .el-tabs__header {
  527. background-color: #f5f7fa;
  528. border-bottom: 1px solid #ebeef5;
  529. margin: 0;
  530. .el-tabs__nav {
  531. width: 100%;
  532. display: flex;
  533. }
  534. .el-tabs__item {
  535. flex: 1;
  536. height: 39px;
  537. line-height: 39px;
  538. font-size: 13px;
  539. padding: 0;
  540. text-align: center;
  541. &.is-active {
  542. background-color: #fff;
  543. border-bottom-color: #fff;
  544. }
  545. }
  546. }
  547. .el-tabs__content {
  548. padding: 10px;
  549. height: calc(100% - 40px);
  550. overflow-y: auto;
  551. }
  552. }
  553. ::v-deep .el-tree {
  554. padding: 0;
  555. }
  556. }
  557. .right-content {
  558. flex: 1;
  559. min-width: 0;
  560. padding-left: 15px;
  561. .search-area {
  562. display: flex;
  563. justify-content: space-between;
  564. align-items: center;
  565. margin-bottom: 10px;
  566. padding-bottom: 10px;
  567. border-bottom: 1px solid #ebeef5;
  568. .view-switch {
  569. margin-left: 20px;
  570. flex-shrink: 0;
  571. }
  572. }
  573. .update-time {
  574. font-size: 12px;
  575. color: #000000;
  576. margin-bottom: 10px;
  577. }
  578. .list-view {
  579. // height: calc(100vh - 260px);
  580. ::v-deep .ele-pro-table {
  581. .el-table {
  582. border: 1px solid #ebeef5;
  583. border-radius: 4px;
  584. }
  585. }
  586. }
  587. }
  588. }
  589. </style>