163 lines
4.9 KiB
JavaScript
163 lines
4.9 KiB
JavaScript
let form, layer, table, tableIns;
|
||
let pageNum = 1, limitSize = 20; // 默认第一页,分页数量为20
|
||
|
||
layui.use(['form', 'layer', 'table'], function () {
|
||
form = layui.form;
|
||
layer = layui.layer;
|
||
table = layui.table;
|
||
pages(1, 20, 1);
|
||
})
|
||
|
||
|
||
function pages(pageNum, pageSize, typeNum) {
|
||
let params = getReqParams(pageNum, pageSize, typeNum);
|
||
$.ajax({
|
||
url: dataUrl + "proteam/pot/collectiveEnterprise/getCollectiveEnterpriseList?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) {
|
||
layui.use(['laypage'], function () {
|
||
let laypage = layui.laypage;
|
||
laypage.render({
|
||
elem: 'voi-page',
|
||
count: total,
|
||
curr: page,
|
||
limit: limit,
|
||
limits: [20, 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, });
|
||
tableIns = table.render({
|
||
id: 'todayTaskTable',
|
||
elem: "#todayTaskTable",
|
||
height: "full-150",
|
||
data: dataList,
|
||
cols: [
|
||
[
|
||
//表头
|
||
{
|
||
title: "序号",
|
||
width: '10%',
|
||
unresize: true,
|
||
align: "center",
|
||
templet: function (d) {
|
||
return (page - 1) * limit + d.LAY_NUM;
|
||
}
|
||
},
|
||
{
|
||
field: "enterpriseName",
|
||
title: "企业名称",
|
||
width: '80%',
|
||
unresize: false,
|
||
align: "center",
|
||
},
|
||
{
|
||
title: "操作",
|
||
width: '10%',
|
||
unresize: false,
|
||
align: "center",
|
||
templet: function (d) {
|
||
return "<a onclick='addData(" + JSON.stringify(d) + ",3)'>配置</a><div>|</div>" +
|
||
"<a onclick='addData(" + JSON.stringify(d) + ",2)'>修改</a><div>|</div>" +
|
||
"<a onclick=\"delData('" + d.enterpriseId + '\')" style="color:#EB3330;">删除</a>';
|
||
}
|
||
},
|
||
],
|
||
],
|
||
limit: limit,
|
||
done: function (res, curr, count) {
|
||
layer.close(loadingMsg);
|
||
},
|
||
});
|
||
}
|
||
|
||
|
||
// 获取参数
|
||
function getReqParams(page, limit, type) {
|
||
let obj = {};
|
||
if (!type) {
|
||
obj = {
|
||
page: page + "",
|
||
limit: limit + "",
|
||
enterpriseName: $('#enterpriseName').val(),
|
||
};
|
||
} else {
|
||
obj = {
|
||
page: 1,
|
||
limit: limit,
|
||
enterpriseName: $('#enterpriseName').val(),
|
||
|
||
};
|
||
}
|
||
return obj;
|
||
}
|
||
|
||
// 查询
|
||
function query() {
|
||
pages(1, limitSize);
|
||
}
|
||
|
||
// 新增/修改 系统外工程
|
||
function addData(params, type) {
|
||
let title = '';
|
||
if (type === 1) {
|
||
title = '新增'
|
||
params = {};
|
||
} else if (type === 2) {
|
||
title = '修改';
|
||
} else {
|
||
title = '配置施工单位';
|
||
}
|
||
params.type = type;
|
||
openIframeByParamObj("collectiveUnitForm", title, "collectiveUnitForm.html", "42%", type === 3 ? "70%" : "40%", params);
|
||
}
|
||
|
||
// 删除数据
|
||
function delData(id) {
|
||
layer.confirm('确定删除吗此条数据吗?', function () {
|
||
let loadingMsg = layer.msg('正在删除,请稍等...', { icon: 16, shade: 0.01, time: '0' });
|
||
let url = dataUrl + "proteam/pot/collectiveEnterprise/delCollectiveEnterprise";
|
||
let params = { enterpriseId: id };
|
||
ajaxRequest2(url, "POST", params, true, function (result) {
|
||
layer.close(loadingMsg); // 关闭提示层
|
||
if (result.code === 200) {
|
||
parent.layer.msg(result.msg, { icon: 1 })
|
||
query(1);
|
||
} else {
|
||
layer.msg(result.msg, { icon: 2 })
|
||
}
|
||
}, function (xhr) {
|
||
layer.close(loadingMsg); // 关闭提示层
|
||
error(xhr)
|
||
}, null, token);
|
||
})
|
||
} |