czl-web/js/project/lineProjectList.js

389 lines
15 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

layui.config({
base: '../../js/layuiModules/', // 第三方模块所在目录
version: 'v1.6.4' // 插件版本号
}).extend({
soulTable: 'notice,layNotify', // 模块
});
let form;
var tree;
var table;
var notice;
var layNotify;
var oldKeyWord = "";
var orgId = "";
var statusId = "";
var volLevelIds = "";
const token = localStorage.getItem("token");
let pers = checkPermission();
$("#resetBt").click(function(){
table.reload('menuTable', {
url: ctxPath + '/linePro/getFirmContentList'
, method: 'post' //方式默认是get
, page: true
, where: {
keyWord: '',
orgId: '',
volLevelIds: '',
statusId: '',
} //设定异步数据接口的额外参数
});
$("#keyWord").val('');
$("#statusId").val('');
getOrgName(form,"");
getVoltageLevel(form,"");
})
$("#searchBt").click(function(){
oldKeyWord = $("#keyWord").val();
orgId = $("#orgId").val();
volLevelIds = $("#volLevelIds").val();
statusId = $("#statusId").val();
table.reload('menuTable', {
url: ctxPath + '/linePro/getFirmContentList'
, method: 'post' //方式默认是get
, page: true
, where: {
keyWord: oldKeyWord,
orgId: orgId,
volLevelIds: volLevelIds,
statusId: statusId,
} //设定异步数据接口的额外参数
});
$("#keyWord").val(oldKeyWord);
$("#orgId").val(orgId);
$("#volLevelIds").val(volLevelIds);
$("#statusId").val(statusId);
})
$("#addBt").click(function(){
localStorage.setItem("id","")
localStorage.setItem('teamTypeId',"");
localStorage.setItem('voltageLevelId',"");
localStorage.setItem('teamName',"");
layerOpenFormForSencond("新增","./lineProjectForm.html");
})
$("#exportBt").click(function(){
oldKeyWord = $("#keyWord").val();
orgId = $("#orgId").val();
volLevelIds = $("#volLevelIds").val();
statusId = $("#statusId").val();
window.location.href = ctxPath + "/linePro/exportPhysicalCheckResult?"
+"orgId=" + orgId
+ "&volLevelIds=" + volLevelIds
+ "&keyWord=" + oldKeyWord
+ "&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;
if ($.inArray('sysFirmContent:add', pers) < 0) {
document.getElementById('addDiv').remove();
}
//渲染表格
table.render({
elem: '#demo'
, url: ctxPath + '/linePro/getFirmContentList' //数据接口
, method: 'post' //方式默认是get
, toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
, where: {} //post请求必须加where post请求需要的参数
, cellMinWidth: 80
, cols: [[ //表头
{
field: 'number', width:80,title: '序号', align: 'center', type: 'numbers'
}
, {field: 'branchName', align: 'center', title: '分公司'}
, {field: 'proName', align: 'center', title: '项目部'}
, {field: 'title', align: 'center', title: '工程名称'}
, {field: 'shortName', align: 'center', title: '工程简称'}
, {field: 'volLevel', align: 'center', title: '电压等级'}
, {field: 'lineLength', align: 'center', title: '线路长度(km)'}
,{field: 'volLevel', align: 'center', title: '经纬度', templet: function(d){
return d.longitude + ',' + d.latitude;
}
}
, {field: 'startTime', align: 'center', title: '计划起止时间'}
, {field: 'endTime', align: 'center', title: '计划结束时间'}
, {field: 'proAddress', align: 'center', title: '项目地址'}
, {
field: 'proStatus', title: '项目状态', align: 'center', templet: d => {
let text = "";
if (d.proStatus === "1") {
text = "<span class='layui-badge-dot layui-bg-green'></span>在建";
} else if (d.proStatus === "2") {
text = "<span class='layui-badge-dot'></span>已完工";
}
return text;
}
},
{
fixed: 'right', width:180, title: '操作', align: 'center', templet: d => {
let text = "";
let proStatus = d.proStatus;
if ($.inArray('sysFirmContent:completed', pers) > 0) {
if (proStatus == "1") {
text +='<a lay-event="completed" style="color: #ffb800;cursor: pointer;font-size: 15px">完工</a>';
text +='<span lay-event="com" style="font-size: 15px;"> | </span>';
}
}
if ($.inArray('sysFirmContent:update', pers) > 0) {
text +='<a lay-event="update" style="color: #009688;cursor: pointer;font-size: 15px" id="updateBtn">修改</a>';
text +='<span lay-event="com" style="font-size: 15px;"> | </span>';
}
if ($.inArray('sysFirmContent:delete', pers) > 0) {
text +='<a lay-event="del" style="color: #009688;cursor: pointer;font-size: 15px" id="deleteBtn" >删除</a>';
}
return text;
}
}
]]
, id: 'menuTable'
, page: true //开启分页
, loading: true //数据加载中。。。
, limits: [5, 10, 20] //一页选择显示3,5或10条数据
, limit: 10 //一页显示5条数据
, 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"
, done: function(res, curr, count) {
for (var i = 0; i < res.data.length; i++) {
// console.log('res.data[i]:', res.data[i])
var data = res.data[i];
data.planTime = data.startTime + ' ~ ' + data.endTime;
console.log('planTime:', data.planTime); // 打印 planTime 的值
}
}
});
//监听工具条
table.on('tool(test)', function (obj) {
var data = obj.data; //当前行数据
console.log(data)
var rowIndex = obj.index;
var layEvent = obj.event; //当前点击的事件名
var proProcess = data.proProcess;
if (layEvent === 'update') {
localStorage.setItem('id',data.id);
localStorage.setItem('title',data.title);
localStorage.setItem('voltageLevelId',data.voltageLevelId);
localStorage.setItem('teamName',data.teamName);
layerOpenFormForSencond("修改","./lineProjectForm.html");
}
if (layEvent === 'del') {
var indexs = layer.confirm('确定要删除吗?', {
btn : [ '确定', '取消' ]
}, function() {
// ajaxCommonMethod('/linePro/delProjectById',{'id': data.id});
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: ctxPath + '/linePro/delProjectById',// 请求地址
contentType: "application/x-www-form-urlencoded",
dataType: 'json', // 服务器返回数据类型
data: {'id': data.id}, //获取提交的表单字段
success: function (data) {
var resMsg = data.resMsg;
layer.close(indexs);
if ("数据获取成功" === resMsg) {
reloadTip("删除","删除成功",'success');
} else if ("数据获取失败" === resMsg) {
reloadTip("删除","删除失败",'error');
}else{
reloadTip("删除",resMsg+",请先解除相应的绑定关系,在删除此工程!",'error');
}
}
});
table.reload('menuTable', {
url: ctxPath + '/linePro/getFirmContentList'
, method: 'post' //方式默认是get
, page: true
, where: {
keyWord: "",
status: "",
branchId: "",
}
});
});
}
if (layEvent === 'completed') {
layer.confirm('确定要更改项目状态?', {
btn : [ '确定', '取消' ]
}, function(index) {
if (proProcess.split('.')[0] == '100') {
const id = data.id;
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: ctxPath + '/linePro/upCompletedById',// 请求地址
contentType: "application/x-www-form-urlencoded",
dataType: 'json', // 服务器返回数据类型
data: {'id': id}, //获取提交的表单字段
success: function (data) {
var resMsg = data.resMsg;
layer.close(index);
if ("数据获取成功" === resMsg) {
reloadTip("完工","完工成功",'success');
} else if ("数据获取失败" === resMsg) {
reloadTip("完工","完工失败",'error');
}else{
// reloadTip("完工",resMsg+",请先解除相应的绑定关系,在完工此工程!",'error');
forcedUnbinding(resMsg, id);
}
}
});
}else {
layer.close(index);
reloadTip("完工","当前项目的基础,组塔,架线还未全部完成!",'error');
}
// ajaxCommonMethod('/linePro/upCompletedById',{'id': data.id});
table.reload('menuTable');
});
}
});
// 单元格编辑事件
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, "");
document.getElementById("searchBt").classList.add("layui-none");
});
function forcedUnbinding(resMsg, id){
layer.confirm('<span style="color: red;">' + '(' + resMsg + ') 没有解绑,是否强制解绑,强制解绑数据无法回退!</span>', {
icon: 7, // 警告图标
title: '警告',
closeBtn: 0, // 关闭按钮
btn: ['确定', '取消']
}, function(index) {
$.ajax({
type: 'POST',
async: false, // 默认异步true,false表示同步
url: ctxPath + '/linePro/upForcedUnbinding',// 请求地址
contentType: "application/x-www-form-urlencoded",
dataType: 'json', // 服务器返回数据类型
data: {'id': id}, //获取提交的表单字段
success: function (data) {
var resMsg = data.resMsg;
layer.close(index);
if ("数据获取成功" === resMsg) {
reloadTip("完工","完工成功",'success');
} else if ("数据获取失败" === resMsg) {
reloadTip("完工","完工失败",'error');
}
},error:function (data) {
layer.close(index);
reloadTip("完工","完工失败",'error');
}
});
table.reload('menuTable');
});
}
// $(document).ready(function() {
// // 判断用户权限数组中是否包含指定权限
// // function hasPermission(permission, callback) {
// // getUserPermissions(function(permissions) {
// // var hasPermission = permissions.includes(permission);
// // callback(hasPermission);
// // });
// // }
//
// // // 获取用户权限数组
// // function getUserPermissions(callback) {
// // $.ajax({
// // type: 'POST',
// // async: false,
// // url: ctxPath + '/linePro/getPermissionList',
// // contentType: "application/x-www-form-urlencoded",
// // dataType: 'json',
// // data: {},
// // success: function(res) {
// // console.log('data:', res.data);
// // callback(res.data);
// // },
// // error: function(error) {
// // console.error('Failed to get user permissions:', error);
// // callback([]);
// // }
// // });
// // }
//
// // 根据权限来显示或隐藏按钮
// hasPermission('sysConfig:delete', function(hasDeletePermission) {
// debugger
// if (!hasDeletePermission) {
// $('#deleteBtn').css('display','none');
// }
// });
//
// hasPermission('sysConfig:update', function(hasUpdatePermission) {
// if (!hasUpdatePermission) {
// $('#updateBtn').hide();
// }
// });
//
// hasPermission('sysConfig:add', function(hasAddPermission) {
// debugger
// if (!hasAddPermission) {
// $('#addBtn').hide();
// }
// });
// });
function reloadTip(tip,message,type){
layNotify.notice({
title: tip+"提示",
type: type,
message: message
});
}