cbd_manual_pest_data.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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.4" />
  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 == "1" or role == "superuser" or role == "staff" %}
  232. <button type="button" onclick="openDetialPage('pest_statis?id={{ e_id }}+')" class="btn btn-sm btn-primary manualBtn">自动害虫统计</button>
  233. {% endif %}
  234. </div>
  235. <div class="searchCover">
  236. 统计图筛选条件:
  237. <input type="text" id="searchTime" autocomplete="off" style="width: 180px;">
  238. <input type="hidden" id="begin" name="begin">
  239. <input type="hidden" id="end" name="end">
  240. <button type="button" onclick="datsub_filter()" class="btn btn-sm btn-primary">筛选</button>
  241. 害虫种类:
  242. <div style="display: inline-block;width: 187px;">
  243. <form class="layui-form" action="" lay-filter="wormTypeForm">
  244. <select name="wormType" id="wormType" lay-verify="" lay-filter="wormType" lay-search>
  245. <option value="">暂无害虫种类</option>
  246. </select>
  247. </form>
  248. </div>
  249. </div>
  250. <div class="container-wrap">
  251. <div>
  252. </div>
  253. <div class="container-cartogram clearfix">
  254. <div class="echartsBox fl" style="width:63%">
  255. <div class="hint"></div>
  256. <div class="fl" id="line-chart"></div>
  257. </div>
  258. <div class="echartsBox fl" style="width:30%">
  259. <div class="hint"></div>
  260. <div class="fl" id="pie-chart"></div>
  261. </div>
  262. </div>
  263. <div>
  264. <input id="imei" type="hidden" type="text" value={{ e_id }}>
  265. </div>
  266. </div>
  267. <div class="searchCover">
  268. 统计图筛选条件:
  269. <input type="text" id="tableSearchTime" autocomplete="off" style="width: 180px;">
  270. <input type="hidden" id="tableBegin" name="begin">
  271. <input type="hidden" id="tableEnd" name="end"> 种类查找:
  272. <div style="display: inline-block;width: 187px;">
  273. <form class="layui-form" action="" lay-filter="demoForm">
  274. <select name="pestCategory" id="pestCategory" lay-verify="" lay-search>
  275. <option value="">害虫种类为空</option>
  276. </select>
  277. </form>
  278. </div>
  279. <button type="button" onclick="table_sub_filter()" class="btn btn-sm btn-primary">筛选</button>
  280. <!-- <button type="button" class="btn btn-success btn-sm" onclick="decideExport()">导出</button> -->
  281. </div>
  282. <div class="innerTable peatdata">
  283. <table id="datatable" class="table table-striped table-hover">
  284. <thead>
  285. <tr>
  286. <!-- <th>设备ID</th>
  287. <th>设备名称</th> -->
  288. <th>害虫名称</th>
  289. <th>害虫数量</th>
  290. <th>作物种类</th>
  291. <th>虫害阶段</th>
  292. <!-- <th>拍照时间</th> -->
  293. <th>统计时间</th>
  294. </tr>
  295. </thead>
  296. <tbody>
  297. {% for i in descs %}
  298. <tr>
  299. <td>{{ i.pest_name }}</td>
  300. <td>{{ i.pest_num }}</td>
  301. <td>{{ i.crop_name }}</td>
  302. <td>{{ i.pest_case }}</td>
  303. <td>{{ i.add_time }}</td>
  304. <!-- <td>
  305. <a class="fpsb-link" href="allot?uname={{ user.username }}" style="display: inline-block;">
  306. <button class="btn btn-primary btn-shaixuan">分配设备</button>
  307. </a>
  308. </td> -->
  309. </tr>
  310. {% endfor %}
  311. </tbody>
  312. </table>
  313. <div class="fenpei-bottom ">
  314. <input type="hidden" id="totalPage" value={{ nums }}>
  315. <div id="page" style="text-align: center;"></div>
  316. </div>
  317. </div>
  318. <!-- 导出提示框 -->
  319. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  320. <div class="modal-dialog" role="document">
  321. <div class="modal-content">
  322. <div class="modal-header">
  323. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  324. <span aria-hidden="true">&times;</span>
  325. </button>
  326. <h4 class="modal-title" id="myModalLabel">导出信息</h4>
  327. </div>
  328. <div class="modal-body">
  329. <div class="row">
  330. <div class="col-xs-3 downTitle">文件名称:</div>
  331. <div class="col-xs-8 downContent" style=>
  332. <input type="text" id="filename" placeholder="请输入文件的名称" maxlength="15" class="col-xs-12">
  333. </div>
  334. <div class="col-xs-3 downTitle">下载类型:</div>
  335. <div class="col-xs-8 downContent">
  336. <select name="downtype" id="downtype" onchange="downtype(this)" class="col-xs-12">
  337. <option value="1">全部</option>
  338. <option value="2">时间段</option>
  339. </select>
  340. </div>
  341. <div class="col-xs-3 downTitle timeStage">时间段:</div>
  342. <div class="col-xs-8 downContent timeStage">
  343. <input type="text" id="timSelectBox3" autocomplete="off" placeholder="请选择时间段 " class="col-xs-12">
  344. <input type="hidden" id="downbegin" name="begin">
  345. <input type="hidden" id="downend" name="end">
  346. </div>
  347. </div>
  348. </div>
  349. <div class="modal-footer">
  350. <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">取消</button>
  351. <button type="button" class="btn btn-primary btn-sm" onclick="operation()">下载</button>
  352. </div>
  353. </div>
  354. </div>
  355. </div>
  356. </div>
  357. <script src="{% static '/lib/js/jquery-2.1.4.min.js' %}"></script>
  358. <script src="{% static '/lib/layui/layui.all.js' %}"></script>
  359. <!-- 统计图 -->
  360. <script src="{% static '/lib/bootstrap-3.3.7/js/bootstrap.js' %}"></script>
  361. <script src="{% static '/js/common.js' %}?versions=0.5.4"></script>
  362. <script src="{% static '/lib/js/echarts.min.js' %}"></script>
  363. <script>
  364. $.ajaxSetup({
  365. data: { csrfmiddlewaretoken: '{{ csrf_token }}' },
  366. });
  367. function openPage(url,id) {
  368. window.location.href = url+"?id=" + id;
  369. }
  370. </script>
  371. <script>
  372. layui.use(['laydate', 'form'], function () {
  373. var laydate = layui.laydate;
  374. var form = layui.form;
  375. var _layDateMark = (new Date()).getTime();
  376. $('#searchTime').attr('lay-key', '11' + _layDateMark);
  377. $('#tableSearchTime').attr('lay-key', '22' + _layDateMark);
  378. $('#timSelectBox3').attr('lay-key', '33' + _layDateMark);
  379. //执行一个laydate实例
  380. laydate.render({
  381. elem: '#searchTime' //指定元素
  382. , type: 'date'
  383. , range: true
  384. , done: function (value, date) {
  385. var dateArray = value.split(' - ')
  386. $('#begin').val(dateArray[0]);
  387. $('#end').val(dateArray[1]);
  388. }
  389. });
  390. //执行一个laydate实例
  391. laydate.render({
  392. elem: '#tableSearchTime' //指定元素
  393. , type: 'date'
  394. , range: true
  395. , done: function (value, date) {
  396. var dateArray = value.split(' - ')
  397. $('#tableBegin').val(dateArray[0]);
  398. $('#tableEnd').val(dateArray[1]);
  399. }
  400. });
  401. //执行一个laydate实例
  402. laydate.render({
  403. elem: '#timSelectBox3' //指定元素
  404. , range: true
  405. , done: function (value, date) {
  406. var dateArray = value.split(' - ')
  407. $('#downbegin').val(dateArray[0])
  408. $('#downend').val(dateArray[1])
  409. }
  410. });
  411. });
  412. $.ajax({
  413. url: 'cbd/cbd_pest_data',
  414. type: 'post',
  415. data: {
  416. 'imei': $('#imei').val(),
  417. 'tbegin': '',
  418. 'tend': '',
  419. },
  420. beforeSend: function (XMLHttpRequest) {
  421. layui.use(['layer'], function () {
  422. var layer = layui.layer;
  423. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  424. loadingFlag= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false ,time:false});
  425. })
  426. },
  427. complete: function (XMLHttpRequest, textStatus) {
  428. layer.close(loadingFlag);
  429. },
  430. dataType: "json",
  431. success: function (data) {
  432. wormEcharts(data)
  433. }
  434. })
  435. $.ajax({
  436. url: 'cbd/cbd_pest_table_data',
  437. type: 'post',
  438. data: {
  439. imei: $('#imei').val(),
  440. page: 1
  441. },
  442. beforeSend: function (XMLHttpRequest) {
  443. layui.use(['layer'], function () {
  444. var layer = layui.layer;
  445. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  446. loadingFlag1= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  447. })
  448. },
  449. complete: function (XMLHttpRequest, textStatus) {
  450. layer.close(loadingFlag1);
  451. },
  452. dataType: "json",
  453. success: function (data) {
  454. if (data.dat.length) {
  455. var categoryArr = [];
  456. var str = '<option value="">害虫种类</option>';
  457. for (var i = 0; i < data.dat.length; i++) {
  458. if(categoryArr.indexOf(data.dat[i].pest_name) == -1 && data.dat[i].pest_name){
  459. categoryArr.push(data.dat[i].pest_name);
  460. }
  461. if(i == data.dat.length-1){
  462. console.log(categoryArr)
  463. for (var z = 0; z < categoryArr.length; z++) {
  464. str += '<option value="' + categoryArr[z] + '">' + categoryArr[z] + '</option>';
  465. if(z == categoryArr.length-1){
  466. $('#pestCategory').html(str);
  467. }
  468. }
  469. }
  470. }
  471. var form = layui.form;
  472. form.render('select');
  473. $('#page').parent().show();
  474. pestFill_Table('datatable', data.dat);
  475. } else {
  476. $('#page').parent().hide();
  477. datFill_null_Table('datatable');
  478. $('#pestCategory').html('<option value="">害虫种类为空</option>');
  479. var form = layui.form;
  480. form.render('select');
  481. }
  482. initPage(data.nums)
  483. }
  484. })
  485. function downtype(obj) {
  486. if ($(obj).val() == 2) {
  487. $('.timeStage').show();
  488. } else {
  489. $('.timeStage').hide();
  490. $('#downbegin').val('');
  491. $('#downend').val('');
  492. $('#downtimSelectBox').val('');
  493. }
  494. }
  495. // 导出提示框
  496. function decideExport() {
  497. $('#myModal').modal('toggle')
  498. }
  499. //导出
  500. function operation() {
  501. if (!$('#filename').val()) {
  502. layer.msg("请填写文件名!", { time: 2000 });
  503. return false;
  504. }
  505. if ($('#downtype').val() == 2) {
  506. if (!($('#downbegin').val() && $('#downbegin').val())) {
  507. layer.msg("请选择时间段!", { time: 2000 });
  508. return false;
  509. }
  510. }
  511. window.location.href = 'pest_export?id=' + $('#imei').val() + '&begin=' + $('#downbegin').val() + '&end=' + $('#downend').val() + '&filename=' + $('#filename').val()
  512. }
  513. function initPage(count, parameter, tbegin, tend, pestCategory) {
  514. layui.use('laypage', function () {
  515. var laypage = layui.laypage;
  516. laypage.render({
  517. elem: 'page' //注意,这里的 test1 是 ID,不用加 # 号
  518. , count: count
  519. , theme: '#428BCA'
  520. , layout: ['prev', 'page', 'next', 'skip']
  521. , jump: function (obj, first) {
  522. if (!first) {
  523. $.ajax({
  524. url: 'cbd/cbd_pest_table_data',
  525. type: 'post',
  526. data: {
  527. imei: $('#imei').val(),
  528. page: obj.curr,
  529. tbegin: tbegin,
  530. tend: tend,
  531. pest_name: pestCategory
  532. },
  533. beforeSend: function (XMLHttpRequest) {
  534. layui.use(['layer'], function () {
  535. var layer = layui.layer;
  536. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  537. loadingFlag2= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  538. })
  539. },
  540. complete: function (XMLHttpRequest, textStatus) {
  541. layer.close(loadingFlag2);
  542. },
  543. dataType: "json",
  544. success: function (data) {
  545. if (data.dat.length) {
  546. $('#page').parent().show();
  547. pestFill_Table('datatable', data.dat);
  548. } else {
  549. $('#page').parent().hide();
  550. datFill_null_Table('datatable');
  551. }
  552. }
  553. })
  554. }
  555. }
  556. })
  557. })
  558. }
  559. function datFill_null_Table(table_id) {
  560. $("#datatable tr:not(:first)").remove();
  561. var table = document.getElementById(table_id).children[1];
  562. var row = table.insertRow(table.rows.length);
  563. var c1 = row.insertCell(0);
  564. c1.setAttribute('colspan', '16');
  565. c1.setAttribute('class', 'nullData');
  566. c1.innerHTML = "暂无数据";
  567. scrollBar();
  568. }
  569. function datFill_Table(table_id, dat) {
  570. var table = document.getElementById(table_id).children[1];
  571. for (var i = 0; i < dat.length - 1; i++) {
  572. var row = table.insertRow(table.rows.length);
  573. if (dat[i].length == 0) { continue; }
  574. //JSON字符串转换JSON对象
  575. // var stat = eval('(' + dat[i].cbd_data + ')');
  576. var c1 = row.insertCell(0);
  577. c1.innerHTML = dat[i].pest_name;
  578. var c2 = row.insertCell(1);
  579. c2.innerHTML = dat[i].pest_num;
  580. var c3 = row.insertCell(2);
  581. if (dat[i].crop_name == '') {
  582. c3.innerHTML = '无';
  583. } else {
  584. c3.innerHTML = dat[i].crop_name;
  585. }
  586. var c4 = row.insertCell(3);
  587. if (dat[i].pest_case == '') {
  588. c4.innerHTML = '无';
  589. } else {
  590. c4.innerHTML = dat[i].pest_case;
  591. }
  592. var c5 = row.insertCell(4);
  593. c5.innerHTML = dat[i].add_time;
  594. }
  595. }
  596. function pestFill_Table(table_id, dat) {
  597. $("#datatable tr:not(:first)").remove();
  598. var table = document.getElementById(table_id).children[1];
  599. for (var i = 0; i < dat.length; i++) {
  600. var row = table.insertRow(table.rows.length);
  601. var c1 = row.insertCell(0);
  602. c1.innerHTML = dat[i].pest_name;
  603. var c2 = row.insertCell(1);
  604. c2.innerHTML = dat[i].pest_num;
  605. var c3 = row.insertCell(2);
  606. c3.innerHTML = dat[i].crop_name;
  607. var c4 = row.insertCell(3);
  608. c4.innerHTML = dat[i].pest_case;
  609. var c5 = row.insertCell(4);
  610. c5.innerHTML = dat[i].add_time;
  611. }
  612. scrollBar();
  613. }
  614. var lineChart = echarts.init(document.getElementById('line-chart'));
  615. lineOption = {
  616. title: {
  617. text: '害虫统计',
  618. textStyle: {
  619. color: '#029eef',
  620. fontSize: 14
  621. }
  622. },
  623. legend: {
  624. 'right': '10%',
  625. data: []
  626. },
  627. tooltip: {
  628. trigger: 'axis',
  629. formatter: function (params) {
  630. return params[0].axisValue + '<br/>' + params[0].marker +params[0].seriesName+':'+params[0].value+'只';
  631. }
  632. },
  633. xAxis: {
  634. data: []
  635. },
  636. yAxis: [{
  637. axisLine: { show: true },
  638. type:'value'
  639. }],
  640. toolbox: {
  641. left: 'center',
  642. },
  643. dataZoom: {
  644. show: true
  645. },
  646. grid: {
  647. left: '3%',
  648. right: '4%',
  649. bottom: '6%',
  650. containLabel: true
  651. },
  652. series: []
  653. }
  654. var color = ['#5689f2', '#00c1de', '#4caf50', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800'];
  655. var pieChart = echarts.init(document.getElementById('pie-chart'));
  656. pieOption = {
  657. title: {
  658. text: '害虫比例',
  659. textStyle: {
  660. color: '#029eef'
  661. }
  662. },
  663. tooltip: {
  664. trigger: 'item',
  665. formatter: "{a} <br/>{b} : {c} ({d}%)"
  666. },
  667. legend: {
  668. orient: 'vertical',
  669. left: 'right',
  670. data: []
  671. },
  672. grid: {
  673. left: '3%',
  674. right: '4%',
  675. bottom: '6%',
  676. containLabel: true
  677. },
  678. series: [
  679. {
  680. name: '害虫种类',
  681. type: 'pie',
  682. radius: '55%',
  683. radius: ['50%', '70%'],
  684. data: [],
  685. itemStyle: {
  686. emphasis: {
  687. shadowBlur: 10,
  688. shadowOffsetX: 0,
  689. shadowColor: 'rgba(0, 0, 0, 0.5)'
  690. }
  691. }
  692. }
  693. ]
  694. };
  695. window.onresize = function () {
  696. //当窗口发生变化时图表显示
  697. lineChart.resize();
  698. pieChart.resize();
  699. }
  700. function wormEcharts(data) {
  701. category = []; //害虫种类
  702. lineVal = []; //折线数据(时间+值+名称)
  703. if(data.length){
  704. for(var i = 0;i<data.length;i++){
  705. var json = {
  706. val:[],
  707. time:[],
  708. }
  709. if(category.indexOf(data[i].pest_name) != -1){
  710. lineVal[category.indexOf(data[i].pest_name)].val.unshift(data[i].pest_num)
  711. lineVal[category.indexOf(data[i].pest_name)].time.unshift(data[i].add_time)
  712. // lineVal[category.indexOf(data[i].dat[z].pest_name)].name.unshift(data[i].dat[z].pest_name)
  713. }else{
  714. category.push(data[i].pest_name);
  715. lineVal.push({
  716. val:[data[i].pest_num],
  717. time:[data[i].add_time],
  718. name:data[i].pest_name,
  719. })
  720. }
  721. if(i == data.length-1){
  722. console.log(category)
  723. console.log(lineVal)
  724. // 害虫种类填充
  725. var html = '';
  726. for (var s = 0; s < category.length; s++) {
  727. html += '<option value="' + s + '">' + category[s] + '</option>';
  728. if (s == category.length - 1) {
  729. if (html) {
  730. $('#wormType').html(html)
  731. } else {
  732. $('#wormType').html('<option value="">暂无害虫种类</option>')
  733. }
  734. }
  735. }
  736. var form = layui.form;
  737. form.render('select');
  738. form.on('select(wormType)', function(data){
  739. fillLineChart(data.value)
  740. });
  741. // 默认第一条折线填充
  742. if(lineVal.length){
  743. fillLineChart(0)
  744. // 害虫比例
  745. if (category.length) {
  746. pieOption.series[0].data = [];
  747. for (var a = 0; a < category.length; a++) {
  748. var num = eval(lineVal[a].val.join("+"))
  749. var da = '{ value:' + num + ', name:"' + lineVal[a].name + '"}';
  750. pieOption.series[0].data.push(eval('(' + da + ')'));
  751. }
  752. $('#pie-chart').prev().html('').css('z-index', 0);
  753. pieChart.setOption(pieOption);
  754. } else {
  755. pieOption.series[0].data = [];
  756. pieChart.setOption(pieOption);
  757. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  758. }
  759. }else{
  760. lineChart.clear();
  761. lineOption.series = [];
  762. lineOption.xAxis.data = [];
  763. pieOption.series[0].data = [];
  764. lineChart.setOption(lineOption);
  765. pieChart.setOption(pieOption);
  766. $('#line-chart').prev().html('暂无害虫数据').css('z-index', 99);
  767. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  768. $('#wormType').html('<option value="">暂无害虫种类</option>')
  769. }
  770. }
  771. }
  772. }else{
  773. lineChart.clear();
  774. lineOption.series = [];
  775. lineOption.xAxis.data = [];
  776. pieOption.series[0].data = [];
  777. lineChart.setOption(lineOption);
  778. pieChart.setOption(pieOption);
  779. $('#line-chart').prev().html('暂无害虫数据').css('z-index', 99);
  780. $('#pie-chart').prev().html('暂无害虫数据').css('z-index', 99);
  781. $('#wormType').html('<option value="">暂无害虫种类</option>')
  782. }
  783. // var legend = ['温度', '湿度', '害虫个数'];
  784. // var kindNum = dat.kind;
  785. var type1 = [];
  786. var typeValue = [];
  787. }
  788. pieChart.on("click", function (param) {
  789. pieConsole(param, '')
  790. });
  791. function pieConsole(param, type) {
  792. $('#wormType').val(param.dataIndex)
  793. $('#wormType').change()
  794. fillLineChart(param.dataIndex)
  795. var form = layui.form;
  796. form.render('select');
  797. }
  798. function fillLineChart(num){
  799. lineChart.clear();
  800. lineOption.series = [];
  801. lineOption.series.unshift({
  802. name: category[num],
  803. type: 'line',
  804. data: lineVal[num].val,
  805. itemStyle: {
  806. normal: {
  807. color: color[2],
  808. shadowBlur: 1,
  809. shadowColor: color[2],
  810. borderColor: color[2],
  811. borderWidth: 2,
  812. backgroundColor: 'transparent'
  813. }
  814. },
  815. areaStyle: {
  816. normal: {
  817. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  818. offset: 0,
  819. color: color[2]
  820. }, {
  821. offset: 1,
  822. color: 'rgba(255, 2555, 255, 0.2)'
  823. }]),
  824. }
  825. }
  826. });
  827. $('#line-chart').prev().html('').css('z-index', 0);
  828. lineOption.xAxis.data = lineVal[num].time;
  829. lineChart.setOption(lineOption);
  830. }
  831. function datsub_filter() {
  832. var tbegin = $('#begin').val();
  833. var tend = $('#end').val();
  834. if (tbegin && tend) {
  835. $.ajax({
  836. url: 'cbd/cbd_pest_data',
  837. type: 'post',
  838. data: {
  839. 'imei': $('#imei').val(),
  840. 'tbegin': tbegin,
  841. 'tend': tend,
  842. },
  843. beforeSend: function (XMLHttpRequest) {
  844. layui.use(['layer'], function () {
  845. var layer = layui.layer;
  846. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  847. loadingFlag= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  848. })
  849. },
  850. complete: function (XMLHttpRequest, textStatus) {
  851. layer.close(loadingFlag);
  852. },
  853. dataType: "json",
  854. success: function (data) {
  855. wormEcharts(data)
  856. }
  857. })
  858. } else {
  859. layer.msg('请填写时间段')
  860. }
  861. }
  862. function table_sub_filter() {
  863. var pestCategory = $('#pestCategory').val();
  864. var tbegin = $('#tableBegin').val();
  865. var tend = $('#tableEnd').val();
  866. if ((tbegin && tend) || pestCategory) {
  867. $.ajax({
  868. url: 'cbd/cbd_pest_table_data',
  869. type: 'post',
  870. data: {
  871. req: 'filter',
  872. 'imei': $('#imei').val(),
  873. tbegin: tbegin,
  874. tend: tend,
  875. pest_name: pestCategory,
  876. page: 1
  877. },
  878. beforeSend: function (XMLHttpRequest) {
  879. layui.use(['layer'], function () {
  880. var layer = layui.layer;
  881. //注意,layer.msg默认3秒自动关闭,如果数据加载耗时比较长,需要设置time
  882. loadingFlag= layer.msg('正在读取数据,请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:false});
  883. })
  884. },
  885. complete: function (XMLHttpRequest, textStatus) {
  886. layer.close(loadingFlag);
  887. },
  888. dataType: "json",
  889. success: function (data) {
  890. if (data.dat.length) {
  891. $('#page').parent().show();
  892. pestFill_Table('datatable', data.dat);
  893. } else {
  894. $('#page').parent().hide();
  895. datFill_null_Table('datatable');
  896. }
  897. initPage(data.nums, 'filter', tbegin, tend, pestCategory);
  898. }
  899. })
  900. } else {
  901. layer.msg('请至少选择一项筛选')
  902. }
  903. }
  904. </script>
  905. </body>
  906. </html>