collectionList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. :datasource="datasource"
  161. :cache-key="cacheKeyUrl"
  162. autoAmendPage
  163. height="calc(100vh - 300px)"
  164. >
  165. </ele-pro-table>
  166. </div>
  167. </div>
  168. </template>
  169. </ele-split-layout>
  170. </el-card>
  171. </div>
  172. </template>
  173. <script>
  174. import dictMixins from '@/mixins/dictMixins';
  175. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  176. import { getTreeByPid } from '@/api/classifyManage';
  177. import { basicAreaPageAPI } from '@/api/factoryModel';
  178. import {
  179. statByDay,
  180. statByMonth,
  181. statByYear,
  182. statByYearRange
  183. } from '@/api/centralizedMeterReading/index.js';
  184. import dayjs from 'dayjs';
  185. import { energyConsumingUnitList } from '@/enum/dict.js';
  186. export default {
  187. mixins: [dictMixins, tableColumnsMixin],
  188. components: {},
  189. props: {
  190. pageName: ''
  191. },
  192. data() {
  193. return {
  194. activeTab: 'org',
  195. // 更新时间
  196. updateTime: dayjs().format('YYYY-M-D HH:mm:ss'),
  197. // 树形数据
  198. treeData: [],
  199. orgTreeData: [],
  200. treeProps: {
  201. children: 'children',
  202. label: 'name'
  203. },
  204. areaId: '',
  205. categoryLevelId: '',
  206. // 表格列配置
  207. cacheKeyUrl: ` ems-collectionList-${this.pageName}-list`,
  208. energyConsumingUnitList,
  209. queryDate: '',
  210. where: {
  211. keyWord: '',
  212. energyClassificationCode: '',
  213. queryDate: '',
  214. queryMonth: '',
  215. queryYear: '',
  216. startYear: '',
  217. endYear: ''
  218. }
  219. };
  220. },
  221. created() {
  222. // 设置默认日期
  223. this.initDefaultDate();
  224. getTreeByPid('29').then((res) => {
  225. this.orgTreeData = res.data;
  226. if (this.orgTreeData.length) {
  227. this.handleNodeClick(this.orgTreeData[0]);
  228. this.$nextTick(() => {
  229. this.$refs.treeRef.setCurrentKey(this.orgTreeData[0].id);
  230. });
  231. }
  232. });
  233. /* 获取区域集合 */
  234. basicAreaPageAPI({
  235. pageNum: 1,
  236. size: 9999
  237. }).then((res) => {
  238. this.treeData = this.$util.toTreeData({
  239. data: res,
  240. idField: 'id',
  241. parentIdField: 'parentId'
  242. });
  243. });
  244. },
  245. computed: {
  246. columns() {
  247. let arr = [
  248. {
  249. columnKey: 'index',
  250. label: '序号',
  251. type: 'index',
  252. width: 55,
  253. align: 'center',
  254. fixed: 'left'
  255. },
  256. {
  257. prop: 'substanceName',
  258. label: '表计',
  259. align: 'center',
  260. minWidth: 130,
  261. showOverflowTooltip: true
  262. }
  263. ];
  264. // 日采集 - 1-24时
  265. if (this.pageName == 'dailyCollection') {
  266. for (let i = 1; i <= 24; i++) {
  267. arr.push({
  268. prop: 'hour0' + i,
  269. label: i + '时',
  270. align: 'center',
  271. minWidth: 90,
  272. showOverflowTooltip: true
  273. });
  274. }
  275. }
  276. // 月采集 - 1-31日(根据选择的月份天数)
  277. if (this.pageName == 'monthlyCollection') {
  278. // 获取选择月份的天数,默认为当前月
  279. const queryMonth = this.where.queryMonth || dayjs().format('YYYY-MM');
  280. const daysInMonth = dayjs(queryMonth).daysInMonth();
  281. for (let i = 1; i <= daysInMonth; i++) {
  282. arr.push({
  283. prop: 'day0' + i,
  284. label: i + '日',
  285. align: 'center',
  286. minWidth: 80,
  287. showOverflowTooltip: true
  288. });
  289. }
  290. }
  291. // 年采集 - 1-12月
  292. if (this.pageName == 'yearlyCollection') {
  293. for (let i = 1; i <= 12; i++) {
  294. arr.push({
  295. prop: 'month0' + i,
  296. label: i + '月',
  297. align: 'center',
  298. minWidth: 100,
  299. showOverflowTooltip: true
  300. });
  301. }
  302. }
  303. // 全年采集 - 根据startYear和endYear生成年度列
  304. if (this.pageName == 'fullYearCollection') {
  305. const startYear = parseInt(this.where.startYear) || dayjs().year();
  306. const endYear = parseInt(this.where.endYear) || dayjs().year();
  307. for (let year = startYear; year <= endYear; year++) {
  308. arr.push({
  309. prop: year + '',
  310. label: year + '年',
  311. align: 'center',
  312. minWidth: 100,
  313. showOverflowTooltip: true
  314. });
  315. }
  316. }
  317. return arr;
  318. }
  319. },
  320. methods: {
  321. // 初始化默认日期
  322. initDefaultDate() {
  323. const today = dayjs();
  324. if (this.pageName == 'dailyCollection') {
  325. this.queryDate = today.format('YYYY-MM-DD');
  326. } else if (this.pageName == 'monthlyCollection') {
  327. this.queryDate = today.format('YYYY-MM');
  328. } else if (this.pageName == 'yearlyCollection') {
  329. this.queryDate = today.format('YYYY');
  330. } else if (this.pageName == 'fullYearCollection') {
  331. const currentYear = today.format('YYYY');
  332. this.where.startYear = currentYear;
  333. this.where.endYear = currentYear;
  334. }
  335. },
  336. // 日期变化处理
  337. handleDateChange(val) {
  338. // 校验不能为空
  339. if (!val && this.pageName != 'fullYearCollection') {
  340. this.$message.warning('查询日期不能为空');
  341. this.initDefaultDate();
  342. return;
  343. }
  344. // 日期变化后重新加载表格
  345. this.$nextTick(() => {
  346. this.$refs.table.reload({ page: 1 });
  347. });
  348. },
  349. // 年度范围变化处理
  350. handleYearRangeChange() {
  351. // 校验不能为空
  352. if (!this.where.startYear || !this.where.endYear) {
  353. this.$message.warning('开始年度和结束年度不能为空');
  354. return;
  355. }
  356. // 校验 startYear 不能大于 endYear
  357. if (parseInt(this.where.startYear) > parseInt(this.where.endYear)) {
  358. this.$message.warning('开始年度不能大于结束年度');
  359. // 交换两个值
  360. const temp = this.where.startYear;
  361. this.where.startYear = this.where.endYear;
  362. this.where.endYear = temp;
  363. }
  364. this.where.startDate = this.where.startYear;
  365. this.where.endDate = this.where.endYear;
  366. // 年度范围变化后重新加载表格
  367. this.$nextTick(() => {
  368. this.$refs.table.reload({ page: 1 });
  369. });
  370. },
  371. // Tab切换
  372. activeTabChange() {
  373. this.categoryLevelId = '';
  374. this.areaId = '';
  375. if (this.activeTab == 'org') {
  376. this.categoryLevelId = this.orgTreeData[0].id;
  377. this.$nextTick(() => {
  378. this.$refs.treeRef &&
  379. this.$refs.treeRef.setCurrentKey(this.orgTreeData[0].id);
  380. });
  381. } else {
  382. this.areaId = this.treeData[0] ? this.treeData[0].id : '';
  383. this.$nextTick(() => {
  384. this.$refs.treeRef1 &&
  385. this.$refs.treeRef1.setCurrentKey(this.treeData[0].id);
  386. });
  387. }
  388. this.$refs.table.reload({ page: 1 });
  389. },
  390. // 搜索
  391. handleSearch() {
  392. // 校验日期不能为空
  393. if (this.pageName == 'fullYearCollection') {
  394. if (!this.where.startYear || !this.where.endYear) {
  395. this.$message.warning('开始年度和结束年度不能为空');
  396. return;
  397. }
  398. if (parseInt(this.where.startYear) > parseInt(this.where.endYear)) {
  399. this.$message.warning('开始年度不能大于结束年度');
  400. return;
  401. }
  402. } else {
  403. if (!this.where.queryDate) {
  404. this.$message.warning('查询日期不能为空');
  405. return;
  406. }
  407. }
  408. this.$refs.table.reload({ page: 1 });
  409. },
  410. // 重置
  411. handleReset() {
  412. this.where = {
  413. keyWord: '',
  414. energyClassificationCode: '',
  415. startDate: '',
  416. endDate: '',
  417. queryDate: '',
  418. queryMonth: '',
  419. queryYear: '',
  420. startYear: '',
  421. endYear: ''
  422. };
  423. this.initDefaultDate();
  424. this.$refs.table.reload({ page: 1 });
  425. },
  426. // 树节点点击
  427. handleNodeClick(data) {
  428. this.categoryLevelId = '';
  429. this.areaId = '';
  430. if (this.activeTab == 'org') {
  431. this.categoryLevelId = data.id;
  432. } else {
  433. this.areaId = data.id;
  434. }
  435. this.$refs.table.reload({ page: 1 });
  436. },
  437. // 表格数据源
  438. async datasource({ page, limit }) {
  439. let api = statByYearRange;
  440. if (this.pageName == 'dailyCollection') {
  441. this.where.queryDate = this.queryDate;
  442. api = statByDay;
  443. } else if (this.pageName == 'monthlyCollection') {
  444. this.where.queryMonth = this.queryDate;
  445. api = statByMonth;
  446. } else if (this.pageName == 'yearlyCollection') {
  447. this.where.queryYear = this.queryDate;
  448. api = statByYear;
  449. }
  450. let res = await api({
  451. pageNum: page,
  452. size: limit,
  453. ...this.where,
  454. areaId: this.areaId,
  455. categoryLevelId: this.categoryLevelId
  456. });
  457. if (this.pageName == 'fullYearCollection') {
  458. if (res.list.length) {
  459. res.list = res.list[0].dataList.map((item) => {
  460. let data = { substanceName: item.substanceName };
  461. for (let key in item.yearDataMap) {
  462. data[key] = item.yearDataMap[key] || '';
  463. }
  464. return data;
  465. });
  466. }
  467. }
  468. console.log(res, 'res');
  469. return res;
  470. },
  471. // 刷新表格
  472. reloadTable() {
  473. this.$refs.table.reload();
  474. }
  475. }
  476. };
  477. </script>
  478. <style lang="scss" scoped>
  479. .energy-monitoring {
  480. .monitoring-card {
  481. height: calc(100vh - 100px);
  482. ::v-deep .el-card__body {
  483. height: 100%;
  484. padding: 15px;
  485. }
  486. }
  487. ::v-deep .ele-split-layout {
  488. .ele-split-layout-left {
  489. padding: 0;
  490. background: transparent;
  491. border: none;
  492. }
  493. .ele-split-layout-right {
  494. padding: 0;
  495. }
  496. .ele-split-layout-trigger {
  497. width: 8px;
  498. background: #f0f0f0;
  499. border-left: 1px solid #e0e0e0;
  500. border-right: 1px solid #e0e0e0;
  501. &:hover {
  502. background: #d0d0d0;
  503. }
  504. .ele-split-layout-trigger-icon {
  505. color: #909399;
  506. }
  507. }
  508. }
  509. .left-sidebar {
  510. height: 100%;
  511. ::v-deep .el-tabs--border-card {
  512. box-shadow: none;
  513. border: 1px solid #ebeef5;
  514. height: 100%;
  515. .el-tabs__header {
  516. background-color: #f5f7fa;
  517. border-bottom: 1px solid #ebeef5;
  518. margin: 0;
  519. .el-tabs__nav {
  520. width: 100%;
  521. display: flex;
  522. }
  523. .el-tabs__item {
  524. flex: 1;
  525. height: 39px;
  526. line-height: 39px;
  527. font-size: 13px;
  528. padding: 0;
  529. text-align: center;
  530. &.is-active {
  531. background-color: #fff;
  532. border-bottom-color: #fff;
  533. }
  534. }
  535. }
  536. .el-tabs__content {
  537. padding: 10px;
  538. height: calc(100% - 40px);
  539. overflow-y: auto;
  540. }
  541. }
  542. ::v-deep .el-tree {
  543. padding: 0;
  544. }
  545. }
  546. .right-content {
  547. flex: 1;
  548. min-width: 0;
  549. padding-left: 15px;
  550. .search-area {
  551. display: flex;
  552. justify-content: space-between;
  553. align-items: center;
  554. margin-bottom: 10px;
  555. padding-bottom: 10px;
  556. border-bottom: 1px solid #ebeef5;
  557. .view-switch {
  558. margin-left: 20px;
  559. flex-shrink: 0;
  560. }
  561. }
  562. .update-time {
  563. font-size: 12px;
  564. color: #000000;
  565. margin-bottom: 10px;
  566. }
  567. .list-view {
  568. // height: calc(100vh - 260px);
  569. ::v-deep .ele-pro-table {
  570. .el-table {
  571. border: 1px solid #ebeef5;
  572. border-radius: 4px;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. </style>