cbd_manual_pest_data.html 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. {% load staticfiles %}
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8" />
  6. <link href="{% static '/lib/bootstrap-3.3.7/css/bootstrap.css' %}" rel="stylesheet">
  7. <link rel="stylesheet" href="{% static '/lib/font-awesome/4.5.0/css/font-awesome.css' %}">
  8. <link rel="stylesheet" href="{% static '/lib/css/ace.min.css' %}" />
  9. <link rel="stylesheet" href="{% static '/lib/css/ace-skins.min.css' %}">
  10. <link rel="stylesheet" href="{% static '/lib/css/ace-rtl.min.css' %}">
  11. <link rel="stylesheet" href="{% static '/lib/layui/css/layui.css' %}">
  12. <link rel="stylesheet" href="{% static '/css/loading.css' %}?versions=0.5.0" />
  13. <style type="text/css">
  14. body {
  15. overflow: hidden;
  16. background: #fff;
  17. }
  18. /* 返回 */
  19. .headerPlace {
  20. font-size: 22px;
  21. color: #418fbb;
  22. cursor: pointer;
  23. }
  24. .headerPlace img {
  25. vertical-align: middle;
  26. margin-right: 10px;
  27. margin-top: -4px;
  28. }
  29. /* table th {
  30. white-space: nowrap;
  31. }
  32. table td {
  33. white-space: nowrap;
  34. }
  35. .form-group {
  36. display: inline-block;
  37. }
  38. #distpicker5 {
  39. display: inline-block;
  40. }
  41. .unusual-title,
  42. .enter-form {
  43. margin: 6px 0;
  44. }
  45. .form-group {
  46. display: inline-block;
  47. margin-top: 6px;
  48. }
  49. .sx-title {
  50. margin-left: 20px;
  51. }
  52. .btn-shaixuan {
  53. margin-left: 40px;
  54. }
  55. .fl {
  56. float: left;
  57. }
  58. .fr {
  59. float: right;
  60. }
  61. .clearfix:after {
  62. content: "";
  63. display: block;
  64. clear: both;
  65. height: 0;
  66. visibility: hidden;
  67. }
  68. .clearfix {
  69. *zoom: 1;
  70. }
  71. .container-wrap {
  72. margin: 30px 0;
  73. }
  74. .container-cartogram>div {
  75. width: 100%;
  76. margin: 0 10px;
  77. height: 300px;
  78. text-align: center;
  79. line-height: 300px;
  80. font-size: 22px;
  81. color: #8a8a8a;
  82. position: relative;
  83. }
  84. .container-cartogram>div>div {
  85. width: 100%;
  86. height: 100%;
  87. }
  88. .container-cartogram>div>.hint {
  89. width: 100%;
  90. height: 100%;
  91. position: absolute;
  92. }
  93. .widget-content {
  94. overflow-x: scroll;
  95. padding-top: 0;
  96. }
  97. .searchBox {
  98. text-align: right;
  99. margin-right: 100px;
  100. margin-bottom: 30px;
  101. }
  102. #searchBtn {
  103. margin-bottom: 10px;
  104. margin-left: 10px;
  105. } */
  106. body {
  107. overflow: hidden;
  108. background: #fff;
  109. }
  110. .searchCover {
  111. margin: 20px 0;
  112. }
  113. .peatdata {
  114. padding: 0 1px 0 0;
  115. min-width: 750px;
  116. overflow-x: scroll;
  117. }
  118. .table,
  119. .table.table-striped>thead>tr>th {
  120. text-align: center;
  121. }
  122. table td {
  123. vertical-align: middle !important;
  124. }
  125. .nullData {
  126. width: 100%;
  127. height: 500px;
  128. background: #ddd;
  129. text-align: center;
  130. line-height: 500px;
  131. font-size: 20px;
  132. border: 1px solid #ddd;
  133. }
  134. .container-wrap {
  135. margin: 30px 0;
  136. }
  137. .container-cartogram>div {
  138. width: 100%;
  139. margin: 0 10px;
  140. height: 300px;
  141. text-align: center;
  142. line-height: 300px;
  143. font-size: 22px;
  144. color: #8a8a8a;
  145. position: relative;
  146. }
  147. .container-cartogram>div>div {
  148. width: 100%;
  149. height: 100%;
  150. }
  151. .container-cartogram>div>.hint {
  152. width: 100%;
  153. height: 100%;
  154. position: absolute;
  155. }
  156. .fl {
  157. float: left;
  158. }
  159. .fr {
  160. float: right;
  161. }
  162. .clearfix:after {
  163. content: "";
  164. display: block;
  165. clear: both;
  166. height: 0;
  167. visibility: hidden;
  168. }
  169. .clearfix {
  170. *zoom: 1;
  171. }
  172. #wormType {
  173. min-width: 150px;
  174. }
  175. .timeStage {
  176. display: none;
  177. }
  178. .downTitle {
  179. text-align: right;
  180. line-height: 27px;
  181. padding-left: 0;
  182. margin-bottom: 5px;
  183. }
  184. .downContent {
  185. padding-left: 0;
  186. margin-bottom: 5px;
  187. }
  188. .title{
  189. font-size: 20px;
  190. border-left: 5px solid #438eb9;
  191. padding-left: 12px;
  192. color: #438eb9;
  193. font-weight: 700;
  194. }
  195. .manualBtn{
  196. float: right;
  197. }
  198. .layui-input{
  199. height: 30px;
  200. }
  201. /* 设备信息 */
  202. .userinfo{
  203. margin: 20px 0;
  204. font-size: 14px;
  205. }
  206. .userinfo .fa {
  207. font-size: 18px;
  208. color: #26b3ff;
  209. margin: 0px 5px;
  210. }
  211. </style>
  212. </head>
  213. <body>
  214. <div class="content">
  215. <div class="page-header">
  216. <span class="headerPlace" onclick="goback('cbd_report')">
  217. <img src="{% static '/img/gobackIcon.png' %}" alt="">返回
  218. </span>
  219. </div>
  220. <div class="userinfo">
  221. <div class=" ">
  222. <i class="fa fa-user-o" aria-hidden="true"></i>
  223. 设备ID:
  224. <span class="userinfoTitle">{{ e_id }}</span>
  225. </div>
  226. </div>
  227. <div>
  228. <div class="title">
  229. 手动害虫统计
  230. </div>
  231. {% if disc == "0" %}{% else %}
  232. <!-- <button type="button" onclick="openPage('pest_statis','{{ e_id }}')" class="btn btn-sm btn-primary manualBtn">自动害虫统计</button> -->
  233. <button type="button" onclick="openDetialPage('pest_statis?id={{ e_id }}+')" class="btn btn-sm btn-primary manualBtn">自动害虫统计</button>
  234. {% endif %}
  235. </div>
  236. <div class="searchCover">
  237. 统计图筛选条件:
  238. <input type="text" id="searchTime" autocomplete="off" style="width: 180px;">
  239. <input type="hidden" id="begin" name="begin">
  240. <input type="hidden" id="end" name="end">
  241. <button type="button" onclick="datsub_filter()" class="btn btn-sm btn-primary">筛选</button>
  242. 害虫种类:
  243. <div style="display: inline-block;width: 187px;">
  244. <form class="layui-form" action="" lay-filter="wormTypeForm">
  245. <select name="wormType" id="wormType" lay-verify="" lay-filter="wormType" lay-search>
  246. <option value="">暂无害虫种类</option>
  247. </select>
  248. </form>
  249. </div>
  250. </div>
  251. <div class="container-wrap">
  252. <div>
  253. </div>
  254. <div class="container-cartogram clearfix">
  255. <div class="echartsBox fl" style="width:63%">
  256. <div class="hint"></div>
  257. <div class="fl" id="line-chart"></div>
  258. </div>
  259. <div class="echartsBox fl" style="width:30%">
  260. <div class="hint"></div>
  261. <div class="fl" id="pie-chart"></div>
  262. </div>
  263. </div>
  264. <div>
  265. <input id="imei" type="hidden" type="text" value={{ e_id }}>
  266. </div>
  267. </div>
  268. <div class="searchCover">
  269. 统计图筛选条件:
  270. <input type="text" id="tableSearchTime" autocomplete="off" style="width: 180px;">
  271. <input type="hidden" id="tableBegin" name="begin">
  272. <input type="hidden" id="tableEnd" name="end"> 种类查找:
  273. <div style="display: inline-block;width: 187px;">
  274. <form class="layui-form" action="" lay-filter="demoForm">
  275. <select name="pestCategory" id="pestCategory" lay-verify="" lay-search>
  276. <option value="">害虫种类为空</option>
  277. </select>
  278. </form>
  279. </div>
  280. <button type="button" onclick="table_sub_filter()" class="btn btn-sm btn-primary">筛选</button>
  281. <!-- <button type="button" class="btn btn-success btn-sm" onclick="decideExport()">导出</button> -->
  282. </div>
  283. <div class="innerTable peatdata">
  284. <table id="datatable" class="table table-striped table-hover">
  285. <thead>
  286. <tr>
  287. <!-- <th>设备ID</th>
  288. <th>设备名称</th> -->
  289. <th>害虫名称</th>
  290. <th>害虫数量</th>
  291. <th>作物种类</th>
  292. <th>虫害阶段</th>
  293. <!-- <th>拍照时间</th> -->
  294. <th>统计时间</th>
  295. </tr>
  296. </thead>
  297. <tbody>
  298. {% for i in descs %}
  299. <tr>
  300. <td>{{ i.pest_name }}</td>
  301. <td>{{ i.pest_num }}</td>
  302. <td>{{ i.crop_name }}</td>
  303. <td>{{ i.pest_case }}</td>
  304. <td>{{ i.add_time }}</td>
  305. <!-- <td>
  306. <a class="fpsb-link" href="allot?uname={{ user.username }}" style="display: inline-block;">
  307. <button class="btn btn-primary btn-shaixuan">分配设备</button>
  308. </a>
  309. </td> -->
  310. </tr>
  311. {% endfor %}
  312. </tbody>
  313. </table>
  314. <div class="fenpei-bottom ">
  315. <input type="hidden" id="totalPage" value={{ nums }}>
  316. <div id="page" style="text-align: center;"></div>
  317. </div>
  318. </div>
  319. <!-- 导出提示框 -->
  320. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  321. <div class="modal-dialog" role="document">
  322. <div class="modal-content">
  323. <div class="modal-header">
  324. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  325. <span aria-hidden="true">&times;</span>
  326. </button>
  327. <h4 class="modal-title" id="myModalLabel">导出信息</h4>
  328. </div>
  329. <div class="modal-body">
  330. <div class="row">
  331. <div class="col-xs-3 downTitle">文件名称:</div>
  332. <div class="col-xs-8 downContent" style=>
  333. <input type="text" id="filename" placeholder="请输入文件的名称" maxlength="15" class="col-xs-12">
  334. </div>
  335. <div class="col-xs-3 downTitle">下载类型:</div>
  336. <div class="col-xs-8 downContent">
  337. <select name="downtype" id="downtype" onchange="downtype(this)" class="col-xs-12">
  338. <option value="1">全部</option>
  339. <option value="2">时间段</option>
  340. </select>
  341. </div>
  342. <div class="col-xs-3 downTitle timeStage">时间段:</div>
  343. <div class="col-xs-8 downContent timeStage">
  344. <input type="text" id="timSelectBox3" autocomplete="off" placeholder="请选择时间段 " class="col-xs-12">
  345. <input type="hidden" id="downbegin" name="begin">
  346. <input type="hidden" id="downend" name="end">
  347. </div>
  348. </div>
  349. </div>
  350. <div class="modal-footer">
  351. <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">取消</button>
  352. <button type="button" class="btn btn-primary btn-sm" onclick="operation()">下载</button>
  353. </div>
  354. </div>
  355. </div>
  356. </div>
  357. </div>
  358. <script src="{% static '/lib/js/jquery-2.1.4.min.js' %}"></script>
  359. <script src="{% static '/lib/layui/layui.all.js' %}"></script>
  360. <!-- 统计图 -->
  361. <script src="{% static '/lib/bootstrap-3.3.7/js/bootstrap.js' %}"></script>
  362. <script src="{% static '/js/common.js' %}?versions=0.5.0"></script>
  363. <script src="{% static '/lib/js/echarts.min.js' %}"></script>
  364. <script>
  365. $.ajaxSetup({
  366. data: { csrfmiddlewaretoken: '{{ csrf_token }}' },
  367. });
  368. function openPage(url,id) {
  369. window.location.href = url+"?id=" + id;
  370. }
  371. </script>
  372. <script>
  373. layui.use(['laydate', 'form'], function () {
  374. var laydate = layui.laydate;
  375. var form = layui.form;
  376. var _layDateMark = (new Date()).getTime();
  377. $('#searchTime').attr('lay-key', '11' + _layDateMark);
  378. $('#tableSearchTime').attr('lay-key', '22' + _layDateMark);
  379. $('#timSelectBox3').attr('lay-key', '33' + _layDateMark);
  380. //执行一个laydate实例
  381. laydate.render({
  382. elem: '#searchTime' //指定元素
  383. , type: 'date'
  384. , range: true
  385. , done: function (value, date) {
  386. var dateArray = value.split(' - ')
  387. $('#begin').val(dateArray[0]);
  388. $('#end').val(dateArray[1]);
  389. }
  390. });
  391. //执行一个laydate实例
  392. laydate.render({
  393. elem: '#tableSearchTime' //指定元素
  394. , type: 'date'
  395. , range: true
  396. , done: function (value, date) {
  397. var dateArray = value.split(' - ')
  398. $('#tableBegin').val(dateArray[0]);
  399. $('#tableEnd').val(dateArray[1]);
  400. }
  401. });
  402. //执行一个laydate实例
  403. laydate.render({
  404. elem: '#timSelectBox3' //指定元素
  405. , range: true
  406. , done: function (value, date) {
  407. var dateArray = value.split(' - ')
  408. $('#downbegin').val(dateArray[0])
  409. $('#downend').val(dateArray[1])
  410. }
  411. });
  412. });
  413. $.ajax({
  414. url: 'cbd/cbd_pest_data',
  415. type: 'post',
  416. data: {
  417. 'imei': $('#imei').val(),
  418. 'tbegin': '',
  419. 'tend': '',
  420. },
  421. beforeSend: function (XMLHttpRequest) {
  422. layui.use(['layer'], function () {
  423. var layer = layui.layer;
  424. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  425. loadingFlag= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false ,time:false});
  426. })
  427. },
  428. complete: function (XMLHttpRequest, textStatus) {
  429. layer.close(loadingFlag);
  430. },
  431. dataType: "json",
  432. success: function (data) {
  433. wormEcharts(data)
  434. }
  435. })
  436. $.ajax({
  437. url: 'cbd/cbd_pest_table_data',
  438. type: 'post',
  439. data: {
  440. imei: $('#imei').val(),
  441. page: 1
  442. },
  443. beforeSend: function (XMLHttpRequest) {
  444. layui.use(['layer'], function () {
  445. var layer = layui.layer;
  446. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  447. loadingFlag1= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  448. })
  449. },
  450. complete: function (XMLHttpRequest, textStatus) {
  451. layer.close(loadingFlag1);
  452. },
  453. dataType: "json",
  454. success: function (data) {
  455. if (data.dat.length) {
  456. var categoryArr = [];
  457. var str = '<option value="">害虫种类</option>';
  458. for (var i = 0; i < data.dat.length; i++) {
  459. if(categoryArr.indexOf(data.dat[i].pest_name) == -1 && data.dat[i].pest_name){
  460. categoryArr.push(data.dat[i].pest_name);
  461. }
  462. if(i == data.dat.length-1){
  463. console.log(categoryArr)
  464. for (var z = 0; z < categoryArr.length; z++) {
  465. str += '<option value="' + categoryArr[z] + '">' + categoryArr[z] + '</option>';
  466. if(z == categoryArr.length-1){
  467. $('#pestCategory').html(str);
  468. }
  469. }
  470. }
  471. }
  472. var form = layui.form;
  473. form.render('select');
  474. $('#page').parent().show();
  475. pestFill_Table('datatable', data.dat);
  476. } else {
  477. $('#page').parent().hide();
  478. datFill_null_Table('datatable');
  479. $('#pestCategory').html('<option value="">害虫种类为空</option>');
  480. var form = layui.form;
  481. form.render('select');
  482. }
  483. initPage(data.nums)
  484. }
  485. })
  486. function downtype(obj) {
  487. if ($(obj).val() == 2) {
  488. $('.timeStage').show();
  489. } else {
  490. $('.timeStage').hide();
  491. $('#downbegin').val('');
  492. $('#downend').val('');
  493. $('#downtimSelectBox').val('');
  494. }
  495. }
  496. // 导出提示框
  497. function decideExport() {
  498. $('#myModal').modal('toggle')
  499. }
  500. //导出
  501. function operation() {
  502. if (!$('#filename').val()) {
  503. layer.msg("请填写文件名!", { time: 2000 });
  504. return false;
  505. }
  506. if ($('#downtype').val() == 2) {
  507. if (!($('#downbegin').val() && $('#downbegin').val())) {
  508. layer.msg("请选择时间段!", { time: 2000 });
  509. return false;
  510. }
  511. }
  512. window.location.href = 'pest_export?id=' + $('#imei').val() + '&begin=' + $('#downbegin').val() + '&end=' + $('#downend').val() + '&filename=' + $('#filename').val()
  513. }
  514. function initPage(count, parameter, tbegin, tend, pestCategory) {
  515. layui.use('laypage', function () {
  516. var laypage = layui.laypage;
  517. laypage.render({
  518. elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号
  519. , count: count
  520. , theme: '#428BCA'
  521. , layout: ['prev', 'page', 'next', 'skip']
  522. , jump: function (obj, first) {
  523. if (!first) {
  524. $.ajax({
  525. url: 'cbd/cbd_pest_table_data',
  526. type: 'post',
  527. data: {
  528. imei: $('#imei').val(),
  529. page: obj.curr,
  530. tbegin: tbegin,
  531. tend: tend,
  532. pest_name: pestCategory
  533. },
  534. beforeSend: function (XMLHttpRequest) {
  535. layui.use(['layer'], function () {
  536. var layer = layui.layer;
  537. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  538. loadingFlag2= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  539. })
  540. },
  541. complete: function (XMLHttpRequest, textStatus) {
  542. layer.close(loadingFlag2);
  543. },
  544. dataType: "json",
  545. success: function (data) {
  546. if (data.dat.length) {
  547. $('#page').parent().show();
  548. pestFill_Table('datatable', data.dat);
  549. } else {
  550. $('#page').parent().hide();
  551. datFill_null_Table('datatable');
  552. }
  553. }
  554. })
  555. }
  556. }
  557. })
  558. })
  559. }
  560. function datFill_null_Table(table_id) {
  561. $("#datatable tr:not(:first)").remove();
  562. var table = document.getElementById(table_id).children[1];
  563. var row = table.insertRow(table.rows.length);
  564. var c1 = row.insertCell(0);
  565. c1.setAttribute('colspan', '16');
  566. c1.setAttribute('class', 'nullData');
  567. c1.innerHTML = "暂无数据";
  568. scrollBar();
  569. }
  570. function datFill_Table(table_id, dat) {
  571. var table = document.getElementById(table_id).children[1];
  572. for (var i = 0; i < dat.length - 1; i++) {
  573. var row = table.insertRow(table.rows.length);
  574. if (dat[i].length == 0) { continue; }
  575. //JSON字符串转换JSON对象
  576. // var stat = eval('(' + dat[i].cbd_data + ')');
  577. var c1 = row.insertCell(0);
  578. c1.innerHTML = dat[i].pest_name;
  579. var c2 = row.insertCell(1);
  580. c2.innerHTML = dat[i].pest_num;
  581. var c3 = row.insertCell(2);
  582. if (dat[i].crop_name == '') {
  583. c3.innerHTML = '无';
  584. } else {
  585. c3.innerHTML = dat[i].crop_name;
  586. }
  587. var c4 = row.insertCell(3);
  588. if (dat[i].pest_case == '') {
  589. c4.innerHTML = '无';
  590. } else {
  591. c4.innerHTML = dat[i].pest_case;
  592. }
  593. var c5 = row.insertCell(4);
  594. c5.innerHTML = dat[i].add_time;
  595. }
  596. }
  597. function pestFill_Table(table_id, dat) {
  598. $("#datatable tr:not(:first)").remove();
  599. var table = document.getElementById(table_id).children[1];
  600. for (var i = 0; i < dat.length; i++) {
  601. var row = table.insertRow(table.rows.length);
  602. var c1 = row.insertCell(0);
  603. c1.innerHTML = dat[i].pest_name;
  604. var c2 = row.insertCell(1);
  605. c2.innerHTML = dat[i].pest_num;
  606. var c3 = row.insertCell(2);
  607. c3.innerHTML = dat[i].crop_name;
  608. var c4 = row.insertCell(3);
  609. c4.innerHTML = dat[i].pest_case;
  610. var c5 = row.insertCell(4);
  611. c5.innerHTML = dat[i].add_time;
  612. }
  613. scrollBar();
  614. }
  615. var lineChart = echarts.init(document.getElementById('line-chart'));
  616. lineOption = {
  617. title: {
  618. text: '害虫统计',
  619. textStyle: {
  620. color: '#029eef',
  621. fontSize: 14
  622. }
  623. },
  624. legend: {
  625. 'right': '10%',
  626. data: []
  627. },
  628. toolbox: { //可视化的工具箱
  629. show: true,
  630. left: 'right',
  631. feature: {
  632. restore: { //重置
  633. show: true
  634. },
  635. dataZoom: { //数据缩放视图
  636. show: true
  637. },
  638. saveAsImage: {//保存图片
  639. show: true
  640. },
  641. magicType: {//动态类型切换
  642. type: ['bar', 'line']
  643. }
  644. }
  645. },
  646. tooltip: {
  647. trigger: 'axis',
  648. formatter: function (params) {
  649. return params[0].axisValue + '<br/>' + params[0].marker +params[0].seriesName+':'+params[0].value+'只';
  650. }
  651. },
  652. xAxis: {
  653. data: []
  654. },
  655. yAxis: [{
  656. axisLine: { show: true },
  657. type:'value'
  658. }],
  659. dataZoom: {
  660. show: true
  661. },
  662. grid: {
  663. left: '3%',
  664. right: '4%',
  665. bottom: '6%',
  666. containLabel: true
  667. },
  668. series: []
  669. }
  670. var color = ['#5689f2', '#00c1de', '#4caf50', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800'];
  671. var pieChart = echarts.init(document.getElementById('pie-chart'));
  672. pieOption = {
  673. title: {
  674. text: '害虫比例',
  675. textStyle: {
  676. color: '#029eef'
  677. }
  678. },
  679. tooltip: {
  680. trigger: 'item',
  681. formatter: "{a} <br/>{b} : {c} ({d}%)"
  682. },
  683. legend: {
  684. orient: 'vertical',
  685. left: 'right',
  686. data: []
  687. },
  688. grid: {
  689. left: '3%',
  690. right: '4%',
  691. bottom: '6%',
  692. containLabel: true
  693. },
  694. series: [
  695. {
  696. name: '害虫种类',
  697. type: 'pie',
  698. radius: '55%',
  699. radius: ['50%', '70%'],
  700. data: [],
  701. itemStyle: {
  702. emphasis: {
  703. shadowBlur: 10,
  704. shadowOffsetX: 0,
  705. shadowColor: 'rgba(0, 0, 0, 0.5)'
  706. }
  707. }
  708. }
  709. ]
  710. };
  711. window.onresize = function () {
  712. //当窗口发生变化时图表显示
  713. lineChart.resize();
  714. pieChart.resize();
  715. }
  716. function wormEcharts(data) {
  717. category = []; //害虫种类
  718. lineVal = []; //折线数据(时间+值+名称)
  719. if(data.length){
  720. for(var i = 0;i<data.length;i++){
  721. var json = {
  722. val:[],
  723. time:[],
  724. }
  725. if(category.indexOf(data[i].pest_name) != -1){
  726. lineVal[category.indexOf(data[i].pest_name)].val.unshift(data[i].pest_num)
  727. lineVal[category.indexOf(data[i].pest_name)].time.unshift(data[i].add_time)
  728. // lineVal[category.indexOf(data[i].dat[z].pest_name)].name.unshift(data[i].dat[z].pest_name)
  729. }else{
  730. category.push(data[i].pest_name);
  731. lineVal.push({
  732. val:[data[i].pest_num],
  733. time:[data[i].add_time],
  734. name:data[i].pest_name,
  735. })
  736. }
  737. if(i == data.length-1){
  738. console.log(category)
  739. console.log(lineVal)
  740. // 害虫种类填充
  741. var html = '';
  742. for (var s = 0; s < category.length; s++) {
  743. html += '<option value="' + s + '">' + category[s] + '</option>';
  744. if (s == category.length - 1) {
  745. if (html) {
  746. $('#wormType').html(html)
  747. } else {
  748. $('#wormType').html('<option value="">暂无害虫种类</option>')
  749. }
  750. }
  751. }
  752. var form = layui.form;
  753. form.render('select');
  754. form.on('select(wormType)', function(data){
  755. fillLineChart(data.value)
  756. });
  757. // 默认第一条折线填充
  758. if(lineVal.length){
  759. fillLineChart(0)
  760. // 害虫比例
  761. if (category.length) {
  762. pieOption.series[0].data = [];
  763. for (var a = 0; a < category.length; a++) {
  764. var num = eval(lineVal[a].val.join("+"))
  765. var da = '{ value:' + num + ', name:"' + lineVal[a].name + '"}';
  766. pieOption.series[0].data.push(eval('(' + da + ')'));
  767. }
  768. $('#pie-chart').prev().html('').css('z-index', 0);
  769. pieChart.setOption(pieOption);
  770. } else {
  771. pieOption.series[0].data = [];
  772. pieChart.setOption(pieOption);
  773. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  774. }
  775. }else{
  776. lineChart.clear();
  777. lineOption.series = [];
  778. lineOption.xAxis.data = [];
  779. pieOption.series[0].data = [];
  780. lineChart.setOption(lineOption);
  781. pieChart.setOption(pieOption);
  782. $('#line-chart').prev().html('暂无害虫数据').css('z-index', 99);
  783. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  784. $('#wormType').html('<option value="">暂无害虫种类</option>')
  785. }
  786. }
  787. }
  788. }else{
  789. lineChart.clear();
  790. lineOption.series = [];
  791. lineOption.xAxis.data = [];
  792. pieOption.series[0].data = [];
  793. lineChart.setOption(lineOption);
  794. pieChart.setOption(pieOption);
  795. $('#line-chart').prev().html('暂无害虫数据').css('z-index', 99);
  796. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  797. $('#wormType').html('<option value="">暂无害虫种类</option>')
  798. }
  799. // var legend = ['温度', '湿度', '害虫个数'];
  800. // var kindNum = dat.kind;
  801. var type1 = [];
  802. var typeValue = [];
  803. }
  804. pieChart.on("click", function (param) {
  805. pieConsole(param, '')
  806. });
  807. function pieConsole(param, type) {
  808. $('#wormType').val(param.dataIndex)
  809. $('#wormType').change()
  810. fillLineChart(param.dataIndex)
  811. var form = layui.form;
  812. form.render('select');
  813. }
  814. function fillLineChart(num){
  815. lineChart.clear();
  816. lineOption.series = [];
  817. lineOption.series.unshift({
  818. name: category[num],
  819. type: 'line',
  820. data: lineVal[num].val,
  821. itemStyle: {
  822. normal: {
  823. color: color[2],
  824. shadowBlur: 1,
  825. shadowColor: color[2],
  826. borderColor: color[2],
  827. borderWidth: 2,
  828. backgroundColor: 'transparent'
  829. }
  830. },
  831. areaStyle: {
  832. normal: {
  833. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  834. offset: 0,
  835. color: color[2]
  836. }, {
  837. offset: 1,
  838. color: 'rgba(255, 2555, 255, 0.2)'
  839. }]),
  840. }
  841. }
  842. });
  843. $('#line-chart').prev().html('').css('z-index', 0);
  844. lineOption.xAxis.data = lineVal[num].time;
  845. lineChart.setOption(lineOption);
  846. }
  847. function datsub_filter() {
  848. var tbegin = $('#begin').val();
  849. var tend = $('#end').val();
  850. if (tbegin && tend) {
  851. $.ajax({
  852. url: 'cbd/cbd_pest_data',
  853. type: 'post',
  854. data: {
  855. 'imei': $('#imei').val(),
  856. 'tbegin': tbegin,
  857. 'tend': tend,
  858. },
  859. beforeSend: function (XMLHttpRequest) {
  860. layui.use(['layer'], function () {
  861. var layer = layui.layer;
  862. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  863. loadingFlag= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  864. })
  865. },
  866. complete: function (XMLHttpRequest, textStatus) {
  867. layer.close(loadingFlag);
  868. },
  869. dataType: "json",
  870. success: function (data) {
  871. wormEcharts(data)
  872. }
  873. })
  874. } else {
  875. layer.msg('请填写时间段')
  876. }
  877. }
  878. function table_sub_filter() {
  879. var pestCategory = $('#pestCategory').val();
  880. var tbegin = $('#tableBegin').val();
  881. var tend = $('#tableEnd').val();
  882. if ((tbegin && tend) || pestCategory) {
  883. $.ajax({
  884. url: 'cbd/cbd_pest_table_data',
  885. type: 'post',
  886. data: {
  887. req: 'filter',
  888. 'imei': $('#imei').val(),
  889. tbegin: tbegin,
  890. tend: tend,
  891. pest_name: pestCategory,
  892. page: 1
  893. },
  894. beforeSend: function (XMLHttpRequest) {
  895. layui.use(['layer'], function () {
  896. var layer = layui.layer;
  897. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  898. loadingFlag= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  899. })
  900. },
  901. complete: function (XMLHttpRequest, textStatus) {
  902. layer.close(loadingFlag);
  903. },
  904. dataType: "json",
  905. success: function (data) {
  906. if (data.dat.length) {
  907. $('#page').parent().show();
  908. pestFill_Table('datatable', data.dat);
  909. } else {
  910. $('#page').parent().hide();
  911. datFill_null_Table('datatable');
  912. }
  913. initPage(data.nums, 'filter', tbegin, tend, pestCategory);
  914. }
  915. })
  916. } else {
  917. layer.msg('请至少选择一项筛选')
  918. }
  919. }
  920. </script>
  921. </body>
  922. </html>