dashboard.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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>{{ monthSales }}元</p>
  198. </div>
  199. <div class="water">
  200. <p>本月累计销售量</p>
  201. <p>{{ monthAmount }}头</p>
  202. </div>
  203. <div class="water">
  204. <p>上月销售总量</p>
  205. <p>{{ weekSales }}元</p>
  206. <p>
  207. <i
  208. v-if="Number(weekSalesChange) > 0"
  209. class="el-icon-caret-top"
  210. style="color: red"
  211. ></i>
  212. <i v-else class="el-icon-caret-bottom" style="color: #1ABC9C"></i>
  213. <span
  214. :style="{
  215. color: Number(weekSalesChange) > 0 ? 'red' : '#1ABC9C',
  216. }"
  217. >{{ weekSalesChange }}%</span
  218. >
  219. &nbsp;
  220. <span style="font-size: 16px; color: #CFDBED">环比上月</span>
  221. </p>
  222. </div>
  223. <div class="water">
  224. <p>上月销售量</p>
  225. <p>{{ weekSalesVolume }}头</p>
  226. <p>
  227. <i
  228. v-if="Number(weekSalesVolumeChange) > 0"
  229. class="el-icon-caret-top"
  230. style="color: red"
  231. ></i>
  232. <i v-else class="el-icon-caret-bottom" style="color: #1ABC9C"></i>
  233. <span
  234. :style="{
  235. color: Number(weekSalesVolumeChange) > 0 ? 'red' : '#1ABC9C',
  236. }"
  237. >{{ weekSalesVolumeChange }}%</span
  238. >
  239. &nbsp;
  240. <span style="font-size: 16px; color: #CFDBED">环比上月</span>
  241. </p>
  242. </div>
  243. </div>
  244. <div style="width: 85%; height: 400px">
  245. <chart-pig
  246. v-if="salesChartData.quantityList.length > 0"
  247. :data="salesChartData"
  248. ></chart-pig>
  249. <el-empty
  250. v-else
  251. description="暂无数据"
  252. style="width: 100%;"
  253. ></el-empty>
  254. </div>
  255. </div>
  256. </div>
  257. </div>
  258. </template>
  259. <script>
  260. import XForm from "../../components/XForm";
  261. import { mapState } from "vuex";
  262. import ChartWsd from "./chart/ChartWsd";
  263. // import ChartDl from "./chart/ChartDl";
  264. import ChartWater from "./chart/ChartWater";
  265. import ChartPig from "./chart/ChartPig";
  266. import {
  267. getByFloor,
  268. getByRoom,
  269. getListClientHome,
  270. getListWater,
  271. getSchool,
  272. getUid,
  273. } from "../../utils/api";
  274. import { timeDate } from "../../utils";
  275. import { getTheSales } from "../../utils/chenApi";
  276. import axios from "axios";
  277. export default {
  278. name: "dashboard",
  279. components: {
  280. ChartWsd,
  281. ChartWater,
  282. ChartPig,
  283. XForm,
  284. },
  285. data() {
  286. return {
  287. dialogVisible: false,
  288. iconList: [
  289. {
  290. icon: "el-icon-s-order",
  291. name: "今日报警总数",
  292. num: 0,
  293. unit: "条",
  294. },
  295. {
  296. icon: "el-icon-shopping-bag-1",
  297. name: "昨日卖猪总数",
  298. num: 0,
  299. unit: "头",
  300. },
  301. {
  302. icon: "el-icon-coin",
  303. name: "昨日卖猪金额",
  304. num: 0,
  305. unit: "元",
  306. },
  307. {
  308. icon: "el-icon-finished",
  309. name: "近7天卖猪总数",
  310. num: 0,
  311. unit: "头",
  312. },
  313. ],
  314. elements: [
  315. {
  316. id: 1,
  317. name: "事件提醒",
  318. data: 10,
  319. },
  320. {
  321. id: 2,
  322. name: "事件提醒",
  323. data: 10,
  324. },
  325. {
  326. id: 3,
  327. name: "事件提醒",
  328. data: 10,
  329. },
  330. {
  331. id: 4,
  332. name: "事件提醒",
  333. data: 10,
  334. },
  335. {
  336. id: 5,
  337. name: "事件提醒",
  338. data: 10,
  339. },
  340. {
  341. id: 6,
  342. name: "事件提醒",
  343. data: 10,
  344. },
  345. ],
  346. dateRange: [],
  347. formItems: [
  348. {
  349. id: 1,
  350. type: "select",
  351. label: "栋舍:",
  352. placeholder: "请选择栋舍",
  353. field: "floorId",
  354. options: [],
  355. col: 4,
  356. },
  357. {
  358. id: 2,
  359. type: "select",
  360. label: "楼层:",
  361. placeholder: "请选择楼层",
  362. field: "uid",
  363. options: [],
  364. col: 4,
  365. },
  366. {
  367. id: 10,
  368. type: "select",
  369. label: "单元:",
  370. placeholder: "请选择单元",
  371. field: "unitId",
  372. options: [],
  373. col: 4,
  374. },
  375. {
  376. id: 4,
  377. type: "text",
  378. text: "本周",
  379. value: 2,
  380. col: 1,
  381. },
  382. {
  383. id: 5,
  384. type: "text",
  385. text: "本月",
  386. value: 3,
  387. col: 1,
  388. },
  389. {
  390. id: 6,
  391. type: "datepicker",
  392. placeholder: [],
  393. field: "value1",
  394. col: 6,
  395. },
  396. {
  397. id: 8,
  398. type: "button",
  399. text: "查询",
  400. col: 1,
  401. click: "search",
  402. },
  403. // {
  404. // id: 7,
  405. // type: 'button',
  406. // text: '导出数据',
  407. // col: 2,
  408. // click: 'derive'
  409. // }
  410. ],
  411. day: 2,
  412. day1: 2,
  413. TempAndHumList: {
  414. humidities: [],
  415. },
  416. waterList: [],
  417. waterRoom: "",
  418. weekWater: 0,
  419. weekWeekPercent: 0,
  420. monthWater: 0,
  421. monthWeekPercent: 0,
  422. monthSales: 0,
  423. monthAmount: 0,
  424. weekSales: 0,
  425. weekSalesChange: 0,
  426. weekSalesVolume: 0,
  427. weekSalesVolumeChange: 0,
  428. salesChartData: {
  429. quantityList: [],
  430. timeList: [],
  431. moneyList: [],
  432. },
  433. loading: false,
  434. tempLoading: false,
  435. waterLoading: false,
  436. };
  437. },
  438. computed: {
  439. ...mapState(["color"]),
  440. },
  441. methods: {
  442. setDay(data) {
  443. this.day = data.type;
  444. let data1 = data.data;
  445. if (data1.unitId) {
  446. let end = timeDate(new Date().getTime());
  447. let params = {
  448. roomId: data1.unitId,
  449. endDate: end,
  450. type: this.day,
  451. };
  452. getByRoom(params).then((res) => {
  453. if (res.code === 10000) {
  454. // this.tempList = {
  455. // name: res.data.roomName,
  456. // list: res.data.semperatures
  457. // }
  458. // this.humList = {
  459. // name: res.data.roomName,
  460. // list: res.data.humidities
  461. // }
  462. this.TempAndHumList = res.data;
  463. }
  464. // getListWater(params).then(res => {
  465. // if(res.code === 10000) {
  466. // this.waterList = res.data.data;
  467. // this.waterRoom = res.data.room;
  468. // }
  469. // })
  470. });
  471. } else {
  472. this.$message.error("请选择栋舍楼层单元查询");
  473. }
  474. },
  475. setDay1(data) {
  476. this.day1 = data.type;
  477. let data1 = data.data;
  478. if (data1.unitId) {
  479. let end = timeDate(new Date().getTime());
  480. let params = {
  481. roomId: data1.unitId,
  482. endDate: end,
  483. type: this.day1,
  484. };
  485. getListWater(params).then((res) => {
  486. if (res.code === 10000) {
  487. this.waterList = res.data.data;
  488. this.waterRoom = res.data.room;
  489. }
  490. });
  491. } else {
  492. this.$message.error("请选择栋舍楼层单元查询");
  493. }
  494. },
  495. getSchool() {
  496. getSchool({}).then((res) => {
  497. if (res.code === 10000) {
  498. res.data.forEach((item) => {
  499. item.value = item.id;
  500. item.label = item.floorName;
  501. });
  502. this.formItems[0].options = res.data;
  503. }
  504. });
  505. },
  506. setChange(item) {
  507. if (item.type === "floorId") {
  508. let params = {
  509. floorId: item.data,
  510. };
  511. getByFloor(params).then((res) => {
  512. res.data.forEach((item) => {
  513. item.value = item.uid;
  514. item.label = item.alias;
  515. });
  516. this.formItems[1].options = res.data;
  517. });
  518. } else if (item.type === "uid") {
  519. let params = {
  520. uid: item.data,
  521. };
  522. getUid(params).then((res) => {
  523. res.data.forEach((item) => {
  524. item.value = item.id;
  525. item.label = item.roomName;
  526. });
  527. this.formItems[2].options = res.data;
  528. });
  529. }
  530. },
  531. setChange1(item) {
  532. if (item.type === "floorId") {
  533. let params = {
  534. floorId: item.data,
  535. };
  536. getByFloor(params).then((res) => {
  537. res.data.forEach((item) => {
  538. item.value = item.uid;
  539. item.label = item.alias;
  540. });
  541. this.formItems[1].options = res.data;
  542. });
  543. } else if (item.type === "uid") {
  544. let params = {
  545. uid: item.data,
  546. };
  547. getUid(params).then((res) => {
  548. res.data.forEach((item) => {
  549. item.value = item.id;
  550. item.label = item.roomName;
  551. });
  552. this.formItems[2].options = res.data;
  553. });
  554. }
  555. },
  556. onClickType(data) {
  557. if (data.type === "search") {
  558. let data1 = data.data;
  559. if (data1.unitId) {
  560. let params;
  561. if (data1.value1) {
  562. params = {
  563. roomId: data1.unitId,
  564. startDate: data1.value1[0],
  565. endDate: data1.value1[1],
  566. type: 4,
  567. };
  568. } else {
  569. this.$message.error("请选择时间区间查询");
  570. }
  571. getByRoom(params).then((res) => {
  572. if (res.code === 10000) {
  573. this.TempAndHumList = res.data;
  574. }
  575. });
  576. } else {
  577. this.$message.error("请选择栋舍楼层单元查询");
  578. }
  579. }
  580. },
  581. onClickType1(data) {
  582. if (data.type === "search") {
  583. let data1 = data.data;
  584. if (data1.unitId) {
  585. let params;
  586. if (data1.value1) {
  587. params = {
  588. roomId: data1.unitId,
  589. startDate: data1.value1[0],
  590. endDate: data1.value1[1],
  591. type: 4,
  592. };
  593. } else {
  594. this.$message.error("请选择时间区间查询");
  595. }
  596. getListWater(params).then((res) => {
  597. if (res.code === 10000) {
  598. this.waterList = res.data.data;
  599. this.waterRoom = res.data.room;
  600. }
  601. });
  602. } else {
  603. this.$message.error("请选择栋舍楼层单元查询");
  604. }
  605. }
  606. },
  607. getTempAndHum() {
  608. let that = this;
  609. axios
  610. .all([
  611. getListClientHome({}),
  612. getByRoom({ type: 2 }),
  613. getListWater({ type: 2 }),
  614. getTheSales({ type: 2 }),
  615. ])
  616. .then(
  617. axios.spread(function(res1, res2, res3, res4) {
  618. that.loading = false;
  619. that.tempLoading = false;
  620. that.waterLoading = false;
  621. if (res1.code === 10000) {
  622. const { money, quantity, warning, weekQuantity } =
  623. res1.data || {};
  624. that.iconList[0].num = warning;
  625. that.iconList[1].num = quantity;
  626. that.iconList[2].num = money;
  627. that.iconList[3].num = weekQuantity;
  628. // that.incon
  629. }
  630. if (res2.code === 10000) {
  631. that.TempAndHumList = res2.data;
  632. }
  633. if (res3.code === 10000) {
  634. that.waterList = res3.data.data;
  635. that.waterRoom = res3.data.room;
  636. that.weekWater = res3.data.weekWater;
  637. that.weekWeekPercent = res3.data.weekWeekPercent;
  638. that.monthWater = res3.data.monthWater;
  639. that.monthWeekPercent = res3.data.monthWeekPercent;
  640. }
  641. if (res4.code === 10000) {
  642. that.monthSales = res4.data.nowMoney.toLocaleString();
  643. that.monthAmount = res4.data.nowQuantity.toLocaleString();
  644. that.weekSales = res4.data.money;
  645. that.weekSalesChange = res4.data.moneyPercent;
  646. that.weekSalesVolume = res4.data.quantity;
  647. that.weekSalesVolumeChange = res4.data.quantityPercent;
  648. that.salesChartData = {
  649. moneyList: res4.data.moneyList,
  650. quantityList: res4.data.quantityList,
  651. timeList: res4.data.timeList,
  652. };
  653. }
  654. })
  655. );
  656. },
  657. jump(num) {
  658. if (num === 1) {
  659. this.$router.push("/pigHouseEnv");
  660. } else if (num === 2) {
  661. this.$router.push("/drinkWater");
  662. } else if (num === 4) {
  663. this.$router.push("/analysis");
  664. }
  665. },
  666. },
  667. mounted() {
  668. this.getSchool();
  669. this.getTempAndHum();
  670. },
  671. };
  672. </script>
  673. <style scoped>
  674. p {
  675. margin: 0;
  676. padding: 0;
  677. }
  678. .box {
  679. width: 100%;
  680. height: 100%;
  681. box-sizing: border-box;
  682. padding: 20px;
  683. }
  684. .header {
  685. width: 100%;
  686. /*height: 150px;*/
  687. }
  688. .box-card {
  689. box-sizing: border-box;
  690. height: 100%;
  691. }
  692. .card-flex {
  693. display: flex;
  694. height: 120px;
  695. }
  696. .flex-left {
  697. width: 40%;
  698. height: 100%;
  699. text-align: center;
  700. display: flex;
  701. align-items: center;
  702. justify-content: center;
  703. }
  704. .flex-right {
  705. width: 60%;
  706. height: 100%;
  707. box-sizing: border-box;
  708. padding: 30px 0;
  709. font-size: 18px;
  710. }
  711. .pending {
  712. width: 100%;
  713. /*height: 300px;*/
  714. border: 1px solid #ddd;
  715. }
  716. .title {
  717. width: 100%;
  718. height: 40px;
  719. border-bottom: 1px solid #ddd;
  720. line-height: 40px;
  721. box-sizing: border-box;
  722. padding-left: 20px;
  723. background-color: #f3f3f3;
  724. font-weight: 700;
  725. }
  726. .fens {
  727. width: 100%;
  728. box-sizing: border-box;
  729. padding: 20px;
  730. }
  731. .fens-text {
  732. width: 100%;
  733. height: 40px;
  734. line-height: 40px;
  735. border-bottom: 1px solid #ddd;
  736. box-sizing: border-box;
  737. padding: 0 10px;
  738. margin-bottom: 20px;
  739. color: #cbbccb;
  740. }
  741. .text-size {
  742. cursor: pointer;
  743. }
  744. .pen-flex {
  745. width: 100%;
  746. height: 400px;
  747. display: flex;
  748. }
  749. .pen-left {
  750. width: 15%;
  751. height: 100%;
  752. border-right: 1px solid #ddd;
  753. text-align: center;
  754. padding-top: 15px;
  755. }
  756. .water {
  757. padding: 10px 0;
  758. font-size: 18px;
  759. }
  760. </style>