device-check.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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. }, function(errorMsg) {
  137. alert("请求数据失败!");
  138. })
  139. }
  140. //单位下拉 ajax请求
  141. //单位下拉
  142. getNameList()
  143. function getNameList() {
  144. ajaxRequest(DEVICE_TYPE_COMPANYLIST, "POST", {}, function(result) {
  145. let data = result.RESULT;
  146. let items = '<option value="">请选择</option>';
  147. data.forEach(function(item, key) {
  148. items += `<option value="${item.owner_id}">${item.owner_name}</option>`
  149. })
  150. $('#getNameList').html(items);
  151. $('#getNameList2').html(items);
  152. }, function(errorMsg) {
  153. alert("请求数据失败!");
  154. })
  155. }
  156. //建筑下拉
  157. getBuildingList()
  158. function getBuildingList() {
  159. ajaxRequest(BUILD_TREE_LIST, "POST", {}, function(result) {
  160. let data = result.data;
  161. let items = '';
  162. data.forEach(function(item, key) {
  163. items += `<option value="${item.id}">${item.buildName}</option>`
  164. })
  165. $('#getBuildingList').append(items);
  166. $('#getBuildingList2').append(items);
  167. }, function(errorMsg) {
  168. alert("请求数据失败!");
  169. })
  170. }
  171. // 建筑与楼层
  172. linkFloor('#getBuildingList')
  173. linkFloor('#getBuildingList2')
  174. function linkFloor(element) {
  175. $(element).on('change', function() {
  176. $("#getRoomList").html("<option value=''>请选择</option>");
  177. $("#getFloorList").html("<option value=''>请选择</option>");
  178. $("#getRoomList2").html("<option value=''>请选择</option>");
  179. $("#getFloorList2").html("<option value=''>请选择</option>");
  180. //获取公司id
  181. let buildId = $(this).find('option:selected').val();
  182. getTypeListDataAjax({ "owner_xh": buildId })
  183. if ($('#getBuildingList').val() || $('#getBuildingList2').val()) {
  184. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  185. let floorItems = '<option value="">请选择</option>';
  186. let buildObj = result.data;
  187. if (buildObj) {
  188. buildObj.forEach(function(item, key) {
  189. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  190. })
  191. $('#getFloorList').html(floorItems);
  192. $('#getFloorList2').html(floorItems);
  193. } else {
  194. $('#getFloorList').html(floorItems);
  195. $('#getFloorList2').html(floorItems);
  196. }
  197. }, function(errorMsg) {
  198. alert("请求数据失败!");
  199. })
  200. }
  201. })
  202. }
  203. // 楼层与房间联动
  204. linkRoom('#getFloorList')
  205. linkRoom('#getFloorList2')
  206. function linkRoom(element) {
  207. $(element).on('change', function() {
  208. $("#getRoomList").html("<option value=''>请选择</option>");
  209. $("#getRoomList2").html("<option value=''>请选择</option>");
  210. //获取楼层id
  211. let floorName = $(this).find('option:selected').val();
  212. let buildName = $('#getBuildingList').val()
  213. if ($('#getFloorList').val() || $('#getFloorList2').val()) {
  214. getTypeListDataAjax({ "louyu": floorName })
  215. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorName }, function(result) {
  216. let roomItems = '<option value="">请选择</option>';
  217. let floorObj = result.data;
  218. floorObj.forEach(function(item, key) {
  219. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  220. })
  221. $('#getRoomList').html(roomItems);
  222. $('#getRoomList2').html(roomItems);
  223. }, function(errorMsg) {
  224. alert("请求数据失败!");
  225. })
  226. } else {
  227. getTypeListDataAjax({ "owner_xh": buildName })
  228. }
  229. })
  230. }
  231. $('#getRoomList').on('change', function() {
  232. //获取楼层id
  233. let roomId = $(this).find('option:selected').val();
  234. if ($('#getRoomList').val() || $('#getRoomList2').val()) {
  235. getTypeListDataAjax({ "rtmp": roomId })
  236. } else {
  237. let floorName = $('#getFloorList').val()
  238. getTypeListDataAjax({ "louyu": floorName })
  239. }
  240. })
  241. $('#getRoomList2').on('change', function() {
  242. //获取楼层id
  243. let roomId = $(this).find('option:selected').val();
  244. if ($('#getRoomList2').val()) {
  245. getTypeListDataAjax({ "rtmp": roomId })
  246. } else {
  247. let floorName = $('#getFloorList2').val()
  248. getTypeListDataAjax({ "louyu": floorName })
  249. }
  250. })
  251. //分页操作
  252. $('#firstPageButton').on('click', function() {
  253. pageNo = 1;
  254. getListDataAjax(getSearchParamObj(), 1);
  255. })
  256. $('#lastPageButton').on('click', function() {
  257. pageNo = totalPages;
  258. getListDataAjax(getSearchParamObj(), pageNo);
  259. })
  260. $('#prevPageButton').on('click', function() {
  261. pageNo -= 1;
  262. getListDataAjax(getSearchParamObj(), pageNo);
  263. })
  264. $('#nextPageButton').on('click', function() {
  265. pageNo += 1;
  266. getListDataAjax(getSearchParamObj(), pageNo);
  267. })
  268. /*新增 修改 关闭 弹框*/
  269. var layer = layui.layer;
  270. var layerCreateIndex = '';
  271. var layerUpdateIndex = ''
  272. layui.use('layer', function() {
  273. //新增弹框
  274. $('.add').click(function() {
  275. getTypeListDataAjax()
  276. layerCreateIndex = layer.open({
  277. type: 1,
  278. title: false,
  279. closeBtn: 0,
  280. shadeClose: true,
  281. skin: 'yourclass',
  282. area: ['1000px', '400px'],
  283. content: $(".addDataOut"),
  284. success: function() {
  285. $('.clsBtn,.cancel').click(function() {
  286. layer.close(layerCreateIndex);
  287. })
  288. }
  289. })
  290. }),
  291. //修改弹框信息
  292. $('.edit').click(function() {
  293. //获取检测对象设备列表 ajax请求
  294. getTypeListDataAjax()
  295. if (!$('.pure-table tr').has('.checked').length) {
  296. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  297. } else {
  298. let userInfo = $('.pure-table tr').find('.checked').data('user');
  299. $('.editDataOut input[name=object_name]').val(userInfo.object_name)
  300. $('.editDataOut input[name=company_code]').val(userInfo.company_name)
  301. $('.editDataOut input[name=id]').val(userInfo.id)
  302. // 建筑赋值
  303. $('.editDataOut select[name=build]').val(userInfo.build)
  304. // 楼层下拉展示及赋值
  305. if ($('#getBuildingList2').val()) {
  306. listFloor()
  307. function listFloor() {
  308. let buildId = $('#getBuildingList2').find('option:selected').val();
  309. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  310. let floorItems = '<option value="">请选择</option>';
  311. let buildObj = result.data;
  312. if (buildObj) {
  313. buildObj.forEach(function(item, key) {
  314. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  315. })
  316. $('#getFloorList2').html(floorItems);
  317. } else {
  318. $('#getFloorList2').html(floorItems);
  319. }
  320. }, function(errorMsg) {
  321. alert("请求数据失败!");
  322. })
  323. }
  324. }
  325. $('.editDataOut select[name=floor]').val(userInfo.floor)
  326. // 房间下拉展示及赋值
  327. if ($('#getFloorList2').val()) {
  328. listRoom()
  329. function listRoom() {
  330. let floorId = $('#getFloorList2').find('option:selected').val();
  331. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorId }, function(result) {
  332. let roomItems = '<option value="">请选择</option>';
  333. let floorObj = result.data;
  334. if (floorObj) {
  335. floorObj.forEach(function(item, key) {
  336. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  337. })
  338. $('#getRoomList2').html(roomItems);
  339. } else {
  340. $('#getRoomList2').html(roomItems);
  341. }
  342. }, function(errorMsg) {
  343. alert("请求数据失败!");
  344. })
  345. }
  346. }
  347. $('.editDataOut select[name=room]').val(userInfo.room)
  348. let buildName = $('#getBuildingList2').find('option:selected').val();
  349. let floorName = $('#getFloorList2').find('option:selected').val();
  350. let roomName = $('#getRoomList2').find('option:selected').val();
  351. // 根据建筑楼层房间赋值,来渲染列表
  352. getTypeListDataAjax({ "owner_xh": buildName, "louyu": floorName, "rtmp": roomName, })
  353. // 复选框赋值
  354. var checkValue = userInfo.device_code_list;
  355. if (checkValue) {
  356. checkValue.forEach(function(item, key) {
  357. if (item.device_code) {
  358. $(".editDataOut input:checkbox[value=" + item.device_code + "]").attr('checked', 'true')
  359. }
  360. })
  361. }
  362. layui.use(['form'], function() {
  363. var form = layui.form;
  364. form.render('checkbox');
  365. });
  366. layerUpdateIndex = layer.open({
  367. type: 1,
  368. title: false,
  369. closeBtn: 0,
  370. shadeClose: true,
  371. skin: 'yourclass',
  372. area: ['1000px', '400px'],
  373. content: $(".editDataOut"),
  374. success: function() {
  375. $('.clsBtn,.cancel').click(function() {
  376. layer.close(layerUpdateIndex);
  377. })
  378. }
  379. });
  380. }
  381. })
  382. //删除信息
  383. $('.delete').click(function() {
  384. if (!$('.pure-table tr').has('.checked').length) {
  385. //layer.msg('请选择一条需要修改的信息');
  386. layer.msg('请选择一条需要删除的信息!', { icon: 5 });
  387. } else {
  388. let dataId = $('.pure-table tr').find('.checked').data('id');
  389. ajaxRequest(DEVICE_CHECK_DELETE, "POST", { "ID_LIST": [{ "id": dataId }] }, function(result) {
  390. $(".pure-table tbody tr.selected").remove()
  391. let data = result
  392. layer.close(layer.layerCreateIndex);
  393. layer.msg('删除成功!', { icon: 6 });
  394. getListDataAjax()
  395. }, function(errorMsg) {
  396. alert("用户删除失败!");
  397. }, 2)
  398. }
  399. })
  400. })
  401. /* 新增发送请求 */
  402. $('#addData').click(function() {
  403. let formAllParam = $("#addDeviceCheckForm").serializeArray();
  404. console.log('formAllParam')
  405. console.log(formAllParam)
  406. let allParam = {};
  407. let deviceCodeArr = [];
  408. for (let key in formAllParam) {
  409. if (formAllParam[key].name == 'device_code') {
  410. deviceCodeArr.push(formAllParam[key].value)
  411. } else {
  412. allParam[formAllParam[key].name] = formAllParam[key].value
  413. }
  414. }
  415. allParam.device_code = deviceCodeArr
  416. //验证数据是否为空
  417. let res = validParamIsEmpty(allParam, {
  418. "object_name": "请填写对象名称",
  419. "company_code": "请选择单位",
  420. });
  421. if (res.code == -1) {
  422. alert(res.msg);
  423. return;
  424. }
  425. //验证通过 请求ajax
  426. ajaxRequest(DEVICE_CHECK_ADD, "POST", { "ID_LIST": [allParam] }, function(result) {
  427. layer.close(layerCreateIndex);
  428. layer.msg('添加成功!', { icon: 6 });
  429. getListDataAjax();
  430. $('#addDeviceCheckForm')[0].reset();
  431. console.log('formAllParam2')
  432. console.log($("#addDeviceCheckForm").serializeArray())
  433. },
  434. function(errorMsg) {
  435. alert("异常错误!");
  436. }, 2)
  437. })
  438. /* 修改发送请求 */
  439. $('#updataData').click(function() {
  440. //获取表单的值 并转换成对象
  441. let formAllParam = $("#editDeviceCheckForm").serializeArray();
  442. let allParam = {};
  443. let deviceCodeArr = [];
  444. for (let key in formAllParam) {
  445. if (formAllParam[key].name == 'device_code') {
  446. deviceCodeArr.push(formAllParam[key].value)
  447. } else {
  448. allParam[formAllParam[key].name] = formAllParam[key].value
  449. }
  450. }
  451. allParam.device_code = deviceCodeArr
  452. //验证数据是否为空
  453. let res = validParamIsEmpty(allParam, {
  454. "object_name": "请填写对象名称",
  455. "company_code": "请选择单位",
  456. });
  457. if (res.code == -1) {
  458. alert(res.msg);
  459. return;
  460. }
  461. ajaxRequest(DEVICE_CHECK_UPDATE, "POST", { "ID_LIST": [allParam] }, function(result) {
  462. layer.close(layerUpdateIndex);
  463. layer.msg('修改成功!', { icon: 6 });
  464. getListDataAjax();
  465. }, function(errorMsg) {
  466. alert("数据修改失败!");
  467. }, 2)
  468. })