353 lines
13 KiB
JavaScript
353 lines
13 KiB
JavaScript
var example = null;
|
||
var pers = null;
|
||
var layer = null;
|
||
var form = null;
|
||
var token = localStorage.getItem("token");
|
||
layui.use(['layer', 'form'], function () {
|
||
layer = layui.layer;
|
||
form = layui.form;
|
||
getProject(form);
|
||
init();
|
||
pers = checkPermission();
|
||
$("#searchBt").click(function () {
|
||
example.ajax.reload();
|
||
});
|
||
});
|
||
|
||
function init() {
|
||
example =
|
||
$('#dt-table').DataTable({
|
||
"searching": false,
|
||
"processing": true, //加载数据时显示进度状态
|
||
"serverSide": true,
|
||
//表头固定
|
||
"fixedHeader": true,
|
||
"scrollX": "500px",
|
||
"scrollY": "650px",
|
||
"scrollCollapse": true,
|
||
"language": {
|
||
"url": contentPath + "/js/plugin/datatables/Chinese.lang"
|
||
},
|
||
"ajax": {
|
||
"url": ctxPath + "/project",
|
||
"type": "get",
|
||
"data": function (d) {
|
||
d.proId = $("#proId").val();
|
||
d.status = $("#status").find("option:selected").text();
|
||
},
|
||
"error": function (xhr, textStatus, errorThrown) {
|
||
var msg = xhr.responseText;
|
||
console.log(msg);
|
||
var response = JSON.parse(msg);
|
||
var code = response.code;
|
||
var message = response.message;
|
||
if (code == 400) {
|
||
layer.msg(message);
|
||
} else if (code == 401) {
|
||
localStorage.removeItem("token");
|
||
layer.msg("token过期,请先登录", {shift: -1, time: 1000}, function () {
|
||
location.href = ctxPath + '/login.html';
|
||
});
|
||
} else if (code == 403) {
|
||
console.log("未授权:" + message);
|
||
layer.msg('未授权');
|
||
} else if (code == 500) {
|
||
console.log('系统错误:' + message);
|
||
}
|
||
}
|
||
},
|
||
"lengthMenu": [ [10, 20, 50], [10, 20, 50] ], // 设置每页显示数据量选项
|
||
"drawCallback": function() {
|
||
// alert( '表格重绘了' );
|
||
var thisDataTable = $('#dt-table').DataTable();
|
||
$(".pagination").append("<li>" +
|
||
"<a class='paginate_button' style='padding:4px;' href='#' tabindex='0'>到 <input style='margin:0px;width:40px;' id='changePage'> 页</a>" +
|
||
"<a class='paginate_button' style='margin-bottom:1px' href='#' tabindex='0' id='dataTable-btn'>确认</a></li>");
|
||
//点击按钮跳转指定页数
|
||
$('#dataTable-btn').click(function (e) {
|
||
if ($("#changePage").val() && $("#changePage").val() > 0) {
|
||
var redirectpage = $("#changePage").val() - 1;
|
||
} else {
|
||
var redirectpage = 0;
|
||
}
|
||
thisDataTable.page(redirectpage).draw( 'page' );
|
||
});
|
||
//敲击回车键跳转指定页数
|
||
$("#changePage").keypress(function (e) {
|
||
if(event.keyCode==13){
|
||
if ($("#changePage").val() && $("#changePage").val() > 0) {
|
||
var redirectpage = $("#changePage").val() - 1;
|
||
} else {
|
||
var redirectpage = 0;
|
||
}
|
||
thisDataTable.page(redirectpage).draw( 'page' );
|
||
}
|
||
});
|
||
},
|
||
"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-4 col-xs-4 hidden-xs'i><'col-xs-8 col-sm-8' p v>><'dt-table-length'l>",
|
||
"columns": [
|
||
{
|
||
width: '4%',
|
||
"orderable": false,
|
||
data: function (row, type, set, meta) {
|
||
var c = meta.settings._iDisplayStart + meta.row + 1;
|
||
return c;
|
||
}
|
||
},
|
||
{"data": "orgName","orderable": false,"width":"15%"},
|
||
{"data": "name","orderable": false,"width":"15%"},
|
||
{"data": "origin","orderable": false,"width":"8%"},
|
||
{"data": "status","orderable": false,"width":"8%"},
|
||
{
|
||
"data": "",
|
||
"width":"10%",
|
||
"defaultContent": "",
|
||
"orderable": false,
|
||
"render": function (data, type, row) {
|
||
var id = row['id'];
|
||
var proStauts = row['status'];
|
||
var html = '';
|
||
if(proStauts != "完工"){
|
||
html += toBeFinished(id, "sys:project:finished", pers);
|
||
}
|
||
html += buttonView(id, "", pers);
|
||
html += buttonEdits(id, "sys:project:add", pers);
|
||
html += buttonDel(id, "sys:project:del", pers);
|
||
return html;
|
||
}
|
||
}
|
||
|
||
],
|
||
"order": [] //在栏目列上显示排序功能
|
||
});
|
||
}
|
||
/**
|
||
* 已完工页面
|
||
* */
|
||
function completedView(id){
|
||
localStorage.setItem("proId",id);
|
||
var height = '75%';
|
||
var width = '75%';
|
||
var index = layer.open({
|
||
title: ['工程完工', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'proCompletion.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['确定', '关闭'],
|
||
success: function (layero, index) {
|
||
},
|
||
yes: function (index, layero) {
|
||
// 获取弹出层中的form表单元素
|
||
var formSubmit = layer.getChildFrame('form', index);
|
||
var submited = formSubmit.find('button')[0];
|
||
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
||
submited.click();
|
||
},
|
||
btn2: function (index, layero) {
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 新增页面
|
||
* */
|
||
function addPorject() {
|
||
var height = '75%';
|
||
var width = '75%';
|
||
var index = layer.open({
|
||
title: ['新增', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'ProManagerForm.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['确定', '关闭'],
|
||
success: function (layero, index) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
myIframe.getRegisterAddressCodes(null);
|
||
myIframe.getCompanys(); //aaa()为子页面的方法
|
||
myIframe.getPayDate(null); //aaa()为子页面的方法
|
||
myIframe.getBankAccount(null); //aaa()为子页面的方法
|
||
myIframe.getLevel(null); //aaa()为子页面的方法
|
||
myIframe.getCompanyId(null,"0"); //aaa()为子页面的方法
|
||
},
|
||
yes: function (index, layero) {
|
||
// 获取弹出层中的form表单元素
|
||
var formSubmit = layer.getChildFrame('form', index);
|
||
var submited = formSubmit.find('button')[4];
|
||
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
myIframe.selectCheck(); //aaa()为子页面的方法
|
||
submited.click();
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 编辑页面
|
||
*/
|
||
function edit(id) {
|
||
$.ajax({
|
||
type: 'POST',
|
||
contentType: "application/x-www-form-urlencoded",
|
||
url: ctxPath + '/project/getProjectById',
|
||
data: {"id": id},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
var height = '75%';
|
||
var width = '75%';
|
||
var index = layer.open({
|
||
title: ['修改', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'ProManagerForm.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['确定', '关闭'],
|
||
success: function (layero, index) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
var fnc = myIframe.setData(data); //aaa()为子页面的方法
|
||
},
|
||
yes: function (index, layero) {
|
||
// 获取弹出层中的form表单元素
|
||
var formSubmit = layer.getChildFrame('form', index);
|
||
var submited = formSubmit.find('button')[4];
|
||
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
||
submited.click();
|
||
},
|
||
btn2: function (index, layero) {
|
||
}
|
||
});
|
||
}
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 查看
|
||
* */
|
||
function view(id) {
|
||
$.ajax({
|
||
type: 'POST',
|
||
contentType: "application/x-www-form-urlencoded",
|
||
url: ctxPath + '/project/getProjectById',
|
||
data: {"id": id},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
var height = '75%';
|
||
var width = '75%';
|
||
var index = layer.open({
|
||
title: ['查看', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'ProManagerFormView.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['关闭'],
|
||
success: function (layero, index) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
var fnc = myIframe.setData(data); //aaa()为子页面的方法
|
||
var fnc = myIframe.setDisable(); //aaa()为子页面的方法
|
||
},
|
||
});
|
||
}
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 删除工程
|
||
* */
|
||
function del(id) {
|
||
layer.confirm("确定删除吗?", function () {
|
||
$.ajax({
|
||
type: 'delete',
|
||
url: ctxPath + '/project/' + id,
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
if (data.resMsg == "删除成功") {
|
||
layer.msg('删除成功', {icon: 1, time: 2000});
|
||
example.ajax.reload(null, false); // 刷新页面
|
||
getProjectParent();
|
||
} else {
|
||
layer.msg(data.resMsg, {icon: 2, time: 3000});
|
||
example.ajax.reload(null, false); // 刷新页面
|
||
getProjectParent();
|
||
}
|
||
}
|
||
})
|
||
})
|
||
}
|
||
//已完工按钮
|
||
function toBeFinished(id, permission, pers){
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='已完工' onclick='completedView(\"" + id + "\")' style='background-color: transparent;color: #009688;'>已完工</button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
// 详情按钮
|
||
function buttonView(id, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='详情' onclick='view(\"" + id + "\")' style='background-color: transparent;color: #009688;'>详情</button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
// 编辑按钮
|
||
function buttonEdits(id, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='编辑' onclick='edit(\"" + id + "\")' style='background-color: transparent;color: #009688;'>编辑</button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
// 删除按钮
|
||
function buttonDel(data, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='删除' onclick='del(\"" + data + "\")' style='background-color: transparent;color: #ff4d4f;'>删除</button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
|
||
function fileImport(){
|
||
var height = '75%';
|
||
var width = '75%';
|
||
var index = layer.open({
|
||
title: ['导入工程信息', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'proImport.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['确定', '关闭'],
|
||
success: function (layero, index) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
},
|
||
yes: function (index, layero) {
|
||
// 获取弹出层中的form表单元素
|
||
var formSubmit = layer.getChildFrame('form', index);
|
||
var submited = formSubmit.find('button')[4];
|
||
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
||
submited.click();
|
||
},
|
||
btn2: function (index, layero) {
|
||
}
|
||
});
|
||
}
|
||
|
||
function templateDownload(){
|
||
window.location.href = ctxPath + "/download/download?filename=工程信息导入模板.xlsx";
|
||
}
|
||
|
||
function getProjectParent() {
|
||
getProject(layui.form);
|
||
}
|