index.js.bak 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. /* 饼图 */
  2. (function() {
  3. /* 饼图初始化 */
  4. var myChartPie = echarts.init(document.querySelector(" .chart"));
  5. var placeHolderStyle = {
  6. normal: {
  7. color: '#fff',
  8. opacity: .1
  9. },
  10. emphasis: {
  11. color: '#fff',
  12. opacity: .1
  13. }
  14. }
  15. optionPie = {
  16. grid: {
  17. left: '4%',
  18. top: '4%',
  19. height: "100%",
  20. containLabel: true
  21. },
  22. textStyle: {
  23. fontSize: 16,
  24. color: '#40E7F4 '
  25. },
  26. tooltip: {
  27. trigger: 'item',
  28. formatter: "{a} :<br/>({d}%)"
  29. },
  30. color: ['#3FFFEA', '#FFFF00'],
  31. legend: {
  32. orient: 'horizontal',
  33. bottom: '0',
  34. left: '12%',
  35. data: ['失电', '低压'],
  36. textStyle: {
  37. color: '#40E7F4 ',
  38. fontSize: 12
  39. },
  40. formatter(name) {
  41. return name
  42. },
  43. itemWidth: 20,
  44. itemHeight: 10,
  45. itemGap: 10
  46. },
  47. series: [{
  48. name: '失电',
  49. type: 'pie',
  50. radius: ['70%', '80%'],
  51. center: ["50%", "40%"],
  52. label: false,
  53. startAngle: 90,
  54. clockWise: true, //顺时加载
  55. hoverAnimation: true,
  56. hoverOffset: 3,
  57. data: [{
  58. value: 103,
  59. name: '失电',
  60. },
  61. {
  62. value: 242,
  63. hoverAnimation: false, //鼠标移入变大
  64. itemStyle: placeHolderStyle
  65. }
  66. ]
  67. }, {
  68. name: '低压',
  69. type: 'pie',
  70. radius: ['50%', '60%'],
  71. center: ["50%", "40%"],
  72. label: false,
  73. startAngle: 270,
  74. clockWise: true,
  75. hoverAnimation: true,
  76. hoverOffset: 3,
  77. data: [{
  78. value: 242,
  79. name: '低压',
  80. },
  81. {
  82. value: 103,
  83. hoverAnimation: false,
  84. itemStyle: placeHolderStyle
  85. }
  86. ]
  87. }]
  88. };
  89. myChartPie.setOption(optionPie);
  90. window.addEventListener("resize", function() {
  91. myChartPie.resize();
  92. });
  93. // 数据统计ajax请求数据
  94. function getStatisticData2(queryParam = {}) {
  95. ajaxRequest(STATISTICS, "get", queryParam, function(result) {
  96. var data = result.data[0]
  97. myChartPie.setOption({
  98. series: [{
  99. data: [{
  100. value: data.powerLossAlarmNumber,
  101. name: '失电',
  102. },
  103. {
  104. value: data.lowPressureAlarmNumber,
  105. hoverAnimation: false, //鼠标移入变大
  106. itemStyle: placeHolderStyle
  107. }
  108. ]
  109. }, {
  110. data: [{
  111. value: data.lowPressureAlarmNumber,
  112. name: '低压',
  113. },
  114. {
  115. value: data.powerLossAlarmNumber,
  116. hoverAnimation: false,
  117. itemStyle: placeHolderStyle
  118. }
  119. ]
  120. }]
  121. })
  122. }, function(errorMsg) {
  123. alert("请求数据失败!");
  124. })
  125. }
  126. getStatisticData2()
  127. })();
  128. /* 地图 */
  129. (function() {
  130. var mapStyle = 'amap://styles/659dc6c4753dc6e87c65c8a874c02133';
  131. var map1 = new AMap.Map('map1', {
  132. mapStyle: mapStyle, //样式URL
  133. viewMode: '3D',
  134. turboMode: false,
  135. resizeEnable: true,
  136. zoom: 11,
  137. center: [121.475644, 31.1857],
  138. features: ['bg', 'road', 'building'],
  139. pitch: 45,
  140. forceVector: true
  141. });
  142. var StatusStore = [{
  143. "address": "沪太路8786弄155号临附近",
  144. "building_name": "宝辉冶金",
  145. "company_code": "2021-01-04 09:13:13",
  146. "company_name": "宝辉冶金",
  147. "d0": 221.5,
  148. "d0a": 0,
  149. "d0ac": 0,
  150. "d0o": 0,
  151. "d0oc": 0,
  152. "fulladdress": "上海市.上海市.沪太路8786弄155号临附近",
  153. "lat": 31.34759,
  154. "lng": 121.3313,
  155. "phone": "13816977298",
  156. "username": "裘怡",
  157. "xmlx": "商业"
  158. }, {
  159. "address": "嘉定区宝安公路2442号北80米",
  160. "building_name": "永鑫汽车配件",
  161. "company_code": "2021-01-04 10:55:02",
  162. "company_name": "永鑫汽车配件",
  163. "d0": 219.06,
  164. "d0a": 0,
  165. "d0ac": 0,
  166. "d0o": 0,
  167. "d0oc": 0,
  168. "fulladdress": "上海市.上海市.嘉定区.嘉定区宝安公路2442号北80米",
  169. "lat": 31.37482,
  170. "lng": 121.26621,
  171. "phone": "15122423833",
  172. "username": "韩锐",
  173. "xmlx": "商业"
  174. }];
  175. var current_company_code = "";
  176. var clear_detail_info = function() {
  177. var d0 = 0,
  178. d0o = 0,
  179. d0oc = 0,
  180. d0a = 0,
  181. d0ac = 0;
  182. var d1 = 0,
  183. d1o = 0,
  184. d1oc = 0,
  185. d1a = 0,
  186. d1ac = 0;
  187. var d2 = 0,
  188. d2o = 0,
  189. d2oc = 0,
  190. d2a = 0,
  191. d2ac = 0;
  192. var d6 = 0,
  193. d6o = 0,
  194. d6oc = 0,
  195. d6a = 0,
  196. d6ac = 0;
  197. var d7 = 0,
  198. d7o = 0,
  199. d7oc = 0,
  200. d7a = 0,
  201. d7ac = 0;
  202. var detail_info = document.getElementById('detail_info');
  203. var real_time_alarm_div = document.getElementById('real_time_alarm_div');
  204. var parent = document.getElementById('map1');
  205. if (detail_info != undefined) {
  206. parent.removeChild(detail_info);
  207. current_company_code = "";
  208. } else if (real_time_alarm_div != undefined) {
  209. parent.removeChild(real_time_alarm_div);
  210. }
  211. }
  212. // //撒点图表弹窗
  213. var showInfo = function(e) {
  214. var pixel = e.pixel;
  215. var company_code = e.target.getExtData().company_code;
  216. var detail_info;
  217. var parent = document.getElementById('map1')
  218. for (var i = 0; i < StatusStore.length; i++) {
  219. if (StatusStore[i].company_code == company_code) {
  220. if (current_company_code == company_code)
  221. return;
  222. clear_detail_info();
  223. current_company_code = company_code;
  224. var qobj = new Object();
  225. qobj.V_LOGINNAME = $("#V_LOGINNAME").val();
  226. qobj.V_PASSWORD = $("#V_PASSWORD").val();
  227. qobj.V_COMPANYID = company_code;
  228. qobj.I_COMMAND = 4;
  229. var qdata = "queryJson=" + JSON.stringify(qobj);
  230. var qurl = 'https://iot.usky.cn/YtIoT/cgi-bin/WebAction2.cgi';
  231. $.ajax({
  232. type: 'POST',
  233. url: qurl,
  234. data: qdata,
  235. success: function(result) {
  236. var json = eval('(' + result + ')');
  237. if (json.action == 'getAlarmList') {
  238. $(".alarm_tab_area").remove();
  239. if ((json.ALARM == undefined) || (json.ALARM.length == 0))
  240. return;
  241. var parent = document.getElementById('map1');
  242. json.ALARM.sort(alarmSortByTime);
  243. var area = document.createElement('div');
  244. area.id = 'alarm_tab_area';
  245. area.setAttribute('class', 'alarm_tab_area');
  246. parent.appendChild(area);
  247. }
  248. }
  249. });
  250. detail_info = document.createElement('div');
  251. detail_info.id = 'detail_info';
  252. detail_info.style.position = 'absolute';
  253. detail_info.style.top = (pixel.getY() - 210) + 'px';
  254. detail_info.style.left = (pixel.getX() - 113) + 'px';
  255. detail_info.style.width = '227px';
  256. detail_info.style.height = '164px';
  257. detail_info.style.backgroundImage = 'url(images/info_bg_wj.png)';
  258. detail_info.style.zIndex = '500';
  259. parent.appendChild(detail_info);
  260. var info_title = document.createElement('div');
  261. info_title.id = 'info_title';
  262. info_title.setAttribute('class', 'info_title');
  263. info_title.innerHTML = '<div style="display:inline-block;vertical-align:middle;align-self:center;">' + StatusStore[i].company_name + '</div>';
  264. detail_info.appendChild(info_title);
  265. var info_body0 = document.createElement('div');
  266. info_body0.id = 'info_body0';
  267. info_body0.setAttribute('class', 'info_body0');
  268. // info_body0.innerHTML = '地址:' + StatusStore[i].address;
  269. info_body0.innerHTML = '<span class="info-text">地理名称:</span>' + StatusStore[i].building_name;
  270. detail_info.appendChild(info_body0);
  271. var info_body1 = document.createElement('div');
  272. info_body1.id = 'info_body1';
  273. info_body1.setAttribute('class', 'info_body1');
  274. info_body1.innerHTML = '<span class="info-text">所在位置:</span>' + StatusStore[i].address;
  275. // info_body1.innerHTML = '联系人:' + StatusStore[i].username;
  276. detail_info.appendChild(info_body1);
  277. var info_body2 = document.createElement('div');
  278. info_body2.id = 'info_body2';
  279. info_body2.setAttribute('class', 'info_body2');
  280. info_body2.innerHTML = '<span class="info-text">电压值:</span>' + StatusStore[i].d0;
  281. // info_body2.innerHTML = '联系电话:' + StatusStore[i].phone;
  282. detail_info.appendChild(info_body2);
  283. var info_btn = document.createElement('div');
  284. var info_body3 = document.createElement('div');
  285. info_body3.id = 'info_body3';
  286. info_body3.setAttribute('class', 'info_body3');
  287. info_body3.innerHTML = '<span class="info-text">采集时间:</span>' + StatusStore[i].company_code;
  288. detail_info.appendChild(info_body3);
  289. var info_btn = document.createElement('div');
  290. // info_btn.id = 'info_btn';
  291. // info_btn.setAttribute('class', 'info_btn');
  292. // info_btn.innerHTML = '查看详情';
  293. // info_btn.company_code = company_code;
  294. // info_btn.onclick = function (e) {
  295. // var event = e;
  296. // location.href = baseUrl + 'view/frontpage/company.jsp?company_code=' + event.currentTarget.company_code;
  297. // }
  298. // detail_info.appendChild(info_btn);
  299. break;
  300. }
  301. }
  302. }
  303. //撒点
  304. var iconWidth = 28;
  305. var iconHeight = 28;
  306. var totalLng = 0;
  307. var totalLat = 0;
  308. var latngCount = 0;
  309. var markers = [];
  310. for (var i = 0; i < StatusStore.length; i++) {
  311. var obj = StatusStore[i];
  312. var iconurl = 'images/building_icon.png';
  313. // var iconurl = baseUrl + 'images/building_icon.png';
  314. if (obj.d0a != obj.d0ac)
  315. iconurl = 'images/building_alarm_icon.png';
  316. //iconurl = baseUrl + 'images/building_alarm_icon.png';
  317. if ((obj.lat > 30) && (obj.lat < 33) && (obj.lng > 120) && (obj.lng < 125)) {
  318. totalLng += obj.lng;
  319. totalLat += obj.lat;
  320. latngCount++;
  321. var marker = new AMap.Marker({
  322. icon: new AMap.Icon({
  323. size: new AMap.Size(iconWidth, iconHeight),
  324. image: iconurl,
  325. imageSize: new AMap.Size(iconWidth, iconHeight)
  326. }),
  327. position: new AMap.LngLat(obj.lng, obj.lat),
  328. extData: {
  329. icontype: 'company',
  330. company_code: obj.company_code
  331. },
  332. offset: new AMap.Pixel(-(iconWidth / 2), -(iconHeight / 2)),
  333. draggable: false,
  334. raiseOnDrag: false,
  335. autoRotation: false,
  336. label: {
  337. offset: new AMap.Pixel(-iconWidth - 5, -(iconHeight / 2) - 10),
  338. content: "<div id='label_" + obj.company_code + "' class='info " + ('shown') + "'>" + obj.company_name + "</div>",
  339. direction: 'right'
  340. }
  341. });
  342. // AMap.event.addListener(marker, 'click', showBuilding, this);
  343. AMap.event.addListener(marker, 'mouseover', showInfo, this);
  344. AMap.event.addListener(marker, 'mouseout', clear_detail_info, this);
  345. marker.setMap(map1);
  346. markers.push(marker);
  347. // if (!MapShow) {
  348. // }
  349. }
  350. }
  351. })();
  352. /* 数据统计 */
  353. (function() {
  354. // 数据统计ajax请求数据
  355. function getStatisticData(queryParam = {}) {
  356. ajaxRequest(STATISTICS, "GET", queryParam, function(result) {
  357. var data = result.data[0]
  358. $('#alarmNumber').html(data.alarmNumber)
  359. $('#processedAlarmNumber').html(data.processedAlarmNumber)
  360. $('#unprocessedAlarmNumber').html(data.unprocessedAlarmNumber)
  361. $('#powerLossAlarmNumber').html(data.powerLossAlarmNumber)
  362. $('#lowPressureAlarmNumber').html(data.lowPressureAlarmNumber)
  363. $('#siteNumber').html(data.siteNumber)
  364. }, function(errorMsg) {
  365. alert("请求数据失败!");
  366. })
  367. }
  368. getStatisticData()
  369. })();
  370. /* 设备列表 */
  371. (function() {
  372. // 设备列表查询ajax请求数据
  373. function getListData(queryParam = {}) {
  374. ajaxRequest(DEVICE_LIST, "POST", queryParam, function(result) {
  375. if (result.code) {
  376. var data = result.data
  377. console.log('data')
  378. console.log(data)
  379. var items = '';
  380. data.forEach(function(item, key) {
  381. var deviceStatusClassName = item.deviceStatus == '在线' ? 'online' : 'offline';
  382. items += ` <tr data-id=${item.deviceCode} class="detail">
  383. <td>${item.deviceName}</td>
  384. <td class="${deviceStatusClassName}">${item.deviceStatus}</td>
  385. <td>${item.deviceAdress}</td>
  386. </tr>`;
  387. })
  388. $('#deviceListBox').html(items)
  389. } else {
  390. alert('errorMSG')
  391. }
  392. }, function(errorMsg) {
  393. alert("请求数据失败!");
  394. }, 2)
  395. }
  396. getListData({ 'deviceCode': '1' })
  397. //按钮搜索
  398. $('#deviceButtonClick').on('click', function() {
  399. getListData(getSearchParamObj());
  400. })
  401. //拼接搜索条件
  402. function getSearchParamObj() {
  403. let queryParam = {};
  404. let deviceStatus = $('#deviceStatus').val();
  405. queryParam.deviceStatus = deviceStatus;
  406. return queryParam;
  407. }
  408. //设备详情弹框
  409. $(document).on('dblclick', 'tr.detail', function() {
  410. let dataId = $('.scroll tbody').find('.selected').data('id');
  411. // console.log('dataId')
  412. // alert(dataId);
  413. ajaxRequest(DEVICE_INFO_LIST, "POST", { "deviceCode": dataId }, function(result) {
  414. if (result.code) {
  415. var data = result.data[0]
  416. console.log('data')
  417. console.log(data)
  418. document.getElementById('dataTime').innerHTML="采集时间:"+data.dataTime;
  419. var items = ` <ul class="leftUl">
  420. <li>${data.Uab}</li>
  421. <li>${data.Ubc}</li>
  422. <li style="margin-bottom:50px">${data.Uca}</li>
  423. <li>${data.F}</li>
  424. </ul>
  425. <ul class="rightUl">
  426. <li>${data.Ia}</li>
  427. <li>${data.Ib}</li>
  428. <li style="margin-bottom:50px">${data.Ic}</li>
  429. <li>${data.P}</li>
  430. <li>${data.Q}</li>
  431. <li>${data.COS}</li>
  432. </ul>`;
  433. $('#txt-box').html(items)
  434. } else {
  435. alert('errorMSG')
  436. }
  437. }, function(errorMsg) {
  438. alert("请求数据失败!");
  439. }, 2)
  440. $('.deviceDetailOut').show()
  441. })
  442. $('.clsBtn,.cancel').click(function() {
  443. $('.deviceDetailOut').hide()
  444. })
  445. })();
  446. /* 告警列表 */
  447. (function() {
  448. // 告警列表查询ajax请求数据
  449. function getListData(queryParam = {}) {
  450. ajaxRequest(ALARM_LIST, "POST", queryParam, function(result) {
  451. // console.log(result)
  452. if (result.code) {
  453. var data = result.RESULT
  454. console.log('告警列表')
  455. console.log(data)
  456. var items = '';
  457. data.forEach(function(item, key) {
  458. var digitalValueClassName = item.digitalValue == '动作' ? 'color-red' : 'color-orange';
  459. var handleStatusClassName = item.handleState == '已处理' ? 'processed' : 'unprocess';
  460. // var timeConsuming = item.timeConsuming == '--' ? '--' : item.timeConsuming.hours;
  461. items += "<tr data-id=" + item.id + " data-alarm='" + JSON.stringify(item) + "'>" +
  462. "<td>" + item.companyName + "</td>" +
  463. "<td>" + item.companyAdress + "</td>" +
  464. "<td class='" + digitalValueClassName + "'>" + item.digitalValue + "</td>" +
  465. "<td>" + item.measDesc + "</td>" +
  466. "<td>" + item.sendingTime + "</td>" +
  467. "<td>" + item.timeConsuming + "</td>" +
  468. "<td class='" + handleStatusClassName + "'>" + item.handleState + "</td>" +
  469. "</tr>"
  470. })
  471. $('#alarmListBox').html(items)
  472. } else {
  473. alert('errorMSG')
  474. }
  475. }, function(errorMsg) {
  476. alert("请求数据失败!");
  477. }, 2)
  478. }
  479. getListData()
  480. //按钮搜索
  481. $('#alarmButtonClick').on('click', function() {
  482. getListData(getAlarmSearchParamObj());
  483. })
  484. //拼接搜索条件
  485. function getAlarmSearchParamObj() {
  486. let queryParam = {};
  487. let digitalValue = $('#digitalValue').val()
  488. let startTime = $('#startTime').val();
  489. let endTime = $('#endTime').val();
  490. queryParam.digitalValue = digitalValue;
  491. queryParam.startTime = startTime;
  492. queryParam.endTime = endTime;
  493. return queryParam;
  494. }
  495. //处置弹框
  496. $(document).on('dblclick', '.alarm-table tbody tr', function() {
  497. let alarmInfo = $('.scroll tbody').find('.selected').data('alarm');
  498. // console.log('alarmInfo')
  499. // console.log(alarmInfo)
  500. $('.alarmHanleOut input[name=companyName]').val(alarmInfo.siteName);
  501. $('.alarmHanleOut input[name=companyAdress]').val(alarmInfo.companyAdress);
  502. $('.alarmHanleOut input[name=lineName]').val(alarmInfo.lineName);
  503. $('.alarmHanleOut input[name=measName]').val(alarmInfo.measName);
  504. $('.alarmHanleOut input[name=digitalValue]').val(alarmInfo.digitalValue);
  505. $('.alarmHanleOut input[name=userName]').val(alarmInfo.userName);
  506. $('.alarmHanleOut input[name=userPhone]').val(alarmInfo.userPhone);
  507. $('.alarmHanleOut input[name=measDesc]').val(alarmInfo.measDesc);
  508. $('.alarmHanleOut input[name=deviceCode]').val(alarmInfo.deviceCode);
  509. $('.alarmHanleOut input[name=handleContent]').val(alarmInfo.handleContent);
  510. // $('.alarmHanleOut input[name=handleMisinformation]').val(alarmInfo.handleMisinformation);
  511. $('.alarmHanleOut input[name=alarmId]').val(alarmInfo.alarmId);
  512. $('.alarmHanleOut input[name=pictureUrl]').val(alarmInfo.pictureUrl);
  513. if(alarmInfo.handleState=="已处理" && alarmInfo.pictureUrl!=null && alarmInfo.pictureUrl!=""){
  514. document.getElementById('drop_area_addimg').setAttribute('src','https://iot.usky.cn/YtIoT'+alarmInfo.pictureUrl);
  515. }
  516. if(alarmInfo.handleState=="已处理"){
  517. $("input[name='handleMisinformation']").each(function() {
  518. if ($(this).val() != alarmInfo.handleMisinformation) {
  519. $(this).removeAttr("checked");
  520. } else {
  521. $(this).prop("checked", "checked");
  522. }
  523. });
  524. // $('.alarmHanleOut input[name=handleMisinformation]').val(alarmInfo.handleMisinformation);
  525. }
  526. layui.use(['form'],function(){
  527. var form = layui.form;
  528. form.render('radio');
  529. })
  530. $('.alarmHanleOut').show()
  531. })
  532. $('.clsBtn,.cancel').click(function() {
  533. $('.alarmHanleOut').hide()
  534. $("tbody tr").removeClass("selected");
  535. })
  536. /* 处理发送请求 */
  537. $('#dataUpdate').click(function() {
  538. //获取表单的值 并转换成对象
  539. let allParam = serializeArrayToObj($("#alarmHandleForm").serializeArray());
  540. //验证数据是否为空
  541. let res = validParamIsEmpty(allParam, {
  542. // "ownerMan": "请填写单位负责人",
  543. });
  544. if (res.code == -1) {
  545. alert(res.msg);
  546. return;
  547. }
  548. //验证图片是否为空
  549. // var uploadImgSrc = $('#drop_area img').attr('src')
  550. // if (uploadImgSrc == 'images/upload.png') {
  551. // alert('请上传图片')
  552. // }
  553. //验证通过 请求ajax
  554. ajaxRequest(ALARM_HANDLE, "POST", allParam, function(result) {
  555. // if (result.code) {
  556. // alert('修改成功')
  557. // } else {
  558. // alert('修改失败')
  559. // }
  560. $('.alarmHanleOut').hide()
  561. getListData();
  562. document.getElementById('drop_area_addimg').setAttribute('src','images/upload.png');
  563. }, function(errorMsg) {
  564. alert("异常错误!");
  565. }, 2)
  566. })
  567. $('#dataCancel').click(function() {
  568. document.getElementById('drop_area_addimg').setAttribute('src','images/upload.png');
  569. })
  570. })()