dashboard.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <template>
  2. <div class="box">
  3. <el-skeleton style="width: 100%;" :rows="6" animated :loading="loading">
  4. <div class="header">
  5. <el-row :gutter="20">
  6. <el-col v-for="(item, i) in iconList" :key="i" :span="6">
  7. <el-card class="box-card">
  8. <div class="card-flex">
  9. <div class="flex-left">
  10. <i :class="[item.icon]" :style="{ fontSize: '72px', color: color }"></i>
  11. </div>
  12. <div class="flex-right">
  13. <p :style="{marginBottom: '8px', color: color}">{{item.name}}</p>
  14. <p>{{item.num}}{{item.unit}}</p>
  15. </div>
  16. </div>
  17. </el-card>
  18. </el-col>
  19. </el-row>
  20. </div>
  21. </el-skeleton>
  22. <br/>
  23. <div class="pending">
  24. <div class="title" :style="{color: color}">待处理事务</div>
  25. <div class="fens">
  26. <el-row :gutter="40">
  27. <el-col v-for="item in elements" :key="item.id" :span="8">
  28. <div class="fens-text">
  29. <span>{{item.name}}</span>
  30. <el-tag effect="dark" type="danger" style="float: right">{{item.data}}</el-tag>
  31. </div>
  32. </el-col>
  33. </el-row>
  34. </div>
  35. </div>
  36. <br/>
  37. <div class="pending">
  38. <div class="title" :style="{color: color}">
  39. <span>猪舍温湿度</span>
  40. <el-button type="text" style="float: right; margin-right: 25px" @click="jump(1)">详情</el-button>
  41. </div>
  42. <x-form :formItems="formItems" :day="day" @setDay="setDay" @setChange="setChange" @onClickType="onClickType"></x-form>
  43. <el-skeleton style="width: 100%;" :rows="10" animated :loading="tempLoading">
  44. <div style="width: 100%; height: 400px">
  45. <chart-wsd v-if="TempAndHumList.humidities.length > 0" :data="TempAndHumList"></chart-wsd>
  46. <el-empty v-else description="暂无数据" style="width: 100%;"></el-empty>
  47. </div>
  48. </el-skeleton>
  49. </div>
  50. <br/>
  51. <div class="pending">
  52. <div class="title" :style="{color: color}">
  53. <span>水量消耗</span>
  54. <el-button type="text" style="float: right; margin-right: 25px" @click="jump(2)">详情</el-button>
  55. </div>
  56. <x-form :formItems="formItems" :day="day" @setDay="setDay" @setChange="setChange" @onClickType="onClickType"></x-form>
  57. <div class="pen-flex" v-if="waterList.length > 0">
  58. <div class="pen-left">
  59. <div class="water">
  60. <p>上月用水量</p>
  61. <p>{{monthWater}}t</p>
  62. <p>
  63. <i v-if="Number(monthWeekPercent) > 0" class="el-icon-caret-top" style="color: red"></i>
  64. <i v-else class="el-icon-caret-bottom" style="color: #1ABC9C"></i>
  65. <span :style="{color: Number(monthWeekPercent) > 0 ? 'red' : '#1ABC9C'}">{{monthWeekPercent}}%</span>
  66. &nbsp;
  67. <span style="font-size: 16px; color: #CFDBED">环比上月</span>
  68. </p>
  69. </div>
  70. <div class="water">
  71. <p>上周用水量</p>
  72. <p>{{weekWater}}t</p>
  73. <p>
  74. <i v-if="Number(weekWeekPercent) > 0" class="el-icon-caret-top" style="color: red"></i>
  75. <i v-else class="el-icon-caret-bottom" style="color: #1ABC9C"></i>
  76. <span :style="{color: Number(weekWeekPercent) > 0 ? 'red' : '#1ABC9C'}">{{weekWeekPercent}}%</span>
  77. &nbsp;
  78. <span style="font-size: 16px; color: #CFDBED">环比上周</span>
  79. </p>
  80. </div>
  81. </div>
  82. <div style="width: 85%; height: 400px">
  83. <chart-water :dataValue="waterList" :room="waterRoom"></chart-water>
  84. </div>
  85. </div>
  86. <div v-else>
  87. <el-empty description="暂无数据" style="width: 100%;"></el-empty>
  88. </div>
  89. </div>
  90. <br/>
  91. <div class="pending">
  92. <div class="title" :style="{color: color}">
  93. <span>电量消耗</span>
  94. <el-button type="text" style="float: right; margin-right: 25px">详情</el-button>
  95. </div>
  96. <x-form :formItems="formItems" :day="day" @setDay="setDay" @setChange="setChange" @onClickType="onClickType"></x-form>
  97. <div class="pen-flex">
  98. <div class="pen-left">
  99. <div class="water">
  100. <p>本月用电量</p>
  101. <p>10000KW·h</p>
  102. <p>
  103. <i class="el-icon-caret-top" style="color: red"></i>
  104. <span style="color: red">10%</span>
  105. &nbsp;
  106. <span style="font-size: 16px; color: #CFDBED">环比上月</span>
  107. </p>
  108. </div>
  109. <div class="water">
  110. <p>本周用电量</p>
  111. <p>10000KW·h</p>
  112. <p>
  113. <i class="el-icon-caret-bottom" style="color: #1ABC9C"></i>
  114. <span style="color: #1ABC9C">10%</span>
  115. &nbsp;
  116. <span style="font-size: 16px; color: #CFDBED">同比上周</span>
  117. </p>
  118. </div>
  119. </div>
  120. <div style="width: 85%; height: 400px">
  121. <chart-dl></chart-dl>
  122. </div>
  123. </div>
  124. </div>
  125. <br/>
  126. <div class="pending">
  127. <div class="title" :style="{color: color}">
  128. <span>卖猪统计</span>
  129. <el-button type="text" style="float: right; margin-right: 25px" @click="jump(4)">详情</el-button>
  130. </div>
  131. <div class="pen-flex">
  132. <div class="pen-left">
  133. <div class="water">
  134. <p>上月销售总量</p>
  135. <p>{{weekSales}}元</p>
  136. <p>
  137. <i v-if="Number(weekSalesChange) > 0" class="el-icon-caret-top" style="color: red"></i>
  138. <i v-else class="el-icon-caret-bottom" style="color: #1ABC9C"></i>
  139. <span :style="{color: Number(weekSalesChange) > 0 ? 'red' : '#1ABC9C'}">{{weekSalesChange}}%</span>
  140. &nbsp;
  141. <span style="font-size: 16px; color: #CFDBED">环比上月</span>
  142. </p>
  143. </div>
  144. <div class="water">
  145. <p>上月销售量</p>
  146. <p>{{ weekSalesVolume }}头</p>
  147. <p>
  148. <i v-if="Number(weekSalesVolumeChange) > 0" class="el-icon-caret-top" style="color: red"></i>
  149. <i v-else class="el-icon-caret-bottom" style="color: #1ABC9C"></i>
  150. <span :style="{color: Number(weekSalesVolumeChange) > 0 ? 'red' : '#1ABC9C'}">{{weekSalesVolumeChange}}%</span>
  151. &nbsp;
  152. <span style="font-size: 16px; color: #CFDBED">环比上月</span>
  153. </p>
  154. </div>
  155. </div>
  156. <div style="width: 85%; height: 400px">
  157. <chart-pig v-if="salesChartData.quantityList.length > 0" :data="salesChartData"></chart-pig>
  158. <el-empty v-else description="暂无数据" style="width: 100%;"></el-empty>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. </template>
  164. <script>
  165. import XForm from "../../components/XForm";
  166. import { mapState } from 'vuex';
  167. import ChartWsd from "./chart/ChartWsd";
  168. import ChartDl from'./chart/ChartDl';
  169. import ChartWater from "./chart/ChartWater";
  170. import ChartPig from "./chart/ChartPig";
  171. import {getByFloor, getByRoom, getListClientHome, getListWater, getSchool, getUid} from "../../utils/api";
  172. import {timeDate} from "../../utils";
  173. import { getTheSales } from "../../utils/chenApi";
  174. import axios from 'axios';
  175. export default {
  176. name: "dashboard",
  177. components: {
  178. ChartWsd,
  179. ChartDl,
  180. ChartWater,
  181. ChartPig,
  182. XForm
  183. },
  184. data() {
  185. return {
  186. dialogVisible: false,
  187. iconList: [
  188. {
  189. icon: 'el-icon-s-order',
  190. name: '今日报警总数',
  191. unit: '条'
  192. },
  193. {
  194. icon: 'el-icon-shopping-bag-1',
  195. name: '昨日卖猪总数',
  196. unit: '头'
  197. },
  198. {
  199. icon: 'el-icon-coin',
  200. name: '昨日卖猪金额',
  201. unit: '元'
  202. },
  203. {
  204. icon: 'el-icon-finished',
  205. name: '近7天卖猪总数',
  206. unit: '头'
  207. },
  208. ],
  209. elements: [
  210. {
  211. id: 1,
  212. name: '事件提醒',
  213. data: 10
  214. },
  215. {
  216. id: 2,
  217. name: '事件提醒',
  218. data: 10
  219. },
  220. {
  221. id: 3,
  222. name: '事件提醒',
  223. data: 10
  224. },
  225. {
  226. id: 4,
  227. name: '事件提醒',
  228. data: 10
  229. },
  230. {
  231. id: 5,
  232. name: '事件提醒',
  233. data: 10
  234. },
  235. {
  236. id: 6,
  237. name: '事件提醒',
  238. data: 10
  239. },
  240. ],
  241. dateRange: [],
  242. formItems: [
  243. {
  244. id: 1,
  245. type: 'select',
  246. label: '栋舍:',
  247. placeholder: '请选择栋舍',
  248. field: 'floorId',
  249. options: [],
  250. col: 4
  251. },
  252. {
  253. id: 2,
  254. type: 'select',
  255. label: '楼层:',
  256. placeholder: '请选择楼层',
  257. field: 'uid',
  258. options: [],
  259. col: 4
  260. },
  261. {
  262. id: 10,
  263. type: 'select',
  264. label: '单元:',
  265. placeholder: '请选择单元',
  266. field: 'unitId',
  267. options: [],
  268. col: 4
  269. },
  270. {
  271. id: 4,
  272. type: 'text',
  273. text: '本周',
  274. value: 2,
  275. col: 1
  276. },
  277. {
  278. id: 5,
  279. type: 'text',
  280. text: '本月',
  281. value: 3,
  282. col: 1
  283. },
  284. {
  285. id: 6,
  286. type: 'datepicker',
  287. placeholder: [],
  288. field: 'value1',
  289. col: 6
  290. },
  291. {
  292. id: 8,
  293. type: 'button',
  294. text: '查询',
  295. col: 1,
  296. click: 'search'
  297. },
  298. // {
  299. // id: 7,
  300. // type: 'button',
  301. // text: '导出数据',
  302. // col: 2,
  303. // click: 'derive'
  304. // }
  305. ],
  306. day: 2,
  307. TempAndHumList: {
  308. humidities: [],
  309. },
  310. waterList: [],
  311. waterRoom: '',
  312. weekWater: 0,
  313. weekWeekPercent: 0,
  314. monthWater: 0,
  315. monthWeekPercent: 0,
  316. weekSales: 0,
  317. weekSalesChange: 0,
  318. weekSalesVolume: 0,
  319. weekSalesVolumeChange: 0,
  320. salesChartData: {
  321. quantityList: [],
  322. timeList: [],
  323. moneyList: []
  324. },
  325. loading: true,
  326. tempLoading: true,
  327. waterLoading: true,
  328. }
  329. },
  330. computed: {
  331. ...mapState(['color'])
  332. },
  333. methods: {
  334. setDay(data) {
  335. this.day = data.type;
  336. let data1 = data.data;
  337. if(data1.unitId) {
  338. let end = timeDate(new Date().getTime())
  339. let params = {
  340. roomId: data1.unitId,
  341. endDate: end,
  342. type: this.day
  343. }
  344. getByRoom(params).then(res => {
  345. if(res.code === 10000) {
  346. this.tempList = {
  347. name: res.data.roomName,
  348. list: res.data.semperatures
  349. }
  350. this.humList = {
  351. name: res.data.roomName,
  352. list: res.data.humidities
  353. }
  354. }
  355. getListWater(params).then(res => {
  356. if(res.code === 10000) {
  357. this.waterList = res.data.data;
  358. this.waterRoom = res.data.room;
  359. }
  360. })
  361. })
  362. } else {
  363. this.$message.error('请选择栋舍楼层单元查询');
  364. }
  365. },
  366. getSchool() {
  367. getSchool({}).then(res => {
  368. if(res.code === 10000) {
  369. res.data.forEach(item => {
  370. item.value = item.id;
  371. item.label = item.floorName;
  372. })
  373. this.formItems[0].options = res.data;
  374. }
  375. })
  376. },
  377. setChange(item) {
  378. if(item.type === 'floorId') {
  379. let params = {
  380. floorId: item.data
  381. }
  382. getByFloor(params).then(res => {
  383. res.data.forEach(item => {
  384. item.value = item.uid;
  385. item.label = item.alias
  386. })
  387. this.formItems[1].options = res.data;
  388. })
  389. } else if(item.type === 'uid') {
  390. let params = {
  391. uid: item.data
  392. }
  393. getUid(params).then(res => {
  394. res.data.forEach(item => {
  395. item.value = item.id;
  396. item.label = item.roomName
  397. })
  398. this.formItems[2].options = res.data
  399. })
  400. }
  401. },
  402. onClickType(data) {
  403. if(data.type === 'search') {
  404. let data1 = data.data;
  405. if(data1.unitId) {
  406. let params;
  407. if(data1.value1) {
  408. params = {
  409. roomId: data1.unitId,
  410. startDate: data1.value1[0],
  411. endDate: data1.value1[1],
  412. type: 4,
  413. }
  414. } else {
  415. let end = timeDate(new Date().getTime())
  416. params = {
  417. roomId: data1.unitId,
  418. endDate: end,
  419. type: this.day
  420. }
  421. }
  422. getByRoom(params).then(res => {
  423. if(res.code === 10000) {
  424. this.tempList = {
  425. name: res.data.roomName,
  426. list: res.data.semperatures
  427. }
  428. this.humList = {
  429. name: res.data.roomName,
  430. list: res.data.humidities
  431. }
  432. }
  433. getListWater(params).then(res => {
  434. if(res.code === 10000) {
  435. this.waterList = res.data.data;
  436. this.waterRoom = res.data.room;
  437. }
  438. })
  439. })
  440. } else {
  441. this.$message.error('请选择栋舍楼层单元查询');
  442. }
  443. }
  444. },
  445. getTempAndHum() {
  446. let that = this;
  447. axios.all([
  448. getListClientHome({}),
  449. getByRoom({type: 2}),
  450. getListWater({type: 2}),
  451. getTheSales({type: 2})
  452. ]).then(axios.spread(function(res1, res2, res3, res4) {
  453. if(res1.code === 10000) {
  454. that.loading = false;
  455. const { money, quantity, warning, weekQuantity } = res1.data || {};
  456. that.iconList[0].num = warning;
  457. that.iconList[1].num = quantity;
  458. that.iconList[2].num = money;
  459. that.iconList[3].num = weekQuantity
  460. // that.incon
  461. }
  462. if(res2.code === 10000) {
  463. that.tempLoading = false;
  464. that.TempAndHumList = res2.data;
  465. }
  466. if(res3.code === 10000) {
  467. that.waterLoading = false;
  468. that.waterList = res3.data.data;
  469. that.waterRoom = res3.data.room;
  470. that.weekWater = res3.data.weekWater;
  471. that.weekWeekPercent = res3.data.weekWeekPercent;
  472. that.monthWater = res3.data.monthWater;
  473. that.monthWeekPercent = res3.data.monthWeekPercent;
  474. }
  475. if (res4.code === 10000) {
  476. that.weekSales = res4.data.money;
  477. that.weekSalesChange = res4.data.moneyPercent;
  478. that.weekSalesVolume = res4.data.quantity;
  479. that.weekSalesVolumeChange = res4.data.quantityPercent;
  480. that.salesChartData = {
  481. moneyList: res4.data.moneyList,
  482. quantityList: res4.data.quantityList,
  483. timeList: res4.data.timeList,
  484. };
  485. }
  486. }))
  487. // getListClientHome({}).then(res => {
  488. // })
  489. // getByRoom({type: 2}).then(res => {
  490. // if(res.code === 10000) {
  491. // this.TempAndHumList = res.data;
  492. // }
  493. // })
  494. // getListWater({type: 2}).then(res => {
  495. // if(res.code === 10000) {
  496. // this.waterList = res.data.data;
  497. // this.waterRoom = res.data.room;
  498. // this.weekWater = res.data.weekWater;
  499. // this.weekWeekPercent = res.data.weekWeekPercent;
  500. // this.monthWater = res.data.monthWater;
  501. // this.monthWeekPercent = res.data.monthWeekPercent;
  502. // }
  503. // })
  504. // getTheSales({type: 2}).then(res => {
  505. // if (res.code === 10000) {
  506. // this.weekSales = res.data.money;
  507. // this.weekSalesChange = res.data.moneyPercent;
  508. // this.weekSalesVolume = res.data.quantity;
  509. // this.weekSalesVolumeChange = res.data.quantityPercent;
  510. // this.salesChartData = {
  511. // moneyList: res.data.moneyList,
  512. // quantityList: res.data.quantityList,
  513. // timeList: res.data.timeList,
  514. // };
  515. // }
  516. // })
  517. },
  518. jump(num) {
  519. if(num === 1) {
  520. this.$router.push('/pigHouseEnv');
  521. } else if(num === 2) {
  522. this.$router.push('/drinkWater');
  523. } else if(num === 4) {
  524. this.$router.push('/analysis');
  525. }
  526. }
  527. },
  528. mounted() {
  529. this.getSchool()
  530. this.getTempAndHum()
  531. }
  532. }
  533. </script>
  534. <style scoped>
  535. p {
  536. margin: 0;
  537. padding: 0;
  538. }
  539. .box {
  540. width: 100%;
  541. height: 100%;
  542. box-sizing: border-box;
  543. padding: 20px;
  544. }
  545. .header {
  546. width: 100%;
  547. /*height: 150px;*/
  548. }
  549. .box-card {
  550. box-sizing: border-box;
  551. height: 100%;
  552. }
  553. .card-flex {
  554. display: flex;
  555. height: 120px;
  556. }
  557. .flex-left {
  558. width: 40%;
  559. height: 100%;
  560. text-align: center;
  561. display: flex;
  562. align-items: center;
  563. justify-content: center;
  564. }
  565. .flex-right {
  566. width: 60%;
  567. height: 100%;
  568. box-sizing: border-box;
  569. padding: 30px 0;
  570. font-size: 18px;
  571. }
  572. .pending {
  573. width: 100%;
  574. /*height: 300px;*/
  575. border: 1px solid #ddd;
  576. }
  577. .title {
  578. width: 100%;
  579. height: 40px;
  580. border-bottom: 1px solid #ddd;
  581. line-height: 40px;
  582. box-sizing: border-box;
  583. padding-left: 20px;
  584. background-color: #F3F3F3;
  585. font-weight: 700;
  586. }
  587. .fens {
  588. width: 100%;
  589. box-sizing: border-box;
  590. padding: 20px;
  591. }
  592. .fens-text {
  593. width: 100%;
  594. height: 40px;
  595. line-height: 40px;
  596. border-bottom: 1px solid #ddd;
  597. box-sizing: border-box;
  598. padding: 0 10px;
  599. margin-bottom: 20px;
  600. color: #CBBCCB;
  601. }
  602. .text-size {
  603. cursor: pointer;
  604. }
  605. .pen-flex {
  606. width: 100%;
  607. height: 400px;
  608. display: flex;
  609. }
  610. .pen-left {
  611. width: 15%;
  612. height: 100%;
  613. border-right: 1px solid #ddd;
  614. text-align: center;
  615. }
  616. .water {
  617. padding: 50px 0;
  618. font-size: 20px;
  619. }
  620. </style>