device-check.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. var pageNo = 1;
  2. var totalPages = 0;
  3. //检测对象列表
  4. getListDataAjax();
  5. //获取检测对象列表 ajax请求
  6. function getListDataAjax(queryParam = {}, pageNo = 1) {
  7. queryParam.pageNo = pageNo;
  8. // queryParam.pageSize = 4;
  9. ajaxRequest(DEVICE_CHECK_LIST, "POST", queryParam, function(result) {
  10. let data = result.RESULT.pageList;
  11. let items = '';
  12. if (result.RESULT.totalCount > 0) {
  13. data.forEach(function(item, key) {
  14. items += "<tr>" +
  15. "<td class='status' data-user='" + JSON.stringify(item) + "' data-id=" + item.id + "></td>" +
  16. "<td>" + item.xh + "</td>" +
  17. "<td>" + item.object_name + "</td>" +
  18. "<td>" + item.company_name + "</td>" +
  19. "<td>" + item.add_people + "</td>" +
  20. "<td>" + getFormatDate(item.add_time.time) + "</td>" +
  21. "</tr>"
  22. })
  23. }
  24. $('#dataList').html(items);
  25. totalPages = result.RESULT.totalPages;
  26. $('#totalPage').html(totalPages); //总共多少页
  27. $('#dataTotal').html(result.RESULT.totalCount); //总共多少条数据
  28. $('#currentPage').val(pageNo); //当前页面
  29. let pageFrom = (pageNo - 1) * result.RESULT.pageSize + 1; //开始
  30. let pageTo = result.RESULT.pageNo * result.RESULT.pageSize; //结束
  31. pageTo = pageTo > result.RESULT.totalCount ? result.RESULT.totalCount : pageTo;
  32. $('#pageFrom').html(pageFrom);
  33. $('#pageTo').html(pageTo);
  34. // 无数据时
  35. if (!data.length) {
  36. $('.pager.has-data').hide()
  37. $('.pager.no-data').show()
  38. } else {
  39. $('.pager.has-data').show()
  40. $('.pager.no-data').hide()
  41. }
  42. if (pageNo < totalPages) {
  43. $('#nextPageButton,#lastPageButton').removeClass('disabled');
  44. } else {
  45. $('#nextPageButton,#lastPageButton').addClass('disabled');
  46. }
  47. if (pageNo === 1) {
  48. $('#firstPageButton,#prevPageButton').addClass('disabled');
  49. } else {
  50. $('#firstPageButton,#prevPageButton').removeClass('disabled');
  51. }
  52. }, function(errorMsg) {
  53. alert("请求数据失败!");
  54. })
  55. }
  56. //获取检测对象设备列表 ajax请求
  57. getTypeListDataAjax()
  58. function getTypeListDataAjax(queryParam = {}) {
  59. ajaxRequest(DEVICE_CHECK_DEVICE_LIST, "POST", queryParam, function(result) {
  60. let data = result.pageList;
  61. let items = '';
  62. data.forEach(function(item, key) {
  63. items += ` <input type="checkbox" name="device_code" value="${item.ownerCode}" lay-skin="primary" title="${item.ownerName}" >`
  64. })
  65. $('#checkselfblock').html(items);
  66. $('#checkselfblock2').html(items);
  67. layui.use(['form'], function() {
  68. var form = layui.form;
  69. form.render('checkbox');
  70. });
  71. }, function(errorMsg) {
  72. alert("请求数据失败!");
  73. })
  74. }
  75. //按钮搜索
  76. $('#buttonClick').on('click', function() {
  77. pageNo = 1
  78. getListDataAjax(getSearchParamObj());
  79. })
  80. //拼接搜索条件
  81. function getSearchParamObj() {
  82. let queryParam = {};
  83. let object_name = $('#object_name').val();
  84. let start_add_time = $('#start_add_time').val();
  85. let end_add_time = $('#end_add_time').val()
  86. queryParam.object_name = object_name;
  87. queryParam.start_add_time = start_add_time;
  88. queryParam.end_add_time = end_add_time;
  89. return queryParam;
  90. }
  91. //重置表单
  92. $('.reset').click(resetForm)
  93. //重置表单
  94. function resetForm() {
  95. pageNo = 1;
  96. $("#object_name").val("");
  97. $("#start_add_time").val("");
  98. $("#end_add_time").val("");
  99. getListDataAjax(getSearchParamObj());
  100. }
  101. let dataDefaultTree = [];
  102. //获取建筑楼层房间树结构 ajax请求
  103. function getBuildTree() {
  104. ajaxRequest(BUILD_TREE_LIST, "POST", {}, function(result) {
  105. let data = result.data;
  106. let treeArray = []
  107. //遍历第一级
  108. data.forEach(function(item, index) {
  109. let treeObj = {}
  110. treeObj.id = item.id;
  111. treeObj.title = item.buildName;
  112. //遍历第二级
  113. if (item.child) {
  114. treeObj.children = [];
  115. item.child.forEach(function(itemChild, indexChild) {
  116. let treeChildObj = {};
  117. treeChildObj.id = itemChild.id;
  118. treeChildObj.title = itemChild.floorName;
  119. //遍历第三级
  120. if (itemChild.child) {
  121. treeChildObj.children = [];
  122. let treeChildChildObj = {};
  123. let childChildData = itemChild.child;
  124. childChildData.forEach(function(itemChildChild, indexChildChild) {
  125. treeChildChildObj.id = itemChildChild.id;
  126. treeChildChildObj.title = itemChildChild.roomName;
  127. treeChildObj.children.push(treeChildChildObj);
  128. })
  129. }
  130. treeObj.children.push(treeChildObj);
  131. })
  132. }
  133. treeArray.push(treeObj)
  134. })
  135. dataDefaultTree = treeArray
  136. let items = '';
  137. let companyItems = '';
  138. let companyDepartmentItems = '<option value="">请选择</option>';
  139. // data.forEach(function (item, key) {
  140. // items += `<li data-id=${item.ownerId} ><span data-id=${item.ownerId} class="treeCompany"><img class="img" src="images/login.png" alt=""> ${item.ownerName} (${item.userNumber})</span>`;
  141. // if (item.child) {
  142. // let data = item.child;
  143. // items += `<ul class="child-three">`;
  144. // data.forEach(function (item, key) {
  145. // items += `<li data-id=${item.departmentId} ><span data-id=${item.departmentId} class="treeDepartment"><img class="img" src="images/login.png" alt="">${item.departmentName}</span></li>`
  146. // });
  147. // items += ` </ul>`;
  148. // }
  149. // `</li>`
  150. // companyItems += `<option value="${item.ownerId}">${item.ownerName}</option>`
  151. // if (key == 0) {
  152. // let departmentObj = item.child;
  153. // if (departmentObj) {
  154. // departmentObj.forEach(function (item, key) {
  155. // companyDepartmentItems += `<option value="${item.id}">${item.departmentName}</option>`
  156. // })
  157. // $('#departmentId').html(companyDepartmentItems);
  158. // $('#departmentIdUpdate').html(companyDepartmentItems);
  159. // }
  160. // }
  161. // })
  162. // $('#child-two').html(items);
  163. // $('#companyId').html(companyItems);
  164. // $('#companyId2').html(companyItems);
  165. // treeClickSearch();
  166. }, function(errorMsg) {
  167. alert("请求数据失败!");
  168. })
  169. }
  170. //单位下拉 ajax请求
  171. //单位下拉
  172. getNameList()
  173. function getNameList() {
  174. ajaxRequest(DEVICE_TYPE_COMPANYLIST, "POST", {}, function(result) {
  175. let data = result.RESULT;
  176. let items = '<option value="">请选择</option>';
  177. data.forEach(function(item, key) {
  178. items += `<option value="${item.owner_id}">${item.owner_name}</option>`
  179. })
  180. $('#getNameList').html(items);
  181. $('#getNameList2').html(items);
  182. }, function(errorMsg) {
  183. alert("请求数据失败!");
  184. })
  185. }
  186. //建筑下拉
  187. getBuildingList()
  188. function getBuildingList() {
  189. ajaxRequest(BUILD_TREE_LIST, "POST", {}, function(result) {
  190. let data = result.data;
  191. let items = '';
  192. data.forEach(function(item, key) {
  193. items += `<option value="${item.id}">${item.buildName}</option>`
  194. })
  195. $('#getBuildingList').append(items);
  196. $('#getBuildingList2').append(items);
  197. }, function(errorMsg) {
  198. alert("请求数据失败!");
  199. })
  200. }
  201. // 建筑与楼层
  202. linkFloor('#getBuildingList')
  203. linkFloor('#getBuildingList2')
  204. function linkFloor(element) {
  205. $(element).on('change', function() {
  206. $("#getRoomList").html("<option value=''>请选择</option>");
  207. $("#getFloorList").html("<option value=''>请选择</option>");
  208. $("#getRoomList2").html("<option value=''>请选择</option>");
  209. $("#getFloorList2").html("<option value=''>请选择</option>");
  210. //获取公司id
  211. let buildId = $(this).find('option:selected').val();
  212. getTypeListDataAjax({ "owner_xh": buildId })
  213. if ($('#getBuildingList').val() || $('#getBuildingList2').val()) {
  214. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  215. let floorItems = '<option value="">请选择</option>';
  216. let buildObj = result.data;
  217. if (buildObj) {
  218. buildObj.forEach(function(item, key) {
  219. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  220. })
  221. $('#getFloorList').html(floorItems);
  222. $('#getFloorList2').html(floorItems);
  223. } else {
  224. $('#getFloorList').html(floorItems);
  225. $('#getFloorList2').html(floorItems);
  226. }
  227. }, function(errorMsg) {
  228. alert("请求数据失败!");
  229. })
  230. }
  231. })
  232. }
  233. // 楼层与房间联动
  234. linkRoom('#getFloorList')
  235. linkRoom('#getFloorList2')
  236. function linkRoom(element) {
  237. $(element).on('change', function() {
  238. $("#getRoomList").html("<option value=''>请选择</option>");
  239. $("#getRoomList2").html("<option value=''>请选择</option>");
  240. //获取楼层id
  241. let floorName = $(this).find('option:selected').val();
  242. let buildName = $('#getBuildingList').val()
  243. if ($('#getFloorList').val() || $('#getFloorList2').val()) {
  244. getTypeListDataAjax({ "louyu": floorName })
  245. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorName }, function(result) {
  246. let roomItems = '<option value="">请选择</option>';
  247. let floorObj = result.data;
  248. floorObj.forEach(function(item, key) {
  249. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  250. })
  251. $('#getRoomList').html(roomItems);
  252. $('#getRoomList2').html(roomItems);
  253. }, function(errorMsg) {
  254. alert("请求数据失败!");
  255. })
  256. } else {
  257. getTypeListDataAjax({ "owner_xh": buildName })
  258. }
  259. })
  260. }
  261. $('#getRoomList').on('change', function() {
  262. //获取楼层id
  263. let roomId = $(this).find('option:selected').val();
  264. if ($('#getRoomList').val() || $('#getRoomList2').val()) {
  265. getTypeListDataAjax({ "rtmp": roomId })
  266. } else {
  267. let floorName = $('#getFloorList').val()
  268. getTypeListDataAjax({ "louyu": floorName })
  269. }
  270. })
  271. $('#getRoomList2').on('change', function() {
  272. //获取楼层id
  273. let roomId = $(this).find('option:selected').val();
  274. if ($('#getRoomList2').val()) {
  275. getTypeListDataAjax({ "rtmp": roomId })
  276. } else {
  277. let floorName = $('#getFloorList2').val()
  278. getTypeListDataAjax({ "louyu": floorName })
  279. }
  280. })
  281. //分页操作
  282. $('#firstPageButton').on('click', function() {
  283. pageNo = 1;
  284. getListDataAjax(getSearchParamObj(), 1);
  285. })
  286. $('#lastPageButton').on('click', function() {
  287. pageNo = totalPages;
  288. getListDataAjax(getSearchParamObj(), pageNo);
  289. })
  290. $('#prevPageButton').on('click', function() {
  291. pageNo -= 1;
  292. getListDataAjax(getSearchParamObj(), pageNo);
  293. })
  294. $('#nextPageButton').on('click', function() {
  295. pageNo += 1;
  296. getListDataAjax(getSearchParamObj(), pageNo);
  297. })
  298. /*新增 修改 关闭 弹框*/
  299. var layer = layui.layer;
  300. var layerCreateIndex = '';
  301. var layerUpdateIndex = ''
  302. layui.use('layer', function() {
  303. //新增弹框
  304. $('.add').click(function() {
  305. //重新渲染表单
  306. // $('#addDeviceCheckForm')[0].reset()
  307. // layui.use(['form'], function() {
  308. // var form = layui.form;
  309. // form.render('checkbox');
  310. // });
  311. layerCreateIndex = layer.open({
  312. type: 1,
  313. title: false,
  314. closeBtn: 0,
  315. shadeClose: true,
  316. skin: 'yourclass',
  317. area: ['1000px', '400px'],
  318. content: $(".addDataOut"),
  319. success: function() {
  320. $('.clsBtn,.cancel').click(function() {
  321. layer.close(layerCreateIndex);
  322. })
  323. }
  324. })
  325. }),
  326. //修改弹框信息
  327. $('.edit').click(function() {
  328. //获取检测对象设备列表 ajax请求
  329. getTypeListDataAjax()
  330. if (!$('.pure-table tr').has('.checked').length) {
  331. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  332. } else {
  333. let userInfo = $('.pure-table tr').find('.checked').data('user');
  334. $('.editDataOut input[name=object_name]').val(userInfo.object_name)
  335. $('.editDataOut select[name=company_code]').val(userInfo.company_code)
  336. $('.editDataOut input[name=id]').val(userInfo.id)
  337. // 建筑赋值
  338. $('.editDataOut select[name=build]').val(userInfo.build)
  339. // 楼层下拉展示及赋值
  340. if ($('#getBuildingList2').val()) {
  341. listFloor()
  342. function listFloor() {
  343. let buildId = $('#getBuildingList2').find('option:selected').val();
  344. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  345. let floorItems = '<option value="">请选择</option>';
  346. let buildObj = result.data;
  347. if (buildObj) {
  348. buildObj.forEach(function(item, key) {
  349. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  350. })
  351. $('#getFloorList2').html(floorItems);
  352. } else {
  353. $('#getFloorList2').html(floorItems);
  354. }
  355. }, function(errorMsg) {
  356. alert("请求数据失败!");
  357. })
  358. }
  359. }
  360. $('.editDataOut select[name=floor]').val(userInfo.floor)
  361. // 房间下拉展示及赋值
  362. if ($('#getFloorList2').val()) {
  363. listRoom()
  364. function listRoom() {
  365. let floorId = $('#getFloorList2').find('option:selected').val();
  366. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorId }, function(result) {
  367. let roomItems = '<option value="">请选择</option>';
  368. let floorObj = result.data;
  369. if (floorObj) {
  370. floorObj.forEach(function(item, key) {
  371. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  372. })
  373. $('#getRoomList2').html(roomItems);
  374. } else {
  375. $('#getRoomList2').html(roomItems);
  376. }
  377. }, function(errorMsg) {
  378. alert("请求数据失败!");
  379. })
  380. }
  381. }
  382. $('.editDataOut select[name=room]').val(userInfo.room)
  383. let buildName = $('#getBuildingList2').find('option:selected').val();
  384. let floorName = $('#getFloorList2').find('option:selected').val();
  385. let roomName = $('#getRoomList2').find('option:selected').val();
  386. // 根据建筑楼层房间赋值,来渲染列表
  387. getTypeListDataAjax({ "owner_xh": buildName, "louyu": floorName, "rtmp": roomName, })
  388. // 复选框赋值
  389. var checkValue = userInfo.device_code_list;
  390. if (checkValue) {
  391. checkValue.forEach(function(item, key) {
  392. if (item.device_code) {
  393. $(".editDataOut input:checkbox[value=" + item.device_code + "]").attr('checked', 'true')
  394. }
  395. })
  396. }
  397. layui.use(['form'], function() {
  398. var form = layui.form;
  399. form.render('checkbox');
  400. });
  401. layerUpdateIndex = layer.open({
  402. type: 1,
  403. title: false,
  404. closeBtn: 0,
  405. shadeClose: true,
  406. skin: 'yourclass',
  407. area: ['1000px', '400px'],
  408. content: $(".editDataOut"),
  409. success: function() {
  410. $('.clsBtn,.cancel').click(function() {
  411. layer.close(layerUpdateIndex);
  412. })
  413. }
  414. });
  415. }
  416. })
  417. //删除信息
  418. $('.delete').click(function() {
  419. if (!$('.pure-table tr').has('.checked').length) {
  420. //layer.msg('请选择一条需要修改的信息');
  421. layer.msg('请选择一条需要删除的信息!', { icon: 5 });
  422. } else {
  423. let dataId = $('.pure-table tr').find('.checked').data('id');
  424. ajaxRequest(DEVICE_CHECK_DELETE, "POST", { "ID_LIST": [{ "id": dataId }] }, function(result) {
  425. $(".pure-table tbody tr.selected").remove()
  426. let data = result
  427. layer.close(layer.layerCreateIndex);
  428. layer.msg('删除成功!', { icon: 6 });
  429. getListDataAjax()
  430. }, function(errorMsg) {
  431. alert("用户删除失败!");
  432. }, 2)
  433. }
  434. })
  435. })
  436. /* 新增发送请求 */
  437. $('#addData').click(function() {
  438. let formAllParam = $("#addDeviceCheckForm").serializeArray();
  439. let allParam = {};
  440. let deviceCodeArr = [];
  441. for (let key in formAllParam) {
  442. if (formAllParam[key].name == 'device_code') {
  443. deviceCodeArr.push(formAllParam[key].value)
  444. } else {
  445. allParam[formAllParam[key].name] = formAllParam[key].value
  446. }
  447. }
  448. allParam.device_code = deviceCodeArr
  449. //验证数据是否为空
  450. let res = validParamIsEmpty(allParam, {
  451. "object_name": "请填写对象名称",
  452. "company_code": "请选择单位",
  453. });
  454. if (res.code == -1) {
  455. alert(res.msg);
  456. return;
  457. }
  458. //验证通过 请求ajax
  459. ajaxRequest(DEVICE_CHECK_ADD, "POST", { "ID_LIST": [allParam] }, function(result) {
  460. layer.close(layerCreateIndex);
  461. layer.msg('添加成功!', { icon: 6 });
  462. getListDataAjax();
  463. }, function(errorMsg) {
  464. alert("异常错误!");
  465. }, 2)
  466. })
  467. /* 修改发送请求 */
  468. $('#updataData').click(function() {
  469. //获取表单的值 并转换成对象
  470. let formAllParam = $("#editDeviceCheckForm").serializeArray();
  471. let allParam = {};
  472. let deviceCodeArr = [];
  473. for (let key in formAllParam) {
  474. if (formAllParam[key].name == 'device_code') {
  475. deviceCodeArr.push(formAllParam[key].value)
  476. } else {
  477. allParam[formAllParam[key].name] = formAllParam[key].value
  478. }
  479. }
  480. allParam.device_code = deviceCodeArr
  481. //验证数据是否为空
  482. let res = validParamIsEmpty(allParam, {
  483. "object_name": "请填写对象名称",
  484. "company_code": "请选择单位",
  485. });
  486. if (res.code == -1) {
  487. alert(res.msg);
  488. return;
  489. }
  490. ajaxRequest(DEVICE_CHECK_UPDATE, "POST", { "ID_LIST": [allParam] }, function(result) {
  491. layer.close(layerUpdateIndex);
  492. layer.msg('修改成功!', { icon: 6 });
  493. getListDataAjax();
  494. }, function(errorMsg) {
  495. alert("数据修改失败!");
  496. }, 2)
  497. })