device-list.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. var pageNo = 1;
  2. var totalPages = 0;
  3. var param1 = '';
  4. var param2 = '';
  5. var param3 = '';
  6. //设备列表
  7. getListDataAjax();
  8. //获取设备列表 ajax请求
  9. function getListDataAjax(queryParam = {}, pageNo = 1) {
  10. queryParam.pageNo = pageNo;
  11. // queryParam.pageSize = 4;
  12. ajaxRequest(DEVICE_LIST_SEARCH, "POST", queryParam, function(result) {
  13. let data = result.pageList;
  14. let items = '';
  15. if (result.totalCount > 0) {
  16. data.forEach(function(item, key) {
  17. let transmissionModel = "";
  18. if (item.transmission_model == 1) {
  19. transmissionModel = "NB-IOT"
  20. } else if (item.transmission_model == 2) {
  21. transmissionModel = "Lora-IOT"
  22. } else {
  23. transmissionModel = "2G/4G/5G"
  24. }
  25. items += "<tr>" +
  26. "<td class='status' data-user='" + JSON.stringify(item) + "' data-ownercode='" + item.ownerCode + "'></td>" +
  27. "<td>" + item.ownerCode + "</td>" +
  28. "<td>" + item.ownerName + "</td>" +
  29. "<td>" + item.dwtype + "</td>" +
  30. "<td>" + item.installMan + "</td>" +
  31. "<td>" + getFormatDate(item.installTime) + "</td>" +
  32. "</tr>"
  33. })
  34. }
  35. $('#dataList').html(items);
  36. totalPages = result.totalPages;
  37. $('#totalPage').html(totalPages); //总共多少页
  38. $('#dataTotal').html(result.totalCount); //总共多少条数据
  39. $('#currentPage').val(pageNo); //当前页面
  40. let pageFrom = (pageNo - 1) * result.pageSize + 1; //开始
  41. let pageTo = result.pageNo * result.pageSize; //结束
  42. pageTo = pageTo > result.totalCount ? result.totalCount : pageTo;
  43. $('#pageFrom').html(pageFrom);
  44. $('#pageTo').html(pageTo);
  45. // 无数据时
  46. if (!data.length) {
  47. $('.pager.has-data').hide()
  48. $('.pager.no-data').show()
  49. } else {
  50. $('.pager.has-data').show()
  51. $('.pager.no-data').hide()
  52. }
  53. if (pageNo < totalPages) {
  54. $('#nextPageButton,#lastPageButton').removeClass('disabled');
  55. } else {
  56. $('#nextPageButton,#lastPageButton').addClass('disabled');
  57. }
  58. if (pageNo === 1) {
  59. $('#firstPageButton,#prevPageButton').addClass('disabled');
  60. } else {
  61. $('#firstPageButton,#prevPageButton').removeClass('disabled');
  62. }
  63. }, function(errorMsg) {
  64. alert("请求数据失败!");
  65. })
  66. }
  67. //按钮搜索
  68. $('#buttonClick').on('click', function() {
  69. pageNo = 1;
  70. getListDataAjax(getSearchParamObj());
  71. param1 = $('#ownerName').val()
  72. param2 = $('#startTime').val()
  73. param3 = $('#endTime').val()
  74. })
  75. //拼接搜索条件
  76. function getSearchParamObj() {
  77. let queryParam = {};
  78. let ownerName = $('#ownerName').val();
  79. let startTime = $('#startTime').val()
  80. let endTime = $('#endTime').val()
  81. queryParam.ownerName = ownerName;
  82. queryParam.startTime = startTime;
  83. queryParam.endTime = endTime;
  84. return queryParam;
  85. }
  86. //重置表单
  87. $('.reset').click(resetForm);
  88. //分页刷新按钮
  89. $('.pg-refresh').click(resetForm)
  90. //重置表单
  91. function resetForm() {
  92. pageNo = 1;
  93. $("#ownerName").val("");
  94. $("#startTime").val("");
  95. $("#endTime").val("");
  96. getListDataAjax(getSearchParamObj());
  97. param1 = $('#ownerName').val()
  98. param2 = $('#startTime').val()
  99. param3 = $('#endTime').val()
  100. }
  101. //分页操作
  102. $('#firstPageButton').on('click', function() {
  103. pageNo = 1;
  104. getListDataAjax(getSearchParamObj(), 1);
  105. })
  106. $('#lastPageButton').on('click', function() {
  107. pageNo = totalPages;
  108. getListDataAjax(getSearchParamObj(), pageNo);
  109. })
  110. $('#prevPageButton').on('click', function() {
  111. pageNo -= 1;
  112. getListDataAjax(getSearchParamObj(), pageNo);
  113. })
  114. $('#nextPageButton').on('click', function() {
  115. pageNo += 1;
  116. getListDataAjax(getSearchParamObj(), pageNo);
  117. })
  118. //单位下拉
  119. getCompanyList()
  120. function getCompanyList() {
  121. ajaxRequest(COMPANY_LIST, "POST", {}, function(result) {
  122. let data = result.data;
  123. let items = '';
  124. data.forEach(function(item, key) {
  125. items += `<option value="${item.ownerId}">${item.ownerName}</option>`
  126. })
  127. $('#getCompanyList').append(items);
  128. $('#getCompanyList2').append(items);
  129. }, function(errorMsg) {
  130. alert("请求数据失败!");
  131. })
  132. }
  133. //类型下拉
  134. getTypeList()
  135. function getTypeList() {
  136. ajaxRequest(DEVICE_TYPE_EXPORT, "POST", {}, function(result) {
  137. let data = result.RESULT.pageList;
  138. let items = '';
  139. data.forEach(function(item, key) {
  140. items += `<option value="${item.id}">${item.type_name}</option>`
  141. })
  142. $('#getTypeList').append(items);
  143. $('#getTypeList2').append(items);
  144. }, function(errorMsg) {
  145. alert("请求数据失败!");
  146. })
  147. }
  148. //建筑下拉
  149. getBuildingList()
  150. function getBuildingList() {
  151. ajaxRequest(BUILD_TREE_LIST, "POST", {}, function(result) {
  152. let data = result.data;
  153. let items = '';
  154. data.forEach(function(item, key) {
  155. items += `<option value="${item.id}">${item.buildName}</option>`
  156. })
  157. $('#getBuildingList').append(items);
  158. $('#getBuildingList2').append(items);
  159. }, function(errorMsg) {
  160. alert("请求数据失败!");
  161. })
  162. }
  163. // 建筑与楼层
  164. linkFloor('#getBuildingList')
  165. linkFloor('#getBuildingList2')
  166. function linkFloor(element) {
  167. $(element).on('change', function() {
  168. //获取公司id
  169. let buildId = $(this).find('option:selected').val();
  170. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  171. let floorItems = '<option value="">请选择</option>';
  172. let buildObj = result.data;
  173. if (buildObj) {
  174. buildObj.forEach(function(item, key) {
  175. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  176. })
  177. $('#getFloorList').html(floorItems);
  178. $('#getFloorList2').html(floorItems);
  179. } else {
  180. $('#getFloorList').html(floorItems);
  181. $('#getFloorList2').html(floorItems);
  182. }
  183. }, function(errorMsg) {
  184. alert("请求数据失败!");
  185. })
  186. })
  187. }
  188. // 楼层与房间联动
  189. linkRoom('#getFloorList')
  190. linkRoom('#getFloorList2')
  191. function linkRoom(element) {
  192. $(element).on('change', function() {
  193. //获取楼层id
  194. let floorName = $(this).find('option:selected').val();
  195. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorName }, function(result) {
  196. let roomItems = '<option value="">请选择</option>';
  197. let floorObj = result.data;
  198. floorObj.forEach(function(item, key) {
  199. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  200. })
  201. $('#getRoomList').html(roomItems);
  202. }, function(errorMsg) {
  203. alert("请求数据失败!");
  204. })
  205. })
  206. }
  207. /*新增 修改 关闭 弹框*/
  208. var layer = layui.layer;
  209. var layerCreateIndex = '';
  210. var layerUpdateIndex = ''
  211. layui.use('layer', function() {
  212. //新增弹框
  213. $('.add').click(function() {
  214. layerCreateIndex = layer.open({
  215. type: 1,
  216. title: false,
  217. closeBtn: 0,
  218. shadeClose: true,
  219. skin: 'yourclass',
  220. area: ['1000px', '400px'],
  221. content: $(".addDeviceListOut"),
  222. success: function() {
  223. $('.clsBtn,.cancel').click(function() {
  224. layer.close(layerCreateIndex);
  225. })
  226. }
  227. })
  228. }),
  229. //修改弹框信息
  230. $('.edit').click(function() {
  231. if (!$('.pure-table tr').has('.checked').length) {
  232. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  233. } else {
  234. let userInfo = $('.pure-table tr').find('.checked').data('user');
  235. $('.editDeviceListOut input[name=ownerCode]').val(userInfo.ownerCode)
  236. $('.editDeviceListOut input[name=ownerName]').val(userInfo.ownerName)
  237. $('.editDeviceListOut input[name=unitinfo').val(userInfo.unitinfo)
  238. // 建筑赋值
  239. $('.editDeviceListOut select[name=ownerXh]').val(userInfo.ownerXh)
  240. // 楼层下拉展示及赋值
  241. if ($('#getBuildingList2').val()) {
  242. listFloor()
  243. function listFloor() {
  244. let buildId = $('#getBuildingList2').find('option:selected').val();
  245. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  246. let floorItems = '<option value="">请选择</option>';
  247. let buildObj = result.data;
  248. if (buildObj) {
  249. buildObj.forEach(function(item, key) {
  250. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  251. })
  252. $('#getFloorList2').html(floorItems);
  253. } else {
  254. $('#getFloorList2').html(floorItems);
  255. }
  256. }, function(errorMsg) {
  257. alert("请求数据失败!");
  258. })
  259. }
  260. }
  261. $('.editDeviceListOut select[name=louyu]').val(userInfo.louyu)
  262. // 房间下拉展示及赋值
  263. if ($('#getFloorList2').val()) {
  264. listRoom()
  265. function listRoom() {
  266. let floorId = $('#getFloorList2').find('option:selected').val();
  267. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorId }, function(result) {
  268. let roomItems = '<option value="">请选择</option>';
  269. let floorObj = result.data;
  270. if (floorObj) {
  271. floorObj.forEach(function(item, key) {
  272. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  273. })
  274. $('#getRoomList2').html(roomItems);
  275. } else {
  276. $('#getRoomList2').html(roomItems);
  277. }
  278. }, function(errorMsg) {
  279. alert("请求数据失败!");
  280. })
  281. }
  282. }
  283. $('.editDeviceListOut select[name=rtmp]').val(userInfo.rtmp)
  284. $('.editDeviceListOut input[name=address').val(userInfo.address)
  285. $('.editDeviceListOut input[name=posistion').val(userInfo.posistion)
  286. $('.editDeviceListOut select[name=dwtype]').val(userInfo.dwtypeCode)
  287. $('.editDeviceListOut select[name=company]').val(userInfo.company)
  288. $('.editDeviceListOut input[name=transferType').val(userInfo.transferType)
  289. $('.editDeviceListOut input[name=hls').val(userInfo.hls)
  290. $('.editDeviceListOut input[name=ownerCode').val(userInfo.ownerCode)
  291. // userInfo.addr1 = "上海";
  292. $('.editDeviceListOut select[name=addr1]').val(userInfo.addr1)
  293. provinceText = userInfo.addr1;
  294. $.each(provinceList, function(i, item) {
  295. if (provinceText == item.name) {
  296. cityItem = i;
  297. return cityItem
  298. }
  299. });
  300. removeEle(city);
  301. removeEle(town);
  302. $.each(provinceList[cityItem].cityList, function(i, item) {
  303. addEle(city, item.name)
  304. })
  305. // userInfo.addr2 = "市辖区"
  306. $('.editDeviceListOut select[name=addr2]').val(userInfo.addr2)
  307. cityText = userInfo.addr2;
  308. removeEle(town);
  309. $.each(provinceList, function(i, item) {
  310. if (provinceText == item.name) {
  311. cityItem = i;
  312. return cityItem
  313. }
  314. });
  315. $.each(provinceList[cityItem].cityList, function(i, item) {
  316. if (cityText == item.name) {
  317. for (var n = 0; n < item.areaList.length; n++) {
  318. addEle(town, item.areaList[n])
  319. }
  320. }
  321. });
  322. // userInfo.addr3 = "黄浦区"
  323. $('.editDeviceListOut select[name=addr3]').val(userInfo.addr3)
  324. layerUpdateIndex = layer.open({
  325. type: 1,
  326. title: false,
  327. closeBtn: 0,
  328. shadeClose: true,
  329. skin: 'yourclass',
  330. area: ['1000px', '400px'],
  331. content: $(".editDeviceListOut"),
  332. success: function() {
  333. $('.clsBtn,.cancel').click(function() {
  334. layer.close(layerUpdateIndex);
  335. })
  336. }
  337. });
  338. }
  339. })
  340. //删除信息
  341. $('.delete').click(function() {
  342. if (!$('.pure-table tr').has('.checked').length) {
  343. layer.msg('请选择一条需要删除的信息!', { icon: 5 });
  344. } else {
  345. let ownerCode = $('.pure-table tr').find('.checked').data('ownercode');
  346. ajaxRequest(DEVICE_LIST_DELETE, "POST", { "ownerCode": ownerCode }, function(result) {
  347. $(".pure-table tbody tr.selected").remove()
  348. layer.close(layer.layerCreateIndex);
  349. layer.msg('删除成功!', { icon: 6 });
  350. getListDataAjax()
  351. }, function(errorMsg) {
  352. alert("用户删除失败!");
  353. })
  354. }
  355. })
  356. })
  357. /* 新增发送请求 */
  358. $('#addData').click(function() {
  359. //获取表单的值 并转换成对象
  360. let allParam = serializeArrayToObj($("#addDataForm").serializeArray());
  361. if (!allParam.ownerCode) {
  362. alert('请输入设备编号');
  363. return;
  364. } else {
  365. let pattern = /(?!^\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{1,23}/
  366. if (!pattern.test(allParam.ownerCode)) {
  367. alert('设备编号只能输入数字或字母!');
  368. return false;
  369. }
  370. }
  371. //验证数据是否为空
  372. let res = validParamIsEmpty(allParam, {
  373. // "ownerCode": "请输入设备编号",
  374. "ownerName": "请输入设备名称",
  375. "unitinfo": "填写安装位置",
  376. "ownerXh": "请选择建筑",
  377. // "louyu": "请选择楼层",
  378. // "rtmp": "请选择房间",
  379. "addr1": "请选择省份",
  380. "addr2": "请选择所属市区",
  381. "addr3": "请选择所属区、县",
  382. "address": "请输入详细地址",
  383. "posistion": "请填写GIS坐标",
  384. "dwtype": "请选择设备类型",
  385. "company": "请选择所属单位",
  386. "transferType": "请输入传输方式",
  387. });
  388. if (res.code == -1) {
  389. alert(res.msg);
  390. return;
  391. }
  392. //验证通过 请求ajax
  393. ajaxRequest(DEVICE_LIST_ADD, "POST", allParam, function(result) {
  394. layer.close(layerCreateIndex);
  395. layer.msg('添加成功!', { icon: 6 });
  396. getListDataAjax();
  397. $('#addDataForm')[0].reset();
  398. }, function(errorMsg) {
  399. alert("异常错误!");
  400. })
  401. })
  402. /* 修改发送请求 */
  403. $('#dataUpdate').click(function() {
  404. //获取表单的值 并转换成对象
  405. let allParam = serializeArrayToObj($("#updateForm").serializeArray());
  406. //验证数据是否为空
  407. let res = validParamIsEmpty(allParam, {
  408. "ownerCode": "请输入设备编号",
  409. "ownerName": "请输入设备名称",
  410. "unitinfo": "填写安装位置",
  411. "ownerXh": "请选择建筑",
  412. // "louyu": "请选择楼层",
  413. // "rtmp": "请选择房间",
  414. "addr1": "请选择省份",
  415. "addr2": "请选择所属市区",
  416. "addr3": "请选择所属区、县",
  417. "address": "请输入详细地址",
  418. "posistion": "请填写GIS坐标",
  419. "dwtype": "请选择设备类型",
  420. "company": "请选择所属单位",
  421. "transferType": "请输入传输方式",
  422. });
  423. if (res.code == -1) {
  424. alert(res.msg);
  425. return;
  426. }
  427. ajaxRequest(DEVICE_LIST_UPDATE, "POST", allParam, function(result) {
  428. if (result.flag) {
  429. layer.msg('修改成功!', { icon: 6 });
  430. } else {
  431. //服务端返回报错
  432. alert(result.msg);
  433. }
  434. layer.close(layerUpdateIndex);
  435. getListDataAjax();
  436. }, function(errorMsg) {
  437. alert("数据修改失败!");
  438. })
  439. })
  440. // 导出 start
  441. $('.export').click(function() {
  442. getDataExport({ "ownerName": param1, "startTime": param2, "endTime": param3 })
  443. })
  444. function getDataExport(queryParam = {}) {
  445. ajaxRequest(DEVICE_LIST_EXPORT, "POST", queryParam, function(result) {
  446. console.log(result)
  447. let data = result.pageList;
  448. let newData = [];
  449. if (data) {
  450. data.forEach(function(item, index) {
  451. var installTime = item.installTime ? getFormatDate(item.installTime) : '';
  452. newData.push({ ownerCode: item.ownerCode, ownerName: item.ownerName, dwtype: item.dwtype, installMan: item.installMan, installTime: installTime })
  453. });
  454. }
  455. let str = '<tr style="text-align:center"><th>设备编号</th><th>设备名称</th><th>设备类型</th><th>添加人</th><th>添加时间</th></tr>';
  456. // 循环遍历,每行加入tr标签,每个单元格加td标签
  457. for (let i = 0; i < newData.length; i++) {
  458. str += '<tr style="text-align:center">';
  459. for (const key in newData[i]) {
  460. // 增加\t为了不让表格显示科学计数法或者其他格式
  461. str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
  462. }
  463. str += '</tr>';
  464. }
  465. downExcel(str, '设备列表数据表')
  466. }, function(errorMsg) {
  467. alert("请求数据失败!");
  468. })
  469. }
  470. // 导出 end