447 lines
17 KiB
JavaScript
447 lines
17 KiB
JavaScript
var example = null;
|
||
var pers = null ;
|
||
var remarkShowLength = 10;
|
||
layui.use([ 'layer' ,'form'], function() {
|
||
var layer = layui.layer;
|
||
var form = layui.form;
|
||
getOrg(form);
|
||
pers = checkPermission();
|
||
|
||
getCompanyType();
|
||
$("#searchBt").click(function(){
|
||
example.ajax.reload();
|
||
});
|
||
init();
|
||
});
|
||
|
||
function init(){
|
||
example =
|
||
$('#dt-table').DataTable({
|
||
"searching": false,
|
||
"processing": true, //加载数据时显示进度状态
|
||
"serverSide" : true,
|
||
"pagingType": "full_numbers", //首页|尾页
|
||
"language": {
|
||
"url": ctxPath + "/js/plugin/datatables/Chinese.lang"
|
||
},
|
||
"ajax": {
|
||
"url" : ctxPath + "/companyManager",
|
||
"type":"get",
|
||
"data":function(d){
|
||
d.companyId = $("#orgId").val();
|
||
d.companyTypeId = $("#companyTypeId").val();
|
||
d.keyWord = $("#keyWord").val();
|
||
},
|
||
"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' );
|
||
}
|
||
});
|
||
},
|
||
|
||
"createdRow": function (row, data, dataIndex) {
|
||
var measures = data.registerCapital;
|
||
if (measures != null) {
|
||
if (measures.length > remarkShowLength) {//只有超长,才有td点击事件
|
||
$(row).children('td').eq(3).attr('onclick', 'javascript:changeShowRemarks(this);');
|
||
$(row).children('td').eq(3).css('cursor', 'pointer');
|
||
}
|
||
$(row).children('td').eq(3).attr('content', data.registerCapital);
|
||
}
|
||
},
|
||
"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","width": "10%"},
|
||
{ "data": "orgType","width": "6%"},
|
||
{ "data": "registerCapital","width": "10%"},
|
||
{ "data": "registerAddress","width": "10%"},
|
||
{ "data": "registDate","width": "6%"},
|
||
{ "data": "officeAddress","width": "10%"},
|
||
{ "data": "legalPersonName","width": "6%"},
|
||
{
|
||
"width": "6%",
|
||
"defaultContent": "",
|
||
"orderable": false,
|
||
"render": function (data, type, row) {
|
||
var createType = row['createType'];
|
||
var html;
|
||
if(createType == '1' ||createType == 1){
|
||
html = '<span>企业注册</span>'
|
||
}else if(createType == '2' || createType == 2){
|
||
html = '<span>后台新增</span>'
|
||
}
|
||
return html;
|
||
}
|
||
},
|
||
{
|
||
"width": "5%",
|
||
"defaultContent": "",
|
||
"orderable": false,
|
||
"render": function (data, type, row) {
|
||
var examineStatus = row['examineStatus'];
|
||
var html;
|
||
if(examineStatus == '0' ||examineStatus == 0 || examineStatus == "" || examineStatus == null){
|
||
html = '<span style="color: orange">未审核</span>'
|
||
}else if(examineStatus == '1' || examineStatus == 1){
|
||
html = '<span style="color:forestgreen;">已通过</span>'
|
||
}else if(examineStatus == '2' || examineStatus == 2){
|
||
html = '<span style="color: red">未通过</span>'
|
||
}
|
||
return html;
|
||
}
|
||
},
|
||
{ "data": "examineUser","width": "6%"},
|
||
{ "data": "examineTime","width": "6%"},
|
||
{ "data": "examineContent","width": "5%"},
|
||
{
|
||
"data": "",
|
||
"width": "10%",
|
||
"defaultContent": "",
|
||
"orderable": false,
|
||
"render": function (data, type, row) {
|
||
var id = row['id'];
|
||
var examineStatus = row['examineStatus'];
|
||
var html = '';
|
||
if (examineStatus == null || examineStatus == '' || examineStatus == '0'){
|
||
html+= buttonAudit(id,"", pers);
|
||
}
|
||
html+= buttonView(id, "", pers);
|
||
html+= buttonEdits(id, "", pers);
|
||
html+= buttonDel(id,"sys:company:del",pers);
|
||
return html;
|
||
}
|
||
},
|
||
],
|
||
"order": [[ 1, "desc" ],[ 2, "desc" ],[ 3, "desc" ],[ 4, "desc" ],[5, "desc"],[6, "desc"],[7, "desc"],[10, "desc"],[11, "desc"]] //在栏目列上显示排序功能
|
||
} );
|
||
}
|
||
function getPartialRemarksHtml(remarks) {
|
||
return remarks.substr(0, remarkShowLength) + ' <a href="javascript:void(0);" ><b>...</b></a>';
|
||
}
|
||
//全部备注信息
|
||
function getTotalRemarksHtml(remarks) {
|
||
return remarks + ' <a href="javascript:void(0);" >收起</a>';
|
||
}
|
||
|
||
//切换显示备注信息,显示部分或者全部
|
||
function changeShowRemarks(obj) {//obj是td
|
||
var content = $(obj).attr("content");
|
||
if (content != null && content != '') {
|
||
if ($(obj).attr("isDetail") == 'true') {//当前显示的是详细备注,切换到显示部分
|
||
//$(obj).removeAttr('isDetail');//remove也可以
|
||
$(obj).attr('isDetail', false);
|
||
$(obj).html(getPartialRemarksHtml(content));
|
||
} else {//当前显示的是部分备注信息,切换到显示全部
|
||
$(obj).attr('isDetail', true);
|
||
$(obj).html(getTotalRemarksHtml(content));
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* 新增页面
|
||
* */
|
||
function insertCorporation() {
|
||
localStorage.setItem("corporationType","新增");
|
||
var height = '85%';
|
||
var width = '85%';
|
||
var index = layer.open({
|
||
title: ['新增', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'addCorporationMag.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['确定', '关闭'],
|
||
yes: function (index, layero) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
myIframe.show();
|
||
myIframe.cancelReadOnly();
|
||
var formSubmit = layer.getChildFrame('form', index);
|
||
var submited = formSubmit.find('button')[0];
|
||
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
||
submited.click();
|
||
// example.ajax.reload(); // 刷新页面
|
||
},
|
||
btn2: function (index, layero) {
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 编辑页面
|
||
*/
|
||
function edit(id) {
|
||
localStorage.setItem("corporationType","修改");
|
||
localStorage.setItem("corporationId",id);
|
||
$.ajax({
|
||
type: 'POST',
|
||
contentType: "application/x-www-form-urlencoded",
|
||
url: ctxPath + '/companyManager/getCompanyInfoById',
|
||
data: {"id": id},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
var height = '85%';
|
||
var width = '85%';
|
||
var index = layer.open({
|
||
title: ['修改', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'addCorporationMag.html',
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['确定', '关闭'],
|
||
success: function (layero, index) {
|
||
var myIframe = window[layero.find('iframe')[0]['name']];
|
||
myIframe.setData(data); //aaa()为子页面的方法
|
||
myIframe.cancelReadOnly();
|
||
myIframe.Hide();
|
||
},
|
||
yes: function (index, layero) {
|
||
// 获取弹出层中的form表单元素
|
||
var formSubmit = layer.getChildFrame('form', index);
|
||
var submited = formSubmit.find('button')[0];
|
||
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
||
submited.click();
|
||
// example.ajax.reload();
|
||
},
|
||
btn2: function (index, layero) {
|
||
}
|
||
});
|
||
}
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 查看
|
||
* */
|
||
|
||
function view(id) {
|
||
$.ajax({
|
||
type: 'POST',
|
||
contentType: "application/x-www-form-urlencoded",
|
||
url: ctxPath + '/companyManager/getCompanyInfoById',
|
||
data: {"id": id},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
localStorage.setItem("corporationType","查看");
|
||
var height = '85%';
|
||
var width = '85%';
|
||
var index = layer.open({
|
||
title: ['查看', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'addCorporationMag.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()为子页面的方法
|
||
myIframe.setReadOnly();//为查看页面设置只读
|
||
myIframe.Hide();
|
||
},
|
||
});
|
||
}
|
||
})
|
||
|
||
}
|
||
|
||
/**
|
||
* 删除班组
|
||
* */
|
||
function del(id) {
|
||
layer.confirm("确定删除吗?", function () {
|
||
$.ajax({
|
||
type: 'delete',
|
||
url: ctxPath + '/companyManager/' + id,
|
||
data: {},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
if (data.resMsg == "删除成功") {
|
||
getCompanys(orgId);
|
||
layer.alert('删除成功', {icon: 1});
|
||
example.ajax.reload(null, false); // 刷新页面
|
||
} else {
|
||
layer.msg(data.resMsg, {icon: 2});
|
||
example.ajax.reload(null, false); // 刷新页面
|
||
}
|
||
}
|
||
})
|
||
})
|
||
}
|
||
|
||
/**
|
||
* 审核
|
||
* */
|
||
function audit(id,) {
|
||
localStorage.setItem("auditId",id);
|
||
var height = '525px';
|
||
var width = '475px';
|
||
var index = layer.open({
|
||
title: ['审核', 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
|
||
type: 2,
|
||
content: 'audit.html',
|
||
data: {"id": id},
|
||
area: [width, height],
|
||
maxmin: false,
|
||
btn: ['确定','关闭'],
|
||
success: function (layero, index) {
|
||
// var myIframe = window[layero.find('iframe')[0]['name']];
|
||
// var fnc = myIframe.setData(data); //aaa()为子页面的方法
|
||
// myIframe.cancelReadOnly();
|
||
},
|
||
yes: function (index, layero) {
|
||
// 获取弹出层中的form表单元素
|
||
var formSubmit = layer.getChildFrame('form', index);
|
||
var submited = formSubmit.find('button')[0];
|
||
// 触发点击事件,会对表单进行验证,验证成功则提交表单,失败则返回错误信息
|
||
submited.click();
|
||
// example.ajax.reload(null, false); // 刷新页面
|
||
},
|
||
btn2: function (index, layero) {
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
// 详情按钮
|
||
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+"\")'><i class='layui-icon'></i></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 + "\")'><i class='layui-icon'></i></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 + "\")'><i class='layui-icon'></i></button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
// 审核按钮
|
||
function buttonAudit(id, permission, pers) {
|
||
if (permission != "") {
|
||
if ($.inArray(permission, pers) < 0) {
|
||
return "";
|
||
}
|
||
}
|
||
var btn = $("<button class='layui-btn layui-btn-xs' title='审核' onclick='audit(\"" + id + "\")'><i class='layui-icon'></i></button>");
|
||
return btn.prop("outerHTML");
|
||
}
|
||
/**
|
||
* 获取分公司
|
||
* */
|
||
function getCompanys(orgId) {
|
||
$("#orgId").empty();
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: ctxPath + '/project/getCompanys',
|
||
data: {},
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
var str = '<option selected value="">请选择分公司</option>';
|
||
if (data.length > 0) {
|
||
for (var i = 0; i < data.length; i++) {
|
||
if (orgId == data[i].id) {
|
||
str += '<option selected value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
||
} else {
|
||
str += '<option value=\'' + data[i].id + '\'>' + data[i].name + '</option>';
|
||
}
|
||
}
|
||
}
|
||
$("#orgId").append(str);
|
||
layui.form.render('select'); //这里就是我们要渲染的地方了
|
||
}
|
||
})
|
||
}
|
||
/**
|
||
* 获取单位类型
|
||
* */
|
||
function getCompanyType() {
|
||
$("#proId").empty();
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: ctxPath + '/companyManager/getOrgType',
|
||
dataType: 'json',
|
||
success: function (data) {
|
||
if(data.length>0){
|
||
var str = '<option selected value="">请选择类型</option>';
|
||
for(var i = 0; i < data.length; i++) {
|
||
str += '<option value=\'' + data[i].id + '\'>' + data[i].orgType + '</option>';
|
||
}
|
||
$("#companyTypeId").append(str);
|
||
layui.form.render('select'); //这里就是我们要渲染的地方了
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
function getProjectParent() {
|
||
getCompanyType(layui.form);
|
||
} |