index.vue 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!-- 左侧树形选择器 -->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input
  8. v-model="areaName"
  9. placeholder="请输入区域名称"
  10. clearable
  11. size="small"
  12. prefix-icon="el-icon-search"
  13. style="margin-bottom: 20px"
  14. @input="filterTree"
  15. />
  16. </div>
  17. <div class="head-container tree-container">
  18. <el-tree
  19. :data="areaOptions"
  20. :props="defaultProps"
  21. :expand-on-click-node="false"
  22. :filter-node-method="filterNode"
  23. ref="tree"
  24. node-key="id"
  25. default-expand-all
  26. highlight-current
  27. @node-click="handleNodeClick"
  28. >
  29. <template #default="{ node, data }">
  30. <div class="tree-node"
  31. :class="{ 'device-node': data.type === 'device', 'area-node': data.type === 'area' }"
  32. >
  33. <i v-if="data.type === 'area'" class="el-icon-folder node-icon area-icon"></i>
  34. <i v-if="data.type === 'device'" class="el-icon-monitor node-icon device-icon"></i>
  35. <span class="node-label">{{ data.label }}</span>
  36. </div>
  37. </template>
  38. </el-tree>
  39. </div>
  40. </el-col>
  41. <!-- 右侧内容区域 -->
  42. <el-col :span="20" :xs="24">
  43. <!-- Tab切换 -->
  44. <el-tabs v-model="activeTab" @tab-click="handleTabChange">
  45. <el-tab-pane label="电表读数" name="first"></el-tab-pane>
  46. <el-tab-pane label="水表读数" name="second"></el-tab-pane>
  47. </el-tabs>
  48. <!-- 查询表单 -->
  49. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
  50. label-width="80px"
  51. >
  52. <el-form-item label="抄表周期">
  53. <el-date-picker
  54. v-model="daterangeRecordTime"
  55. style="width: 240px"
  56. value-format="yyyy-MM-dd"
  57. type="daterange"
  58. range-separator="-"
  59. start-placeholder="开始日期"
  60. end-placeholder="结束日期"
  61. :picker-options="pickerOptions"
  62. @change="handleQuery"
  63. />
  64. </el-form-item>
  65. <el-form-item>
  66. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  67. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  68. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
  69. </el-form-item>
  70. </el-form>
  71. <!-- 用电统计卡片 -->
  72. <div v-if="activeTab === 'first' && numElecMeterHData">
  73. <!-- 汇总统计区域 -->
  74. <div class="summary-container">
  75. <!-- 总量统计卡片 -->
  76. <div class="summary-row">
  77. <el-card class="summary-inline-card">
  78. <div class="inline-card-content">
  79. <div class="inline-card-left">
  80. <i class="el-icon-lightning inline-icon elec-icon"></i>
  81. <span class="inline-label">总用电量</span>
  82. </div>
  83. <div class="inline-card-right">
  84. <span class="inline-value">{{ formatNumber(numElecMeterHData && numElecMeterHData.total ? numElecMeterHData.total.quantity : 0) }}</span>
  85. <span class="inline-unit">kWh</span>
  86. </div>
  87. </div>
  88. </el-card>
  89. <el-card class="summary-inline-card">
  90. <div class="inline-card-content">
  91. <div class="inline-card-left">
  92. <i class="el-icon-money inline-icon cost-icon"></i>
  93. <span class="inline-label">总电费</span>
  94. </div>
  95. <div class="inline-card-right">
  96. <span class="inline-value">{{ formatNumber(numElecMeterHData && numElecMeterHData.total ? numElecMeterHData.total.useCost : 0, 2) }}</span>
  97. <span class="inline-unit">元</span>
  98. </div>
  99. </div>
  100. </el-card>
  101. </div>
  102. <!-- 动态峰谷电统计卡片 - 仅在有数据时显示 -->
  103. <div v-if="supportedMeterTypes && supportedMeterTypes.length > 0" class="peak-valley-row">
  104. <el-card
  105. v-for="meterType in supportedMeterTypes"
  106. :key="meterType.value"
  107. class="peak-inline-card"
  108. >
  109. <div class="peak-inline-content">
  110. <div class="peak-inline-header">
  111. <span class="peak-type-badge" :class="meterType.tagClass">{{ meterType.tagName }}</span>
  112. </div>
  113. <div class="peak-inline-body">
  114. <div class="peak-inline-info">
  115. <span class="peak-label">电量</span>
  116. <span class="peak-value">{{ formatNumber(getMeterTypeData(meterType.value, 'quantity')) }}</span>
  117. <span class="peak-unit">kWh</span>
  118. </div>
  119. <div class="peak-percentage">
  120. 占比 {{
  121. numElecMeterHData && numElecMeterHData.total && numElecMeterHData.total.quantity > 0 ? calculatePercentage(getMeterTypeData(meterType.value, 'quantity'), numElecMeterHData.total.quantity) : '0.0'
  122. }}%
  123. </div>
  124. </div>
  125. </div>
  126. </el-card>
  127. </div>
  128. </div>
  129. </div>
  130. <!-- 用水统计卡片 -->
  131. <div v-if="activeTab === 'second'">
  132. <!-- 汇总统计区域 -->
  133. <div class="summary-container">
  134. <div class="summary-row">
  135. <el-card class="summary-inline-card">
  136. <div class="inline-card-content">
  137. <div class="inline-card-left">
  138. <i class="el-icon-set-up inline-icon water-icon"></i>
  139. <span class="inline-label">总用水量</span>
  140. </div>
  141. <div class="inline-card-right">
  142. <span class="inline-value">{{ formatNumber(getWaterTotal('quantity')) }}</span>
  143. <span class="inline-unit">m³</span>
  144. </div>
  145. </div>
  146. </el-card>
  147. <el-card class="summary-inline-card">
  148. <div class="inline-card-content">
  149. <div class="inline-card-left">
  150. <i class="el-icon-money inline-icon cost-icon"></i>
  151. <span class="inline-label">总水费</span>
  152. </div>
  153. <div class="inline-card-right">
  154. <span class="inline-value">{{ formatNumber(getWaterTotal('useCost'), 2) }}</span>
  155. <span class="inline-unit">元</span>
  156. </div>
  157. </div>
  158. </el-card>
  159. </div>
  160. </div>
  161. </div>
  162. <!-- 电表数据表格 -->
  163. <el-table v-if="activeTab === 'first'" v-loading="loading" :data="elecMeterHList" style="margin-top: 20px">
  164. <el-table-column label="表计名称" align="left" prop="deviceName" width="250px"/>
  165. <el-table-column label="表计编号" align="left" prop="deviceCode"/>
  166. <el-table-column label="抄表时间" align="center" prop="recordTime" width="180">
  167. <template slot-scope="scope">
  168. <span>{{ formatDateTime(scope.row.recordTime) }}</span>
  169. </template>
  170. </el-table-column>
  171. <el-table-column label="计量时段" align="center" prop="meterType">
  172. <template slot-scope="scope">
  173. <el-tag :type="getMeterTypeTagType(scope.row.meterType)" size="small">
  174. {{ getElecMeterType(scope.row.meterType) }}
  175. </el-tag>
  176. <span style="margin-left: 5px; color: #909399;">{{
  177. formatNumber(scope.row.meterUnitPrice, 2)
  178. }} 元/kWh</span>
  179. </template>
  180. </el-table-column>
  181. <el-table-column label="用电量(kWh)" align="center" prop="elecQuantity">
  182. <template slot-scope="scope">
  183. <span>{{ formatNumber(scope.row.elecQuantity) }}</span>
  184. </template>
  185. </el-table-column>
  186. <el-table-column label="小时电费(元)" align="center" prop="useElecCost">
  187. <template slot-scope="scope">
  188. <span>{{ formatNumber(scope.row.useElecCost, 2) }}</span>
  189. </template>
  190. </el-table-column>
  191. </el-table>
  192. <!-- 水表数据表格 -->
  193. <el-table v-if="activeTab === 'second'" v-loading="loading" :data="waterMeterHList" style="margin-top: 20px">
  194. <el-table-column label="表计名称" align="left" prop="deviceName" width="250"/>
  195. <el-table-column label="表计编号" align="left" prop="deviceCode"/>
  196. <el-table-column label="抄表时间" align="center" prop="recordTime" width="180">
  197. <template slot-scope="scope">
  198. <span>{{ formatDateTime(scope.row.recordTime) }}</span>
  199. </template>
  200. </el-table-column>
  201. <el-table-column label="用水量(m³)" align="center" prop="waterQuantity">
  202. <template slot-scope="scope">
  203. <span>{{ formatNumber(scope.row.waterQuantity) }}</span>
  204. </template>
  205. </el-table-column>
  206. <el-table-column label="小时水费(元)" align="center" prop="useWaterCost">
  207. <template slot-scope="scope">
  208. <span>{{ formatNumber(scope.row.useWaterCost, 2) }}</span>
  209. </template>
  210. </el-table-column>
  211. </el-table>
  212. <!-- 分页 -->
  213. <pagination
  214. v-show="total > 0"
  215. :total="total"
  216. :page.sync="queryParams.pageNum"
  217. :limit.sync="queryParams.pageSize"
  218. @pagination="getList"
  219. />
  220. </el-col>
  221. </el-row>
  222. </div>
  223. </template>
  224. <script>
  225. import { getDeviceTree } from '@/api/device/meterDevice'
  226. import { getElechourTypes, getElecMdevHourList, getElecMdevHourSummary, getWaterMdevHourList, getWaterMdevHourSummary } from '@/api/device/energyConsumption'
  227. export default {
  228. name: 'MeterReading',
  229. data() {
  230. return {
  231. // 存储用电统计数据
  232. numElecMeterHData: null,
  233. // 存储用水统计数据
  234. numWaterMeterHData: null,
  235. // 当前激活的标签页
  236. activeTab: 'first',
  237. // 遮罩层
  238. loading: true,
  239. // 显示搜索条件
  240. showSearch: true,
  241. // 总条数
  242. total: 0,
  243. // 用电计量-小时表格数据
  244. elecMeterHList: [],
  245. // 用水计量-小时表格数据
  246. waterMeterHList: [],
  247. // 小时电费时间范围
  248. daterangeRecordTime: [],
  249. // 支持的电量类型
  250. supportedMeterTypes: [],
  251. // 电量类型映射
  252. meterTypeMap: {
  253. '-2': {
  254. name: '深谷电量',
  255. tagName: '深谷',
  256. tagClass: 'deep-valley-tag',
  257. field: 'deepValleyElec'
  258. },
  259. '-1': {
  260. name: '谷段电量',
  261. tagName: '谷段',
  262. tagClass: 'valley-tag',
  263. field: 'lowElec'
  264. },
  265. '0': {
  266. name: '平段电量',
  267. tagName: '平段',
  268. tagClass: 'normal-tag',
  269. field: 'normalElec'
  270. },
  271. '1': {
  272. name: '峰段电量',
  273. tagName: '峰段',
  274. tagClass: 'high-peak-tag',
  275. field: 'highElec'
  276. },
  277. '2': {
  278. name: '尖峰电量',
  279. tagName: '尖峰',
  280. tagClass: 'peak-tag',
  281. field: 'peakElec'
  282. }
  283. },
  284. // 查询参数
  285. queryParams: {
  286. pageNum: 1,
  287. pageSize: 10,
  288. areaCode: null,
  289. deviceCode: null,
  290. recordTime: null,
  291. startRecTime: null,
  292. endRecTime: null,
  293. meterCls: 45,
  294. orderFlag: 'desc'
  295. },
  296. // 区域名称
  297. areaName: undefined,
  298. areaOptions: [],
  299. defaultProps: {
  300. children: 'children',
  301. label: 'label'
  302. },
  303. // 日期选择器配置
  304. pickerOptions: {
  305. disabledDate(time) {
  306. return time.getTime() > Date.now()
  307. }
  308. }
  309. }
  310. },
  311. created() {
  312. this.initDefaultDateRange()
  313. this.getAreaTreeSelect().then(() => {
  314. const firstValidNode = this.findFirstValidNode(this.areaOptions)
  315. if (firstValidNode) {
  316. this.queryParams.deviceCode = firstValidNode.id
  317. this.handleQuery()
  318. } else {
  319. this.getList()
  320. }
  321. })
  322. },
  323. methods: {
  324. // 初始化默认查询时间范围:当月1号到今天
  325. initDefaultDateRange() {
  326. const today = new Date()
  327. const currentYear = today.getFullYear()
  328. const currentMonth = today.getMonth()
  329. const startDate = new Date(currentYear, currentMonth, 1)
  330. const endDate = new Date(today)
  331. const formatDate = (date) => {
  332. const year = date.getFullYear()
  333. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  334. const day = date.getDate().toString().padStart(2, '0')
  335. return `${year}-${month}-${day}`
  336. }
  337. this.daterangeRecordTime = [formatDate(startDate), formatDate(endDate)]
  338. },
  339. // 加载支持的电量类型
  340. async loadSupportedMeterTypes() {
  341. if (this.activeTab !== 'first' || !this.queryParams.deviceCode) {
  342. this.supportedMeterTypes = []
  343. return
  344. }
  345. try {
  346. const query = {
  347. objCode: this.queryParams.deviceCode,
  348. objType: 2, // 设备类型
  349. startRecTime: this.queryParams.startRecTime,
  350. endRecTime: this.queryParams.endRecTime
  351. }
  352. // 尝试获取支持的电量类型
  353. const response = await getElechourTypes(query)
  354. if (response.data && Array.isArray(response.data)) {
  355. const types = response.data
  356. .filter(type => type !== null && type !== undefined && this.meterTypeMap[type])
  357. .sort((a, b) => Number(b) - Number(a))
  358. .map(type => ({
  359. value: type,
  360. ...this.meterTypeMap[type]
  361. }))
  362. this.supportedMeterTypes = types.length > 0 ? types : this.getDefaultMeterTypes()
  363. } else {
  364. this.supportedMeterTypes = this.getDefaultMeterTypes()
  365. }
  366. } catch (error) {
  367. console.error('加载电量类型失败:', error)
  368. this.supportedMeterTypes = this.getDefaultMeterTypes()
  369. }
  370. },
  371. // 获取默认的电量类型
  372. getDefaultMeterTypes() {
  373. // 根据已有数据判断支持的类型
  374. const availableTypes = []
  375. if (this.numElecMeterHData) {
  376. // 尖峰电量
  377. if (this.numElecMeterHData.peakElec && this.numElecMeterHData.peakElec.quantity > 0) {
  378. availableTypes.push('2')
  379. }
  380. // 峰段电量
  381. if (this.numElecMeterHData.highElec && this.numElecMeterHData.highElec.quantity > 0) {
  382. availableTypes.push('1')
  383. }
  384. // 平段电量
  385. if (this.numElecMeterHData.normalElec && this.numElecMeterHData.normalElec.quantity > 0) {
  386. availableTypes.push('0')
  387. }
  388. // 谷段电量
  389. if (this.numElecMeterHData.lowElec && this.numElecMeterHData.lowElec.quantity > 0) {
  390. availableTypes.push('-1')
  391. }
  392. // 深谷电量
  393. if (this.numElecMeterHData.deepValleyElec && this.numElecMeterHData.deepValleyElec.quantity > 0) {
  394. availableTypes.push('-2')
  395. }
  396. }
  397. // 如果没有任何数据,返回空数组
  398. return availableTypes.length > 0
  399. ? availableTypes.map(type => ({ value: type, ...this.meterTypeMap[type] }))
  400. : []
  401. },
  402. // 获取指定类型的电量数据
  403. getMeterTypeData(meterType, field) {
  404. if (!this.numElecMeterHData) return 0
  405. const typeMapping = {
  406. '-2': 'deepValleyElec',
  407. '-1': 'lowElec',
  408. '0': 'normalElec',
  409. '1': 'highElec',
  410. '2': 'peakElec'
  411. }
  412. const typeName = typeMapping[meterType]
  413. return typeName && this.numElecMeterHData[typeName]
  414. ? (this.numElecMeterHData[typeName][field] || 0)
  415. : 0
  416. },
  417. // Tab切换处理
  418. handleTabChange() {
  419. // 清空之前的数据,防止数据污染
  420. this.elecMeterHList = []
  421. this.waterMeterHList = []
  422. this.numElecMeterHData = null
  423. this.numWaterMeterHData = null
  424. this.supportedMeterTypes = []
  425. this.total = 0
  426. if (this.activeTab === 'first') {
  427. this.queryParams.meterCls = '45'
  428. } else if (this.activeTab === 'second') {
  429. this.queryParams.meterCls = '70'
  430. }
  431. this.getAreaTreeSelect().then(() => {
  432. const firstValidNode = this.findFirstValidNode(this.areaOptions)
  433. if (firstValidNode) {
  434. this.queryParams.deviceCode = firstValidNode.id
  435. this.handleQuery()
  436. } else {
  437. this.getList()
  438. }
  439. })
  440. },
  441. // 筛选节点
  442. filterNode(value, data) {
  443. if (!value) return true
  444. return data.label.indexOf(value) !== -1
  445. },
  446. // 过滤树节点
  447. filterTree() {
  448. this.$refs.tree.filter(this.areaName)
  449. },
  450. // 节点单击事件
  451. handleNodeClick(data) {
  452. // 仅处理设备节点
  453. if (data.type === 'device') {
  454. this.queryParams.deviceCode = data.id
  455. this.handleQuery()
  456. }
  457. },
  458. // 查找第一个设备节点
  459. findFirstValidNode(nodes) {
  460. for (const node of nodes) {
  461. if (node.type === 'device') {
  462. return node
  463. }
  464. if (node.children && node.children.length > 0) {
  465. const foundNode = this.findFirstValidNode(node.children)
  466. if (foundNode) return foundNode
  467. }
  468. }
  469. return null
  470. },
  471. // 树结构加载
  472. async getAreaTreeSelect() {
  473. await getDeviceTree(0, this.queryParams.meterCls, 0).then(response => {
  474. this.areaOptions = response.data
  475. })
  476. },
  477. // 格式化日期时间
  478. formatDateTime(dateTime) {
  479. if (!dateTime) return ''
  480. const date = new Date(dateTime)
  481. const year = date.getFullYear()
  482. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  483. const day = date.getDate().toString().padStart(2, '0')
  484. const hours = date.getHours().toString().padStart(2, '0')
  485. const minutes = date.getMinutes().toString().padStart(2, '0')
  486. return `${year}-${month}-${day} ${hours}:${minutes}`
  487. },
  488. // 获取列表数据
  489. getList() {
  490. if (this.activeTab === 'first') {
  491. this.getElecList()
  492. } else {
  493. this.getWaterList()
  494. }
  495. },
  496. // 查询用电计量-小时列表
  497. getElecList() {
  498. this.loading = true
  499. getElecMdevHourList(this.queryParams).then(response => {
  500. this.elecMeterHList = response.rows
  501. this.total = response.total
  502. this.loading = false
  503. })
  504. },
  505. // 查询用水计量-小时列表
  506. getWaterList() {
  507. this.loading = true
  508. listWaterMeterH(this.queryParams).then(response => {
  509. this.waterMeterHList = response.rows
  510. this.total = response.total
  511. this.loading = false
  512. })
  513. },
  514. // 搜索按钮操作
  515. async handleQuery() {
  516. // 处理日期范围
  517. if (this.daterangeRecordTime && this.daterangeRecordTime.length === 2) {
  518. this.queryParams.startRecTime = this.daterangeRecordTime[0] + ' 00:00:00'
  519. this.queryParams.endRecTime = this.daterangeRecordTime[1] + ' 23:59:59'
  520. } else {
  521. this.queryParams.startRecTime = null
  522. this.queryParams.endRecTime = null
  523. }
  524. if (this.activeTab === 'first') {
  525. this.queryParams.meterCls = '45'
  526. await this.loadSupportedMeterTypes()
  527. this.getElecList()
  528. this.getElecMdevHourSummary()
  529. } else if (this.activeTab === 'second') {
  530. this.queryParams.meterCls = '70'
  531. this.getWaterList()
  532. this.getNumWaterMeterH()
  533. }
  534. },
  535. // 获取用电统计数据
  536. async getElecMdevHourSummary() {
  537. const query = {
  538. deviceCode: this.queryParams.deviceCode,
  539. startRecTime: this.queryParams.startRecTime,
  540. endRecTime: this.queryParams.endRecTime
  541. }
  542. try {
  543. const response = await getElecMdevHourSummary(query)
  544. // 处理空数据情况
  545. if (!response.data || (typeof response.data === 'object' && Object.keys(response.data).length === 0)) {
  546. this.numElecMeterHData = {
  547. total: {
  548. quantity: 0,
  549. useCost: 0
  550. },
  551. deepValleyElec: { quantity: 0, useCost: 0 },
  552. lowElec: { quantity: 0, useCost: 0 },
  553. normalElec: { quantity: 0, useCost: 0 },
  554. highElec: { quantity: 0, useCost: 0 },
  555. peakElec: { quantity: 0, useCost: 0 }
  556. }
  557. } else {
  558. const flatData = response.data
  559. // 将扁平数据转换为原来的嵌套结构
  560. this.numElecMeterHData = {
  561. total: {
  562. areaCode: flatData.areaCode,
  563. objType: flatData.objType,
  564. objCode: flatData.objCode,
  565. objName: flatData.objName,
  566. quantity: flatData.totalElecQuantity || 0,
  567. useCost: flatData.totalElecCost || 0
  568. },
  569. deepValleyElec: {
  570. areaCode: flatData.areaCode,
  571. objType: flatData.objType,
  572. objCode: '-2',
  573. objName: 'deepValleyElec',
  574. quantity: flatData.deepValleyQuantity || 0,
  575. useCost: 0 // 深谷费用暂时无法直接从新接口获取,设置为0
  576. },
  577. lowElec: {
  578. areaCode: flatData.areaCode,
  579. objType: flatData.objType,
  580. objCode: '-1',
  581. objName: 'lowElec',
  582. quantity: flatData.valleyQuantity || 0,
  583. useCost: 0 // 谷段费用暂时无法直接从新接口获取,设置为0
  584. },
  585. normalElec: {
  586. areaCode: flatData.areaCode,
  587. objType: flatData.objType,
  588. objCode: '0',
  589. objName: 'normalElec',
  590. quantity: flatData.normalQuantity || 0,
  591. useCost: 0 // 平段费用暂时无法直接从新接口获取,设置为0
  592. },
  593. highElec: {
  594. areaCode: flatData.areaCode,
  595. objType: flatData.objType,
  596. objCode: '1',
  597. objName: 'highElec',
  598. quantity: flatData.peakQuantity || 0,
  599. useCost: 0 // 峰段费用暂时无法直接从新接口获取,设置为0
  600. },
  601. peakElec: {
  602. areaCode: flatData.areaCode,
  603. objType: flatData.objType,
  604. objCode: '2',
  605. objName: 'peakElec',
  606. quantity: flatData.sharpPeakQuantity || 0,
  607. useCost: 0 // 尖峰费用暂时无法直接从新接口获取,设置为0
  608. }
  609. }
  610. }
  611. // 重新加载支持的电量类型
  612. await this.loadSupportedMeterTypes()
  613. } catch (error) {
  614. // 出错时设置默认空数据结构
  615. this.numElecMeterHData = {
  616. total: { quantity: 0, useCost: 0 },
  617. deepValleyElec: { quantity: 0, useCost: 0 },
  618. lowElec: { quantity: 0, useCost: 0 },
  619. normalElec: { quantity: 0, useCost: 0 },
  620. highElec: { quantity: 0, useCost: 0 },
  621. peakElec: { quantity: 0, useCost: 0 }
  622. }
  623. this.$message.error('获取用电统计数据失败')
  624. }
  625. },
  626. // 获取用水统计数据
  627. async getNumWaterMeterH() {
  628. const query = {
  629. deviceCode: this.queryParams.deviceCode,
  630. startRecTime: this.queryParams.startRecTime,
  631. endRecTime: this.queryParams.endRecTime
  632. }
  633. try {
  634. const response = await getWaterMdevHourSummary(query)
  635. // 处理空数据情况
  636. if (!response.data || (typeof response.data === 'object' && Object.keys(response.data).length === 0)) {
  637. this.numWaterMeterHData = {
  638. quantity: 0,
  639. useCost: 0
  640. }
  641. } else {
  642. // 修改字段映射:使用新的字段名
  643. this.numWaterMeterHData = {
  644. quantity: response.data.totalWaterQuantity || 0,
  645. useCost: response.data.totalWaterCost || 0
  646. }
  647. }
  648. } catch (error) {
  649. // 出错时设置默认空数据结构
  650. this.numWaterMeterHData = {
  651. quantity: 0,
  652. useCost: 0
  653. }
  654. this.$message.error('获取用水统计数据失败')
  655. }
  656. },
  657. // 重置按钮操作
  658. resetQuery() {
  659. this.daterangeRecordTime = []
  660. this.resetForm('queryForm')
  661. this.initDefaultDateRange()
  662. this.handleQuery()
  663. },
  664. // 导出按钮操作
  665. handleExport() {
  666. const filename = this.activeTab === 'first'
  667. ? `电表读数_${new Date().getTime()}.xlsx`
  668. : `水表读数_${new Date().getTime()}.xlsx`
  669. const url = this.activeTab === 'first'
  670. ? 'ems/consumption/mdev/elec/hour/export'
  671. : 'ems/consumption/mdev/water/hour/export'
  672. this.download(url, { ...this.queryParams }, filename)
  673. },
  674. // 获取电表类型名称
  675. getElecMeterType(meterType) {
  676. const meterTypeMap = {
  677. '-2': '深谷',
  678. '-1': '谷段',
  679. '0': '平段',
  680. '1': '峰段',
  681. '2': '尖峰'
  682. }
  683. return meterTypeMap[meterType] || '未知'
  684. },
  685. // 获取电表类型标签颜色
  686. getMeterTypeTagType(meterType) {
  687. const typeMap = {
  688. '-2': 'primary',
  689. '-1': 'success',
  690. '0': 'info',
  691. '1': 'warning',
  692. '2': 'danger'
  693. }
  694. return typeMap[meterType] || 'info'
  695. },
  696. // 计算百分比
  697. calculatePercentage(value, total) {
  698. if (!value || !total || total === 0) {
  699. return '0.0'
  700. }
  701. const percentage = (value / total) * 100
  702. return percentage.toFixed(1)
  703. },
  704. // 获取用水总计数据
  705. getWaterTotal(field) {
  706. if (this.numWaterMeterHData && this.numWaterMeterHData[field] !== undefined) {
  707. return this.numWaterMeterHData[field]
  708. }
  709. // 如果没有统计数据,尝试从列表数据计算
  710. if (this.waterMeterHList && this.waterMeterHList.length > 0) {
  711. if (field === 'quantity') {
  712. return this.waterMeterHList.reduce((sum, item) => sum + (item.waterQuantity || 0), 0)
  713. } else if (field === 'useCost') {
  714. return this.waterMeterHList.reduce((sum, item) => sum + (item.useWaterCost || 0), 0)
  715. }
  716. }
  717. return 0
  718. },
  719. // 格式化数字
  720. formatNumber(num, decimals = 2) {
  721. if (num === null || num === undefined || isNaN(num)) {
  722. return '0.' + '0'.repeat(decimals)
  723. }
  724. return Number(num).toFixed(decimals)
  725. },
  726. // 查询用电计量-小时列表
  727. getElecList() {
  728. this.loading = true
  729. getElecMdevHourList(this.queryParams).then(response => {
  730. // 处理空数据情况
  731. this.elecMeterHList = response.rows || []
  732. this.total = response.total || 0
  733. this.loading = false
  734. }).catch(error => {
  735. console.error('获取用电列表失败:', error)
  736. this.elecMeterHList = []
  737. this.total = 0
  738. this.loading = false
  739. })
  740. },
  741. // 查询用水计量-小时列表
  742. getWaterList() {
  743. this.loading = true
  744. getWaterMdevHourList(this.queryParams).then(response => {
  745. // 处理空数据情况
  746. this.waterMeterHList = response.rows || []
  747. this.total = response.total || 0
  748. this.loading = false
  749. }).catch(error => {
  750. console.error('获取用水列表失败:', error)
  751. this.waterMeterHList = []
  752. this.total = 0
  753. this.loading = false
  754. })
  755. },
  756. // 树结构加载
  757. async getAreaTreeSelect() {
  758. try {
  759. await getDeviceTree(0, this.queryParams.meterCls, 0).then(response => {
  760. // 处理空数据情况
  761. this.areaOptions = response.data || []
  762. })
  763. } catch (error) {
  764. console.error('加载设备树失败:', error)
  765. this.areaOptions = []
  766. }
  767. }
  768. }
  769. }
  770. </script>
  771. <style scoped>
  772. /* 树容器样式 */
  773. .tree-container {
  774. height: calc(100vh - 200px);
  775. overflow-y: auto;
  776. border: 1px solid #e8e8e8;
  777. border-radius: 4px;
  778. padding: 10px;
  779. background-color: #fafafa;
  780. }
  781. /* 树节点样式 */
  782. .tree-node {
  783. display: flex;
  784. align-items: center;
  785. width: 100%;
  786. padding: 2px 0;
  787. transition: all 0.3s;
  788. }
  789. .node-icon {
  790. margin-right: 8px;
  791. font-size: 16px;
  792. transition: color 0.3s;
  793. }
  794. .area-icon {
  795. color: #909399;
  796. }
  797. .device-icon {
  798. color: #409EFF;
  799. }
  800. .node-label {
  801. flex: 1;
  802. font-size: 14px;
  803. }
  804. /* 区域节点样式 - 不可点击 */
  805. .area-node {
  806. cursor: not-allowed;
  807. opacity: 0.7;
  808. }
  809. .area-node:hover {
  810. background-color: transparent !important;
  811. }
  812. .area-node:hover .area-icon {
  813. color: #909399;
  814. }
  815. /* 设备节点样式 - 可点击 */
  816. .device-node {
  817. cursor: pointer;
  818. }
  819. .device-node:hover {
  820. background-color: #f0f7ff;
  821. border-radius: 4px;
  822. padding-left: 4px;
  823. }
  824. .device-node:hover .device-icon {
  825. color: #2b7bff;
  826. transform: scale(1.1);
  827. }
  828. /* 高亮当前选中的节点 */
  829. .el-tree-node.is-current > .el-tree-node__content .device-node {
  830. background-color: #e6f7ff;
  831. border-radius: 4px;
  832. padding-left: 4px;
  833. }
  834. .el-tree-node.is-current > .el-tree-node__content .device-icon {
  835. color: #1890ff;
  836. }
  837. /* 压缩卡片高度 */
  838. .compact-card {
  839. min-height: auto !important;
  840. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  841. transition: all 0.3s;
  842. }
  843. .compact-card:hover {
  844. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  845. transform: translateY(-2px);
  846. }
  847. .compact-card .el-card__header {
  848. padding: 12px 15px !important;
  849. border-bottom: 1px solid #f0f0f0;
  850. background: linear-gradient(to right, #f7f8fa, #ffffff);
  851. }
  852. .compact-card .el-card__body {
  853. padding: 20px 15px !important;
  854. }
  855. /* 新的汇总统计容器 */
  856. .summary-container {
  857. margin-bottom: 20px;
  858. }
  859. .summary-row {
  860. display: flex;
  861. gap: 15px;
  862. margin-bottom: 15px;
  863. }
  864. /* 横向紧凑卡片样式 */
  865. .summary-inline-card {
  866. flex: 1;
  867. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  868. transition: all 0.3s;
  869. }
  870. .summary-inline-card:hover {
  871. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  872. transform: translateY(-2px);
  873. }
  874. .summary-inline-card .el-card__body {
  875. padding: 12px 20px !important;
  876. }
  877. .inline-card-content {
  878. display: flex;
  879. justify-content: space-between;
  880. align-items: center;
  881. }
  882. .inline-card-left {
  883. display: flex;
  884. align-items: center;
  885. gap: 10px;
  886. }
  887. .inline-icon {
  888. font-size: 24px;
  889. }
  890. .elec-icon {
  891. color: #409EFF;
  892. }
  893. .water-icon {
  894. color: #67C23A;
  895. }
  896. .cost-icon {
  897. color: #E6A23C;
  898. }
  899. .inline-label {
  900. font-size: 14px;
  901. color: #606266;
  902. font-weight: 500;
  903. }
  904. .inline-card-right {
  905. display: flex;
  906. align-items: baseline;
  907. gap: 5px;
  908. }
  909. .inline-value {
  910. font-size: 24px;
  911. font-weight: bold;
  912. background: linear-gradient(135deg, #409EFF 0%, #66b1ff 100%);
  913. -webkit-background-clip: text;
  914. -webkit-text-fill-color: transparent;
  915. }
  916. .inline-unit {
  917. font-size: 12px;
  918. color: #909399;
  919. }
  920. /* 峰谷电横向紧凑卡片 */
  921. .peak-valley-row {
  922. display: flex;
  923. gap: 12px;
  924. flex-wrap: wrap;
  925. }
  926. .peak-inline-card {
  927. flex: 1;
  928. min-width: 200px;
  929. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  930. transition: all 0.3s;
  931. }
  932. .peak-inline-card:hover {
  933. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  934. transform: translateY(-2px);
  935. }
  936. .peak-inline-card .el-card__body {
  937. padding: 10px 15px !important;
  938. }
  939. .peak-inline-content {
  940. display: flex;
  941. align-items: center;
  942. gap: 15px;
  943. }
  944. .peak-inline-header {
  945. flex-shrink: 0;
  946. }
  947. .peak-type-badge {
  948. display: inline-block;
  949. padding: 4px 10px;
  950. font-size: 12px;
  951. border-radius: 4px;
  952. color: white;
  953. font-weight: 500;
  954. min-width: 40px;
  955. text-align: center;
  956. }
  957. /* 峰谷电类型标签样式 */
  958. .deep-valley-tag {
  959. background: linear-gradient(135deg, #409EFF 0%, #1976D2 100%);
  960. }
  961. .valley-tag {
  962. background: linear-gradient(135deg, #67C23A 0%, #4CAF50 100%);
  963. }
  964. .normal-tag {
  965. background: linear-gradient(135deg, #909399 0%, #606266 100%);
  966. }
  967. .high-peak-tag {
  968. background: linear-gradient(135deg, #E6A23C 0%, #FF9800 100%);
  969. }
  970. .peak-tag {
  971. background: linear-gradient(135deg, #F56C6C 0%, #f44336 100%);
  972. }
  973. .peak-inline-body {
  974. flex: 1;
  975. display: flex;
  976. align-items: center;
  977. gap: 20px;
  978. }
  979. .peak-inline-info {
  980. display: flex;
  981. align-items: baseline;
  982. gap: 5px;
  983. }
  984. .peak-label {
  985. font-size: 12px;
  986. color: #909399;
  987. }
  988. .peak-value {
  989. font-size: 16px;
  990. font-weight: bold;
  991. color: #303133;
  992. }
  993. .peak-unit {
  994. font-size: 11px;
  995. color: #909399;
  996. }
  997. .peak-percentage {
  998. margin-left: auto;
  999. font-size: 12px;
  1000. color: #909399;
  1001. padding: 2px 8px;
  1002. background-color: #f4f4f5;
  1003. border-radius: 12px;
  1004. white-space: nowrap;
  1005. }
  1006. /* 汇总卡片样式 - 已删除 */
  1007. /* 峰谷电卡片样式 - 已删除旧样式 */
  1008. /* 响应式布局 */
  1009. @media (max-width: 1680px) {
  1010. .inline-value {
  1011. font-size: 20px;
  1012. }
  1013. .peak-value {
  1014. font-size: 14px;
  1015. }
  1016. }
  1017. @media (max-width: 1366px) {
  1018. .peak-valley-row .peak-inline-card {
  1019. flex: 1 1 calc(50% - 6px);
  1020. }
  1021. .inline-value {
  1022. font-size: 18px;
  1023. }
  1024. .peak-inline-body {
  1025. gap: 15px;
  1026. }
  1027. }
  1028. @media (max-width: 768px) {
  1029. .summary-row {
  1030. flex-direction: column;
  1031. }
  1032. .peak-valley-row .peak-inline-card {
  1033. flex: 1 1 100%;
  1034. }
  1035. .peak-inline-body {
  1036. gap: 10px;
  1037. }
  1038. }
  1039. @media (max-width: 480px) {
  1040. .inline-card-content {
  1041. flex-direction: column;
  1042. align-items: flex-start;
  1043. gap: 10px;
  1044. }
  1045. .peak-inline-content {
  1046. flex-direction: column;
  1047. align-items: flex-start;
  1048. gap: 10px;
  1049. }
  1050. .peak-inline-body {
  1051. width: 100%;
  1052. flex-direction: column;
  1053. align-items: flex-start;
  1054. gap: 5px;
  1055. }
  1056. .peak-percentage {
  1057. margin-left: 0;
  1058. margin-top: 5px;
  1059. }
  1060. }
  1061. /* 过渡动画 */
  1062. .el-card {
  1063. transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  1064. }
  1065. /* 加载动画优化 */
  1066. .el-loading-mask {
  1067. background-color: rgba(255, 255, 255, 0.9);
  1068. }
  1069. </style>