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. skin: 'yourclass',
  219. area: ['1000px', '400px'],
  220. content: $(".addDeviceListOut"),
  221. success: function() {
  222. $('.clsBtn,.cancel').click(function() {
  223. layer.close(layerCreateIndex);
  224. })
  225. }
  226. })
  227. }),
  228. //修改弹框信息
  229. $('.edit').click(function() {
  230. if (!$('.pure-table tr').has('.checked').length) {
  231. layer.msg('请选择一条需要修改的信息!', { icon: 5 });
  232. } else {
  233. let userInfo = $('.pure-table tr').find('.checked').data('user');
  234. $('.editDeviceListOut input[name=ownerCode]').val(userInfo.ownerCode)
  235. $('.editDeviceListOut input[name=ownerName]').val(userInfo.ownerName)
  236. $('.editDeviceListOut input[name=unitinfo').val(userInfo.unitinfo)
  237. // 建筑赋值
  238. $('.editDeviceListOut select[name=ownerXh]').val(userInfo.ownerXh)
  239. // 楼层下拉展示及赋值
  240. if ($('#getBuildingList2').val()) {
  241. listFloor()
  242. function listFloor() {
  243. let buildId = $('#getBuildingList2').find('option:selected').val();
  244. ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
  245. let floorItems = '<option value="">请选择</option>';
  246. let buildObj = result.data;
  247. if (buildObj) {
  248. buildObj.forEach(function(item, key) {
  249. floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
  250. })
  251. $('#getFloorList2').html(floorItems);
  252. } else {
  253. $('#getFloorList2').html(floorItems);
  254. }
  255. }, function(errorMsg) {
  256. alert("请求数据失败!");
  257. })
  258. }
  259. }
  260. $('.editDeviceListOut select[name=louyu]').val(userInfo.louyu)
  261. // 房间下拉展示及赋值
  262. if ($('#getFloorList2').val()) {
  263. listRoom()
  264. function listRoom() {
  265. let floorId = $('#getFloorList2').find('option:selected').val();
  266. ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorId }, function(result) {
  267. let roomItems = '<option value="">请选择</option>';
  268. let floorObj = result.data;
  269. if (floorObj) {
  270. floorObj.forEach(function(item, key) {
  271. roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
  272. })
  273. $('#getRoomList2').html(roomItems);
  274. } else {
  275. $('#getRoomList2').html(roomItems);
  276. }
  277. }, function(errorMsg) {
  278. alert("请求数据失败!");
  279. })
  280. }
  281. }
  282. $('.editDeviceListOut select[name=rtmp]').val(userInfo.rtmp)
  283. $('.editDeviceListOut input[name=address').val(userInfo.address)
  284. $('.editDeviceListOut input[name=posistion').val(userInfo.posistion)
  285. $('.editDeviceListOut select[name=dwtype]').val(userInfo.dwtypeCode)
  286. $('.editDeviceListOut select[name=company]').val(userInfo.company)
  287. $('.editDeviceListOut input[name=transferType').val(userInfo.transferType)
  288. $('.editDeviceListOut input[name=hls').val(userInfo.hls)
  289. $('.editDeviceListOut input[name=ownerCode').val(userInfo.ownerCode)
  290. // userInfo.addr1 = "上海";
  291. $('.editDeviceListOut select[name=addr1]').val(userInfo.addr1)
  292. provinceText = userInfo.addr1;
  293. $.each(provinceList, function(i, item) {
  294. if (provinceText == item.name) {
  295. cityItem = i;
  296. return cityItem
  297. }
  298. });
  299. removeEle(city);
  300. removeEle(town);
  301. $.each(provinceList[cityItem].cityList, function(i, item) {
  302. addEle(city, item.name)
  303. })
  304. // userInfo.addr2 = "市辖区"
  305. $('.editDeviceListOut select[name=addr2]').val(userInfo.addr2)
  306. cityText = userInfo.addr2;
  307. removeEle(town);
  308. $.each(provinceList, function(i, item) {
  309. if (provinceText == item.name) {
  310. cityItem = i;
  311. return cityItem
  312. }
  313. });
  314. $.each(provinceList[cityItem].cityList, function(i, item) {
  315. if (cityText == item.name) {
  316. for (var n = 0; n < item.areaList.length; n++) {
  317. addEle(town, item.areaList[n])
  318. }
  319. }
  320. });
  321. // userInfo.addr3 = "黄浦区"
  322. $('.editDeviceListOut select[name=addr3]').val(userInfo.addr3)
  323. layerUpdateIndex = layer.open({
  324. type: 1,
  325. title: false,
  326. closeBtn: 0,
  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. if (!allParam.ownerCode) {
  360. alert('请输入设备编号');
  361. return;
  362. } else {
  363. let pattern = /(?!^\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{1,23}/
  364. if (!pattern.test(allParam.ownerCode)) {
  365. alert('设备编号只能输入数字或字母!');
  366. return false;
  367. }
  368. }
  369. //验证数据是否为空
  370. let res = validParamIsEmpty(allParam, {
  371. // "ownerCode": "请输入设备编号",
  372. "ownerName": "请输入设备名称",
  373. "unitinfo": "填写安装位置",
  374. "ownerXh": "请选择建筑",
  375. // "louyu": "请选择楼层",
  376. // "rtmp": "请选择房间",
  377. "addr1": "请选择省份",
  378. "addr2": "请选择所属市区",
  379. "addr3": "请选择所属区、县",
  380. "address": "请输入详细地址",
  381. "posistion": "请填写GIS坐标",
  382. "dwtype": "请选择设备类型",
  383. "company": "请选择所属单位",
  384. "transferType": "请输入传输方式",
  385. });
  386. if (res.code == -1) {
  387. alert(res.msg);
  388. return;
  389. }
  390. //验证通过 请求ajax
  391. ajaxRequest(DEVICE_LIST_ADD, "POST", allParam, function(result) {
  392. layer.close(layerCreateIndex);
  393. layer.msg('添加成功!', { icon: 6 });
  394. getListDataAjax();
  395. $('#addDataForm')[0].reset();
  396. }, function(errorMsg) {
  397. alert("异常错误!");
  398. })
  399. })
  400. /* 修改发送请求 */
  401. $('#dataUpdate').click(function() {
  402. //获取表单的值 并转换成对象
  403. let allParam = serializeArrayToObj($("#updateForm").serializeArray());
  404. //验证数据是否为空
  405. let res = validParamIsEmpty(allParam, {
  406. "ownerCode": "请输入设备编号",
  407. "ownerName": "请输入设备名称",
  408. "unitinfo": "填写安装位置",
  409. "ownerXh": "请选择建筑",
  410. // "louyu": "请选择楼层",
  411. // "rtmp": "请选择房间",
  412. "addr1": "请选择省份",
  413. "addr2": "请选择所属市区",
  414. "addr3": "请选择所属区、县",
  415. "address": "请输入详细地址",
  416. "posistion": "请填写GIS坐标",
  417. "dwtype": "请选择设备类型",
  418. "company": "请选择所属单位",
  419. "transferType": "请输入传输方式",
  420. });
  421. if (res.code == -1) {
  422. alert(res.msg);
  423. return;
  424. }
  425. ajaxRequest(DEVICE_LIST_UPDATE, "POST", allParam, function(result) {
  426. if (result.flag) {
  427. layer.msg('修改成功!', { icon: 6 });
  428. } else {
  429. //服务端返回报错
  430. alert(result.msg);
  431. }
  432. layer.close(layerUpdateIndex);
  433. getListDataAjax();
  434. }, function(errorMsg) {
  435. alert("数据修改失败!");
  436. })
  437. })
  438. // 导出 start
  439. $('.export').click(function() {
  440. getDataExport({ "ownerName": param1, "startTime": param2, "endTime": param3 })
  441. })
  442. function getDataExport(queryParam = {}) {
  443. ajaxRequest(DEVICE_LIST_EXPORT, "POST", queryParam, function(result) {
  444. console.log(result)
  445. let data = result.pageList;
  446. let newData = [];
  447. if (data) {
  448. data.forEach(function(item, index) {
  449. var installTime = item.installTime ? getFormatDate(item.installTime) : '';
  450. newData.push({ ownerCode: item.ownerCode, ownerName: item.ownerName, dwtype: item.dwtype, installMan: item.installMan, installTime: installTime })
  451. });
  452. }
  453. let str = '<tr style="text-align:center"><th>设备编号</th><th>设备名称</th><th>设备类型</th><th>添加人</th><th>添加时间</th></tr>';
  454. // 循环遍历,每行加入tr标签,每个单元格加td标签
  455. for (let i = 0; i < newData.length; i++) {
  456. str += '<tr style="text-align:center">';
  457. for (const key in newData[i]) {
  458. // 增加\t为了不让表格显示科学计数法或者其他格式
  459. str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
  460. }
  461. str += '</tr>';
  462. }
  463. downExcel(str, '设备列表数据表')
  464. }, function(errorMsg) {
  465. alert("请求数据失败!");
  466. })
  467. }
  468. // 导出 end