PigHouseEnv.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div class="pigHouse">
  3. <el-skeleton style="width: 100%; height: 200px;" :loading="loading" animated>
  4. <div style="height: 200px">
  5. <swiper class="swiper" :options="swiperOption">
  6. <swiper-slide v-for="(item, i) in list" :key="i" style="padding-top: 10px">
  7. <div class="box">
  8. <p>{{item.room}}</p>
  9. <div class="flex">
  10. <div>
  11. <i class="icon1"></i>
  12. </div>
  13. <div>
  14. <span>{{item.temperature ? item.temperature + '℃' : '设备暂无数据'}}</span>
  15. </div>
  16. </div>
  17. <div style="margin-top: 20px" class="flex">
  18. <div>
  19. <i class="icon2"></i>
  20. </div>
  21. <div>
  22. <span>{{item.humidity ? item.humidity + 'RH' : '设备暂无数据'}}</span>
  23. </div>
  24. </div>
  25. </div>
  26. </swiper-slide>
  27. <div class="swiper-pagination" slot="pagination"></div>
  28. <div class="swiper-button-prev" slot="button-prev"></div>
  29. <div class="swiper-button-next" slot="button-next"></div>
  30. </swiper>
  31. </div>
  32. </el-skeleton>
  33. <br/>
  34. <x-form :formItems="formItems" :day="day" @setDay="setDay" @setChange="setChange" @onClickType="onClickType"></x-form>
  35. <br/>
  36. <div style="height: 600px">
  37. <chart-pig-temp v-if="tempList.list.length > 0" :tempList="tempList"></chart-pig-temp>
  38. <el-empty v-else description="暂无数据"></el-empty>
  39. </div>
  40. <div style="height: 600px">
  41. <chart-pig-hum v-if="humList.list.length > 0" :humList="humList"></chart-pig-hum>
  42. <el-empty v-else description="暂无数据"></el-empty>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import { swiper, swiperSlide } from 'vue-awesome-swiper'
  48. import XForm from "@/components/XForm";
  49. import ChartPigTemp from "./chart/ChartPigTemp";
  50. import ChartPigHum from "./chart/ChartPigHum";
  51. import 'swiper/css/swiper.css'
  52. import { getEnv, getSchool, getByFloor, getUid, getByRoom } from "../../utils/api";
  53. import {timeDate} from "../../utils";
  54. export default {
  55. name: "PigHouseEnv",
  56. components: {
  57. swiper,
  58. swiperSlide,
  59. XForm,
  60. ChartPigTemp,
  61. ChartPigHum
  62. },
  63. data() {
  64. return {
  65. swiperOption: {
  66. slidesPerView: 8,
  67. spaceBetween: 30,
  68. autoplay: {
  69. delay: 2500,
  70. disableOnInteraction: false
  71. },
  72. pagination: {
  73. el: '.swiper-pagination',
  74. type: 'progressbar'
  75. },
  76. navigation: {
  77. nextEl: '.swiper-button-next',
  78. prevEl: '.swiper-button-prev'
  79. }
  80. },
  81. list: [],
  82. formItems: [
  83. {
  84. id: 1,
  85. type: 'select',
  86. label: '栋舍:',
  87. placeholder: '请选择栋舍',
  88. field: 'floorId',
  89. options: [],
  90. col: 4
  91. },
  92. {
  93. id: 2,
  94. type: 'select',
  95. label: '楼层:',
  96. placeholder: '请选择楼层',
  97. field: 'uid',
  98. options: [],
  99. col: 4
  100. },
  101. {
  102. id: 10,
  103. type: 'select',
  104. label: '单元:',
  105. placeholder: '请选择单元',
  106. field: 'unitId',
  107. options: [],
  108. col: 4
  109. },
  110. {
  111. id: 3,
  112. type: 'text',
  113. text: '今日',
  114. value: 1,
  115. col: 1
  116. },
  117. {
  118. id: 4,
  119. type: 'text',
  120. text: '本周',
  121. value: 2,
  122. col: 1
  123. },
  124. {
  125. id: 5,
  126. type: 'text',
  127. text: '本月',
  128. value: 3,
  129. col: 1
  130. },
  131. {
  132. id: 6,
  133. type: 'datepicker',
  134. placeholder: [],
  135. field: 'value1',
  136. col: 6
  137. },
  138. {
  139. id: 8,
  140. type: 'button',
  141. text: '查询',
  142. col: 1,
  143. click: 'search'
  144. },
  145. // {
  146. // id: 7,
  147. // type: 'button',
  148. // text: '导出数据',
  149. // col: 2,
  150. // click: 'derive'
  151. // }
  152. ],
  153. // 默认选择本周
  154. day: 2,
  155. tempList: {
  156. name: '',
  157. list: [],
  158. },
  159. humList: {
  160. name: '',
  161. list: [],
  162. },
  163. loading: true
  164. }
  165. },
  166. methods: {
  167. init() {
  168. getEnv({}).then(res => {
  169. if(res.code === 10000) {
  170. setTimeout(() => {
  171. this.list = res.data;
  172. this.loading = false;
  173. }, 1000)
  174. }
  175. })
  176. },
  177. getSchool() {
  178. getSchool({}).then(res => {
  179. if(res.code === 10000) {
  180. res.data.forEach(item => {
  181. item.value = item.id;
  182. item.label = item.floorName;
  183. })
  184. this.formItems[0].options = res.data;
  185. }
  186. })
  187. },
  188. setChange(item) {
  189. if(item.type === 'floorId') {
  190. let params = {
  191. floorId: item.data
  192. }
  193. getByFloor(params).then(res => {
  194. res.data.forEach(item => {
  195. item.value = item.uid;
  196. item.label = item.alias
  197. })
  198. this.formItems[1].options = res.data;
  199. })
  200. } else if(item.type === 'uid') {
  201. let params = {
  202. uid: item.data
  203. }
  204. getUid(params).then(res => {
  205. res.data.forEach(item => {
  206. item.value = item.id;
  207. item.label = item.roomName
  208. })
  209. this.formItems[2].options = res.data
  210. })
  211. }
  212. },
  213. setDay(data) {
  214. this.day = data;
  215. },
  216. onClickType(data) {
  217. if(data.type === 'search') {
  218. let data1 = data.data;
  219. if(data1.unitId) {
  220. let params;
  221. if(data1.value1) {
  222. params = {
  223. roomId: data1.unitId,
  224. startDate: data1.value1[0],
  225. endDate: data1.value1[1],
  226. type: 4,
  227. }
  228. } else {
  229. let end = timeDate(new Date().getTime())
  230. params = {
  231. roomId: data1.unitId,
  232. endDate: end,
  233. type: this.day
  234. }
  235. }
  236. getByRoom(params).then(res => {
  237. if(res.code === 10000) {
  238. this.tempList = {
  239. name: res.data.roomName,
  240. list: res.data.semperatures
  241. }
  242. this.humList = {
  243. name: res.data.roomName,
  244. list: res.data.humidities
  245. }
  246. }
  247. })
  248. } else {
  249. this.$message.error('请选择栋舍楼层单元查询');
  250. }
  251. }
  252. },
  253. // 默认显示
  254. getTempAndHum() {
  255. getByRoom({}).then(res => {
  256. if(res.code === 10000) {
  257. this.tempList = {
  258. name: res.data.roomName,
  259. list: res.data.semperatures
  260. }
  261. this.humList = {
  262. name: res.data.roomName,
  263. list: res.data.humidities
  264. }
  265. }
  266. })
  267. }
  268. },
  269. mounted() {
  270. this.init()
  271. this.getSchool()
  272. this.getTempAndHum()
  273. }
  274. }
  275. </script>
  276. <style scoped>
  277. .pigHouse {
  278. width: 100%;
  279. height: 100%;
  280. padding: 20px 20px 0 20px;
  281. }
  282. .swiper {
  283. width: 100%;
  284. height: 100%;
  285. }
  286. .box {
  287. width: 100%;
  288. height: 100%;
  289. border: 1px solid #ddd;
  290. box-sizing: border-box;
  291. padding: 30px 0;
  292. text-align: center;
  293. cursor: pointer;
  294. }
  295. .flex {
  296. width: 100%;
  297. height: 32px;
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. }
  302. .icon1 {
  303. width: 32px;
  304. height: 32px;
  305. background: url('../../assets/images/u3028.svg') no-repeat;
  306. display: inline-block;
  307. }
  308. .icon2 {
  309. width: 32px;
  310. height: 32px;
  311. background: url('../../assets/images/u3029.svg') no-repeat;
  312. background-size: 100% 100%;
  313. display: inline-block;
  314. }
  315. </style>