474 lines
14 KiB
JavaScript
474 lines
14 KiB
JavaScript
import { observable, action, toJS } from "mobx";
|
|
import { message } from "antd";
|
|
import { WeaForm, WeaTableNew } from "comsMobx";
|
|
|
|
import * as API from "../apis/attendance"; // 引入API接口文件
|
|
|
|
const { TableStore } = WeaTableNew;
|
|
|
|
export class AttendanceStore {
|
|
@observable tableStore = new TableStore(); // new table
|
|
@observable attendTableStore = new TableStore();
|
|
@observable form = new WeaForm(); // nrew 一个form
|
|
@observable condition = []; // 存储后台得到的form数据
|
|
@observable hasRight = true; // 判断用户是有权限查看当前页面: 没有权限渲染无权限页面,有权限渲染数据
|
|
@observable showSearchAd = false; // 高级搜索面板显示
|
|
@observable loading = true; // 数据加载状态
|
|
@observable step = 0;
|
|
@observable modalVisiable = false;
|
|
@observable slideVisiable = false;
|
|
@observable currentItem = {};
|
|
@observable currentItemOperate = "add";
|
|
@observable fieldSettingAttendList = []; // 表头考勤列表
|
|
@observable fieldSettingCustomList = []; // 表头自定义列表
|
|
|
|
requestFeildAttendList = []; // 请求数据
|
|
requestFeildCustomList = []; // 请求数据
|
|
|
|
// 考勤字段
|
|
@observable fieldDataSource = []; // 字段列表
|
|
@observable fieldTableStore = new TableStore(); // new Table
|
|
@observable fieldPageInfo = {};
|
|
|
|
// 考勤数据列表
|
|
@observable attendanceDataSource = [];
|
|
@observable attendancePageInfo = {};
|
|
@observable attendanceColumns = [];
|
|
|
|
// 导入
|
|
@observable importLedgerList = []; // 表单-账套列表
|
|
@observable previewAttendQuoteList = []; // 导入-预览列表
|
|
@observable previewAttendQuoteColumns = []; // 导入预览-列表对应列
|
|
@observable previewAttendQuoteDataSource = []; // 导入预览-列表
|
|
@observable importResult = {};
|
|
|
|
// 考勤数据详情
|
|
@observable attendQuoteDetailPageInfo = {}; // 详情列表分页数据
|
|
@observable attendQuoteDetailTableStore = new TableStore(); // 详情列表表头数据
|
|
|
|
@observable cycle = {};
|
|
|
|
// ** 设置导入参数 start **
|
|
@action
|
|
setPreviewAttendQuoteColumns = (previewAttendQuoteColumns) => {
|
|
this.previewAttendQuoteColumns = previewAttendQuoteColumns;
|
|
};
|
|
|
|
@action
|
|
setPreviewAttendQuoteDataSource = (previewAttendQuoteDataSource) => {
|
|
this.previewAttendQuoteDataSource = previewAttendQuoteDataSource;
|
|
};
|
|
|
|
@action
|
|
setImportResult = (importResult) => {
|
|
this.importResult = importResult;
|
|
};
|
|
// ** 设置导入参数 end **
|
|
|
|
@action
|
|
searchFieldSettingList = (value) => {
|
|
if (value != "") {
|
|
let requestFeildAttendList = [...this.requestFeildAttendList];
|
|
this.fieldSettingAttendList = requestFeildAttendList.filter(
|
|
(item) => item.name.indexOf(value) > -1
|
|
);
|
|
let requestFeildCustomList = [...this.requestFeildCustomList];
|
|
this.fieldSettingCustomList = requestFeildCustomList.filter(
|
|
(item) => item.name.indexOf(value) > -1
|
|
);
|
|
} else {
|
|
this.fieldSettingAttendList = [...this.requestFeildAttendList];
|
|
this.fieldSettingCustomList = [...this.requestFeildCustomList];
|
|
}
|
|
};
|
|
|
|
@action
|
|
setFieldSettingAttendList = (fieldSettingAttendList) => {
|
|
this.fieldSettingAttendList = fieldSettingAttendList;
|
|
let requestFeildAttendList = [...this.requestFeildAttendList];
|
|
requestFeildAttendList.map((item) => {
|
|
this.fieldSettingAttendList.map((inner) => {
|
|
if (inner.id == item.id && inner.checked != item.checked) {
|
|
item.checked = inner.checked;
|
|
}
|
|
});
|
|
});
|
|
this.requestFeildAttendList = requestFeildAttendList;
|
|
};
|
|
|
|
@action
|
|
setFieldSettingCustomList = (fieldSettingCustomList) => {
|
|
this.fieldSettingCustomList = fieldSettingCustomList;
|
|
let requestFeildCustomList = [...this.requestFeildCustomList];
|
|
requestFeildCustomList.map((item) => {
|
|
this.fieldSettingCustomList.map((inner) => {
|
|
if (inner.id == item.id && inner.checked != item.checked) {
|
|
item.checked = inner.checked;
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
@action
|
|
setCurrentItem = (currentItem) => (this.currentItem = currentItem);
|
|
|
|
@action
|
|
setCurrentItemOperate = (currentItemOperate) =>
|
|
(this.currentItemOperate = currentItemOperate);
|
|
|
|
@action
|
|
setSlideVisiable = (slideVisiable) => (this.slideVisiable = slideVisiable);
|
|
|
|
@action
|
|
setStep = (step) => (this.step = step);
|
|
|
|
@action
|
|
setModalVisiable = (modalVisiable) => (this.modalVisiable = modalVisiable);
|
|
|
|
// 初始化操作
|
|
@action
|
|
doInit = () => {
|
|
// this.getCondition();
|
|
// this.getTableDatas();
|
|
this.getAttendanceList({});
|
|
// this.getAttendanceFieldSettingList({sourceType:'IMPORT'})
|
|
};
|
|
|
|
// 获得高级搜索表单数据
|
|
@action
|
|
getCondition = () => {
|
|
API.getCondition().then(
|
|
action((res) => {
|
|
if (res.api_status) {
|
|
// 接口请求成功/失败处理
|
|
this.condition = res.condition;
|
|
this.form.initFormFields(res.condition); // 渲染高级搜索form表单
|
|
} else {
|
|
message.error(res.errormsg || "接口调用失败!");
|
|
}
|
|
})
|
|
);
|
|
};
|
|
|
|
// 渲染table数据
|
|
@action
|
|
getTableDatas = (params) => {
|
|
this.loading = true;
|
|
const formParams = this.form.getFormParams() || {};
|
|
params = params || formParams;
|
|
API.getTableDatas(params).then(
|
|
action((res) => {
|
|
if (res.api_status) {
|
|
// 接口请求成功/失败处理
|
|
this.tableStore.getDatas(res.datas); // table 请求数据
|
|
this.hasRight = res.hasRight;
|
|
} else {
|
|
message.error(res.errormsg || "接口调用失败!");
|
|
}
|
|
this.loading = false;
|
|
})
|
|
);
|
|
};
|
|
|
|
@action
|
|
setShowSearchAd = (bool) => (this.showSearchAd = bool);
|
|
|
|
// 高级搜索 - 搜索
|
|
@action doSearch = () => {
|
|
this.getTableDatas();
|
|
this.showSearchAd = false;
|
|
};
|
|
|
|
// 字段列表
|
|
@action getAttendanceFieldList = (params) => {
|
|
this.loading = true;
|
|
API.getAttendanceFieldList(params).then((res) => {
|
|
if (res.status) {
|
|
// 接口请求成功/失败处理
|
|
this.fieldTableStore.getDatas(res.data.dataKey.datas); // table 请求数据
|
|
this.fieldDataSource = res.data.pageInfo.list;
|
|
this.fieldPageInfo = res.data.pageInfo;
|
|
} else {
|
|
message.error(res.errormsg || "接口调用失败!");
|
|
}
|
|
this.loading = false;
|
|
});
|
|
};
|
|
|
|
@action saveAttendanceField = (params) => {
|
|
API.saveAttendanceField(params).then((res) => {
|
|
if (res.status) {
|
|
message.success("保存成功");
|
|
} else {
|
|
message.error(res.errormsg || "保存失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
@action deleteAttendanceField = (params) => {
|
|
API.deleteAttendanceField(params).then((res) => {
|
|
if (res.status) {
|
|
message.success("删除成功");
|
|
} else {
|
|
message.error(res.errormsg || "删除失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
// 批量删除
|
|
@action
|
|
doBatchDelete = () => {
|
|
let ids = toJS(this.tableStore.selectedRowKeys);
|
|
if (ids.length == 0) {
|
|
message.warning("未选择任何条目");
|
|
return;
|
|
}
|
|
API.deleteAttendanceField(this.tableStore.selectedRowKeys).then((res) => {
|
|
if (res.status) {
|
|
message.success("删除成功");
|
|
} else {
|
|
message.error(res.errormsg || "删除失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
// 更新
|
|
@action
|
|
updateAttendanceField = (params) => {
|
|
API.updateAttendanceField(params).then((res) => {
|
|
if (res.status) {
|
|
message.success("修改成功");
|
|
} else {
|
|
message.error(res.errormsg || "修改失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
// 更新状态
|
|
@action
|
|
updateAttendanceFieldStatus = (params) => {
|
|
return API.updateAttendanceFieldStatus(params).then((res) => {
|
|
if (res.status) {
|
|
message.success("修改成功");
|
|
return new Promise((resolve, reject) => {
|
|
resolve(true);
|
|
});
|
|
} else {
|
|
message.error(res.errormsg || "修改失败");
|
|
return new Promise((resolve, reject) => {
|
|
resolve(false);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
// 考勤数据列表
|
|
@action
|
|
getAttendanceList = (params) => {
|
|
this.loading = true;
|
|
API.getAttendanceList(params).then((res) => {
|
|
if (res.status) {
|
|
// 接口请求成功/失败处理
|
|
// this.attendTableStore.getDatas(res.data.datas); // table 请求数据
|
|
this.attendanceDataSource = res.data.list;
|
|
this.attendancePageInfo = res.data;
|
|
this.attendanceColumns = res.data.columns;
|
|
} else {
|
|
message.error(res.errormsg || "接口调用失败!");
|
|
}
|
|
this.loading = false;
|
|
});
|
|
};
|
|
|
|
//数据采集-考勤引用-考勤引用字段设置-列表
|
|
@action
|
|
getAttendanceFieldSettingList = (params) => {
|
|
this.loading = true;
|
|
API.getAttendanceFieldSettingList(params).then((res) => {
|
|
if (res.status) {
|
|
this.requestFeildAttendList = res.data[0] ? res.data[0].items : [];
|
|
this.fieldSettingAttendList = this.requestFeildAttendList;
|
|
this.requestFeildCustomList = res.data[1] ? res.data[1].items : [];
|
|
this.fieldSettingCustomList = this.requestFeildCustomList;
|
|
} else {
|
|
message.error(res.errormsg || "接口调用失败!");
|
|
}
|
|
this.loading = false;
|
|
});
|
|
};
|
|
|
|
//数据采集-考勤引用-考勤引用字段设置-保存
|
|
@action
|
|
saveAttendanceFieldSetting = (sourceType = "IMPORT") => {
|
|
let attendList = this.requestFeildAttendList.map((item) => ({
|
|
id: item.id,
|
|
checked: item.checked,
|
|
}));
|
|
let customList = this.requestFeildCustomList.map((item) => ({
|
|
id: item.id,
|
|
checked: item.checked,
|
|
}));
|
|
let request = {
|
|
sourceType: sourceType,
|
|
currentSettingFields: [...attendList, ...customList],
|
|
};
|
|
API.saveAttendanceFieldSetting(request).then((res) => {
|
|
if (res.status) {
|
|
message.success("保存成功");
|
|
} else {
|
|
message.error(res.errormsg || "保存失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
//数据采集-考勤引用-考勤引用字段设置-恢复默认设置
|
|
@action
|
|
returnToAttendanceFieldSettingDefault = (sourceType = "IMPORT") => {
|
|
API.returnToAttendanceFieldSettingDefault({ sourceType: sourceType }).then(
|
|
(res) => {
|
|
if (res.status) {
|
|
this.requestFeildAttendList = res.data[0] ? res.data[0].items : [];
|
|
this.fieldSettingAttendList = this.requestFeildAttendList;
|
|
this.requestFeildCustomList = res.data[1] ? res.data[1].items : [];
|
|
this.fieldSettingCustomList = this.requestFeildCustomList;
|
|
} else {
|
|
message.error(res.errormsg || "获取数据失败");
|
|
}
|
|
}
|
|
);
|
|
};
|
|
|
|
//数据采集-考勤引用-考勤引用字段设置-设为默认设置
|
|
@action
|
|
saveAttendanceFieldSettingAsDefault = (sourceType = "IMPORT") => {
|
|
let attendList = this.requestFeildAttendList.map((item) => ({
|
|
id: item.id,
|
|
checked: item.checked,
|
|
}));
|
|
let customList = this.requestFeildCustomList.map((item) => ({
|
|
id: item.id,
|
|
checked: item.checked,
|
|
}));
|
|
let request = {
|
|
sourceType: sourceType,
|
|
currentSettingFields: [...attendList, ...customList],
|
|
};
|
|
API.saveAttendanceFieldSettingAsDefault(request).then((res) => {
|
|
if (res.status) {
|
|
message.success("设置成功");
|
|
} else {
|
|
message.error(res.errormsg || "设置失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
// 导入表单-账套列表
|
|
@action
|
|
getLedgerList = () => {
|
|
return new Promise((resolve, reject) => {
|
|
API.getLedgerList({}).then((res) => {
|
|
if (res.status) {
|
|
this.importLedgerList = res.data;
|
|
resolve(this.importLedgerList);
|
|
} else {
|
|
message.error(res.errormsg || "获取失败");
|
|
reject();
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
// 下载导入模板
|
|
@action
|
|
downloadTemplate = (salaryYearMonth, salarySobId) => {
|
|
API.downloadTemplate(salaryYearMonth, salarySobId);
|
|
};
|
|
|
|
// 导入预览
|
|
@action
|
|
previewAttendQuote = (params) => {
|
|
API.previewAttendQuote(params).then((res) => {
|
|
if (res.status) {
|
|
this.previewAttendQuoteList = res.data;
|
|
this.previewAttendQuoteColumns = res.data.headers.map((item, index) => {
|
|
let column = {};
|
|
column.title = item;
|
|
column.dataIndex = "" + index;
|
|
column.key = index + "";
|
|
return column;
|
|
});
|
|
|
|
this.previewAttendQuoteDataSource = res.data.list.map((item) => {
|
|
let data = {};
|
|
item.map((i, index) => {
|
|
data[index + ""] = i;
|
|
});
|
|
return data;
|
|
});
|
|
} else {
|
|
message.error(res.errormsg || "获取失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
// 考勤导入
|
|
@action
|
|
importAttendQuoteData = (params) => {
|
|
API.importAttendQuoteData(params).then((res) => {
|
|
if (res.status) {
|
|
this.importResult = res.data;
|
|
} else {
|
|
message.error(res.errormsg || "导入失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
// 考勤数据详情
|
|
@action
|
|
viewAttendQuote = (params = {}) => {
|
|
API.viewAttendQuote(params).then((res) => {
|
|
if (res.status) {
|
|
this.attendQuoteDetailPageInfo = res.data.pageInfo;
|
|
this.attendQuoteDetailTableStore.getDatas(res.data.dataKey.datas);
|
|
} else {
|
|
message.error(res.errormsg || "获取失败");
|
|
}
|
|
});
|
|
};
|
|
|
|
// 考勤引用同步
|
|
@action
|
|
syncAttendanceRefer = (params) => {
|
|
return new Promise((resolve, reject) => {
|
|
API.syncAttendanceRefer(params).then((res) => {
|
|
if (res.status) {
|
|
message.success("同步成功");
|
|
resolve();
|
|
} else {
|
|
message.error(res.errormsg || "同步失败");
|
|
reject();
|
|
}
|
|
});
|
|
});
|
|
};
|
|
// 考勤引用同步
|
|
@action
|
|
checkOperation = (params) => {
|
|
return API.checkOperation(params);
|
|
};
|
|
|
|
// 根据所属月和账套获取周期
|
|
@action
|
|
getSalaryCycleAndAttendCycle = (salaryYearMonthStr, salarySobId) => {
|
|
API.getSalaryCycleAndAttendCycle({ salaryYearMonthStr, salarySobId }).then(
|
|
(res) => {
|
|
if (res.status) {
|
|
this.cycle = res.data;
|
|
} else {
|
|
message.error(res.errormsg || "获取失败");
|
|
}
|
|
}
|
|
);
|
|
};
|
|
}
|