var pageCurr;
|
layui.use(['table','laydate', 'form'], function(){
|
var table = layui.table;
|
var $ = layui.jquery;
|
var layer = layui.layer;
|
var layDate = layui.laydate;
|
var form = layui.form;
|
|
var doneCallback = function(res, curr, count) {
|
if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
}
|
pageCurr=curr;
|
limit();
|
if (typeof I18n !== 'undefined') {
|
I18n.updatePage();
|
I18n.updateLayuiPagination();
|
}
|
};
|
|
function getCol() {
|
return [[
|
{type: 'checkbox', fixed: 'left'}
|
// ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
|
,{field: 'locSts', align: 'center',sort:true,title: I18n.t('loc_status_code')}
|
,{field: 'locDesc', align: 'center',sort: true,title: I18n.t('loc_status_desc'), templet: function(d) {
|
var key = 'loc_status_' + d.locSts;
|
var text = I18n.t(key);
|
return text === key ? d.locDesc : text;
|
}}
|
,{field: 'modiUser$', align: 'center',title: I18n.t('modifier')}
|
,{field: 'modiTime$', align: 'center',title: I18n.t('modify_time')}
|
// ,{field: 'appeUser$', align: 'center',title: '创建者',event: 'appeUser', style: 'text-decoration: underline;cursor:pointer'}
|
// ,{field: 'appeTime$', align: 'center',title: '添加时间'}
|
|
,{fixed: 'right', title: I18n.t('operation'), align: 'center', toolbar: '#operate', width:150}
|
]];
|
}
|
|
$(document).on('i18n:languageChanged', function() {
|
tableIns.reload({
|
cols: getCol(),
|
done: doneCallback
|
});
|
});
|
|
// 数据渲染
|
tableIns = table.render({
|
elem: '#basLocSts',
|
headers: {token: localStorage.getItem('token')},
|
url: baseUrl+'/basLocSts/list/auth',
|
page: true,
|
limit: 16,
|
limits: [16, 30, 50, 100, 200, 500],
|
even: true,
|
toolbar: '#toolbar',
|
cellMinWidth: 50,
|
cols: getCol(),
|
request: {
|
pageName: 'curr',
|
pageSize: 'limit'
|
},
|
parseData: function (res) {
|
return {
|
'code': res.code,
|
'msg': res.msg,
|
'count': res.data.total,
|
'data': res.data.records
|
}
|
},
|
response: {
|
statusCode: 200
|
},
|
done: doneCallback
|
});
|
|
// 监听排序事件
|
table.on('sort(basLocSts)', function (obj) {
|
var searchData = {};
|
$.each($('#search-box [name]').serializeArray(), function() {
|
searchData[this.name] = this.value;
|
});
|
searchData['orderByField'] = obj.field;
|
searchData['orderByType'] = obj.type;
|
tableIns.reload({
|
where: searchData,
|
page: {
|
curr: 1
|
},
|
cols: getCol(),
|
done: doneCallback
|
});
|
});
|
|
// 监听头工具栏事件
|
table.on('toolbar(basLocSts)', function (obj) {
|
var checkStatus = table.checkStatus(obj.config.id);
|
switch(obj.event) {
|
case 'addData':
|
layer.open({
|
type: 2,
|
title: I18n.t('add'),
|
maxmin: true,
|
area: ['500px', top.detailHeight],
|
shadeClose: false,
|
content: 'basLocSts_detail.html',
|
success: function(layero, index){
|
layer.getChildFrame('#data-detail-submit-edit', index).hide();
|
clearFormVal(layer.getChildFrame('#detail', index));
|
layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
|
}
|
});
|
break;
|
case 'refreshData':
|
tableIns.reload({
|
page: {
|
curr: pageCurr
|
},
|
cols: getCol(),
|
done: doneCallback
|
});
|
limit();
|
break;
|
case 'deleteData':
|
var data = checkStatus.data;
|
if (data.length === 0){
|
layer.msg(I18n.t('select_data_alert') || '请选择数据');
|
} else {
|
layer.confirm(I18n.t('confirm_delete_alert') || '确定删除选中的数据吗', function(){
|
$.ajax({
|
url: baseUrl+"/basLocSts/delete/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: {param: JSON.stringify(data)},
|
method: 'POST',
|
traditional:true,
|
success: function (res) {
|
if (res.code === 200){
|
layer.closeAll();
|
tableIns.reload({cols: getCol(), done: doneCallback});
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
})
|
});
|
}
|
break;
|
case 'exportData':
|
layer.confirm(I18n.t('confirm_export') || '确定导出Excel吗', {shadeClose: true}, function(){
|
var titles=[];
|
var fields=[];
|
obj.config.cols[0].map(function (col) {
|
if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
|
titles.push(col.title);
|
fields.push(col.field);
|
}
|
});
|
var exportData = {};
|
$.each($('#search-box [name]').serializeArray(), function() {
|
exportData[this.name] = this.value;
|
});
|
var param = {
|
'basLocSts': exportData,
|
'fields': fields
|
};
|
$.ajax({
|
url: baseUrl+"/basLocSts/export/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: JSON.stringify(param),
|
dataType:'json',
|
contentType:'application/json;charset=UTF-8',
|
method: 'POST',
|
success: function (res) {
|
layer.closeAll();
|
if (res.code === 200) {
|
table.exportFile(titles,res.data,'xls');
|
} else if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
});
|
});
|
break;
|
}
|
});
|
|
// 监听行工具事件
|
table.on('tool(basLocSts)', function(obj){
|
var data = obj.data;
|
switch (obj.event) {
|
// 详情
|
case 'detail':
|
layer.open({
|
type: 2,
|
title: I18n.t('detail'),
|
maxmin: true,
|
area: [top.detailWidth, top.detailHeight],
|
shadeClose: false,
|
content: 'basLocSts_detail.html',
|
success: function(layero, index){
|
setFormVal(layer.getChildFrame('#detail', index), data, true);
|
top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
|
layer.getChildFrame('#data-detail-submit-save,#prompt', index).hide();
|
layer.getChildFrame('#data-detail-submit-edit', index).hide();
|
layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
|
layero.find('iframe')[0].contentWindow.layui.form.render('select');
|
}
|
});
|
break;
|
// 编辑
|
case 'edit':
|
layer.open({
|
type: 2,
|
title: I18n.t('modify'),
|
maxmin: true,
|
area: ['500px', top.detailHeight],
|
shadeClose: false,
|
content: 'basLocSts_detail.html',
|
success: function(layero, index){
|
layer.getChildFrame('#data-detail-submit-save', index).hide();
|
setFormVal(layer.getChildFrame('#detail', index), data, false);
|
top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
|
top.convertDisabled(layer.getChildFrame('#locSts', index), true);
|
layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
|
layero.find('iframe')[0].contentWindow.layui.form.render('select');
|
}
|
});
|
break;
|
case 'modiUser':
|
var param = top.reObject(data).modiUser;
|
if (param === undefined) {
|
layer.msg("无数据");
|
} else {
|
layer.open({
|
type: 2,
|
title: I18n.t('modify_detail'),
|
maxmin: true,
|
area: [top.detailWidth, top.detailHeight],
|
shadeClose: false,
|
content: '../user/user_detail.html',
|
success: function(layero, index){
|
$.ajax({
|
url: baseUrl+"/user/"+ param +"/auth",
|
headers: {'token': localStorage.getItem('token')},
|
method: 'GET',
|
success: function (res) {
|
if (res.code === 200){
|
setFormVal(layer.getChildFrame('#detail', index), res.data, true);
|
top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
|
layer.getChildFrame('#password,#createTime\\$,#status', index).parent().parent().hide();
|
layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
|
layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
|
layero.find('iframe')[0].contentWindow.layui.form.render('select');
|
} else if (res.code === 403){
|
parent.location.href = "/";
|
}else {
|
layer.msg(res.msg)
|
}
|
}
|
})
|
}
|
});
|
}
|
break;
|
case 'appeUser':
|
var param = top.reObject(data).appeUser;
|
if (param === undefined) {
|
layer.msg("无数据");
|
} else {
|
layer.open({
|
type: 2,
|
title: I18n.t('create_detail'),
|
maxmin: true,
|
area: [top.detailWidth, top.detailHeight],
|
shadeClose: false,
|
content: '../user/user_detail.html',
|
success: function(layero, index){
|
$.ajax({
|
url: baseUrl+"/user/"+ param +"/auth",
|
headers: {'token': localStorage.getItem('token')},
|
method: 'GET',
|
success: function (res) {
|
if (res.code === 200){
|
setFormVal(layer.getChildFrame('#detail', index), res.data, true);
|
top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
|
layer.getChildFrame('#data-detail-submit', index).hide();
|
layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
|
layero.find('iframe')[0].contentWindow.layui.form.render('select');
|
} else if (res.code === 403){
|
parent.location.href = "/";
|
}else {
|
layer.msg(res.msg)
|
}
|
}
|
})
|
}
|
});
|
}
|
break;
|
|
}
|
});
|
|
// 数据保存动作
|
form.on('submit(save)', function () {
|
if (banMsg != null){
|
layer.msg(banMsg);
|
return;
|
}
|
method("add");
|
});
|
|
// 数据修改动作
|
form.on('submit(edit)', function () {
|
if (banMsg != null){
|
layer.msg(banMsg);
|
return;
|
}
|
method("edit");
|
});
|
|
function method(key) {
|
var data = {};
|
$.each($('#detail [name]').serializeArray(), function() {
|
data[this.name] = this.value;
|
});
|
$.each($('#detail .layui-input').serializeArray(), function() {
|
data[this.name] = this.value;
|
});
|
|
var url = "";
|
if (key === "add") url = baseUrl+"/basLocSts/add/auth";
|
else if (key === "edit") url = baseUrl+"/basLocSts/update/auth";
|
|
$.ajax({
|
url: url,
|
headers: {'token': localStorage.getItem('token')},
|
data: JSON.stringify(data),
|
contentType: "application/json;charset=UTF-8",
|
method: 'POST',
|
success: function (res) {
|
if (res.code === 200){
|
layer.msg(res.msg);
|
setTimeout(function () {
|
var index = parent.layer.getFrameIndex(window.name);
|
parent.layer.close(index);
|
parent.tableIns.reload({cols: parent.getCol(), done: parent.doneCallback});
|
}, 1000)
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
})
|
}
|
});
|