device-list.js 16 KB

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