layui.config({
base: '../../js/layuiModules/', // 第三方模块所在目录
version: 'v1.6.4' // 插件版本号
}).extend({
soulTable: 'notice,layNotify', // 模块
});
let form;
var tree;
var table;
var notice;
var layNotify;
var proName = "";
var realName = "";
var statusId = "";
const token = localStorage.getItem("czl-token");
let pers = checkPermission();
$("#resetBt").click(function(){
table.reload('menuTable', {
url: czl_ht_url + '/RnProjectBind/getRnProjectList'
, method: 'post' //方式默认是get
, page: true
, where: {
proName: '',
realName: '',
statusId: '',
} //设定异步数据接口的额外参数
});
// $("#statusId").val('');
$("#proName").val('');
$("#realName").val('');
var form = layui.form;
form.val('', {
'statusId': ''
});
})
$("#searchBt").click(function(){
proName = $("#proName").val();
realName = $("#realName").val();
statusId = $("#statusId").val();
table.reload('menuTable', {
url: czl_ht_url + '/RnProjectBind/getRnProjectList'
, method: 'post' //方式默认是get
, page: true
, where: {
proName: proName,
realName: realName,
statusId: statusId,
} //设定异步数据接口的额外参数
});
$("#proName").val(proName);
$("#realName").val(realName);
$("#statusId").val(statusId);
})
$("#exportBt").click(function(){
oldKeyWord = $("#keyWord").val();
orgId = $("#orgId").val();
volLevelIds = $("#volLevelIds").val();
statusId = $("#statusId").val();
window.location.href = czl_ht_url + "/RnProjectBind/exportPhysicalCheckResult?"
+"proName=" + proName
+ "&realName=" + realName
+ "&statusId=" + statusId
+ "&type=" + '1'
+ "&token=" + token; //下载文件
})
layui.use(['table', 'form','notice', 'layNotify'], function () {
table = layui.table;
form = layui.form;
tree = layui.tree;
notice = layui.notice;
layNotify = layui.layNotify;
//渲染表格
table.render({
elem: '#demo'
, url: czl_ht_url + '/RnProjectBind/getRnProjectList' //数据接口
, method: 'post' //方式默认是get
, toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
, where: {
} //post请求必须加where ,post请求需要的参数
, cellMinWidth: 80
, cols: [[ //表头
{
field: 'number', width:80,title: '序号', align: 'center', type: 'numbers'
}
, {field: 'proName', align: 'center', title: '承载力工程名称'}
, {field: 'realName', align: 'center', title: '实名制线路工程名称'}
, {
field: 'mach', title: '匹配状态', align: 'center', templet: d => {
let text = "";
if (d.mach === "0") {
text = "未匹配";
} else if (d.mach === "1") {
text = "已匹配";
}
return text;
}
}
, {
fixed: 'right', width:180, title: '操作', align: 'center', templet: d => {
let text = "";
if(d.mach == '1'){
if ($.inArray('sysRnProject:untie', pers) > 0) {
text +='解绑';
}
}else {
if ($.inArray('sysRnProject:bind', pers) > 0) {
text +='匹配';
}
}
return text;
}
}
]]
, id: 'menuTable'
, page: true //开启分页
, loading: true //数据加载中。。。
, limits: [5, 10, 20] //一页选择显示3,5或10条数据
, limit: 10 //一页显示10条数据
, response: {
statusCode: 200 //规定成功的状态码,默认:0
}, parseData: function (res) { //将原始数据解析成 table 组件所规定的数据,res为从url中get到的数据
let result;
if (res.data !== '' && res.data != null && res.data !== "null") {
if (this.page.curr) {
result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
} else {
result = res.data.slice(0, this.limit);
}
}
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.count, //解析数据长度
"data": result, //解析数据列表
};
}
,toolbar: "#toolbar"
});
//监听工具条
table.on('tool(test)', function (obj) {
var data = obj.data; //当前行数据
console.log(data)
var rowIndex = obj.index;//当前行索引
var layEvent = obj.event; //当前点击的事件名
if (layEvent === 'Unbind') {
layer.confirm('确定要解除绑定吗?', {
btn : [ '确定', '取消' ]
}, function() {
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: czl_ht_url + '/RnProjectBind/delRnProjectById',// 请求地址
contentType: "application/x-www-form-urlencoded",
dataType: 'json', // 服务器返回数据类型
data: {'id': data.id,'proId':data.proId}, //获取提交的表单字段
success: function (data) {
var resMsg = data.resMsg;
if ("数据获取成功" == resMsg) {
reloadTip("解绑","解绑成功",'success',layNotify);
setTimeout(function(){
layer.closeAll();
table.reload('menuTable', {
url: czl_ht_url + '/RnProjectBind/getRnProjectList'
, method: 'post' //方式默认是get
, page: true
, where: {
keyWord: '',
orgId: '',
volLevelIds: '',
statusId: '',
} //设定异步数据接口的额外参数
});
}, 2000);
}else {
reloadTip("解绑","解绑失败",'error',layNotify);
setTimeout(function(){
layer.closeAll();
}, 2000);
}
}
});
});
}
if (layEvent === 'match') {
localStorage.setItem('id',data.id);
layerOpenFormForSencond("匹配","./RnProjectBindForm.html");
}
});
// 单元格编辑事件
table.on('edit(test)', function (obj) {
var field = obj.field; // 得到字段
var value = obj.value; // 得到修改后的值
var oldValue = obj.oldValue;
var data = obj.data; // 得到所在行所有键值
var update = {};
// 值的校验
if (field === 'idNumber') {
if (value.length != 18) {
update[field] = oldValue;
obj.update(update);
layer.tips('输入的身份证不正确,请重新编辑', this, {tips: 1});
return obj.reedit(); // 重新编辑 -- v2.8.0 新增
} else {
update[field] = value;
obj.update(update);
}
}
// 编辑后续操作,如提交更新请求,以完成真实的数据更新
// …
layer.msg('编辑成功', {icon: 1});
});
getOrgName(form,null);
getVoltageLevel(form, "");
});
function reloadTip(tip,message,type){
layNotify.notice({
title: tip+"提示",
type: type,
message: message
});
}