123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- var pageNo = 1;
- var totalPages = 0;
- var param1 = '';
- var param2 = '';
- var param3 = '';
- //设备列表
- getListDataAjax();
- //获取设备列表 ajax请求
- function getListDataAjax(queryParam = {}, pageNo = 1) {
- queryParam.pageNo = pageNo;
- // queryParam.pageSize = 4;
- ajaxRequest(DEVICE_LIST_SEARCH, "POST", queryParam, function(result) {
- let data = result.pageList;
- let items = '';
- if (result.totalCount > 0) {
- data.forEach(function(item, key) {
- let transmissionModel = "";
- if (item.transmission_model == 1) {
- transmissionModel = "NB-IOT"
- } else if (item.transmission_model == 2) {
- transmissionModel = "Lora-IOT"
- } else {
- transmissionModel = "2G/4G/5G"
- }
- items += "<tr>" +
- "<td class='status' data-user='" + JSON.stringify(item) + "' data-ownercode='" + item.ownerCode + "'></td>" +
- "<td>" + item.ownerCode + "</td>" +
- "<td>" + item.ownerName + "</td>" +
- "<td>" + item.dwtype + "</td>" +
- "<td>" + item.installMan + "</td>" +
- "<td>" + getFormatDate(item.installTime) + "</td>" +
- "</tr>"
- })
- }
- $('#dataList').html(items);
- totalPages = result.totalPages;
- $('#totalPage').html(totalPages); //总共多少页
- $('#dataTotal').html(result.totalCount); //总共多少条数据
- $('#currentPage').val(pageNo); //当前页面
- let pageFrom = (pageNo - 1) * result.pageSize + 1; //开始
- let pageTo = result.pageNo * result.pageSize; //结束
- pageTo = pageTo > result.totalCount ? result.totalCount : pageTo;
- $('#pageFrom').html(pageFrom);
- $('#pageTo').html(pageTo);
- // 无数据时
- if (!data.length) {
- $('.pager.has-data').hide()
- $('.pager.no-data').show()
- } else {
- $('.pager.has-data').show()
- $('.pager.no-data').hide()
- }
- if (pageNo < totalPages) {
- $('#nextPageButton,#lastPageButton').removeClass('disabled');
- } else {
- $('#nextPageButton,#lastPageButton').addClass('disabled');
- }
- if (pageNo === 1) {
- $('#firstPageButton,#prevPageButton').addClass('disabled');
- } else {
- $('#firstPageButton,#prevPageButton').removeClass('disabled');
- }
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- //按钮搜索
- $('#buttonClick').on('click', function() {
- pageNo = 1;
- getListDataAjax(getSearchParamObj());
- param1 = $('#ownerName').val()
- param2 = $('#startTime').val()
- param3 = $('#endTime').val()
- })
- //拼接搜索条件
- function getSearchParamObj() {
- let queryParam = {};
- let ownerName = $('#ownerName').val();
- let startTime = $('#startTime').val()
- let endTime = $('#endTime').val()
- queryParam.ownerName = ownerName;
- queryParam.startTime = startTime;
- queryParam.endTime = endTime;
- return queryParam;
- }
- //重置表单
- $('.reset').click(resetForm);
- //分页刷新按钮
- $('.pg-refresh').click(resetForm)
- //重置表单
- function resetForm() {
- pageNo = 1;
- $("#ownerName").val("");
- $("#startTime").val("");
- $("#endTime").val("");
- getListDataAjax(getSearchParamObj());
- param1 = $('#ownerName').val()
- param2 = $('#startTime').val()
- param3 = $('#endTime').val()
- }
- //分页操作
- $('#firstPageButton').on('click', function() {
- pageNo = 1;
- getListDataAjax(getSearchParamObj(), 1);
- })
- $('#lastPageButton').on('click', function() {
- pageNo = totalPages;
- getListDataAjax(getSearchParamObj(), pageNo);
- })
- $('#prevPageButton').on('click', function() {
- pageNo -= 1;
- getListDataAjax(getSearchParamObj(), pageNo);
- })
- $('#nextPageButton').on('click', function() {
- pageNo += 1;
- getListDataAjax(getSearchParamObj(), pageNo);
- })
- //单位下拉
- getCompanyList()
- function getCompanyList() {
- ajaxRequest(COMPANY_LIST, "POST", {}, function(result) {
- let data = result.data;
- let items = '';
- data.forEach(function(item, key) {
- items += `<option value="${item.ownerId}">${item.ownerName}</option>`
- })
- $('#getCompanyList').append(items);
- $('#getCompanyList2').append(items);
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- //类型下拉
- getTypeList()
- function getTypeList() {
- ajaxRequest(DEVICE_TYPE_EXPORT, "POST", {}, function(result) {
- let data = result.RESULT.pageList;
- let items = '';
- data.forEach(function(item, key) {
- items += `<option value="${item.id}">${item.type_name}</option>`
- })
- $('#getTypeList').append(items);
- $('#getTypeList2').append(items);
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- //建筑下拉
- getBuildingList()
- function getBuildingList() {
- ajaxRequest(BUILD_TREE_LIST, "POST", {}, function(result) {
- let data = result.data;
- let items = '';
- data.forEach(function(item, key) {
- items += `<option value="${item.id}">${item.buildName}</option>`
- })
- $('#getBuildingList').append(items);
- $('#getBuildingList2').append(items);
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- // 建筑与楼层
- linkFloor('#getBuildingList')
- linkFloor('#getBuildingList2')
- function linkFloor(element) {
- $(element).on('change', function() {
- //获取公司id
- let buildId = $(this).find('option:selected').val();
- ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
- let floorItems = '<option value="">请选择</option>';
- let buildObj = result.data;
- if (buildObj) {
- buildObj.forEach(function(item, key) {
- floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
- })
- $('#getFloorList').html(floorItems);
- $('#getFloorList2').html(floorItems);
- } else {
- $('#getFloorList').html(floorItems);
- $('#getFloorList2').html(floorItems);
- }
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- })
- }
- // 楼层与房间联动
- linkRoom('#getFloorList')
- linkRoom('#getFloorList2')
- function linkRoom(element) {
- $(element).on('change', function() {
- //获取楼层id
- let floorName = $(this).find('option:selected').val();
- ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorName }, function(result) {
- let roomItems = '<option value="">请选择</option>';
- let floorObj = result.data;
- floorObj.forEach(function(item, key) {
- roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
- })
- $('#getRoomList').html(roomItems);
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- })
- }
- /*新增 修改 关闭 弹框*/
- var layer = layui.layer;
- var layerCreateIndex = '';
- var layerUpdateIndex = ''
- layui.use('layer', function() {
- //新增弹框
- $('.add').click(function() {
- layerCreateIndex = layer.open({
- type: 1,
- title: false,
- closeBtn: 0,
- skin: 'yourclass',
- area: ['1000px', '400px'],
- content: $(".addDeviceListOut"),
- success: function() {
- $('.clsBtn,.cancel').click(function() {
- layer.close(layerCreateIndex);
- })
- }
- })
- }),
- //修改弹框信息
- $('.edit').click(function() {
- if (!$('.pure-table tr').has('.checked').length) {
- layer.msg('请选择一条需要修改的信息!', { icon: 5 });
- } else {
- let userInfo = $('.pure-table tr').find('.checked').data('user');
- $('.editDeviceListOut input[name=ownerCode]').val(userInfo.ownerCode)
- $('.editDeviceListOut input[name=ownerName]').val(userInfo.ownerName)
- $('.editDeviceListOut input[name=unitinfo').val(userInfo.unitinfo)
- // 建筑赋值
- $('.editDeviceListOut select[name=ownerXh]').val(userInfo.ownerXh)
- // 楼层下拉展示及赋值
- if ($('#getBuildingList2').val()) {
- listFloor()
- function listFloor() {
- let buildId = $('#getBuildingList2').find('option:selected').val();
- ajaxRequest(BUILD_TREE_LIST, "POST", { "buildId": buildId }, function(result) {
- let floorItems = '<option value="">请选择</option>';
- let buildObj = result.data;
- if (buildObj) {
- buildObj.forEach(function(item, key) {
- floorItems += `<option value="${item.floorId}">${item.floorName}</option>`
- })
- $('#getFloorList2').html(floorItems);
- } else {
- $('#getFloorList2').html(floorItems);
- }
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- }
- $('.editDeviceListOut select[name=louyu]').val(userInfo.louyu)
- // 房间下拉展示及赋值
- if ($('#getFloorList2').val()) {
- listRoom()
- function listRoom() {
- let floorId = $('#getFloorList2').find('option:selected').val();
- ajaxRequest(BUILD_TREE_LIST, "POST", { "floorId": floorId }, function(result) {
- let roomItems = '<option value="">请选择</option>';
- let floorObj = result.data;
- if (floorObj) {
- floorObj.forEach(function(item, key) {
- roomItems += `<option value="${item.roomId}">${item.roomName}</option>`
- })
- $('#getRoomList2').html(roomItems);
- } else {
- $('#getRoomList2').html(roomItems);
- }
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- }
- $('.editDeviceListOut select[name=rtmp]').val(userInfo.rtmp)
- $('.editDeviceListOut input[name=address').val(userInfo.address)
- $('.editDeviceListOut input[name=posistion').val(userInfo.posistion)
- $('.editDeviceListOut select[name=dwtype]').val(userInfo.dwtypeCode)
- $('.editDeviceListOut select[name=company]').val(userInfo.company)
- $('.editDeviceListOut input[name=transferType').val(userInfo.transferType)
- $('.editDeviceListOut input[name=hls').val(userInfo.hls)
- $('.editDeviceListOut input[name=ownerCode').val(userInfo.ownerCode)
- // userInfo.addr1 = "上海";
- $('.editDeviceListOut select[name=addr1]').val(userInfo.addr1)
- provinceText = userInfo.addr1;
- $.each(provinceList, function(i, item) {
- if (provinceText == item.name) {
- cityItem = i;
- return cityItem
- }
- });
- removeEle(city);
- removeEle(town);
- $.each(provinceList[cityItem].cityList, function(i, item) {
- addEle(city, item.name)
- })
- // userInfo.addr2 = "市辖区"
- $('.editDeviceListOut select[name=addr2]').val(userInfo.addr2)
- cityText = userInfo.addr2;
- removeEle(town);
- $.each(provinceList, function(i, item) {
- if (provinceText == item.name) {
- cityItem = i;
- return cityItem
- }
- });
- $.each(provinceList[cityItem].cityList, function(i, item) {
- if (cityText == item.name) {
- for (var n = 0; n < item.areaList.length; n++) {
- addEle(town, item.areaList[n])
- }
- }
- });
- // userInfo.addr3 = "黄浦区"
- $('.editDeviceListOut select[name=addr3]').val(userInfo.addr3)
- layerUpdateIndex = layer.open({
- type: 1,
- title: false,
- closeBtn: 0,
- skin: 'yourclass',
- area: ['1000px', '400px'],
- content: $(".editDeviceListOut"),
- success: function() {
- $('.clsBtn,.cancel').click(function() {
- layer.close(layerUpdateIndex);
- })
- }
- });
- }
- })
- //删除信息
- $('.delete').click(function() {
- if (!$('.pure-table tr').has('.checked').length) {
- layer.msg('请选择一条需要删除的信息!', { icon: 5 });
- } else {
- let ownerCode = $('.pure-table tr').find('.checked').data('ownercode');
- ajaxRequest(DEVICE_LIST_DELETE, "POST", { "ownerCode": ownerCode }, function(result) {
- $(".pure-table tbody tr.selected").remove()
- layer.close(layer.layerCreateIndex);
- layer.msg('删除成功!', { icon: 6 });
- getListDataAjax()
- }, function(errorMsg) {
- alert("用户删除失败!");
- })
- }
- })
- })
- /* 新增发送请求 */
- $('#addData').click(function() {
- //获取表单的值 并转换成对象
- let allParam = serializeArrayToObj($("#addDataForm").serializeArray());
- if (!allParam.ownerCode) {
- alert('请输入设备编号');
- return;
- } else {
- let pattern = /(?!^\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{1,23}/
- if (!pattern.test(allParam.ownerCode)) {
- alert('设备编号只能输入数字或字母!');
- return false;
- }
- }
- //验证数据是否为空
- let res = validParamIsEmpty(allParam, {
- // "ownerCode": "请输入设备编号",
- "ownerName": "请输入设备名称",
- "unitinfo": "填写安装位置",
- "ownerXh": "请选择建筑",
- // "louyu": "请选择楼层",
- // "rtmp": "请选择房间",
- "addr1": "请选择省份",
- "addr2": "请选择所属市区",
- "addr3": "请选择所属区、县",
- "address": "请输入详细地址",
- "posistion": "请填写GIS坐标",
- "dwtype": "请选择设备类型",
- "company": "请选择所属单位",
- "transferType": "请输入传输方式",
- });
- if (res.code == -1) {
- alert(res.msg);
- return;
- }
- //验证通过 请求ajax
- ajaxRequest(DEVICE_LIST_ADD, "POST", allParam, function(result) {
- layer.close(layerCreateIndex);
- layer.msg('添加成功!', { icon: 6 });
- getListDataAjax();
- $('#addDataForm')[0].reset();
- }, function(errorMsg) {
- alert("异常错误!");
- })
- })
- /* 修改发送请求 */
- $('#dataUpdate').click(function() {
- //获取表单的值 并转换成对象
- let allParam = serializeArrayToObj($("#updateForm").serializeArray());
- //验证数据是否为空
- let res = validParamIsEmpty(allParam, {
- "ownerCode": "请输入设备编号",
- "ownerName": "请输入设备名称",
- "unitinfo": "填写安装位置",
- "ownerXh": "请选择建筑",
- // "louyu": "请选择楼层",
- // "rtmp": "请选择房间",
- "addr1": "请选择省份",
- "addr2": "请选择所属市区",
- "addr3": "请选择所属区、县",
- "address": "请输入详细地址",
- "posistion": "请填写GIS坐标",
- "dwtype": "请选择设备类型",
- "company": "请选择所属单位",
- "transferType": "请输入传输方式",
- });
- if (res.code == -1) {
- alert(res.msg);
- return;
- }
- ajaxRequest(DEVICE_LIST_UPDATE, "POST", allParam, function(result) {
- if (result.flag) {
- layer.msg('修改成功!', { icon: 6 });
- } else {
- //服务端返回报错
- alert(result.msg);
- }
- layer.close(layerUpdateIndex);
- getListDataAjax();
- }, function(errorMsg) {
- alert("数据修改失败!");
- })
- })
- // 导出 start
- $('.export').click(function() {
- getDataExport({ "ownerName": param1, "startTime": param2, "endTime": param3 })
- })
- function getDataExport(queryParam = {}) {
- ajaxRequest(DEVICE_LIST_EXPORT, "POST", queryParam, function(result) {
- console.log(result)
- let data = result.pageList;
- let newData = [];
- if (data) {
- data.forEach(function(item, index) {
- var installTime = item.installTime ? getFormatDate(item.installTime) : '';
- newData.push({ ownerCode: item.ownerCode, ownerName: item.ownerName, dwtype: item.dwtype, installMan: item.installMan, installTime: installTime })
- });
- }
- let str = '<tr style="text-align:center"><th>设备编号</th><th>设备名称</th><th>设备类型</th><th>添加人</th><th>添加时间</th></tr>';
- // 循环遍历,每行加入tr标签,每个单元格加td标签
- for (let i = 0; i < newData.length; i++) {
- str += '<tr style="text-align:center">';
- for (const key in newData[i]) {
- // 增加\t为了不让表格显示科学计数法或者其他格式
- str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
- }
- str += '</tr>';
- }
- downExcel(str, '设备列表数据表')
- }, function(errorMsg) {
- alert("请求数据失败!");
- })
- }
- // 导出 end
|