272 lines
8.9 KiB
Plaintext
272 lines
8.9 KiB
Plaintext
let personnelTypeParam;
|
||
let form, layer, table, laypage, laydate;
|
||
let personTypeParam;
|
||
let pageNum = 1, limitSize = 50; // 默认第一页,分页数量为10
|
||
function setParams(personnelType, bePresentType) {
|
||
personnelTypeParam = personnelType;
|
||
if (personnelType === '普通作业') {
|
||
personTypeParam = '3';
|
||
} else if (personnelType === '班组骨干') {
|
||
personTypeParam = '1';
|
||
}else if (personnelType === 'ALL') {
|
||
personTypeParam = '9';
|
||
} else {
|
||
personTypeParam = '2';
|
||
}
|
||
layui.use(['form', 'layer', 'table', 'laypage', 'laydate'], function () {
|
||
form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
|
||
table = layui.table;
|
||
laypage = layui.laypage; //分页
|
||
layer = layui.layer;
|
||
laydate = layui.laydate;
|
||
laydate.render({
|
||
elem: '#curryDay', //指定元素 元素选择器
|
||
type: 'date', //选择时间类型 可选值:year(年) month(年月) date(年月日) time(时分秒) datetime(年月日时分秒)
|
||
trigger: 'click',
|
||
format: 'yyyy-MM-dd', //时间格式 常用时间格式:yyyy-MM-dd HH:mm:ss
|
||
btns: ['clear', 'now', 'confirm'], //选择框右下角显示的按钮 清除-现在-确定
|
||
done: function (value, date) { //时间回调
|
||
}
|
||
});
|
||
layui.form.render();
|
||
$('#curryDay').val(getNowTime())
|
||
pages(1, 50, 1);
|
||
// initTable();
|
||
})
|
||
}
|
||
|
||
function pages(pageNum, pageSize, typeNum) {
|
||
let params = getReqParams(pageNum, pageSize, typeNum);
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify(params))
|
||
},
|
||
url: dataUrl + "proteam/pot/home/getPersonList?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 initTable(dataList, limit, page) {
|
||
let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
||
table.render({
|
||
elem: "#personnelTable",
|
||
id: "personnelTable",
|
||
height: "full-220",
|
||
data: dataList,
|
||
limit: limit,
|
||
cols: [
|
||
[
|
||
//表头
|
||
{
|
||
title: "序号", width: 100, unresize: true, align: "center", templet: function (d) {
|
||
return (page - 1) * limit + d.LAY_INDEX;
|
||
}
|
||
},
|
||
{
|
||
field: "personName",
|
||
title: "人员姓名",
|
||
unresize: true,
|
||
align: "center",
|
||
sort: true
|
||
},
|
||
{
|
||
field: "personType",
|
||
title: "工种",
|
||
unresize: true,
|
||
align: "center",
|
||
sort: true
|
||
},
|
||
{
|
||
field: "idNumber",
|
||
title: "年龄",
|
||
width: 100,
|
||
align: "center",
|
||
sort: true,
|
||
templet: function (item) {
|
||
var age = analyzeIDCard(item.idNumber);
|
||
return age;
|
||
},
|
||
|
||
},
|
||
{
|
||
field: "proName",
|
||
title: "所属工程",
|
||
width: 350,
|
||
unresize: true,
|
||
align: "center",
|
||
sort: true
|
||
},
|
||
{
|
||
field: "teamName",
|
||
title: "所属班组",
|
||
width: 200,
|
||
unresize: true,
|
||
align: "center",
|
||
sort: true
|
||
},
|
||
{
|
||
field: "workManage",
|
||
title: "班组长",
|
||
unresize: true,
|
||
align: "center",
|
||
sort: true
|
||
}
|
||
],
|
||
],
|
||
done: function (res, curr, count) {
|
||
layer.close(loadingMsg);
|
||
$(".layui-laypage-skip").css("display", "none");
|
||
table.resize("personnelTable");
|
||
count || this.elem.next(".layui-table-view").find(".layui-table-header").css("display", "inline-block");
|
||
count || this.elem.next(".layui-table-view").find(".layui-table-box").css("overflow", "auto");
|
||
let that = this.elem.next();
|
||
if (res.data) {
|
||
res.data.forEach(function (item, index) {
|
||
if (index % 2 === 0) {
|
||
let tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#06182E')
|
||
} else {
|
||
let tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css('background-color', '#1F2F43')
|
||
}
|
||
})
|
||
}
|
||
},
|
||
});
|
||
}
|
||
|
||
// 获取参数
|
||
function getReqParams(page, limit, type) {
|
||
let obj = {};
|
||
if (!type) {
|
||
obj = {
|
||
page: page + "",
|
||
limit: limit + "",
|
||
personType: personTypeParam,
|
||
personName: $("#personName").val(),
|
||
teamName: $("#teamName").val(),
|
||
proName: $("#proName").val(),
|
||
currentDay: $('#curryDay').val()
|
||
};
|
||
} else {
|
||
obj = {
|
||
page: '1',
|
||
limit: '50',
|
||
personType: personTypeParam,
|
||
personName: '',
|
||
teamName: '',
|
||
proName: '',
|
||
currentDay: getNowTime()
|
||
};
|
||
}
|
||
return obj;
|
||
|
||
}
|
||
|
||
|
||
// 查询/重置
|
||
function query(type) {
|
||
let pattern = new RegExp("[%_<>]");
|
||
if (pattern.test($("#personName").val())) {
|
||
$("#personName").val('');
|
||
return layer.msg('人员姓名查询包含特殊字符,请重新输入', {
|
||
icon: 2,
|
||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||
});
|
||
}
|
||
if (pattern.test($("#teamName").val())) {
|
||
$("#teamName").val('');
|
||
return layer.msg('班组名称查询包含特殊字符,请重新输入', {
|
||
icon: 2,
|
||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||
});
|
||
}
|
||
if (pattern.test($("#proName").val())) {
|
||
$("#proName").val('');
|
||
return layer.msg('工程名称查询包含特殊字符,请重新输入', {
|
||
icon: 2,
|
||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||
});
|
||
}
|
||
pages(1, limitSize)
|
||
}
|
||
|
||
// 关闭页面
|
||
function closePage(type) {
|
||
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
|
||
parent.layer.close(index); //再执行关闭
|
||
}
|
||
|
||
/**
|
||
* 计算年龄
|
||
* @param IDCard
|
||
* @returns {string|number}
|
||
*/
|
||
function analyzeIDCard(IDCard) {
|
||
var age = 0, yearBirth, monthBirth, dayBirth;
|
||
//获取用户身份证号码
|
||
var userCard = IDCard;
|
||
//如果身份证号码为undefind则返回空
|
||
if (!userCard) {
|
||
return IDCard;
|
||
}
|
||
var reg = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/; //验证身份证号码的正则
|
||
if (reg.test(userCard)) {
|
||
if (userCard.length == 15) {
|
||
var org_birthday = userCard.substring(6, 12);
|
||
//获取出生年月日
|
||
yearBirth = "19" + org_birthday.substring(0, 2);
|
||
monthBirth = org_birthday.substring(2, 4);
|
||
dayBirth = org_birthday.substring(4, 6);
|
||
} else if (userCard.length == 18) {
|
||
//获取出生年月日
|
||
yearBirth = userCard.substring(6, 10);
|
||
monthBirth = userCard.substring(10, 12);
|
||
dayBirth = userCard.substring(12, 14);
|
||
|
||
}
|
||
//获取当前年月日并计算年龄
|
||
var myDate = new Date();
|
||
var monthNow = myDate.getMonth() + 1;
|
||
var dayNow = myDate.getDate();
|
||
var age = myDate.getFullYear() - yearBirth;
|
||
if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
|
||
age--;
|
||
}
|
||
//返回年龄
|
||
return age;
|
||
} else {
|
||
return IDCard;
|
||
}
|
||
} |