cbd_imageList.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. $(document).ready(function () {
  2. if ($('#totalPage').val() > 0) {
  3. $('.pestBtn').show();
  4. $('.delbox .batchesBtn').show();
  5. } else {
  6. $('.pestBtn').hide();
  7. $('.delbox .batchesBtn').hide();
  8. $('#page').parent().hide();
  9. }
  10. // $('.popup-gallery').magnificPopup({
  11. // delegate: '.popupA',
  12. // type: 'image',
  13. // tLoading: 'Loading image ......',
  14. // mainClass: 'mfp-img-mobile',
  15. // gallery: {
  16. // enabled: true,
  17. // navigateByImgClick: true,
  18. // preload: [0, 1], // Will preload 0 - before current, and 1 after the current image
  19. // arrowMarkup: '<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>', // markup of an arrow button
  20. // tPrev: 'Previous (Left arrow key)', // title for left button
  21. // tNext: 'Next (Right arrow key)', // title for right button
  22. // tCounter: '<span class="mfp-counter">%curr% of %total%</span>' // 标记的计数器
  23. // },
  24. // image: {
  25. // tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
  26. // titleSrc: function (item) {
  27. // return item.el.attr('title') + '<small></small>';
  28. // }
  29. // }
  30. // });
  31. // 添加描述
  32. $('.addDetial').on('click',function(){
  33. var _this = this;
  34. layer.open({
  35. type: 1,
  36. title:'添加详情',
  37. area:['550px','330px'],
  38. content: $('#test-popup'),
  39. success:function(){
  40. var photoTime = $(_this).parent().find('.photoTime').val();
  41. var addr = $(_this).parent().find('img').attr('src');
  42. $('#imgPath').val(addr);
  43. $('#photo_time').val(photoTime);
  44. $.ajax({
  45. url: 'cbd_describe_img',
  46. type: 'get',
  47. data: { req: "pest_kind", addr: addr },
  48. success: function (data) {
  49. var msg = $.parseJSON(data);
  50. if (msg.length) {
  51. //配置数据回显
  52. $('#pupopForm select[name="wormName"]').empty();
  53. $('#delwormType .pupopBody').empty();
  54. for (var i = 0; i < msg.length; i++) {
  55. var html = "<option value='" + msg[i].pest_name + "'>" + msg[i].pest_name + "</option>"
  56. $('#pupopForm select[name="wormName"]').append(html);
  57. var pestName = '<label class="my_protocol">'+
  58. '<input class="input_agreement_protocol" value="'+msg[i].pest_name+'" type="checkbox">'+
  59. '<span></span>'+msg[i].pest_name+'</label>';
  60. $('#delwormType .pupopBody').append(pestName);
  61. }
  62. if (msg.length >= 180 ) {
  63. $('#addNameBtn').hide();
  64. }else{
  65. $('#addNameBtn').show();
  66. }
  67. if ($('#pupopForm option').length <= 0) {
  68. $('#delNameBtn').hide();
  69. } else {
  70. $('#delNameBtn').show();
  71. }
  72. }else{
  73. $('#delNameBtn').hide();
  74. }
  75. if (msg.length >= 180 ) {
  76. $('#addNameBtn').hide();
  77. }else{
  78. $('#addNameBtn').show();
  79. }
  80. if ($('#pupopForm option').length <= 0) {
  81. $('#delNameBtn').hide();
  82. } else {
  83. $('#delNameBtn').show();
  84. }
  85. }
  86. })
  87. }
  88. });
  89. })
  90. // $('.addDetial').magnificPopup({
  91. // type: 'inline',
  92. // closeOnBgClick:false,
  93. // midClick: true,
  94. // callbacks: {
  95. // open: function () {
  96. // // 当前选中项
  97. // var item = this.currItem.el[0];
  98. // var addr = $(item).parent().find('img').attr('src');
  99. // var photoTime = $(item).parent().find('.photoTime').val();
  100. // $('#imgPath').val(addr);
  101. // $('#photo_time').val(photoTime);
  102. // $.ajax({
  103. // url: 'cbd_describe_img',
  104. // type: 'get',
  105. // data: { req: "pest_kind", addr: addr },
  106. // success: function (data) {
  107. // var msg = $.parseJSON(data);
  108. // if (msg.length) {
  109. // //配置数据回显
  110. // $('#pupopForm select[name="wormName"]').empty();
  111. // $('#delwormType .pupopBody').empty();
  112. // for (var i = 0; i < msg.length; i++) {
  113. // var html = "<option value='" + msg[i].pest_name + "'>" + msg[i].pest_name + "</option>"
  114. // $('#pupopForm select[name="wormName"]').append(html);
  115. // var pestName = '<label class="my_protocol">'+
  116. // '<input class="input_agreement_protocol" value="'+msg[i].pest_name+'" type="checkbox">'+
  117. // '<span></span>'+msg[i].pest_name+'</label>';
  118. // $('#delwormType .pupopBody').append(pestName);
  119. // }
  120. // if (msg.length >= 180 ) {
  121. // $('#addNameBtn').hide();
  122. // }else{
  123. // $('#addNameBtn').show();
  124. // }
  125. // if ($('#pupopForm option').length <= 0) {
  126. // $('#delNameBtn').hide();
  127. // } else {
  128. // $('#delNameBtn').show();
  129. // }
  130. // }else{
  131. // $('#delNameBtn').hide();
  132. // }
  133. // }
  134. // })
  135. // goBackAddDetial();
  136. // }
  137. // }
  138. // });
  139. //查看详情
  140. $('.lookDetial').on('click',function(){
  141. var _this = this;
  142. layer.open({
  143. type: 1,
  144. area:'800px',
  145. offset: '100px',
  146. content: $('#lookDescribe'),
  147. success:function(){
  148. $("#wormDetails tr:not(:first)").remove();
  149. var addr = $(_this).parent().find('img').attr('src');
  150. $('#imgPath_dteial').val(addr);
  151. $.ajax({
  152. url: 'cbd_describe_img',
  153. type: 'get',
  154. data: { req: "desc", addr: addr },
  155. success: function (data) {
  156. var msg = $.parseJSON(data);
  157. if (msg.length) {
  158. //配置数据回显
  159. console.log('data:', data)
  160. for (var i = 0; i < msg.length; i++) {
  161. var html = '<tr><td class="optionName">' + msg[i].pest_name + '</td><td class="option">' + msg[i].pest_num + '</td>' +
  162. '<td class="option">' + msg[i].crop_name + '</td><td class="option">' + msg[i].pest_case + '</td>' +
  163. '<td><button type="button" class="btn editBtn btn-xs btn-primary" onclick="edit($(this))">编辑</button>' +
  164. '<button type="button" class="btn btn-xs saveBtn btn-success" onclick="save($(this))">保存</button>' +
  165. '<button type="button" style="margin-left:5px" class="btn btn-xs delBtn btn-danger" onclick="delItemDetial($(this))">删除</button></td></tr>';
  166. $('#wormDetails').append(html);
  167. }
  168. } else {
  169. var html = '<tr><td class="nullData" colspan="5">暂无数据</td></tr>'
  170. $('#wormDetails').append(html);
  171. }
  172. }
  173. })
  174. }
  175. });
  176. })
  177. // $('.lookDetial').magnificPopup({
  178. // type: 'inline',
  179. // closeOnBgClick:false,//点击蒙版消失
  180. // midClick: true,
  181. // callbacks: {
  182. // open: function () {
  183. // // 当前选中项
  184. // $("#wormDetails tr:not(:first)").remove();
  185. // var item = this.currItem.el[0];
  186. // var addr = $(item).parent().find('img').attr('src');
  187. // $('#imgPath_dteial').val(addr);
  188. // $.ajax({
  189. // url: 'cbd_describe_img',
  190. // type: 'get',
  191. // data: { req: "desc", addr: addr },
  192. // success: function (data) {
  193. // var msg = $.parseJSON(data);
  194. // if (msg.length) {
  195. // //配置数据回显
  196. // console.log('data:', data)
  197. // for (var i = 0; i < msg.length; i++) {
  198. // var html = '<tr><td class="optionName">' + msg[i].pest_name + '</td><td class="option">' + msg[i].pest_num + '</td>' +
  199. // '<td class="option">' + msg[i].crop_name + '</td><td class="option">' + msg[i].pest_case + '</td>' +
  200. // '<td><button type="button" class="btn editBtn btn-xs btn-primary" onclick="edit($(this))">编辑</button>' +
  201. // '<button type="button" class="btn btn-xs saveBtn btn-success" onclick="save($(this))">保存</button>' +
  202. // '<button type="button" style="margin-left:5px" class="btn btn-xs delBtn btn-danger" onclick="delItemDetial($(this))">删除</button></td></tr>';
  203. // $('#wormDetails').append(html);
  204. // }
  205. // } else {
  206. // var html = '<tr><td class="nullData" colspan="5">暂无数据</td></tr>'
  207. // $('#wormDetails').append(html);
  208. // }
  209. // }
  210. // })
  211. // }
  212. // }
  213. // });
  214. // $('.addwormTypeBtn').magnificPopup({
  215. // type: 'inline',
  216. // closeOnBgClick:false,
  217. // midClick: true,
  218. // })
  219. })
  220. // 自动识别
  221. function autoSeeWormType(obj){
  222. var addr = $(obj).parent().find('img').attr('src');
  223. $.ajax({
  224. url: 'pests_identification',
  225. type: 'post',
  226. dataType:'json',
  227. data: {img_addr: addr },
  228. beforeSend: function () {
  229. loadingFlag = layer.load();
  230. },
  231. success: function (data) {
  232. layer.close(loadingFlag);
  233. if(data.result){
  234. var html = '';
  235. var wormArr = data.result.split('#');
  236. var wormImg = data.image;
  237. html += '<div class="resultTitle">图片标记</div>';
  238. html += '<div class="wormImgTag"><img src="'+wormImg+'" /></div>';
  239. html += '<div class="resultTitle">识别结果</div>';
  240. for(var i = 0;i < wormArr.length;i++){
  241. var worm = wormArr[i].split(',');
  242. var wormName = worm[0];
  243. var wormNum = worm[1];
  244. html += '<div class="wormResult"><span>害虫名称:<i>'+insect_dict[wormName]+'(序号:'+wormName+')</i></span><span>害虫个数:<i>'+wormNum+'</i></span></div>';
  245. if(i == wormArr.length-1){
  246. html += '<div class="clear"></div>';
  247. $('.wormBox').html(html);
  248. }
  249. }
  250. }else{
  251. var html = '';
  252. html += '<i class="fa fa-times wormIcon" style="color:#bd0606" aria-hidden="true"></i><div>'+
  253. '<h4 class="">此类暂未录入</h4></div>'
  254. $('.wormBox').html(html);
  255. }
  256. $.magnificPopup.open({
  257. items: {
  258. src: '#autoDiscern',
  259. midClick: true,
  260. type: 'inline'
  261. },
  262. closeOnBgClick:false,
  263. });
  264. },
  265. error:function(){
  266. layer.close(loadingFlag);
  267. $.magnificPopup.open({
  268. items: {
  269. src: '#autoDiscern',
  270. midClick: true,
  271. type: 'inline'
  272. },
  273. closeOnBgClick:false,
  274. });
  275. var html = '';
  276. html += '<i class="fa fa-times wormIcon" style="color:#bd0606" aria-hidden="true"></i><div>'+
  277. '<h4 class="">识别失败</h4></div>'
  278. $('.wormBox').html(html);
  279. }
  280. })
  281. }
  282. function newAutoDiscern(obj){
  283. var addr = $(obj).parent().find('img').attr('src');
  284. $.ajax({
  285. url: 'pests_identification_new',
  286. type: 'post',
  287. dataType:'json',
  288. data: {img_addr: addr },
  289. beforeSend: function () {
  290. loadingFlag = layer.load();
  291. },
  292. success: function (data) {
  293. layer.close(loadingFlag);
  294. if(data.result){
  295. var html = '';
  296. var htmlA = '';
  297. var htmlB = '';
  298. var wormArr = data.result.split('#');
  299. var wormImg = data.image;
  300. htmlB += '<div class="resultTitle">图片标记<button class="btn btn-sm btn-primary resultLookGitImg" onclick="window.open(\''+wormImg+'\')">查看大图</button></div>';
  301. htmlB += '<div class="wormImgTag"><img src="'+wormImg+'" /></div>';
  302. htmlA += '<div class="resultTitle">识别结果</div>';
  303. for(var i = 0;i < wormArr.length;i++){
  304. var worm = wormArr[i].split(',');
  305. var wormName = worm[0];
  306. var wormNum = worm[1];
  307. htmlA += '<div class="wormResult"><span>害虫名称:<a target="_blank" href = "https://baike.baidu.com/item/'+insect_dict[wormName]+'?fr=aladdin"><i>'+insect_dict[wormName]+'(序号:'+wormName+')</i></a></span><span class="dataNums">害虫个数:<i>'+wormNum+'</i></span></div>';
  308. if(i == wormArr.length-1){
  309. html += '<div class="dataListB">' + htmlB +'</div>';
  310. html += '<div class="dataListA">' + htmlA +'</div>';
  311. html += '<div class="clear"></div>';
  312. $('.wormBox').html(html);
  313. layui.use('layer', function(){
  314. var layer = layui.layer;
  315. layer.open({
  316. type:1,
  317. offset:'100px',
  318. // area:'900px',
  319. // area:'90%',
  320. area:'1400px',
  321. title:'害虫计数',
  322. content:$('#autoDiscern')
  323. });
  324. });
  325. }
  326. }
  327. }else{
  328. var html = '';
  329. html += '<i class="fa fa-times wormIcon" style="color:#bd0606" aria-hidden="true"></i><div>'+
  330. '<h4 class="">此类暂未录入</h4></div>'
  331. $('.wormBox').html(html);
  332. layui.use('layer', function(){
  333. var layer = layui.layer;
  334. layer.open({
  335. type:1,
  336. area:['400px','250px'],
  337. title:'提示',
  338. content:$('#failure')
  339. });
  340. });
  341. }
  342. // $.magnificPopup.open({
  343. // items: {
  344. // src: '#autoDiscern',
  345. // midClick: true,
  346. // type: 'inline'
  347. // },
  348. // closeOnBgClick:false,
  349. // });
  350. },
  351. error:function(){
  352. layer.close(loadingFlag);
  353. layui.use('layer', function(){
  354. var layer = layui.layer;
  355. layer.open({
  356. type:1,
  357. area:['400px','250px'],
  358. title:'提示',
  359. content:$('#failure')
  360. });
  361. });
  362. var html = '';
  363. html += '<i class="fa fa-times wormIcon" style="color:#bd0606" aria-hidden="true"></i><div>'+
  364. '<h4 class="">识别失败</h4></div>'
  365. $('.wormBox').html(html);
  366. }
  367. })
  368. }