energy.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <template>
  2. <view class="container">
  3. <!-- 水电表统计区域 -->
  4. <view class="box">
  5. <view class="box_title">水电表统计</view>
  6. <!-- 水表区域 -->
  7. <view class="box_info">
  8. <view class="info_title">水表</view>
  9. <view class="info_day">
  10. <view class="top">
  11. {{ waterDay }}
  12. <view class="text">吨</view>
  13. </view>
  14. <view class="bottom">近24小时</view>
  15. </view>
  16. <view class="info_month">
  17. <view class="top">
  18. {{ waterMonth }}
  19. <view class="text">吨</view>
  20. </view>
  21. <view class="bottom">近30天</view>
  22. </view>
  23. <view class="info_year">
  24. <view class="top">
  25. {{ waterYear }}
  26. <view class="text">吨</view>
  27. </view>
  28. <view class="bottom">近1年</view>
  29. </view>
  30. </view>
  31. <!-- 电表区域 -->
  32. <view class="box_info">
  33. <view class="info_title">电表</view>
  34. <view class="info_day">
  35. <view class="top">
  36. {{ elcDay }}
  37. <view class="text">度</view>
  38. </view>
  39. <view class="bottom">近24小时</view>
  40. </view>
  41. <view class="info_month">
  42. <view class="top">
  43. {{ elcMonth }}
  44. <view class="text">度</view>
  45. </view>
  46. <view class="bottom">近30天</view>
  47. </view>
  48. <view class="info_year">
  49. <view class="top">
  50. {{ elcYear }}
  51. <view class="text">度</view>
  52. </view>
  53. <view class="bottom">近1年</view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 区域统计图表区域 -->
  58. <view class="chart">
  59. <view class="chart_title">区域统计</view>
  60. <!-- 切换区域 -->
  61. <view class="chart_switch">
  62. <view class="switch_box" :class="{ switch_active: activeIndex == 1 }" @click="switchChange(1)">水</view>
  63. <view class="switch_box" :class="{ switch_active: activeIndex == 2 }" @click="switchChange(2)">电</view>
  64. </view>
  65. <!-- 图表区域 -->
  66. <view class="chart_box">
  67. <qiun-data-charts type="column" :opts="opts" :chartData="chartData" />
  68. </view>
  69. </view>
  70. <!-- 区域能耗统计表格区域 -->
  71. <view class="form">
  72. <view class="form_title">区域能耗统计</view>
  73. <!-- 日期选择区域 -->
  74. <view class="form_time" :class="{ active: time_area }" @click="handleOpen">
  75. {{ time_area ? time_area : '请选择月份' }}
  76. <view v-if="time_area" @click.stop="handleClose">
  77. <uni-icons type="close" size="20" color="#808080"></uni-icons>
  78. </view>
  79. <image class="time_img" src="/static/images/time.png" mode="aspectFill"></image>
  80. <uv-datetime-picker ref="datetimePicker" :value="Date.now()" mode="year-month" @confirm="handleConfirm"></uv-datetime-picker>
  81. </view>
  82. <!-- 表格区域 -->
  83. <view class="form_table">
  84. <uni-table ref="table" border emptyText="暂无更多数据">
  85. <uni-tr>
  86. <uni-th width="1" align="center">序号</uni-th>
  87. <uni-th width="1" align="center">电(kw/h)</uni-th>
  88. <uni-th width="1" align="center">水(L)</uni-th>
  89. <uni-th width="1" align="center">&nbsp;楼栋&nbsp;</uni-th>
  90. <uni-th width="1" align="center">日期</uni-th>
  91. </uni-tr>
  92. <uni-tr v-for="(item, index) in tableData_area" :key="item.id">
  93. <uni-td align="center">
  94. <view class="td">{{ index + 1 }}</view>
  95. </uni-td>
  96. <uni-td align="center">
  97. <view class="td">{{ item.eNum || 0 }}</view>
  98. </uni-td>
  99. <uni-td align="center">
  100. <view class="td">{{ item.wNum || 0 }}</view>
  101. </uni-td>
  102. <uni-td align="center">
  103. <view class="td">{{ item.name }}</view>
  104. </uni-td>
  105. <uni-td align="center">
  106. <view class="td">{{ item.date }}</view>
  107. </uni-td>
  108. </uni-tr>
  109. </uni-table>
  110. </view>
  111. <!-- 分页器区域 -->
  112. <view class="pagination">
  113. <uni-pagination show-icon pageSize="4" :total="total_area" :current="currentPage_area" @change="changePage_area"></uni-pagination>
  114. </view>
  115. </view>
  116. <!-- 实时抄表表格区域 -->
  117. <view class="form">
  118. <view class="form_title">实时抄表</view>
  119. <!-- 筛选区域 -->
  120. <view class="form_select">
  121. <!-- 时间选择区域 -->
  122. <view class="select_time" :class="{ active: time_now }" @click="handleOpen_now">
  123. {{ time_now ? time_now : '请选择日期' }}
  124. <view v-if="time_now" @click.stop="handleClose_now">
  125. <uni-icons type="close" size="20" color="#808080"></uni-icons>
  126. </view>
  127. <image class="time_img" src="/static/images/time.png" mode="aspectFill"></image>
  128. <uv-datetime-picker ref="datetimePicker_now" :value="Date.now()" mode="date" @confirm="handleConfirm_now"></uv-datetime-picker>
  129. </view>
  130. <view class="select_box">
  131. <view class="box_item" :class="{ active: activeIndex_now == 0 }" @click="switchChange_now(0)">水</view>
  132. <view class="box_item" :class="{ active: activeIndex_now == 1 }" @click="switchChange_now(1)">电</view>
  133. </view>
  134. </view>
  135. <!-- 表格区域 -->
  136. <view class="form_table">
  137. <uni-table ref="table" border emptyText="暂无更多数据">
  138. <uni-tr>
  139. <uni-th width="1" align="center">序号</uni-th>
  140. <uni-th width="1" align="center">位置</uni-th>
  141. <uni-th width="1" align="center">{{ activeIndex_now == 0 ? '水表码数(吨)' : '电表码数(kw)' }}</uni-th>
  142. <uni-th width="1" align="center">&nbsp;楼栋&nbsp;</uni-th>
  143. <uni-th width="1" align="center">表号</uni-th>
  144. <uni-th width="1" align="center">时间</uni-th>
  145. </uni-tr>
  146. <uni-tr v-for="(item, index) in tableData_now" :key="item.id">
  147. <uni-td align="center">
  148. <view class="td">{{ index + 1 }}</view>
  149. </uni-td>
  150. <uni-td align="center">
  151. <view class="td">{{ item.address }}</view>
  152. </uni-td>
  153. <uni-td align="center">
  154. <view class="td">{{ item.meterPowerRecord }}</view>
  155. </uni-td>
  156. <uni-td align="center">
  157. <view class="td">{{ item.buildAddress }}</view>
  158. </uni-td>
  159. <uni-td align="center">
  160. <view class="td">{{ item.meterNo }}</view>
  161. </uni-td>
  162. <uni-td align="center">
  163. <view class="td">{{ item.createTime }}</view>
  164. </uni-td>
  165. </uni-tr>
  166. </uni-table>
  167. </view>
  168. <!-- 分页器区域 -->
  169. <view class="pagination">
  170. <uni-pagination show-icon pageSize="4" :total="total_now" :current="currentPage_now" @change="changePage_now"></uni-pagination>
  171. </view>
  172. </view>
  173. </view>
  174. </template>
  175. <script setup>
  176. import { ref } from 'vue'
  177. import { onLoad } from '@dcloudio/uni-app'
  178. import { myRequest } from '@/utils/api.js'
  179. import { decryptDes } from '@/utils/des.js'
  180. import dayjs from 'dayjs'
  181. // 水-日
  182. const waterDay = ref()
  183. // 水-月
  184. const waterMonth = ref()
  185. // 水-年
  186. const waterYear = ref()
  187. // 电-日
  188. const elcDay = ref()
  189. // 电-日
  190. const elcMonth = ref()
  191. // 电-日
  192. const elcYear = ref()
  193. // 图表激活索引
  194. const activeIndex = ref(1)
  195. // 图表配置
  196. const opts = ref({})
  197. // 图表数据
  198. const chartData = ref({})
  199. // 图表Y轴数据
  200. const categories = ref([])
  201. // 图表地点数据
  202. const seriesData = ref([
  203. {
  204. name: '',
  205. data: []
  206. },
  207. {
  208. name: '',
  209. data: []
  210. },
  211. {
  212. name: '',
  213. data: []
  214. }
  215. ])
  216. // 区域能耗筛选时间组件DOM
  217. const datetimePicker = ref()
  218. // 区域能耗筛选时间
  219. const time_area = ref('')
  220. // 区域能耗表格数据总条数
  221. const total_area = ref(0)
  222. // 区域能耗表格当前页
  223. const currentPage_area = ref(1)
  224. // 区域能耗表格数据
  225. const tableData_area = ref([])
  226. // 实时抄表筛选时间组件DOM
  227. const datetimePicker_now = ref()
  228. // 实时抄表筛选时间
  229. const time_now = ref('')
  230. // 实时抄表当前激活索引
  231. const activeIndex_now = ref(0)
  232. // 实时抄表表格数据总条数
  233. const total_now = ref(0)
  234. // 实时抄表表格当前页
  235. const currentPage_now = ref(1)
  236. // 实时抄表表格数据
  237. const tableData_now = ref([])
  238. onLoad(() => {
  239. // 获取水电能耗统计数据
  240. getData_waterAndEle()
  241. // 获取图表数据
  242. getData_chart()
  243. // 获取区域能耗统计表格数据
  244. getData_area()
  245. // 获取实时抄表数据
  246. getData_now()
  247. })
  248. // 获取水电能耗统计数据
  249. const getData_waterAndEle = async () => {
  250. const res = await myRequest({
  251. url: '/wanzai/api/wechat/waterAndElectricityStatistics'
  252. })
  253. // console.log(res)
  254. const result = JSON.parse(decryptDes(res.data))
  255. // console.log(result)
  256. waterDay.value = result.waterDay
  257. waterMonth.value = result.waterMonth
  258. waterYear.value = result.waterYear
  259. elcDay.value = result.elcDay
  260. elcMonth.value = result.elcMonth
  261. elcYear.value = result.elcYear
  262. }
  263. // 获取图表数据
  264. const getData_chart = async () => {
  265. const res = await myRequest({
  266. url: '/wanzai/api/driver/getEnergyMonth',
  267. data: {
  268. type: activeIndex.value == 1 ? 0 : 1
  269. }
  270. })
  271. // console.log(res)
  272. categories.value = res.data.map((ele) => ele.month.slice(5, 7) + '月')
  273. seriesData.value[0].name = res.data[0].data[0].name
  274. res.data.forEach((ele) => {
  275. ele.data.forEach((item) => {
  276. if (item.name == seriesData.value[0].name) {
  277. seriesData.value[0].data.push(item.num)
  278. }
  279. })
  280. })
  281. seriesData.value[1].name = res.data[0].data[1].name
  282. res.data.forEach((ele) => {
  283. ele.data.forEach((item) => {
  284. if (item.name == seriesData.value[1].name) {
  285. seriesData.value[1].data.push(item.num)
  286. }
  287. })
  288. })
  289. seriesData.value[2].name = res.data[0].data[2].name
  290. res.data.forEach((ele) => {
  291. ele.data.forEach((item) => {
  292. if (item.name == seriesData.value[2].name) {
  293. seriesData.value[2].data.push(item.num)
  294. }
  295. })
  296. })
  297. // console.log(seriesData.value)
  298. // 初始化图表
  299. initChart()
  300. }
  301. // 初始化图表
  302. const initChart = () => {
  303. opts.value = {
  304. color: ['#3A4DE9', '#00BAAD', '#FF8D1A'],
  305. padding: [25, 15, 0, 5],
  306. enableScroll: false,
  307. dataLabel: false,
  308. legend: {},
  309. xAxis: {
  310. disableGrid: true
  311. },
  312. yAxis: {
  313. showTitle: true,
  314. gridType: 'dash',
  315. data: [
  316. {
  317. min: 0,
  318. title: activeIndex.value == 1 ? '吨' : '度',
  319. titleOffsetY: -10
  320. }
  321. ]
  322. },
  323. extra: {
  324. column: {
  325. type: 'group',
  326. width: 10,
  327. activeBgColor: '#000000',
  328. activeBgOpacity: 0.08
  329. }
  330. }
  331. }
  332. let res = {
  333. categories: categories.value,
  334. series: seriesData.value
  335. }
  336. chartData.value = JSON.parse(JSON.stringify(res))
  337. }
  338. // 水电图表切换回调
  339. const switchChange = (v) => {
  340. activeIndex.value = v
  341. seriesData.value[0].data = []
  342. seriesData.value[1].data = []
  343. seriesData.value[2].data = []
  344. getData_chart()
  345. }
  346. // 获取区域能耗统计表格数据
  347. const getData_area = async () => {
  348. const res = await myRequest({
  349. url: '/wanzai/api/wechat/getAppMeterMonthPage',
  350. data: {
  351. currentPage: currentPage_area.value,
  352. pageCount: 4,
  353. date: time_area.value
  354. }
  355. })
  356. // console.log(res)
  357. const result = JSON.parse(decryptDes(res.data))
  358. // console.log(result)
  359. total_area.value = result.total
  360. tableData_area.value = result.list
  361. }
  362. // 区域能耗统计时间组件打开回调
  363. const handleOpen = () => {
  364. datetimePicker.value.open()
  365. }
  366. // 区域能耗统计时间组件关闭图标回调
  367. const handleClose = () => {
  368. time_area.value = ''
  369. currentPage_area.value = 1
  370. getData_area()
  371. }
  372. // 区域能耗统计时间组件确定回调
  373. const handleConfirm = (e) => {
  374. // console.log(e)
  375. time_area.value = dayjs(e.value).format('YYYY-MM')
  376. currentPage_area.value = 1
  377. getData_area()
  378. }
  379. // 区域能耗统计表格切换当前页回调
  380. const changePage_area = (e) => {
  381. currentPage_area.value = e.current
  382. getData_area()
  383. }
  384. // 获取实时抄表数据
  385. const getData_now = async () => {
  386. const res = await myRequest({
  387. url: '/wanzai/api/wechat/getAppMeterDayPage',
  388. data: {
  389. currentPage: currentPage_now.value,
  390. pageCount: 4,
  391. date: time_now.value,
  392. type: activeIndex_now.value
  393. }
  394. })
  395. // console.log(res)
  396. const result = JSON.parse(decryptDes(res.data))
  397. // console.log(result)
  398. total_now.value = result.total
  399. tableData_now.value = result.list
  400. }
  401. // 区域能耗统计时间组件打开回调
  402. const handleOpen_now = () => {
  403. datetimePicker_now.value.open()
  404. }
  405. // 区域能耗统计时间组件关闭图标回调
  406. const handleClose_now = () => {
  407. time_now.value = ''
  408. currentPage_now.value = 1
  409. getData_now()
  410. }
  411. // 区域能耗统计时间组件确定回调
  412. const handleConfirm_now = (e) => {
  413. // console.log(e)
  414. time_now.value = dayjs(e.value).format('YYYY-MM-DD')
  415. currentPage_now.value = 1
  416. getData_now()
  417. }
  418. // 实时抄表切换类别回调
  419. const switchChange_now = (v) => {
  420. activeIndex_now.value = v
  421. currentPage_now.value = 1
  422. time_now.value = ''
  423. getData_now()
  424. }
  425. // 实时抄表表格切换当前页回调
  426. const changePage_now = (e) => {
  427. // console.log(e)
  428. currentPage_now.value = e.current
  429. getData_now()
  430. }
  431. </script>
  432. <style lang="scss" scoped>
  433. .container {
  434. padding: 20rpx;
  435. .box {
  436. margin-top: 30rpx;
  437. .box_title {
  438. margin-bottom: 40rpx;
  439. font-size: 32rpx;
  440. font-weight: bold;
  441. }
  442. .box_info {
  443. display: flex;
  444. margin-bottom: 50rpx;
  445. height: 80rpx;
  446. .info_title {
  447. width: 100rpx;
  448. line-height: 80rpx;
  449. font-size: 28rpx;
  450. font-weight: bold;
  451. border-right: 2rpx solid #000;
  452. }
  453. .info_day,
  454. .info_month,
  455. .info_year {
  456. display: flex;
  457. flex-direction: column;
  458. align-items: center;
  459. width: 200rpx;
  460. height: 80rpx;
  461. text-align: center;
  462. .top {
  463. margin-top: -18rpx;
  464. width: 180rpx;
  465. font-size: 28rpx;
  466. font-weight: bold;
  467. overflow: hidden;
  468. white-space: nowrap;
  469. text-overflow: ellipsis;
  470. .text {
  471. display: inline-block;
  472. margin-top: -8rpx;
  473. margin-left: -8rpx;
  474. font-size: 22rpx;
  475. font-weight: 400;
  476. }
  477. }
  478. .bottom {
  479. margin-top: 20rpx;
  480. font-size: 22rpx;
  481. color: #808080;
  482. }
  483. }
  484. }
  485. }
  486. .chart {
  487. .chart_title {
  488. font-size: 32rpx;
  489. font-weight: bold;
  490. }
  491. .chart_switch {
  492. display: flex;
  493. justify-content: space-between;
  494. margin-top: 38rpx;
  495. width: 280rpx;
  496. .switch_box {
  497. display: flex;
  498. justify-content: center;
  499. align-items: center;
  500. width: 128rpx;
  501. height: 66rpx;
  502. border-radius: 6rpx;
  503. font-size: 28rpx;
  504. color: #a6a6a6;
  505. background-color: #f2f2f2;
  506. }
  507. .switch_active {
  508. color: #000;
  509. border: 2rpx solid #0061ff;
  510. background-color: #e8f1ff;
  511. }
  512. }
  513. .chart_box {
  514. margin-top: 30rpx;
  515. width: 100%;
  516. height: 550rpx;
  517. }
  518. }
  519. .form {
  520. margin-top: 20rpx;
  521. padding-bottom: 40rpx;
  522. .form_title {
  523. font-size: 32rpx;
  524. font-weight: bold;
  525. }
  526. .form_time {
  527. display: flex;
  528. justify-content: space-between;
  529. align-items: center;
  530. box-sizing: border-box;
  531. padding: 0 20rpx;
  532. margin-top: 38rpx;
  533. width: 280rpx;
  534. height: 66rpx;
  535. font-size: 28rpx;
  536. color: #a6a6a6;
  537. border-radius: 6rpx;
  538. border: 2rpx solid #999999;
  539. background-color: #f2f2f2;
  540. .time_img {
  541. width: 36rpx;
  542. height: 36rpx;
  543. }
  544. }
  545. .active {
  546. color: #000;
  547. }
  548. .form_select {
  549. display: flex;
  550. justify-content: space-between;
  551. align-items: center;
  552. margin-top: 38rpx;
  553. .select_time {
  554. display: flex;
  555. justify-content: space-between;
  556. align-items: center;
  557. box-sizing: border-box;
  558. padding: 0 20rpx;
  559. width: 280rpx;
  560. height: 66rpx;
  561. font-size: 28rpx;
  562. color: #a6a6a6;
  563. border-radius: 6rpx;
  564. border: 2rpx solid #999999;
  565. background-color: #f2f2f2;
  566. .time_img {
  567. width: 36rpx;
  568. height: 36rpx;
  569. }
  570. }
  571. .select_box {
  572. display: flex;
  573. justify-content: space-between;
  574. width: 280rpx;
  575. .box_item {
  576. display: flex;
  577. justify-content: center;
  578. align-items: center;
  579. width: 128rpx;
  580. height: 66rpx;
  581. border-radius: 6rpx;
  582. font-size: 28rpx;
  583. color: #a6a6a6;
  584. background-color: #f2f2f2;
  585. }
  586. .active {
  587. color: #000;
  588. border: 2rpx solid #0061ff;
  589. background-color: #e8f1ff;
  590. }
  591. }
  592. .active {
  593. color: #000;
  594. }
  595. }
  596. .form_table {
  597. margin-top: 40rpx;
  598. .td {
  599. font-size: 24rpx;
  600. white-space: nowrap;
  601. }
  602. }
  603. .pagination {
  604. margin-top: 25rpx;
  605. }
  606. }
  607. }
  608. </style>