var pageCurr;
|
layui.config({
|
base: baseUrl + "/static/layui/lay/modules/"
|
}).extend({
|
cascader: 'cascader/cascader',
|
}).use(['table','laydate', 'form', 'admin', 'cascader', 'tree', 'dropdown'], function(){
|
var table = layui.table;
|
var $ = layui.jquery;
|
var layer = layui.layer;
|
var layDate = layui.laydate;
|
var form = layui.form;
|
var admin = layui.admin;
|
var cascader = layui.cascader;
|
var tree = layui.tree;
|
var dropdown = layui.dropdown;
|
|
$('#organization').html(localStorage.getItem('nickname') + ' <i class="layui-icon"></i>');
|
|
// 部门人员 筛选
|
dropdown.render({
|
elem: '#organization'
|
,content: ['<div id="organizationTree" style="height: calc(100vh - 525px);border: none"></div>'].join('')
|
,style: 'width: 370px; height: 350px; padding: 0 15px; box-shadow: 1px 1px 30px rgb(0 0 0 / 12%);'
|
,ready: function(){
|
loadTree();
|
}
|
});
|
|
// 树形图
|
var organizationTree;
|
window.loadTree = function(condition){
|
var loadIndex = layer.load(2);
|
$.ajax({
|
url: baseUrl+"/dept/user/tree/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: {
|
'condition': condition
|
},
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
if (res.code === 200){
|
organizationTree = tree.render({
|
elem: '#organizationTree',
|
id: 'organizationTree',
|
onlyIconControl: true,
|
data: res.data,
|
click: function (obj) {
|
treeCond = {
|
key: obj.data.key,
|
val: obj.data.id
|
}
|
$('#organization').html(obj.data.title + ' <i class="layui-icon"></i>');
|
$('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
|
$(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
|
clearFormVal($('#search-box'));
|
tableIns.reload({
|
where: {[obj.data.key]: obj.data.id},
|
page: {curr: 1}
|
});
|
}
|
});
|
treeData = res.data;
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
})
|
}
|
|
// 数据渲染
|
tableIns = table.render({
|
elem: '#businessTrip',
|
headers: {token: localStorage.getItem('token')},
|
url: baseUrl+'/businessTrip/list/auth',
|
page: true,
|
limit: 15,
|
limits: [15, 30, 50, 100, 200, 500],
|
toolbar: '#toolbar',
|
cellMinWidth: 50,
|
height: 'full-120',
|
cols: [[
|
// {type: 'checkbox'},
|
{field: 'id', align: 'center',title: 'ID',hide: true}
|
,{field: 'businessTripReasons', align: 'center',title: '出差事由',hide: false}
|
,{field: 'businessTransportation$', align: 'center',title: '交通工具',hide: false}
|
,{field: 'businessReturn$', align: 'center',title: '单程往返',hide: false}
|
,{field: 'businessStartAddr', align: 'center',title: '出发地', templet:function(d){return emptyShow(d.businessStartAddr)},hide: true}
|
,{field: 'businessStartAddr$', align: 'center',title: '出发地',hide: false}
|
,{field: 'businessEndAddr', align: 'center',title: '目的地', templet:function(d){return emptyShow(d.businessEndAddr)},hide: true}
|
,{field: 'businessEndAddr$', align: 'center',title: '目的地',hide: false}
|
,{field: 'businessStartTimeDay$', align: 'center',title: '出发日期',hide: false,width: 165}
|
,{field: 'businessEndTimeDay$', align: 'center',title: '结束日期',hide: false,width: 165}
|
,{field: 'businessDuration$', align: 'center',title: '出差时长',hide: false}
|
,{field: 'businessTripDays$', align: 'center',title: '出差天数',hide: false}
|
,{field: 'businessPeers', align: 'center',title: '同行人',hide: false}
|
,{field: 'businessPeersId', align: 'center',title: '时间戳',hide: true}
|
,{field: 'carNumber', align: 'center',title: '自驾私家车车牌号',hide: false}
|
,{field: 'kilometers', align: 'center',title: '自驾私家车行程明细及公里数',hide: false}
|
,{field: 'userId$', align: 'center',title: '申请人',hide: false}
|
,{field: 'deptId$', align: 'center',title: '所属部门',hide: false}
|
,{field: 'hostId', align: 'center',title: 'hostId',hide: true}
|
,{field: 'orderId', align: 'center',title: '跟踪项目',hide: false}
|
,{field: 'createTime$', align: 'center',title: '创建时间',hide: false,width: 125}
|
,{field: 'updateTime$', align: 'center',title: '更新时间',hide: false,width: 125}
|
,{field: 'updateId$', align: 'center',title: '更新人员',hide: false}
|
,{field: 'settle$', align: 'center',title: '进度', style: 'color: #1890ff;cursor:pointer', event: 'more',hide: false}
|
,{field: 'status$', align: 'center',title: '状态',hide: false}
|
,{field: 'businessTripType', align: 'center',title: '类型',hide: true}
|
,{field: 'businessNotes', align: 'center',title: '出差备注',hide: false}
|
|
,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:180}
|
]],
|
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: function(res, curr, count) {
|
if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
}
|
pageCurr=curr;
|
limit();
|
}
|
});
|
|
// 监听排序事件
|
table.on('sort(businessTrip)', 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}
|
});
|
});
|
|
// 监听头工具栏事件
|
table.on('toolbar(businessTrip)', function (obj) {
|
var checkStatus = table.checkStatus(obj.config.id).data;
|
switch(obj.event) {
|
case 'addData':
|
showEditModel();
|
break;
|
case 'deleteData':
|
if (checkStatus.length === 0) {
|
layer.msg('请选择要删除的数据', {icon: 2});
|
return;
|
}
|
del(checkStatus.map(function (d) {
|
return d.id;
|
}));
|
break;
|
case 'exportData':
|
admin.confirm('确定导出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 = {
|
'businessTrip': exportData,
|
'fields': fields
|
};
|
$.ajax({
|
url: baseUrl+"/businessTrip/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, {icon: 2})
|
}
|
}
|
});
|
});
|
break;
|
}
|
});
|
|
// 监听行工具事件
|
table.on('tool(businessTrip)', function(obj){
|
var data = obj.data;
|
switch (obj.event) {
|
case 'approval':
|
layer.confirm('审批通过?', {
|
skin: 'layui-layer-admin',
|
shade: .1,
|
offset: '200px',
|
title: data.name
|
}, function (i) {
|
layer.close(i);
|
approval(data.id);
|
});
|
break;
|
case 'more':
|
top.businessTripByMore = data.id;
|
admin.popupRight({
|
type: 1,
|
window: "top",
|
area: "1250px",
|
url: "businessTrip_more.html",
|
end: function () {
|
// $(".layui-laypage-btn")[0].click();
|
}
|
})
|
break;
|
case 'edit':
|
showEditModel(data);
|
break;
|
case "del":
|
del([data.id]);
|
break;
|
}
|
});
|
|
/* 弹窗 - 新增、修改 */
|
function showEditModel(mData) {
|
admin.open({
|
type: 1,
|
area: ["95%", "75%"],
|
title: (mData ? '修改' : '添加') + '出差申请',
|
content: $('#editDialog').html(),
|
success: function (layero, dIndex) {
|
if (mData) {
|
$('#cascaderValStart').val(mData.pcdStart);
|
}
|
if (mData) {
|
$('#cascaderValEnd').val(mData.pcdEnd);
|
}
|
layDateRender(mData);
|
cascaderRenderStart();
|
cascaderRenderEnd();
|
form.val('detail', mData);
|
form.on('submit(editSubmit)', function (data) {
|
var loadIndex = layer.load(2);
|
$.ajax({
|
url: baseUrl+"/businessTrip/"+(mData?'update':'add')+"/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: data.field,
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
if (res.code === 200){
|
layer.close(dIndex);
|
layer.msg(res.msg, {icon: 1});
|
tableReload();
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
}else {
|
layer.msg(res.msg, {icon: 2});
|
}
|
}
|
})
|
return false;
|
});
|
$(layero).children('.layui-layer-content').css('overflow', 'visible');
|
layui.form.render('select');
|
}
|
});
|
}
|
|
/* 删除 */
|
function del(ids) {
|
layer.confirm('确定要删除选中数据吗?', {
|
skin: 'layui-layer-admin',
|
shade: .1
|
}, function (i) {
|
layer.close(i);
|
var loadIndex = layer.load(2);
|
$.ajax({
|
url: baseUrl+"/businessTrip/delete/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: {ids: ids},
|
method: 'POST',
|
success: function (res) {
|
layer.close(loadIndex);
|
if (res.code === 200){
|
layer.msg(res.msg, {icon: 1});
|
tableReload();
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg, {icon: 2});
|
}
|
}
|
})
|
});
|
}
|
|
// 搜索
|
form.on('submit(search)', function (data) {
|
pageCurr = 1;
|
tableReload(false);
|
});
|
|
// 重置
|
form.on('submit(reset)', function (data) {
|
pageCurr = 1;
|
clearFormVal($('#search-box'));
|
tableReload(false);
|
});
|
|
// 时间选择器
|
function layDateRender(data) {
|
setTimeout(function () {
|
layDate.render({
|
elem: '#businessStartTime\\$',
|
type: 'datetime',
|
value: data!==undefined?data['businessStartTime\\$']:null
|
});
|
layDate.render({
|
elem: '#businessEndTime\\$',
|
type: 'datetime',
|
value: data!==undefined?data['businessEndTime\\$']:null
|
});
|
layDate.render({
|
elem: '#createTime\\$',
|
type: 'datetime',
|
value: data!==undefined?data['createTime\\$']:null
|
});
|
layDate.render({
|
elem: '#updateTime\\$',
|
type: 'datetime',
|
value: data!==undefined?data['updateTime\\$']:null
|
});
|
|
}, 300);
|
}
|
layDateRender();
|
|
// 省市区选择
|
function cascaderRenderStart() {
|
cascader.render({
|
elem: '#cascaderValStart',
|
data: citysData,
|
itemHeight: '250px',
|
filterable: true,
|
onChange: function (values, data) {
|
// console.log(values);console.log(data);
|
}
|
});
|
}
|
|
// 省市区选择
|
function cascaderRenderEnd() {
|
cascader.render({
|
elem: '#cascaderValEnd',
|
data: citysData,
|
itemHeight: '250px',
|
filterable: true,
|
onChange: function (values, data) {
|
// console.log(values);console.log(data);
|
}
|
});
|
}
|
|
function approval(planId, plannerId, dIdx) {
|
let loadIndex = layer.load(2);
|
$.ajax({
|
url: baseUrl+"/businessTrip/approval/auth",
|
headers: {'token': localStorage.getItem('token')},
|
data: {
|
planId: planId,
|
plannerId: plannerId
|
},
|
method: 'POST',
|
success: function (res) {
|
if (dIdx) {
|
layer.close(dIdx);
|
}
|
layer.close(loadIndex);
|
if (res.code === 200){
|
layer.msg(res.msg, {icon: 1});
|
tableReload();
|
} else if (res.code === 403){
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg, {icon: 2});
|
}
|
}
|
})
|
}
|
|
});
|
|
// 关闭动作
|
$(document).on('click','#data-detail-close', function () {
|
parent.layer.closeAll();
|
});
|
|
function tableReload(child) {
|
var searchData = {};
|
$.each($('#search-box [name]').serializeArray(), function() {
|
searchData[this.name] = this.value;
|
});
|
tableIns.reload({
|
where: searchData,
|
page: {curr: pageCurr}
|
});
|
}
|