device-check.js 18 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. skin: 'yourclass',
  283. area: ['1000px', '400px'],
  284. content: $(".addDataOut"),
  285. success: function() {
  286. $('.clsBtn,.cancel').click(function() {
  287. layer.close(layerCreateIndex);
  288. })
  289. }
  290. })
  291. }),
  292. //修改弹框信息
  293. $('.edit').click(function() {
  294. //获取检测对象设备列表 ajax请求
  295. getTypeListDataAjax()
  296. if (!$('.pure-table tr').has('.checked').length) {
  297. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  298. } else {
  299. let userInfo = $('.pure-table tr').find('.checked').data('user');
  300. $('.editDataOut input[name=object_name]').val(userInfo.object_name)
  301. $('.editDataOut input[name=company_code]').val(userInfo.company_name)
  302. $('.editDataOut input[name=id]').val(userInfo.id)
  303. // 建筑赋值
  304. $('.editDataOut select[name=build]').val(userInfo.build)
  305. // 楼层下拉展示及赋值
  306. if ($('#getBuildingList2').val()) {
  307. listFloor()
  308. function listFloor() {
  309. let buildId = $('#getBuildingList2').find('option:selected').val();
  310. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  311. let floorItems = '<option value="">请选择</option>';
  312. let buildObj = result.data;
  313. if (buildObj) {
  314. buildObj.forEach(function(item, key) {
  315. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  316. })
  317. $('#getFloorList2').html(floorItems);
  318. } else {
  319. $('#getFloorList2').html(floorItems);
  320. }
  321. }, function(errorMsg) {
  322. alert("请求数据失败!");
  323. })
  324. }
  325. }
  326. $('.editDataOut select[name=floor]').val(userInfo.floor)
  327. // 房间下拉展示及赋值
  328. if ($('#getFloorList2').val()) {
  329. listRoom()
  330. function listRoom() {
  331. let floorId = $('#getFloorList2').find('option:selected').val();
  332. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorId }, function(result) {
  333. let roomItems = '<option value="">请选择</option>';
  334. let floorObj = result.data;
  335. if (floorObj) {
  336. floorObj.forEach(function(item, key) {
  337. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  338. })
  339. $('#getRoomList2').html(roomItems);
  340. } else {
  341. $('#getRoomList2').html(roomItems);
  342. }
  343. }, function(errorMsg) {
  344. alert("请求数据失败!");
  345. })
  346. }
  347. }
  348. $('.editDataOut select[name=room]').val(userInfo.room)
  349. let buildName = $('#getBuildingList2').find('option:selected').val();
  350. let floorName = $('#getFloorList2').find('option:selected').val();
  351. let roomName = $('#getRoomList2').find('option:selected').val();
  352. // 根据建筑楼层房间赋值,来渲染列表
  353. getTypeListDataAjax({ "owner_xh": buildName, "louyu": floorName, "rtmp": roomName, })
  354. // 复选框赋值
  355. var checkValue = userInfo.device_code_list;
  356. if (checkValue) {
  357. checkValue.forEach(function(item, key) {
  358. if (item.device_code) {
  359. $(".editDataOut input:checkbox[value=" + item.device_code + "]").attr('checked', 'true')
  360. }
  361. })
  362. }
  363. layui.use(['form'], function() {
  364. var form = layui.form;
  365. form.render('checkbox');
  366. });
  367. layerUpdateIndex = layer.open({
  368. type: 1,
  369. title: false,
  370. closeBtn: 0,
  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. })