dashboard.vue 20 KB

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