device-check.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. layerCreateIndex = layer.open({
  276. type: 1,
  277. title: false,
  278. closeBtn: 0,
  279. shadeClose: true,
  280. skin: 'yourclass',
  281. area: ['1000px', '400px'],
  282. content: $(".addDataOut"),
  283. success: function() {
  284. $('.clsBtn,.cancel').click(function() {
  285. layer.close(layerCreateIndex);
  286. })
  287. }
  288. })
  289. }),
  290. //修改弹框信息
  291. $('.edit').click(function() {
  292. //获取检测对象设备列表 ajax请求
  293. getTypeListDataAjax()
  294. if (!$('.pure-table tr').has('.checked').length) {
  295. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  296. } else {
  297. let userInfo = $('.pure-table tr').find('.checked').data('user');
  298. $('.editDataOut input[name=object_name]').val(userInfo.object_name)
  299. $('.editDataOut input[name=company_code]').val(userInfo.company_name)
  300. $('.editDataOut input[name=id]').val(userInfo.id)
  301. // 建筑赋值
  302. $('.editDataOut select[name=build]').val(userInfo.build)
  303. // 楼层下拉展示及赋值
  304. if ($('#getBuildingList2').val()) {
  305. listFloor()
  306. function listFloor() {
  307. let buildId = $('#getBuildingList2').find('option:selected').val();
  308. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  309. let floorItems = '<option value="">请选择</option>';
  310. let buildObj = result.data;
  311. if (buildObj) {
  312. buildObj.forEach(function(item, key) {
  313. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  314. })
  315. $('#getFloorList2').html(floorItems);
  316. } else {
  317. $('#getFloorList2').html(floorItems);
  318. }
  319. }, function(errorMsg) {
  320. alert("请求数据失败!");
  321. })
  322. }
  323. }
  324. $('.editDataOut select[name=floor]').val(userInfo.floor)
  325. // 房间下拉展示及赋值
  326. if ($('#getFloorList2').val()) {
  327. listRoom()
  328. function listRoom() {
  329. let floorId = $('#getFloorList2').find('option:selected').val();
  330. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorId }, function(result) {
  331. let roomItems = '<option value="">请选择</option>';
  332. let floorObj = result.data;
  333. if (floorObj) {
  334. floorObj.forEach(function(item, key) {
  335. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  336. })
  337. $('#getRoomList2').html(roomItems);
  338. } else {
  339. $('#getRoomList2').html(roomItems);
  340. }
  341. }, function(errorMsg) {
  342. alert("请求数据失败!");
  343. })
  344. }
  345. }
  346. $('.editDataOut select[name=room]').val(userInfo.room)
  347. let buildName = $('#getBuildingList2').find('option:selected').val();
  348. let floorName = $('#getFloorList2').find('option:selected').val();
  349. let roomName = $('#getRoomList2').find('option:selected').val();
  350. // 根据建筑楼层房间赋值,来渲染列表
  351. getTypeListDataAjax({ "owner_xh": buildName, "louyu": floorName, "rtmp": roomName, })
  352. // 复选框赋值
  353. var checkValue = userInfo.device_code_list;
  354. if (checkValue) {
  355. checkValue.forEach(function(item, key) {
  356. if (item.device_code) {
  357. $(".editDataOut input:checkbox[value=" + item.device_code + "]").attr('checked', 'true')
  358. }
  359. })
  360. }
  361. layui.use(['form'], function() {
  362. var form = layui.form;
  363. form.render('checkbox');
  364. });
  365. layerUpdateIndex = layer.open({
  366. type: 1,
  367. title: false,
  368. closeBtn: 0,
  369. shadeClose: true,
  370. skin: 'yourclass',
  371. area: ['1000px', '400px'],
  372. content: $(".editDataOut"),
  373. success: function() {
  374. $('.clsBtn,.cancel').click(function() {
  375. layer.close(layerUpdateIndex);
  376. })
  377. }
  378. });
  379. }
  380. })
  381. //删除信息
  382. $('.delete').click(function() {
  383. if (!$('.pure-table tr').has('.checked').length) {
  384. //layer.msg('请选择一条需要修改的信息');
  385. layer.msg('请选择一条需要删除的信息!', { icon: 5 });
  386. } else {
  387. let dataId = $('.pure-table tr').find('.checked').data('id');
  388. ajaxRequest(DEVICE_CHECK_DELETE, "POST", { "ID_LIST": [{ "id": dataId }] }, function(result) {
  389. $(".pure-table tbody tr.selected").remove()
  390. let data = result
  391. layer.close(layer.layerCreateIndex);
  392. layer.msg('删除成功!', { icon: 6 });
  393. getListDataAjax()
  394. }, function(errorMsg) {
  395. alert("用户删除失败!");
  396. }, 2)
  397. }
  398. })
  399. })
  400. /* 新增发送请求 */
  401. $('#addData').click(function() {
  402. let formAllParam = $("#addDeviceCheckForm").serializeArray();
  403. console.log('formAllParam')
  404. console.log(formAllParam)
  405. let allParam = {};
  406. let deviceCodeArr = [];
  407. for (let key in formAllParam) {
  408. if (formAllParam[key].name == 'device_code') {
  409. deviceCodeArr.push(formAllParam[key].value)
  410. } else {
  411. allParam[formAllParam[key].name] = formAllParam[key].value
  412. }
  413. }
  414. allParam.device_code = deviceCodeArr
  415. //验证数据是否为空
  416. let res = validParamIsEmpty(allParam, {
  417. "object_name": "请填写对象名称",
  418. "company_code": "请选择单位",
  419. });
  420. if (res.code == -1) {
  421. alert(res.msg);
  422. return;
  423. }
  424. //验证通过 请求ajax
  425. ajaxRequest(DEVICE_CHECK_ADD, "POST", { "ID_LIST": [allParam] }, function(result) {
  426. layer.close(layerCreateIndex);
  427. layer.msg('添加成功!', { icon: 6 });
  428. getListDataAjax();
  429. $('#addDeviceCheckForm')[0].reset();
  430. getTypeListDataAjax()
  431. // allParam.device_code = []
  432. console.log('formAllParam2')
  433. console.log($("#addDeviceCheckForm").serializeArray())
  434. },
  435. function(errorMsg) {
  436. alert("异常错误!");
  437. }, 2)
  438. })
  439. /* 修改发送请求 */
  440. $('#updataData').click(function() {
  441. //获取表单的值 并转换成对象
  442. let formAllParam = $("#editDeviceCheckForm").serializeArray();
  443. let allParam = {};
  444. let deviceCodeArr = [];
  445. for (let key in formAllParam) {
  446. if (formAllParam[key].name == 'device_code') {
  447. deviceCodeArr.push(formAllParam[key].value)
  448. } else {
  449. allParam[formAllParam[key].name] = formAllParam[key].value
  450. }
  451. }
  452. allParam.device_code = deviceCodeArr
  453. //验证数据是否为空
  454. let res = validParamIsEmpty(allParam, {
  455. "object_name": "请填写对象名称",
  456. "company_code": "请选择单位",
  457. });
  458. if (res.code == -1) {
  459. alert(res.msg);
  460. return;
  461. }
  462. ajaxRequest(DEVICE_CHECK_UPDATE, "POST", { "ID_LIST": [allParam] }, function(result) {
  463. layer.close(layerUpdateIndex);
  464. layer.msg('修改成功!', { icon: 6 });
  465. getListDataAjax();
  466. }, function(errorMsg) {
  467. alert("数据修改失败!");
  468. }, 2)
  469. })