272 lines
8.9 KiB
Plaintext
272 lines
8.9 KiB
Plaintext
let table, form, layer, laydate, util;
|
||
let pageNum = 1, limitSize = 30;
|
||
$(function () {
|
||
layui.use(['layer', 'laydate', 'form', 'table', 'util'], function () {
|
||
layer = layui.layer;
|
||
form = layui.form;
|
||
table = layui.table;
|
||
util = layui.util;
|
||
form.render();
|
||
util.event('lay-active', {
|
||
query: function () {
|
||
pages(1, limitSize);
|
||
},
|
||
reset: function () {
|
||
$('#teamName').val('');
|
||
$('#type').val('');
|
||
form.render();
|
||
pages(1, limitSize);
|
||
},
|
||
export: function () {
|
||
exportData();
|
||
}
|
||
});
|
||
pages(1, 30, 1);
|
||
//触发单元格工具事件
|
||
table.on('tool(blackTable)', function (obj) { // 双击 toolDouble
|
||
let data = obj.data;
|
||
if (obj.event === 'detail') {
|
||
layer.confirm('确认把该班组移出黑名单?', {
|
||
btn: ['确定', '关闭'],//按钮
|
||
title: ['提示', 'font-size:24px;'],
|
||
}, function () {
|
||
Ajax().post({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify({
|
||
id: data.id + ""
|
||
}))
|
||
},
|
||
url: dataUrl + 'proteam/pot/team/deleteTeamBlack',
|
||
data: {
|
||
id: data.id + ""
|
||
},
|
||
success: function (data) {
|
||
if (data.code === 200) {
|
||
layer.msg(data.msg, {
|
||
icon: 1,
|
||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||
}, function () {
|
||
pages(1, limitSize);
|
||
});
|
||
} else {
|
||
layer.msg(data.msg, {icon: -1});
|
||
}
|
||
},
|
||
async: false
|
||
});
|
||
});
|
||
}
|
||
});
|
||
|
||
});
|
||
});
|
||
|
||
function pages(pageNum, pageSize) {
|
||
let params = getReqParams(pageNum, pageSize);
|
||
$.ajax({
|
||
headers: {
|
||
"encrypt": sm3(JSON.stringify(params))
|
||
},
|
||
url: dataUrl + "proteam/pot/team/getTeamBlackList" + '?token=' + token,
|
||
data: params,
|
||
type: 'POST',
|
||
async: false,
|
||
success: function (result) {
|
||
if (result.code === 200) {
|
||
if (result.rows) {
|
||
initTable(result.rows, limitSize, pageNum)
|
||
laypages(result.total, pageNum, limitSize)
|
||
}
|
||
} 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) {
|
||
layui.use(['laypage'], function () {
|
||
let laypage = layui.laypage;
|
||
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) {
|
||
table.render({
|
||
elem: "#blackTable",
|
||
id: "blackTable",
|
||
height: "full-150",
|
||
data: dataList,
|
||
cols: [
|
||
[//表头
|
||
{
|
||
title: "序号",
|
||
width: 100,
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
return (page - 1) * limit + d.LAY_INDEX;
|
||
}
|
||
},
|
||
{
|
||
field: "teamName",
|
||
title: "名称",
|
||
unresize: false,
|
||
sort: true,
|
||
minWidth: 200,
|
||
align: "center",
|
||
},
|
||
{
|
||
field: 'idNumber',
|
||
title: "身份证",
|
||
unresize: false,
|
||
sort: true,
|
||
minWidth: 200,
|
||
align: "center"
|
||
},
|
||
|
||
{
|
||
field: "content",
|
||
title: "状态",
|
||
unresize: false,
|
||
sort: true,
|
||
minWidth: 80,
|
||
align: "center",
|
||
templet: function (d) {
|
||
if (d.content === '拉黑人员') {
|
||
return '<span style="color: red">' + d.content + '</span><br>'
|
||
}
|
||
if (d.content === '重点关注人员') {
|
||
return '<span style="color: #F9770F">' + d.content + '</span><br>'
|
||
}
|
||
}
|
||
},
|
||
{
|
||
field: "userId",
|
||
title: "违章记录",
|
||
unresize: false,
|
||
sort: true,
|
||
minWidth: 200,
|
||
align: "center",
|
||
templet: function (d) {
|
||
let list = d.list;
|
||
let html = "";
|
||
$.each(list, function (index, item) {
|
||
html = html + '<span>第' + toChinesNum(index + 1) + '次违章扣分:' + item + '</span><br>'
|
||
})
|
||
return html;
|
||
}
|
||
}
|
||
],
|
||
],
|
||
limit: limit,
|
||
done: function (res, curr, count) {
|
||
$(".layui-laypage-skip").css("display", "none");
|
||
}
|
||
});
|
||
}
|
||
|
||
// 获取参数
|
||
function getReqParams(page, limit) {
|
||
return {
|
||
pageNum: page + "",
|
||
pageSize: limit + "",
|
||
teamName: $('#teamName').val(),
|
||
fzrName: $('#type').val()
|
||
};
|
||
}
|
||
|
||
//导出
|
||
function exportData() {
|
||
let loadingMsg = layer.msg("数据导出中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
|
||
let url = dataUrl + "proteam/pot/team/exportTeamBlackData?" + setData(getReqParams(pageNum, limitSize)) + '&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(
|
||
getReqParams(pageNum, limitSize)
|
||
)));
|
||
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();
|
||
}
|
||
|
||
/**
|
||
* 数字转成汉字
|
||
* @params num === 要转换的数字
|
||
* @return 汉字
|
||
* */
|
||
function toChinesNum(num) {
|
||
let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
|
||
let unit = ['', '十', '百', '千', '万']
|
||
num = parseInt(num)
|
||
let getWan = (temp) => {
|
||
let strArr = temp.toString().split('').reverse()
|
||
let newNum = ''
|
||
let newArr = []
|
||
strArr.forEach((item, index) => {
|
||
newArr.unshift(item === '0' ? changeNum[item] : changeNum[item] + unit[index])
|
||
})
|
||
let numArr = []
|
||
newArr.forEach((m, n) => {
|
||
if (m !== '零') numArr.push(n)
|
||
})
|
||
if (newArr.length > 1) {
|
||
newArr.forEach((m, n) => {
|
||
if (newArr[newArr.length - 1] === '零') {
|
||
if (n <= numArr[numArr.length - 1]) {
|
||
newNum += m
|
||
}
|
||
} else {
|
||
newNum += m
|
||
}
|
||
})
|
||
} else {
|
||
newNum = newArr[0]
|
||
}
|
||
|
||
return newNum
|
||
}
|
||
let overWan = Math.floor(num / 10000)
|
||
let noWan = num % 10000
|
||
if (noWan.toString().length < 4) {
|
||
noWan = '0' + noWan
|
||
}
|
||
return overWan ? getWan(overWan) + '万' + getWan(noWan) : getWan(num)
|
||
} |