let table; let deviceTable; let form; let per; let laypage; let pageNum = 1, limitSize = 30; // 默认第一页,分页数量为10 let user=getUser(); console.log(user) layui.use(['layer', 'form', 'element','laypage'], function(){ var layer = layui.layer; //弹层 laypage = layui.laypage; //分页 table = layui.table; //表格 form=layui.form; //注册权限 // per=getPer(); $('#myModal_edit').on('show.bs.modal', centerModals); //初始化下拉选 pages(1, 30, 1); $(".layui-add").click(function(){ layer.open({ title: '新增反馈', type: 2, area: ['40%','70%'], content: '../../../html/problem/job/addproblem.html', cancel: function(){ // layer.msg('捕获就是从页面已经存在的元素上,包裹layer的结构', {time: 5000, icon:6}); }, btn: ['确定', '取消'] //只是为了演示 ,yes: function(index,leyuo){ var body = layer.getChildFrame('body', index); body.find('#add-data').click(); } ,btn2: function(){ layer.closeAll(); } }); }) $(".layui-td").click(function(){ layer.open({ title: '设备通道', type: 2, area: ['35%','40%'], content: '../../../html/device/equment/deviceTd.html', cancel: function(){ // layer.msg('捕获就是从页面已经存在的元素上,包裹layer的结构', {time: 5000, icon:6}); }, btn: ['确定', '取消'] //只是为了演示 ,success: function (layero, index) { var body = layer.getChildFrame('body', index); var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象,执行iframe页的方法: iframeWin.setForm(form);//调用子页面的方法,页面锁定 } ,yes: function(index,leyuo){ var body = layer.getChildFrame('body', index); body.find('#add-td').click(); } ,btn2: function(){ layer.closeAll(); } }); }) $(".layui-export").click(function(){ exportData(); }) $("#downloadExcel").click(function(){ window.open(dataUrl + 'proteam/pot/device/downloadExcel' + '?token=' + token); }) $(".layui-import").click(function(){ $("#import-excel").trigger('click'); }) $(".layui-refresh").click(function(){ refresh(""); }) $(".layui-cz").click(function(){ refreshDevice(""); }) $("#import-excel").change(function () { if($(this).val()){ let files = $(this)[0].files[0]; let fileType = files.name.substring( files.name.lastIndexOf(".") + 1, files.name.length ); if (fileType === "xlsx" || fileType === "xls") { excelUpload(this, dataUrl + "proteam/pot/device/importExcel" + '?token=' + token, ""); } else { layer.msg("仅支持上传文件格式为:xlx、xlsx", {icon: 5,}); $("#import-excel").val(""); } } }); $("#query").off().click(function(){ if(/^[a-zA-Z0-9\u4e80-\u9fa5\\s-]+$/.test($("#deviceName").val()) || ""==$("#deviceName").val()){ }else { layer.msg("不能包合特殊字符", {icon: 5,}); return; } pages(1, limitSize,false); return ; }) //重置 $("#reset").off().click(function(){ pages(1, limitSize,true); }) // 头工具栏事件 table.on('tool(device-table)', function(obj){ console.log(obj); var event=obj.event; var key=obj.data.id;//唯一值 if(event=='detail'){//查看详情 layer.open({ title: '回复', type: 2, area: ['40%','70%'], content: '../../../html/problem/job/hfProblem.html', btn: ['确定', '取消'] //只是为了演示 ,success: function (layero, index) { var body = layer.getChildFrame('body', index); var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象,执行iframe页的方法: iframeWin.setForm(key,obj.data.model,obj.data.content,obj.data.status, pageNum,limitSize); } ,yes: function(index,leyuo){ var body = layer.getChildFrame('body', index); body.find('#add-data').click(); } ,btn2: function(){ layer.closeAll(); } }); }else if(event=='update'){//修改数据 layer.open({ title: '修改问题', type: 2, area: ['40%','70%'], content: '../../../html/problem/job/addproblem.html', btn: ['确定', '取消'] ,success: function (layero, index) { var body = layer.getChildFrame('body', index); var iframeWin = window[layero.find('iframe')[0]['name']];//获得iframe页的窗口对象,执行iframe页的方法: iframeWin.setForm(key,obj.data.model,obj.data.content, pageNum,limitSize);//调用子页面的方法,页面锁定 } ,yes: function(index,leyuo){ var body = layer.getChildFrame('body', index); body.find('#add-data').click(); } ,btn2: function(){ layer.closeAll(); } }); }else if(event=='del'){//删除数据 layer.msg('是否删除该数据?', { time: 10000, //10s后自动关闭 btn: ['确定', '取消'] ,yes: function(index,leyuo){ layer.closeAll(); delData(key) } }); } }) //查询按钮 }) function pages(pageNum, pageSize, typeNum) { let params = getReqParams(pageNum, pageSize, typeNum); $.ajax({ headers: { "encrypt": sm3(JSON.stringify(params)) }, url: dataUrl+'proteam/sys/problem/getProblemPage?token='+token, data: params, type: 'POST', async: false, success: function (result) { if (result.code === 200) { if (result.data) { initTable(result.data, result.limit, result.curr) laypages(result.count, result.curr, result.limit) } } else if (result.code === 500) { layer.alert(result.msg, {icon: 2}) } else if (result.code === 401) { logout(1); } }, error: function () { } }); } function laypages(total, page, limit) { laypage.render({ elem: 'voi-page', count: total, curr: page, limit: limit, limits: [30, 50, 100], layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'], groups: 5, jump: function (obj, first) { if (!first) { pageNum = obj.curr, limitSize = obj.limit; pages(obj.curr, obj.limit, null); } } }); } // 获取参数 function getReqParams(page, limit, type) { let obj = {}; if (!type) { obj = { page: page + "", limit: limit + "", status:$("#status").val(), keyWord:$("#keyWord").val(), }; } else { obj = { page: '1', limit: '30', status:"", keyWord:"", }; } return obj; } //初始化表格 function initTable(dataList, limit, page) { // 执行一个 table 实例 deviceTable=table.render({ id:'deviceTable', elem: '#device-table', height: "full-200", data: dataList, limit: limit, title: '设备表', cols: [[ //表头 {type: 'checkbox', fixed: 'left'}, {title: "序号", width: 80, align: "center", templet: function (d) { return (page - 1) * limit + d.LAY_INDEX; } } ,{field: 'model', title: '功能模块', width:200,align:'center'} ,{field: 'userName', title: '反馈人', width:200,align:'center'} ,{field: 'content', title: '具体内容', width:500,align:'center'} // ,{field: 'image', title: '反馈图片', width:200,align:'center'} ,{field: 'status', title: '状态', width:200,align:'center',templet:function(d){ console.log(d.status); if(d.status==0){ return '未处理'; }else if(d.status==1){ return '已解决'; }else if(d.status==2){ return '协调处理中'; }else if(d.status==3){ return '暂时无法解决'; }else if(d.status==4){ return '修改中...'; } }} ,{field: 'createTime', title: '反馈时间', width:200,align:'center'} ,{field: 'hf', title: '反馈结果', width:200,align:'center'} ,{field: 'updateTime', title: '回复时间', width:200,align:'center'} ,{fixed: 'right', title: '操作', width: 200,align:'center', toolbar: '#device-bar'} ]], done:function (res,curr,count){ } }); } //删除数据 function delData(keyId){ Ajax().post({ url: dataUrl + 'proteam/sys/problem/delete', headers: { "encrypt": sm3(JSON.stringify({'id':keyId})) }, data: { id:keyId }, async : true, success : function(data) { pages(1, limitSize,false); if(data.code=='200') { layer.msg(data.msg, { icon: 1, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); }else{ layer.msg(data.msg, { icon: 2, time: 2000 //2秒关闭(如果不配置,默认是3秒) }); } } }); } function query(){ pages(1, limitSize,false); } function reloadTable(pageNum,limitSize){ pages(pageNum, limitSize,false); } function refreshDevice(keyId){ Ajax().post({ url: dataUrl + 'proteam/pot/device/refreshDevice', headers: { "encrypt": sm3(JSON.stringify({'params':"refresh"})) }, data: { params: "refresh" }, async : true, success : function(data) { if(data.code==200){ console.log("刷新成功"); } } }); } function refresh(keyId){ Ajax().post({ url: dataUrl + 'proteam/pot/device/refresh', headers: { "encrypt": sm3(JSON.stringify({'params':"refresh"})) }, data: { params: "refresh" }, async : true, success : function(data) { if(data.code==200){ console.log("刷新成功"); } } }); } //设备类型下拉选 function initDeviceTypeSelect(keyId){ Ajax().post({ url: dataUrl + 'system/sys/selected/getDeviceTypeSelected', headers: { "encrypt": sm3(JSON.stringify({'params':"device_type"})) }, data: { params: "device_type" }, async : true, success : function(data) { console.log(data); var html=""; $(".typeCode").empty(); html+="" if(data!=null &&data.length>0){ for(var i = 0;i"+name+""; }else { html+=""; } }; } $(".typeCode").append(html); form.render(); } }); } //所属单位 function initSsdwSelected(keyId){ Ajax().post({ url: dataUrl + 'system/sys/selected/getDictSelected', headers: { "encrypt": sm3(JSON.stringify({'params':"ss_dw"})) }, data: { params: "ss_dw" }, async : true, success : function(data) { console.log(data); var html=""; $(".ssdw").empty(); html+="" if(data!=null &&data.length>0){ for(var i = 0;i"+name+""; }else { html+=""; } }; } $(".ssdw").append(html); form.render(); } }); } //导出 function exportData() { let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,}); let url = dataUrl + "proteam/pot/device/exportDevice?" + getParam()+'&token='+token; let xhr = new XMLHttpRequest(); let a = document.createElement("a"); xhr.open("get", url, true); xhr.responseType = "blob"; // 转换流 xhr.setRequestHeader("encrypt",sm3(JSON.stringify(getParames()))); xhr.onload = function () { layer.close(loadingMsg); if (this.status === 200) { let url = window.URL.createObjectURL(new Blob([this.response])) let link = document.createElement('a') link.style.display = 'none' link.href = url link.setAttribute('download', "设备台账.xlsx") document.body.appendChild(link) link.click() // 释放URL对象所占资源 window.URL.revokeObjectURL(url) // 用完即删 document.body.removeChild(link) } else { layer.msg("数据发生异常,请稍后重试", {icon: 16, scrollbar: false, time: 2000}); } }; xhr.send(); } function getParam(){ var params="deviceName="+$("#deviceName").val()+"&macId="+$("#macId").val()+"&gbCode="+$("#gbCode").val()+"&typeCode="+$("#typeCode").val()+"&ssdw="+$("#ssdw").val() +"&ist="+$("#ist").val() +"&tName="+$("#tName").val()+"&tCode="+$("#tCode").val()+"&keyWord="+$("#keyWord").val(); return params; } function getParames(){ var params={ deviceName:$("#deviceName").val(), macId:$("#macId").val(), gbCode:$("#gbCode").val(), typeCode:$("#typeCode").val(), ssdw:$("#ssdw").val(), ist:$("#ist").val(), tName:$("#tName").val(), tCode:$("#tCode").val(), keyWord:$("#keyWord").val(), } return params; } // 弹出模态框 function centerModals() { $('#myModal_edit').each(function (i) { var $clone = $(this).clone().css('display', 'block').appendTo('body'); var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 3); top = top > 0 ? top : 0; $clone.remove(); $(this).find('.modal-content').css("margin-top", top); }); };