device-list.js 18 KB

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