Detail.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <div class="Detail">
  3. <header class="header">
  4. <el-page-header @back="goBack" content="产床信息" />
  5. <el-row type="flex" align="middle">
  6. <el-col :span="8" style="text-align:right;">
  7. <h2 class="title" style="color:#444">{{ $route.query.roomNum }}</h2>
  8. </el-col>
  9. <el-col :span="6" style="text-align:right;">
  10. <div>
  11. <!-- <el-date-picker
  12. v-model="date"
  13. @change="pickerChange"
  14. type="date"
  15. placeholder="选择日期"
  16. ></el-date-picker>-->
  17. </div>
  18. </el-col>
  19. <el-col :span="2" style="text-align:right;">
  20. <!-- <el-link type="primary" @click="toSowDetail">查看母猪信息</el-link> -->
  21. </el-col>
  22. </el-row>
  23. </header>
  24. <section class="section">
  25. <article class="video">
  26. <!-- <div>母猪情况【母猪耳标、上床时间、预计产仔】【断奶时间】</div> -->
  27. <div class="mainInfo" v-if="bed">
  28. <ul>
  29. <li>
  30. <span class="titel">母猪耳标:</span>
  31. <el-link
  32. class="content"
  33. type="primary"
  34. v-if="bed"
  35. @click="isShow=true"
  36. style="font-size: 25px"
  37. >{{bed.litter.mother.earTagNo}}</el-link>
  38. </li>
  39. <li>
  40. <span class="titel">状态:</span>
  41. <span
  42. class="content"
  43. style="font-size:20px"
  44. >{{ bed.status==2?"上床":bed.status==3?"分娩":bed.status==4?"断奶":"" }}</span>
  45. </li>
  46. <li v-if="bed.status == 2">
  47. <span class="titel">上床时间:</span>
  48. <span class="content">{{ bed.created }}</span>
  49. </li>
  50. <li v-if="bed.status == 2">
  51. <span class="titel">预计产仔:</span>
  52. <span class="content">{{ bed.litter.dueDate }}</span>
  53. </li>
  54. <li v-if="bed.status == 3">
  55. <span class="titel">产子时间:</span>
  56. <span class="content">{{ bed.litter.deliverTime }}</span>
  57. </li>
  58. <li v-if="bed.status == 4">
  59. <span class="titel">断奶时间:</span>
  60. <span class="content">{{ bed.litter.weaningTime }}</span>
  61. </li>
  62. </ul>
  63. </div>
  64. <!-- <div>
  65. <ul>99</ul>
  66. </div>-->
  67. </article>
  68. <article class="pigletInfo" v-if="bed && bed.status!=2">
  69. <h3 class="title">
  70. <span>猪仔情况</span>
  71. <span>生产时间:{{ bed.litter.deliverTime }}</span>
  72. </h3>
  73. <div class="content">
  74. <el-progress
  75. type="circle"
  76. :percentage="100"
  77. :stroke-width="22"
  78. :format="format.f1"
  79. :width="200"
  80. ></el-progress>
  81. <el-progress
  82. type="circle"
  83. :percentage="100"
  84. :stroke-width="22"
  85. :format="format.f2"
  86. color="#6AD288"
  87. :width="200"
  88. ></el-progress>
  89. <el-progress
  90. type="circle"
  91. :percentage="100"
  92. :stroke-width="22"
  93. :format="format.f3"
  94. color="#FCDA56"
  95. :width="200"
  96. ></el-progress>
  97. <el-progress
  98. v-if="bed.status < 4"
  99. type="circle"
  100. :percentage="100"
  101. :stroke-width="22"
  102. :format="format.f4"
  103. color="#FF2727"
  104. :width="200"
  105. ></el-progress>
  106. <el-progress
  107. type="circle"
  108. :percentage="90"
  109. :stroke-width="22"
  110. :format="format.f5"
  111. color="#FCDA56"
  112. :width="200"
  113. ></el-progress>
  114. </div>
  115. </article>
  116. <article class="carousel">
  117. <div class="contianer" v-if="img1" style="height:480px;width:700px; overflow: hidden;">
  118. <!-- <el-carousel height="480px" indicator-position="none" :interval="300000">
  119. <el-carousel-item v-for="(item, index) in empty[0]" :key="index">
  120. <img :src="item" style="width:100%" />
  121. </el-carousel-item>
  122. </el-carousel>-->
  123. <img :src="img1" style="width:700px" />
  124. </div>
  125. <div class="contianer" v-if="img2" style="height:480px;700px; overflow: hidden;">
  126. <!-- <el-carousel height="480px" indicator-position="none" :interval="300000">
  127. <el-carousel-item v-for="(item, index) in empty[1]" :key="index">
  128. <img :src="item" style="width:100%" />
  129. </el-carousel-item>
  130. </el-carousel>-->
  131. <img :src="img2" style="width:700px;" />
  132. </div>
  133. </article>
  134. <article class="charts">
  135. <div>
  136. <!-- <E-Con-T :dataArr="containerT" :timeArr="containertime"></E-Con-T> -->
  137. <E-Con-T :dataArr="envTemp" :timeArr="time"></E-Con-T>
  138. </div>
  139. <div>
  140. <E-Sow-T :dataArr="animalTemp" :timeArr="time"></E-Sow-T>
  141. </div>
  142. <div>
  143. <E-Env-T :dataArr="envTemp" :timeArr="time"></E-Env-T>
  144. </div>
  145. <div>
  146. <E-Ele-T :dataArr="battery" :timeArr="time"></E-Ele-T>
  147. </div>
  148. </article>
  149. </section>
  150. <el-dialog title="母猪信息" :visible.sync="isShow" width="40%">
  151. <ul class="dialog">
  152. <li class="cell">
  153. <span>入场时间:</span>
  154. <span>2020-08-19</span>
  155. </li>
  156. <li class="cell">
  157. <span>品种:</span>
  158. <span>大白</span>
  159. </li>
  160. <li class="cell">
  161. <span>当前状态:</span>
  162. <span>怀孕</span>
  163. </li>
  164. <li class="cell">
  165. <span>窝均活仔:</span>
  166. <span>11头</span>
  167. </li>
  168. <li class="cell">
  169. <span>配种胎次:</span>
  170. <span>1次</span>
  171. </li>
  172. <li class="cell">
  173. <span>日龄:</span>
  174. <span>395天</span>
  175. </li>
  176. <li class="cell">
  177. <span>窝均断奶:</span>
  178. <span>10头</span>
  179. </li>
  180. </ul>
  181. <h3 class="hr">分娩情况</h3>
  182. <article class="dialog_article">
  183. <el-steps direction="vertical" :active="active" finish-status="success">
  184. <el-step title="断奶">
  185. <template v-slot:description>
  186. <span class="description">2020-08-08 断奶头数:14头 断奶窝重109.80kg</span>
  187. </template>
  188. </el-step>
  189. <el-step title="分娩">
  190. <template v-slot:description>
  191. <span class="description">总仔:14 健:14 弱:0 活:14 木:0 死:0</span>
  192. </template>
  193. </el-step>
  194. <el-step title="妊检" description="妊检结果:阳性">
  195. <template v-slot:description>
  196. <span class="description">妊检结果:阳性</span>
  197. </template>
  198. </el-step>
  199. <el-step title="配种">
  200. <template v-slot:description>
  201. <span
  202. class="description"
  203. >配种天数:115 配种公猪:27003 配种时间:2020-04-25 预产期:2020-07-17 配种方式:人工授精</span>
  204. </template>
  205. </el-step>
  206. </el-steps>
  207. </article>
  208. </el-dialog>
  209. </div>
  210. </template>
  211. <script>
  212. import EConT from "./charts/EConT";
  213. import EEleT from "./charts/EEleT";
  214. import EEnvT from "./charts/EEnvT";
  215. import ESowT from "./charts/ESowT";
  216. import {
  217. reqBedInfo,
  218. reqPiggyData,
  219. reqEarTagTemp
  220. } from "@/api/deliveryRoomManagement.js";
  221. import { fabric } from "fabric";
  222. // 时间选择器配置
  223. const pickerOptions = {
  224. // 禁用时间
  225. disabledDate(time) {
  226. return time.getTime() > Date.now();
  227. },
  228. shortcuts: [
  229. {
  230. text: "今天",
  231. onClick(picker) {
  232. picker.$emit("pick", new Date());
  233. }
  234. },
  235. {
  236. text: "昨天",
  237. onClick(picker) {
  238. const date = new Date();
  239. date.setTime(date.getTime() - 3600 * 1000 * 24);
  240. picker.$emit("pick", date);
  241. }
  242. },
  243. {
  244. text: "前天",
  245. onClick(picker) {
  246. const date = new Date();
  247. date.setTime(date.getTime() - 3600 * 1000 * 24 * 2);
  248. picker.$emit("pick", date);
  249. }
  250. }
  251. ]
  252. };
  253. export default {
  254. name: "Detail",
  255. components: {
  256. EConT,
  257. EEleT,
  258. EEnvT,
  259. ESowT
  260. },
  261. data() {
  262. return {
  263. active: 3,
  264. bed: null,
  265. date: "",
  266. format: {
  267. f1: percentage => {
  268. return `产仔数:${this.bed.litter.deliverNumber}`;
  269. },
  270. f2: percentage => {
  271. return `活仔数:${this.bed.litter.deliverNumber}`;
  272. },
  273. f3: percentage => {
  274. return `存活率:${percentage}%`;
  275. },
  276. f4: percentage => {
  277. return `预计断奶剩余天数:${30}`;
  278. },
  279. f5: percentage => {
  280. return `仔猪日龄:${30}`;
  281. }
  282. },
  283. empty: [[], []],
  284. img1: null,
  285. img2: null,
  286. isShow: false,
  287. containerT: [],
  288. containertime: [],
  289. time: [],
  290. envTemp: [],
  291. animalTemp: [],
  292. battery: [],
  293. piggyData: null,
  294. imgData: null,
  295. timer: null
  296. };
  297. },
  298. created() {
  299. //this.$route.query.id bed.litter.mother.earTagNo
  300. this.getDeliveryTable(this.$route.query.code);
  301. this.timer = setInterval(() => {
  302. //this.getPiggyData(this.bed.deviceId, this.bed.deviceCh);
  303. this.getDeliveryTable(this.$route.query.code);
  304. }, 1000 * 30);
  305. },
  306. beforeDestroy() {
  307. clearInterval(this.timer)
  308. },
  309. methods: {
  310. getDeliveryTable(code) {
  311. let data = { code };
  312. reqBedInfo(data)
  313. .then(res => {
  314. this.bed = res;
  315. // 获取耳标温度
  316. this.getEarTagTemp();
  317. //加载分析系统 设备数据
  318. if (this.bed.deviceId && this.bed.deviceCh >= 0)
  319. this.getPiggyData(this.bed.deviceId, this.bed.deviceCh);
  320. })
  321. .catch(err => {
  322. console.error(err);
  323. });
  324. },
  325. // 获取耳标温度
  326. getEarTagTemp() {
  327. reqEarTagTemp({
  328. deviceId: this.bed.litter.mother.earTagId,
  329. start: new Date().getTime() - 3600 * 1000,
  330. end: new Date().getTime()
  331. })
  332. .then(res => {
  333. this.time = [];
  334. this.envTemp = [];
  335. this.animalTemp = [];
  336. this.battery = [];
  337. res.content.forEach(item => {
  338. this.time.push(item.time);
  339. this.envTemp.push(item.envTemp);
  340. this.animalTemp.push(item.animalTemp);
  341. this.battery.push(item.battery * 100);
  342. });
  343. this.time.reverse()
  344. this.envTemp.reverse()
  345. this.animalTemp.reverse()
  346. this.battery.reverse()
  347. })
  348. .catch(err => {
  349. console.error(err);
  350. });
  351. },
  352. getPiggyData(deviceId, ch) {
  353. let end = new Date().getTime();
  354. let start = end - 36000000; //向前一个小时
  355. let data = { deviceId, ch, start, end };
  356. reqPiggyData(data)
  357. .then(res => {
  358. this.piggyData = res.content;
  359. if (this.piggyData.length > 0) {
  360. this.containerT = [];
  361. this.containertime = [];
  362. //加载一张图片
  363. this.loadImage(this.piggyData[0]);
  364. for (let i = 0; i < this.piggyData.length; i++) {
  365. // this.loadImage(this.piggyData[i], i);
  366. //
  367. this.containerT.push(this.piggyData[i].temp);
  368. this.containertime.push(
  369. this.piggyData[i].created
  370. );
  371. }
  372. this.containerT.reverse()
  373. this.containertime.reverse()
  374. }
  375. })
  376. .catch(err => {
  377. console.error(err);
  378. });
  379. },
  380. loadImage(piggydata) {
  381. //每个有两个图片
  382. let file1 = piggydata.file1;
  383. let ai1 = JSON.parse(piggydata.aiData1);
  384. this.drawImage(file1, ai1, 1);
  385. let file2 = piggydata.file2;
  386. let ai2 = JSON.parse(piggydata.aiData2);
  387. this.drawImage(file2, ai2, 2);
  388. },
  389. drawImage(file, ai, x) {
  390. //x一维,y二维
  391. let canvas = new fabric.Canvas(file);
  392. canvas.clear();
  393. let img = document.createElement("img");
  394. img.onload = () => {
  395. canvas.setWidth(img.width);
  396. canvas.setHeight(img.height);
  397. let ci = new fabric.Image(img);
  398. canvas.insertAt(ci, 0);
  399. //画画
  400. if (ai.result === "success") {
  401. for (let i = 0; i < ai.piggy.length; i++) {
  402. let o = ai.piggy[i];
  403. canvas.insertAt(
  404. new fabric.Circle({
  405. left: o.point[0] - 5,
  406. top: o.point[1] - 5,
  407. radius: 10,
  408. fill: "red"
  409. }),
  410. i + 1
  411. ); //0被图片占了
  412. }
  413. }
  414. let tmp = canvas.toDataURL("image/png");
  415. if (x === 1) this.$set(this, "img1", tmp);
  416. else this.$set(this, "img2", tmp);
  417. // this.empty[x][y] = tmp;
  418. this.$forceUpdate();
  419. };
  420. img.crossOrigin = "Anonymous";
  421. img.src = "http://115.238.57.190:8888/uploads/" + file;
  422. // console.log("http://115.238.57.190:8888/uploads/"+file)
  423. },
  424. // 请求厂房列表
  425. getDeliveryRoomInfo(data) {
  426. reqDeliveryRoomInfo(data)
  427. .then(res => {
  428. this.images = res.value.images;
  429. this.value = res.value;
  430. this.hoursD = [];
  431. this.hoursT = [];
  432. this.daysD = [];
  433. this.daysT = [];
  434. res.value.thours.reverse().forEach(item => {
  435. this.hoursD.push(item.temperature.toFixed(2));
  436. this.hoursT.push(item.timestamp.substr(0, 14) + "时");
  437. });
  438. res.value.tdays.reverse().forEach(item => {
  439. this.daysD.push(item.temperature.toFixed(2));
  440. this.daysT.push(item.timestamp.substr(0, 10));
  441. });
  442. })
  443. .catch(err => {
  444. console.error(err);
  445. });
  446. },
  447. // 拿到图片数组
  448. getImglist() {
  449. reqImglist()
  450. .then(res => {
  451. this.empty.a = res;
  452. })
  453. .catch(err => {
  454. console.error(err);
  455. });
  456. },
  457. pickerChange(value) {
  458. console.log(value);
  459. },
  460. toSowDetail() {
  461. console.log("查看母猪信息");
  462. },
  463. goBack() {
  464. this.$router.go(-1);
  465. }
  466. }
  467. };
  468. </script>
  469. <style lang="scss" scoped>
  470. .Detail {
  471. .section {
  472. .video {
  473. margin: 30px;
  474. .mainInfo {
  475. font-size: 17px;
  476. > ul {
  477. background-color: #eee;
  478. border-radius: 10px;
  479. padding: 15px;
  480. > li {
  481. margin: 5px 15px;
  482. > .titel {
  483. font-weight: 600;
  484. color: #444;
  485. }
  486. > .content {
  487. font-size: 16px;
  488. }
  489. }
  490. }
  491. }
  492. }
  493. .pigletInfo {
  494. padding: 0 200px 40px 100px;
  495. .title {
  496. display: flex;
  497. justify-content: space-between;
  498. margin: 0 0 30px 0;
  499. color: #444;
  500. }
  501. .content {
  502. display: flex;
  503. justify-content: space-around;
  504. }
  505. }
  506. .carousel {
  507. display: flex;
  508. justify-content: space-around;
  509. margin: 30px;
  510. > div {
  511. width: 700px;
  512. height: 500px;
  513. // border: 1px solid #00f;
  514. }
  515. }
  516. .charts {
  517. > div {
  518. margin: 60px;
  519. }
  520. }
  521. }
  522. }
  523. .dialog {
  524. display: flex;
  525. flex-wrap: wrap;
  526. font-size: 18px;
  527. padding: 25px;
  528. .cell {
  529. width: 45%;
  530. margin: 4px;
  531. }
  532. }
  533. .hr {
  534. margin: 25px;
  535. }
  536. .dialog_article {
  537. height: 300px;
  538. margin: 20px;
  539. .description {
  540. font-size: 17px;
  541. }
  542. }
  543. // border: 1px solid #00f;
  544. </style>