device-check.js 19 KB

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