dashboard.vue 16 KB

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