deviceTongji.vue 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. <template>
  2. <div>
  3. <el-breadcrumb separator-class="el-icon-arrow-right">
  4. <el-breadcrumb-item>测报系统</el-breadcrumb-item>
  5. <el-breadcrumb-item :to="{ path: '/index/cbd' }"
  6. >虫情测报</el-breadcrumb-item
  7. >
  8. <el-breadcrumb-item>害虫排名</el-breadcrumb-item>
  9. </el-breadcrumb>
  10. <div class="equipInfo">
  11. <div>
  12. <el-button type="success" size="mini" @click="goBackPage()"
  13. ><i class="el-icon--left el-icon-d-arrow-left"></i>返回</el-button
  14. >
  15. </div>
  16. <div class="dateBox">
  17. <DateSearch
  18. ref="timeCirculation"
  19. @dateChange="dateChange"
  20. @btnSelected="btnSelected"
  21. @timeScreen="timeScreen"
  22. ></DateSearch>
  23. </div>
  24. </div>
  25. <el-row :gutter="10">
  26. <el-col :md="24" :lg="19">
  27. <el-card class="box-card" v-loading="lineLoading">
  28. <div class="chartsSelect">
  29. <!-- <el-select
  30. v-model="pestName"
  31. @change="screenInsect()"
  32. size="mini"
  33. placeholder="请选择"
  34. >
  35. <el-option
  36. v-for="item in worms"
  37. :key="item.value"
  38. :label="item.label"
  39. :value="item.value"
  40. ></el-option>
  41. </el-select> -->
  42. </div>
  43. <div class="charts">
  44. <highcharts
  45. :options="options"
  46. v-if="ChartData.length > 0"
  47. ></highcharts>
  48. <div class="noDataClass" v-else>暂无数据</div>
  49. </div>
  50. </el-card>
  51. </el-col>
  52. <!-- 害虫排行 -->
  53. <el-col :md="24" :lg="5">
  54. <el-card v-if="isShow" v-loading="pieLoading" style="height: 442px">
  55. <div class="chartsSelect">
  56. <div style="color: #333333">害虫排名</div>
  57. <div class="deviceTongji_rankingBox">
  58. <ul class="deviceTongji_rankingBox_ul">
  59. <li class="backdropStyle">
  60. <div class="backdropStyle_box">
  61. <div class="backdropStyle_boxName">
  62. {{ plantSeniorityObj.name }}
  63. </div>
  64. <!-- <div style="font-size: 15px; margin: 3px 0 0 0; text-align: center;"> -->
  65. <div
  66. style="
  67. font-size: 15px;
  68. margin: 3px 0 0 7%;
  69. text-align: center;
  70. "
  71. >
  72. {{ plantSeniorityObj.val }}头
  73. </div>
  74. <div class="backdropStyle_boxNum">第一名</div>
  75. </div>
  76. </li>
  77. <li
  78. v-for="(item, index) in plantSeniorityArr"
  79. :key="index"
  80. class="deviceTongji_rankingBox_list"
  81. >
  82. <div class="deviceTongji_rankingBox_listNumber">
  83. {{ item.sum }}
  84. </div>
  85. <div class="deviceTongji_rankingBox_listName">
  86. {{ item.name }}
  87. </div>
  88. <div class="deviceTongji_rankingBox_listSum">
  89. {{ item.val }}头
  90. </div>
  91. </li>
  92. </ul>
  93. </div>
  94. </div>
  95. </el-card>
  96. <el-card
  97. style="
  98. height: 442px;
  99. color: #7a7373;
  100. line-height: 402px;
  101. font-size: 25px;
  102. text-align: center;
  103. "
  104. v-else
  105. >暂无数据</el-card
  106. >
  107. </el-col>
  108. </el-row>
  109. <!-- 搜索 + 导出 -->
  110. <div class="dataTableSearch">
  111. <!-- <el-button type="primary" size="mini" @click="deriveData()"
  112. >导出</el-button
  113. > -->
  114. <!-- 搜索 -->
  115. <el-autocomplete
  116. v-model="state"
  117. :fetch-suggestions="querySearchAsync"
  118. placeholder="请输入需要查看的害虫名称"
  119. @change="handleSelect"
  120. @select="handleSelect"
  121. clearable
  122. ></el-autocomplete>
  123. </div>
  124. <!-- 统计信息 -->
  125. <el-card class="box-card" style="margin: -60px 0 0 0">
  126. <el-table
  127. @cell-click="plantName"
  128. v-loading="tabLoading"
  129. :data="tableDataA"
  130. stripe
  131. style="width: 100%"
  132. >
  133. <el-table-column prop="device_id" label="设备ID"></el-table-column>
  134. <el-table-column prop="device_name" label="设备名称"></el-table-column>
  135. <el-table-column prop="pest_name" label="害虫名称(数量)">
  136. <template slot-scope="scope">
  137. <div style="width: 195px; height: 29px; cursor: pointer">
  138. <span v-for="(item, index) in scope.row.pest_name" :key="index">{{
  139. item.pest_name + "、"
  140. }}</span>
  141. </div>
  142. </template>
  143. </el-table-column>
  144. <el-table-column prop="pest_num" label="种类个数"></el-table-column>
  145. <el-table-column prop="device_addr" label="设备位置"></el-table-column>
  146. </el-table>
  147. <el-pagination
  148. v-if="tableDataA.length > 0"
  149. background
  150. layout="prev, pager, next"
  151. :total="total"
  152. :current-page="queryInfo.page"
  153. @current-change="changePage"
  154. :page-size="10"
  155. ></el-pagination>
  156. </el-card>
  157. <!-- 病虫害档案弹框 -->
  158. <el-dialog
  159. title="病虫害档案"
  160. :close-on-click-modal="false"
  161. :visible.sync="dialogFormVisible"
  162. >
  163. <ul class="expertDiagnosis_library_main_popUp">
  164. <li class="expertDiagnosis_library_main_popUp_li">
  165. <div class="expertDiagnosis_library_main_popUp_li_name">
  166. 害虫名称:
  167. </div>
  168. <div class="expertDiagnosis_library_main_popUp_li_nameVal">
  169. {{ popUpData.name }}
  170. </div>
  171. </li>
  172. <li class="expertDiagnosis_library_main_popUp_li">
  173. <div class="expertDiagnosis_library_main_popUp_li_img">
  174. 害虫图片:
  175. </div>
  176. <div class id="viewerDom" v-viewer>
  177. <img
  178. style="cursor: pointer"
  179. :src="popUpData.img_urls"
  180. @error="$imghost + errImg"
  181. alt
  182. class="expertDiagnosis_library_main_popUp_li_imgVal"
  183. />
  184. </div>
  185. </li>
  186. <li class="expertDiagnosis_library_main_popUp_li">
  187. <div class="expertDiagnosis_library_main_popUp_li_details">
  188. 详细信息:
  189. </div>
  190. <!-- <div class="expertDiagnosis_library_main_popUp_li_detailsVal">
  191. {{ popUpData.prevention }}
  192. </div> -->
  193. <div>
  194. <div
  195. v-for="(item, index) in preventio"
  196. :key="index"
  197. class="expertDiagnosis_library_main_popUp_li_detailsVal"
  198. >
  199. {{ item }}
  200. </div>
  201. </div>
  202. </li>
  203. </ul>
  204. </el-dialog>
  205. <!-- 害虫名称数量 -->
  206. <el-dialog
  207. title="害虫名称数量"
  208. width="30%"
  209. :close-on-click-modal="false"
  210. :visible.sync="dialogFormVisibleA"
  211. >
  212. <ul class="dialogFormVisibleA_ul">
  213. <li
  214. @click="plantQuery(item)"
  215. class="dialogFormVisibleA_list"
  216. v-for="(item, index) in dialogFormVisibleAList"
  217. :key="index"
  218. >
  219. {{ item.pest_name }} - {{ item.num }}个
  220. </li>
  221. </ul>
  222. </el-dialog>
  223. </div>
  224. </template>
  225. <script>
  226. import DateSearch from "@/components/DateSearch";
  227. import { arrayMax } from "highcharts";
  228. import HighCharts from "highcharts";
  229. export default {
  230. //限时数据文本的字数限时
  231. filters: {
  232. ellipsis(value) {
  233. if (!value) return "";
  234. if (value.length > 11) {
  235. return value.slice(0, 11) + "...";
  236. }
  237. return value;
  238. },
  239. },
  240. data() {
  241. return {
  242. queryInfo: {
  243. begin: "",
  244. end: "",
  245. page: 1,
  246. pageall: 1,
  247. },
  248. tableDataAllA: [], //统计
  249. tableDataAllB: [], //详细
  250. tableDataA: [],
  251. worms: [],
  252. pestName: "",
  253. lineData: [],
  254. ChartData: [],
  255. allPest: [],
  256. lineLoading: true,
  257. pieLoading: false,
  258. popUpData: {}, //虫害数据
  259. preventio: [], // 虫害详情数据数组
  260. dialogFormVisible: false,
  261. plantSeniorityArr: [], //害虫排名
  262. plantSeniorityObj: {}, //害虫排名
  263. ceshiaddtime: [],
  264. dialogFormVisibleA: false, //害虫名称数量
  265. dialogFormVisibleAList: [], // 害虫名称数量数组
  266. isShow: true,
  267. tabLoading: false, //表格
  268. total: null,
  269. timeScreenData: null, //保存一个标识,用来区分是点击还是自动获取
  270. // 搜索
  271. restaurants: [],
  272. state: "",
  273. timeout: null,
  274. };
  275. },
  276. created() {
  277. this.getPests();
  278. },
  279. mounted() {
  280. this.plantSeniority(); //害虫paiming
  281. this.tableDataAxios(); //表格
  282. this.refreshData();
  283. },
  284. computed: {
  285. options() {
  286. return {
  287. chart: {
  288. zoomType: "x",
  289. // zoomType: 'y'
  290. },
  291. title: {
  292. text: "虫情统计走势图",
  293. align: "left",
  294. },
  295. subtitle: {
  296. text: "",
  297. },
  298. xAxis: {
  299. crosshair: true, //十字基准线
  300. type: "datetime",
  301. dateTimeLabelFormats: {
  302. //根据时间间距X轴自动显示哪种格式
  303. millisecond: "%H:%M:%S",
  304. second: "%H:%M:%S",
  305. minute: "%H:%M",
  306. hour: "%H:%M",
  307. day: "%m-%d",
  308. week: "%m-%d",
  309. month: "%Y-%m",
  310. year: "%Y",
  311. },
  312. },
  313. yAxis: {
  314. title: {
  315. text: "",
  316. },
  317. },
  318. legend: {
  319. // layout: 'vertical',
  320. align: "center",
  321. verticalAlign: "top",
  322. },
  323. plotOptions: {
  324. series: {
  325. label: {
  326. connectorAllowed: false,
  327. },
  328. pointStart: 2010,
  329. },
  330. },
  331. series: this.ChartData,
  332. colors: ["#00e29d", "#6cbbff", "#ff3f3f"],
  333. credits: {
  334. //去掉默认的highcharts.com
  335. enabled: false,
  336. },
  337. tooltip: {
  338. // crosshairs: true,
  339. shared: true, //折线共享
  340. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  341. },
  342. responsive: {
  343. rules: [
  344. {
  345. condition: {
  346. maxWidth: 500,
  347. },
  348. chartOptions: {
  349. legend: {
  350. layout: "horizontal",
  351. align: "center",
  352. verticalAlign: "bottom",
  353. },
  354. },
  355. },
  356. ],
  357. },
  358. };
  359. },
  360. totalall() {
  361. return this.tableDataAllB.length;
  362. },
  363. },
  364. methods: {
  365. refreshData() {
  366. HighCharts.setOptions({
  367. lang: {
  368. resetZoom: "刷新",
  369. resetZoomTitle: "重置缩放比例",
  370. },
  371. });
  372. },
  373. //子向父传值
  374. dateChange(data) {
  375. this.queryInfo.begin = data.begin;
  376. this.queryInfo.end = data.end;
  377. this.lineLoading = true;
  378. this.pieLoading = true;
  379. this.pestName = "";
  380. this.newLineChart(); //测试折线图
  381. this.plantSeniority(); //害虫排行
  382. this.tableDataAxios(); //表格
  383. },
  384. btnSelected(data) {
  385. console.log(data);
  386. },
  387. // 当使用日期筛选
  388. timeScreen(data) {
  389. this.timeScreenData = data;
  390. },
  391. insectData(index, row) {
  392. let obj = {
  393. code: "2", //1病害 2虫害
  394. name: row.name, //害虫名称
  395. page: 1,
  396. };
  397. this.$axios({
  398. method: "post",
  399. url: "/api/api_gateway?method=pest.pests.pests_search",
  400. data: this.qs.stringify(obj),
  401. })
  402. .then((res) => {
  403. if (res.data.data.nums == 0) {
  404. //没有数据
  405. if (document.getElementsByClassName("el-message").length == 0) {
  406. this.$message({
  407. message: "暂无此虫害的信息",
  408. type: "warning",
  409. duration: 1500,
  410. });
  411. }
  412. } else if (res.data.data.data.length !== 0) {
  413. //有数据
  414. this.insectAxios(res.data.data.data[0].id);
  415. }
  416. })
  417. .catch((err) => {
  418. console.log(err);
  419. });
  420. },
  421. insectAxios(id) {
  422. console.log(id);
  423. let postData = this.qs.stringify({
  424. code: "2",
  425. page: 1,
  426. pest_id: id,
  427. });
  428. this.$axios({
  429. method: "post",
  430. url: "api/api_gateway?method=pest.pests.pests_info",
  431. data: postData,
  432. })
  433. .then((res) => {
  434. this.popUpData = res.data.data;
  435. this.dialogFormVisible = true;
  436. })
  437. .catch((err) => {
  438. console.log(err);
  439. });
  440. },
  441. changePage() {},
  442. //返回上一页
  443. goBackPage() {
  444. this.$router.go(-1);
  445. },
  446. // 获取折线和数据列表
  447. getPestAllData() {
  448. this.$axios({
  449. method: "POST",
  450. url: "/api/api_gateway?method=forecast.worm_lamp.pest_statistics_total",
  451. data: this.qs.stringify({
  452. start_time: this.queryInfo.begin,
  453. end_time: this.queryInfo.end,
  454. pest_name: this.pestName,
  455. }),
  456. }).then((res) => {
  457. if (res.data.data) {
  458. let { date, percentage, time_d_sums } = res.data.data;
  459. if (percentage.length > 0) {
  460. //害虫种类,下拉框
  461. this.worms = percentage.map((item) => {
  462. // 表格统计信息
  463. this.tableDataAllA.push({
  464. name: item.name_num,
  465. sum: item.sum,
  466. });
  467. return {
  468. value: item.name_num,
  469. label: item.name_num,
  470. };
  471. });
  472. this.tableDataA = this.tableDataAllA.slice(0, 10);
  473. this.worms.unshift({
  474. value: "",
  475. label: "全部",
  476. });
  477. }
  478. this.ChartData = [
  479. {
  480. name: "棉铃虫",
  481. dat: [],
  482. },
  483. ];
  484. // 折线图
  485. // console.log(this.ChartData);
  486. for (let i of date) {
  487. this.ChartData[0].dat.push([i.addtime * 1000, Number(i.at)]);
  488. }
  489. console.log(this.ChartData);
  490. // 表格详细信息
  491. if (time_d_sums.length > 0) {
  492. this.tableDataAllB = [];
  493. time_d_sums.forEach((i) => {
  494. let arr = i.pest.split("#");
  495. arr.forEach((j) => {
  496. let arr2 = j.split(",");
  497. let obj = {
  498. name: this.allPest[arr2[0]],
  499. sum: arr2[1],
  500. upl_time: this.formatTime(i.addtime * 1000),
  501. };
  502. this.tableDataAllB.push(obj);
  503. });
  504. });
  505. this.tableDataB = this.tableDataAllB.slice(0, 10);
  506. }
  507. this.lineLoading = false;
  508. this.pieLoading = false;
  509. }
  510. });
  511. },
  512. // screenInsect() {
  513. // this.lineLoading = true;
  514. // this.newLineChart();
  515. // this.newDropDown();
  516. // },
  517. //获取害虫种类
  518. getPests() {
  519. this.$axios({
  520. method: "POST",
  521. url: "/api/api_gateway?method=forecast.worm_lamp.worm_list",
  522. }).then((res) => {
  523. if (res.data.message == "") {
  524. this.allPest = res.data.data;
  525. this.restaurants = this.loadAll(res.data.data); // 搜索
  526. }
  527. });
  528. },
  529. changePage(e) {
  530. console.log(e);
  531. this.queryInfo.page = e;
  532. this.tableDataAxios();
  533. },
  534. // 害虫排行数据
  535. plantSeniority() {
  536. var that = this;
  537. that.tabLoading = true;
  538. let postData = that.qs.stringify({
  539. start_time: this.queryInfo.begin, //开始时间 时间戳
  540. end_time: this.queryInfo.end, //结束时间 时间戳
  541. // page: "", //页数
  542. // page_size: "", //一页默认10条数据
  543. ret: "num", // num: 害虫排名 type: 列表详情数据
  544. });
  545. that
  546. .$axios({
  547. method: "POST",
  548. url: "/api/api_gateway?method=forecast.forecast_system.cbd_pest_type_ranking",
  549. data: postData,
  550. })
  551. .then((res) => {
  552. console.log(res.data.data);
  553. // 自动获取数据
  554. if (res.data.data.length == 0 && this.timeScreenData == null) {
  555. this.$refs.timeCirculation.say();
  556. console.log("这是自动的");
  557. } else {
  558. console.log("这是点击的");
  559. }
  560. if (res.data.data.length !== 0) {
  561. var arr = [];
  562. var objA = {};
  563. for (var i = 0; i < res.data.data.length; i++) {
  564. if (i !== 0) {
  565. var obj = {};
  566. obj["name"] = Object.keys(res.data.data[i])[0];
  567. obj["val"] = res.data.data[i][obj.name];
  568. obj["sum"] = i + 1;
  569. arr.push(obj);
  570. } else {
  571. objA["name"] = Object.keys(res.data.data[i])[0];
  572. objA["val"] = res.data.data[i][objA.name];
  573. }
  574. }
  575. this.plantSeniorityArr = arr;
  576. this.plantSeniorityObj = objA;
  577. this.isShow = true;
  578. } else {
  579. this.isShow = false;
  580. }
  581. this.pieLoading = false;
  582. })
  583. .catch((err) => {
  584. console.log(err);
  585. });
  586. },
  587. // 表格
  588. tableDataAxios() {
  589. var that = this;
  590. that.tabLoading = true;
  591. let postData = that.qs.stringify({
  592. start_time: this.queryInfo.begin, //开始时间 时间戳
  593. end_time: this.queryInfo.end, //结束时间 时间戳
  594. page: this.queryInfo.page, //页数
  595. page_size: "10", //一页默认10条数据
  596. ret: "type", // num: 害虫排名 type: 列表详情数据
  597. pest_name: this.state,
  598. });
  599. that
  600. .$axios({
  601. method: "POST",
  602. url: "/api/api_gateway?method=forecast.forecast_system.cbd_pest_type_ranking",
  603. data: postData,
  604. })
  605. .then((res) => {
  606. console.log(res.data.data.cbd_photo_data);
  607. if (res.data.data.cbd_photo_data.length !== 0) {
  608. var data = res.data.data.cbd_photo_data;
  609. console.log(data);
  610. var arr = [];
  611. for (var i = 0; i < data.length; i++) {
  612. var obj = {};
  613. obj["device_addr"] =
  614. data[i].device_addr == "" ? "暂无地址" : data[i].device_addr;
  615. obj["device_id"] = data[i].device_id;
  616. obj["device_name"] = data[i].device_name;
  617. obj["pest_num"] = data[i].pest_num;
  618. obj["pest_name"] = data[i].pest_name;
  619. arr.push(obj);
  620. }
  621. this.tableDataA = arr;
  622. this.total = res.data.data.num;
  623. } else {
  624. this.tableDataA = [];
  625. }
  626. console.log(this.tableDataA);
  627. // console.log(this.tableDataA)
  628. that.tabLoading = false;
  629. })
  630. .catch((err) => {
  631. console.log(err);
  632. });
  633. },
  634. // 害虫名称事件
  635. plantName(row, column, event, cell) {
  636. console.log(row);
  637. this.dialogFormVisibleAList = row.pest_name;
  638. this.dialogFormVisibleA = true;
  639. },
  640. // 测试新折线图接口
  641. newLineChart() {
  642. var that = this;
  643. let postData = that.qs.stringify({
  644. start_time: that.queryInfo.begin, // 开始时间
  645. end_time: that.queryInfo.end, //结束时间
  646. pest_name: this.pestName, // 害虫名称
  647. ret: "day_month", //day_month: 24小时数据、近一个月数据 half_year: 半年、一年数据
  648. });
  649. that
  650. .$axios({
  651. method: "POST",
  652. url: "/api/api_gateway?method=forecast.forecast_system.cbd_pest_line_chart",
  653. data: postData,
  654. })
  655. .then((res) => {
  656. // 自动获取数据
  657. if (res.data.data.length == 0 && this.timeScreenData == null) {
  658. this.$refs.timeCirculation.say();
  659. }
  660. var date = res.data.data;
  661. var percentage = res.data.data;
  662. if (percentage.length > 0) {
  663. //害虫种类,下拉框
  664. this.worms = percentage.map((item) => {
  665. return {
  666. value: item.pest_name,
  667. label: item.pest_name,
  668. };
  669. });
  670. this.worms.unshift({
  671. value: "",
  672. label: "全部",
  673. });
  674. }
  675. // 折线图
  676. var dataList = [];
  677. var index = 0;
  678. for (let i of date.data) {
  679. var obj = {};
  680. var arr = [];
  681. obj["name"] = i.pest_name;
  682. if (date.data.length > 10) {
  683. if (
  684. index == 0 ||
  685. index == 1 ||
  686. index == 2 ||
  687. index == 3 ||
  688. index == 4
  689. ) {
  690. obj["visible"] = true;
  691. // console.log("显示");
  692. } else {
  693. // console.log("不显示");
  694. obj["visible"] = false;
  695. }
  696. }
  697. arr.push([
  698. Math.floor(new Date(i.addtime).getTime() + 8 * 60 * 60 * 1000),
  699. Number(i.pest_num),
  700. ]);
  701. obj["data"] = arr;
  702. dataList.push(obj);
  703. index++;
  704. }
  705. // 测试
  706. // 折线图
  707. var ChartData = [];
  708. var index = 0;
  709. for (let i of date.data) {
  710. var obj = {};
  711. var arr = [];
  712. obj["name"] = i.pest_name;
  713. if (date.data.length > 10) {
  714. if (
  715. index == 0 ||
  716. index == 1 ||
  717. index == 2 ||
  718. index == 3 ||
  719. index == 4
  720. ) {
  721. obj["visible"] = true;
  722. } else {
  723. obj["visible"] = false;
  724. }
  725. }
  726. arr.push([
  727. Math.floor(new Date(i.addtime).getTime() + 8 * 60 * 60 * 1000), // 毫秒
  728. Number(i.pest_num),
  729. ]);
  730. obj["data"] = arr;
  731. ChartData.push(obj);
  732. index++;
  733. }
  734. // 将name重复的数据合并
  735. this.jfList(ChartData);
  736. this.lineLoading = false;
  737. // 测试
  738. var a = [];
  739. var flag;
  740. for (let i in this.ChartData.length) {
  741. flag = true;
  742. for (var j in a) {
  743. if (a[j].label == this.ChartData[i]) {
  744. flag = false;
  745. break;
  746. }
  747. }
  748. if (flag) {
  749. var obj = { name: this.ChartData[i].visible };
  750. }
  751. }
  752. console.log(a);
  753. })
  754. .catch((err) => {
  755. console.log(err);
  756. });
  757. },
  758. // 新下拉框接口
  759. newDropDown() {
  760. var that = this;
  761. let postData = that.qs.stringify({
  762. start_time: that.queryInfo.begin, // 开始时间
  763. end_time: that.queryInfo.end, //结束时间
  764. pest_name: this.pestName, // 害虫名称
  765. ret: "day_month", //day_month: 24小时数据、近一个月数据 half_year: 半年、一年数据
  766. });
  767. that
  768. .$axios({
  769. method: "POST",
  770. url: "/api/api_gateway?method=forecast.forecast_system.cbd_pest_line_chart",
  771. data: postData,
  772. })
  773. .then((res) => {
  774. if (res.data.data.length !== 0) {
  775. var date = res.data.data;
  776. var percentage = res.data.data;
  777. if (percentage.length > 0) {
  778. //害虫种类,下拉框
  779. this.worms = percentage.map((item) => {
  780. return {
  781. value: item.pest_name,
  782. label: item.pest_name,
  783. };
  784. });
  785. this.worms.unshift({
  786. value: "",
  787. label: "全部",
  788. });
  789. }
  790. }
  791. })
  792. .catch((err) => {
  793. console.log(err);
  794. });
  795. },
  796. // 点击查询害虫信息 - name搜索
  797. plantQuery(data) {
  798. console.log(data.pest_name);
  799. var that = this;
  800. // 先使用害虫名称进行搜索获取到虫害ID
  801. let postData = that.qs.stringify({
  802. code: "2", // 病虫害区别 1:病害 2:虫害
  803. name: data.pest_name, // 病虫害名字 如果传name代表搜索 如果不穿name代表搜索列表
  804. page: 1, //页数
  805. });
  806. that
  807. .$axios({
  808. method: "POST",
  809. url: "/api/api_gateway?method=pest.pests.pests_search",
  810. data: postData,
  811. })
  812. .then((res) => {
  813. if (
  814. res.data.data.data !== undefined &&
  815. res.data.data.data.length != 0
  816. ) {
  817. console.log(res.data.data.data[0].id);
  818. that.seekPlantId(res.data.data.data[0].id);
  819. } else {
  820. if (document.getElementsByClassName("el-message").length == 0) {
  821. this.$message({
  822. message: "没有查询到该害虫的相关详情",
  823. type: "error",
  824. duration: 1500,
  825. });
  826. }
  827. }
  828. })
  829. .catch((err) => {
  830. console.log(err);
  831. });
  832. },
  833. // 点击查询害虫信息 - id搜索
  834. seekPlantId(id) {
  835. var that = this;
  836. let postData = that.qs.stringify({
  837. pest_id: id, //病虫害id
  838. });
  839. that
  840. .$axios({
  841. method: "POST",
  842. url: "/api/api_gateway?method=pest.pests.pests_info",
  843. data: postData,
  844. })
  845. .then((res) => {
  846. console.log(res.data);
  847. var data = res.data.data;
  848. that.popUpData = data;
  849. let Adata = data.prevention;
  850. var a = Adata.replace(/]/g, ":");
  851. let Bdata = new Array();
  852. Bdata = a.split("[");
  853. that.preventio = Bdata;
  854. that.dialogFormVisible = true;
  855. })
  856. .catch((err) => {
  857. console.log(err);
  858. });
  859. },
  860. // 测试
  861. jfList(data) {
  862. var listArr = [];
  863. data.forEach(function (el, index) {
  864. for (var i = 0; i < listArr.length; i++) {
  865. // 对比相同的字段key,相同放入对应的数组
  866. if (listArr[i].name == el.name && el.data !== undefined) {
  867. listArr[i].data.push(el.data[0]);
  868. if (i == 0 || i == 1 || i == 2 || i == 3 || i == 4) {
  869. listArr[i].visible = true;
  870. } else {
  871. // listArr[i].visible = el.visible;
  872. listArr[i].visible = false;
  873. }
  874. return;
  875. }
  876. }
  877. // 第一次对比没有参照,放入参照
  878. listArr.push({
  879. name: el.name,
  880. data: el.data,
  881. visible: el.visible,
  882. });
  883. });
  884. console.log("处理后。。。", listArr);
  885. this.ChartData = listArr;
  886. },
  887. // 搜索
  888. loadAll(data) {
  889. var list = [];
  890. for (var i in data) {
  891. list.push({
  892. value: data[i],
  893. label: data[i],
  894. });
  895. }
  896. return list;
  897. },
  898. querySearchAsync(queryString, cb) {
  899. var restaurants = this.restaurants;
  900. var results = queryString
  901. ? restaurants.filter(this.createStateFilter(queryString))
  902. : restaurants;
  903. clearTimeout(this.timeout);
  904. this.timeout = setTimeout(() => {
  905. cb(results);
  906. }, 3000 * Math.random());
  907. },
  908. createStateFilter(queryString) {
  909. return (state) => {
  910. return (
  911. state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
  912. );
  913. };
  914. },
  915. handleSelect(item) {
  916. this.tableDataAxios();
  917. },
  918. },
  919. components: {
  920. DateSearch,
  921. },
  922. };
  923. </script>
  924. <style lang='less' scoped>
  925. .equipInfo {
  926. .equipMsg {
  927. font-size: 14px;
  928. color: #3d3d3d;
  929. span {
  930. margin-left: 5px;
  931. }
  932. }
  933. .dateBox {
  934. display: flex;
  935. }
  936. display: flex;
  937. justify-content: space-between;
  938. margin-top: 10px;
  939. margin-bottom: 10px;
  940. }
  941. .dataTableSearch {
  942. display: flex;
  943. justify-content: space-between;
  944. margin: 20px 0 80px 0;
  945. .el-input__inner {
  946. width: 222px;
  947. }
  948. }
  949. .box-card {
  950. position: relative;
  951. .chartsSelect {
  952. text-align: right;
  953. position: absolute;
  954. z-index: 999;
  955. left: 0;
  956. right: 21px;
  957. }
  958. }
  959. // 弹框
  960. .expertDiagnosis_library_main_popUp {
  961. .expertDiagnosis_library_main_popUp_li {
  962. display: flex;
  963. margin: 0 0 30px 0;
  964. // 害虫名称
  965. .expertDiagnosis_library_main_popUp_li_name {
  966. color: #000;
  967. font-size: 16px;
  968. font-weight: 550;
  969. }
  970. .expertDiagnosis_library_main_popUp_li_nameVal {
  971. font-weight: 550;
  972. }
  973. // 害虫图片
  974. .expertDiagnosis_library_main_popUp_li_img {
  975. font-size: 16px;
  976. font-weight: 550;
  977. color: #000;
  978. }
  979. .expertDiagnosis_library_main_popUp_li_imgVal {
  980. width: 160px;
  981. height: 160px;
  982. border-radius: 10px;
  983. }
  984. // 详细信息
  985. .expertDiagnosis_library_main_popUp_li_details {
  986. // width: 188px;
  987. width: 80px;
  988. font-size: 16px;
  989. font-weight: 550;
  990. color: #000;
  991. }
  992. .expertDiagnosis_library_main_popUp_li_detailsVal {
  993. line-height: 30px;
  994. font-weight: 550;
  995. width: 800px;
  996. text-align: left;
  997. }
  998. }
  999. }
  1000. // 害虫排名
  1001. .deviceTongji_rankingBox {
  1002. // border: 1px solid #000;
  1003. margin: 0 auto;
  1004. .deviceTongji_rankingBox_ul {
  1005. .deviceTongji_rankingBox_list {
  1006. margin: 25px auto;
  1007. display: flex;
  1008. width: 80%;
  1009. justify-content: space-between;
  1010. font-size: 13px;
  1011. .deviceTongji_rankingBox_listNumber {
  1012. color: #333333;
  1013. }
  1014. .deviceTongji_rankingBox_listName {
  1015. color: #333333;
  1016. }
  1017. .deviceTongji_rankingBox_listSum {
  1018. color: #59da97;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. .backdropStyle {
  1024. background: url(../../../../static/images/deviceTongji/1.png) no-repeat;
  1025. position: relative;
  1026. background-size: 45% 100%;
  1027. background-position: center top;
  1028. background-repeat: no-repeat;
  1029. height: 135px;
  1030. }
  1031. .backdropStyle_box {
  1032. position: absolute;
  1033. // top: 45px;
  1034. // left: 121px;
  1035. top: 35px;
  1036. // left: 41%;
  1037. left: 34%;
  1038. color: #fff;
  1039. width: 30%;
  1040. }
  1041. .backdropStyle_boxName {
  1042. // font-size: 20px;
  1043. font-size: 17px;
  1044. // margin: 0 0 0 -6px;
  1045. // margin: 0 0 0 6%;
  1046. text-align: center;
  1047. }
  1048. .backdropStyle_boxNum {
  1049. font-size: 12px;
  1050. margin: 2px 0 0 8px;
  1051. text-align: center;
  1052. }
  1053. // 暂无数据
  1054. .noDataClass {
  1055. text-align: center;
  1056. font-size: 25px;
  1057. line-height: 402px;
  1058. color: rgb(122, 115, 115);
  1059. }
  1060. // 害虫名称数量
  1061. .dialogFormVisibleA_ul {
  1062. display: flex;
  1063. flex-flow: wrap;
  1064. // justify-content: space-between;
  1065. .dialogFormVisibleA_list {
  1066. border: 1px solid #c4c8d0;
  1067. padding: 10px 15px;
  1068. margin: 5px 0 5px 15px;
  1069. border-radius: 5px;
  1070. cursor: pointer;
  1071. }
  1072. }
  1073. // 表格文字居中
  1074. /deep/.el-table th > .cell {
  1075. text-align: center;
  1076. }
  1077. /deep/.el-table .cell {
  1078. text-align: center;
  1079. }
  1080. </style>