layui.use('table', function(){ var table = layui.table; var layer = layui.layer; var form = layui.form; //告警汇总 table.render({ elem: '#Area' ,url: '/hxzkuwb/FindTongJiArea' ,page: true //开启分页 ,size:'sm' ,toolbar: '#toolbarDemo' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档 ,cols: [[ //表头 {type:'checkbox',sort: true,fixed: "left"} ,{field: 'id', title: '序号', sort: true} ,{ field: 'areaname', title: '名称'} ,{field: 'floornum', title: '楼层' } ,{field: 'dangerlevel', title: '危险等级',templet: '#titleTpl'} ,{field: 'quyucolor', title: '区域颜色'} ,{field: 'quyupoint', title: '区域坐标'} ,{field: 'baoliu1', title: '人员上限'} ,{field: 'username', title: '绘制人'} ,{field: 'addtime', title: '绘制时间'} ]] ,limits: [1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,100000] ,limit: 1000, }); table.on('toolbar(Area)', function(obj) { var checkStatus = table.checkStatus(obj.config.id); var ds = "username="+sessionStorage.getItem("username") var add = "Yes"; var udelete = "Yes"; var uupdate = "Yes"; $.ajax({ url: "/hxzkuwb/findUserRole", type: "GET", data:ds, dataType: "json", async: false, // 设置为同步 success: function(data) { if (data.uadd == "No") { add = "No"; } if (data.udelete == "No") { udelete = "No"; } if (data.uupdate == "No") { uupdate = "No"; } } }); switch(obj.event) { case 'getUpdate': if (uupdate == "Yes") { var data = checkStatus.data; if (data.length > 1) { layer.alert("一次只能选中一个进行修改") } else if (data.length == 0) { layer.alert("请选中一条数据", { offset: '150px' // 设置偏移量为100像素 }); } else { $(".update").show(); $(".heimu").show(); $("#up1").val(data[0].areaname) $("#up2").val(data[0].floornum) $("#up3").val(data[0].baoliu1) var selectData = []; var selectData1 = []; // 动态生成下拉框选项 if (data[0].dangerlevel == "1") { selectData = [ { value: "1", title: "甲类" }, { value: "2", title: "乙类" }, { value: "3", title: "丙类" }, { value: "4", title: "丁类" }, { value: "5", title: "戊类" } ] } if (data[0].dangerlevel == "2") { selectData = [ { value: "2", title: "乙类" }, { value: "1", title: "甲类" }, { value: "3", title: "丙类" }, { value: "4", title: "丁类" }, { value: "5", title: "戊类" } ] } if (data[0].dangerlevel == "3") { selectData = [ { value: "3", title: "丙类" }, { value: "1", title: "甲类" }, { value: "2", title: "乙类" }, { value: "4", title: "丁类" }, { value: "5", title: "戊类" } ] } if (data[0].dangerlevel == "4") { selectData = [ { value: "4", title: "丁类" }, { value: "3", title: "丙类" }, { value: "2", title: "乙类" }, { value: "1", title: "甲类" }, { value: "5", title: "戊类" } ] } if (data[0].dangerlevel == "5") { selectData = [ { value: "5", title: "戊类" }, { value: "1", title: "甲" }, { value: "2", title: "乙类" }, { value: "3", title: "丙类" }, { value: "4", title: "丁类" }, ] } if (data[0].dangerlevel == "6") { selectData = [ { value: "1", title: "甲类" }, { value: "2", title: "乙类" }, { value: "3", title: "丙类" }, { value: "4", title: "丁类" }, { value: "5", title: "戊类" } ] } if (data[0].quyucolor == "1") { selectData1 = [ { value: "1", title: "红色(A级)" }, { value: "2", title: "黄色(B级)" }, { value: "3", title: "蓝色(C级)" }, { value: "4", title: "绿色(D级)" } ] } if (data[0].quyucolor == "2") { selectData1 = [ { value: "2", title: "黄色(B级)" }, { value: "1", title: "红色(A级)" }, { value: "3", title: "蓝色(C级)" }, { value: "4", title: "绿色(D级)" } ] } if (data[0].quyucolor == "3") { selectData1 = [ { value: "3", title: "蓝色(C级)" }, { value: "2", title: "黄色(B级)" }, { value: "1", title: "红色(A级)" }, { value: "4", title: "绿色(D级)" } ] } if (data[0].quyucolor == "4") { selectData1 = [ { value: "4", title: "绿色(D级)" }, { value: "2", title: "黄色(B级)" }, { value: "1", title: "红色(A级)" }, { value: "3", title: "蓝色(C级)" } ] } var selectElem2 = document.getElementById('wxdj'); for (var i = 0; i < selectData.length; i++) { var optionElem = document.createElement('option'); optionElem.value = selectData[i].value; optionElem.text = selectData[i].title; selectElem2.appendChild(optionElem); } var selectElem3 = document.getElementById('qycolor'); for (var i = 0; i < selectData1.length; i++) { var optionElem = document.createElement('option'); optionElem.value = selectData1[i].value; optionElem.text = selectData1[i].title; selectElem3.appendChild(optionElem); } // 重新渲染下拉框 form.render('select'); } } break; case 'getdelete': if (udelete == "Yes") { var data = checkStatus.data; if (data < 1) { layer.alert("请选中一条数据") } else { for (var i = 0; i < data.length; i++) { var ds = "areaname=" + data[i].areaname $.get("/hxzkuwb/deleteTongJiArea", ds, function (data) { }) } location.reload() } } break; case 'getshuaxin': layer.msg('刷新成功') setTimeout(function (){ location.reload(); },500) break; } }) }); function quxiao(){ setTimeout(function() { $(".add").hide(); $(".update").hide() $(".heimu").hide(); }, 500); layer.msg("操作成功", { offset: '200px' // 设置偏移量为100像素 }); }