salary-management-front/pc4mobx/hrmSalary/stores/archives.js

263 lines
7.7 KiB
JavaScript

import { observable, action, toJS } from 'mobx';
import { message } from 'antd';
import { WeaForm, WeaTableNew } from 'comsMobx';
import { removePropertyCondition } from '../util/response'
import * as API from '../apis/welfareArchive'; // 引入API接口文件
const { TableStore } = WeaTableNew;
export class ArchivesStore {
@observable tableStore = new TableStore(
// {dataHandle: (datas) => {
// return dataSource;
// }}
);
@observable form = new WeaForm(); // nrew 一个form
@observable condition = []; // 存储后台得到的form数据
@observable hasRight = true; // 判断用户是有权限查看当前页面: 没有权限渲染无权限页面,有权限渲染数据
@observable showSearchAd = false; // 高级搜索面板显示
@observable loading = true; // 数据加载状态
@observable dataSource = [];
// Slide 表单
@observable baseFormData = {}
@observable socialSecurityForm = {} // 社保表单
@observable accumulationFundForm = {} // 公积金表单
@observable otherForm = {}; // 其他福利表单
// 基数表单
@observable socialSecurityPaymentForm = {}; // 社保表单
@observable accumulationFundPaymentForm = {}; // 公积金表单
@observable otherPaymentForm = {}; // 其他福利表单
@observable pageInfo = {};
// 导入预览
@observable previewCurDataList = {}
@observable previewCurDataColumns = []
@observable previewCurDataDataSource = []
@observable importResult = {}
@action
initImportParams = () => {
this.previewCurDataList = {};
this.previewCurDataColumns = [];
this.previewCurDataDataSource = [];
this.importResult = {}
}
// ** 设置导入参数 start **
@action
setPreviewCurDataColumns = (previewCurDataColumns) => {
this.previewCurDataColumns = previewCurDataColumns
}
@action
setPreviewCurDataDataSource = (previewCurDataDataSource) => {
this.previewCurDataDataSource = previewCurDataDataSource
}
@action
setImportResult = (importResult) => {
this.importResult = importResult
}
// ** 设置导入参数 end **
// 社保表单
@action
setSocialSecurityForm = socialSecurityForm => this.socialSecurityForm = socialSecurityForm;
// 公积金表单
@action
setAccumulationFundForm = accumulationFundForm => this.accumulationFundForm = accumulationFundForm
// 其他福利表单
@action
setOtherForm = otherForm => this.otherForm = otherForm
// 社保表单
@action
setSocialSecurityPaymentForm = socialSecurityPaymentForm => this.socialSecurityPaymentForm = socialSecurityPaymentForm
// 公积金表单
@action
setAccumulationFundPaymentForm = accumulationFundPaymentForm => this.accumulationFundPaymentForm = accumulationFundPaymentForm
// 其他福利基数表单
@action
setOtherPaymentForm = otherPaymentForm => this.otherPaymentForm = otherPaymentForm
// 初始化操作
@action
doInit = () => {
this.getCondition();
// this.getTableDatas();
}
// 获得高级搜索表单数据
@action
getCondition = () => {
API.getCondition().then(action(res => {
if (res.status) { // 接口请求成功/失败处理
let condition = removePropertyCondition(res.data.condition)
this.condition = condition;
this.form.initFormFields(condition); // 渲染高级搜索form表单
} else {
message.error(res.msg || '接口调用失败!')
}
}));
}
// 渲染table数据
@action
getTableDatas = (params = {}) => {
this.loading = true;
const formParams = this.form.getFormParams() || {};
params = {...formParams, ...params};
API.getTable(params).then(action(res => {
if (res.status) { // 接口请求成功/失败处理
this.dataSource = res.data.datas.map(item => {
item = {...item}
item.key = item.employeeId
return item;
})
// this.columns = res.data.columns;
this.tableStore.getDatas(res.data.dataKey.datas)
this.pageInfo = res.data.pageInfo
} else {
message.error(res.msg || '接口调用失败!')
}
this.loading = false;
}));
}
@action
setShowSearchAd = bool => this.showSearchAd = bool;
// 高级搜索 - 搜索
@action doSearch = () => {
this.getTableDatas();
this.showSearchAd = false;
}
// 查询档案基本信息表单
@action
getBaseForm = (employeeId, welfareTypeEnum ="") => {
API.getBaseForm({employeeId, welfareTypeEnum}).then(action(res => {
if(res.status) {
if(welfareTypeEnum == "") {
this.baseFormData = res.data.data
} else if(welfareTypeEnum == "SOCIAL_SECURITY"){
this.socialSecurityForm = res.data
} else if(welfareTypeEnum == "ACCUMULATION_FUND") {
this.accumulationFundForm = res.data
} else if(welfareTypeEnum == "OTHER") {
this.otherForm = res.data
}
// if(res.data && res.data.data && res.data.data.id) {
// this.getPaymentForm(employeeId, welfareTypeEnum, res.data.data.id)
// }
} else {
message.error(res.errormsg || "获取失败")
}
}))
}
// 查询档案缴纳基数表单
@action
getPaymentForm = (employeeId, welfareTypeEnum, schemeId) => {
API.getPaymentForm({employeeId, welfareTypeEnum, schemeId}).then(res => {
if(welfareTypeEnum == "SOCIAL_SECURITY") {
this.socialSecurityPaymentForm = res.data
} else if(welfareTypeEnum == "ACCUMULATION_FUND") {
this.accumulationFundPaymentForm = res.data
} else if(welfareTypeEnum == "OTHER") {
this.otherPaymentForm = res.data
}
})
}
// 保存表单
@action
save = (welfareType) => {
let baseForm = ""
let paymentForm = ""
if(welfareType == "SOCIAL_SECURITY") {
baseForm = JSON.stringify(this.socialSecurityForm.data)
paymentForm = JSON.stringify(this.socialSecurityPaymentForm.data)
} else if(welfareType == "ACCUMULATION_FUND") {
baseForm = JSON.stringify(this.accumulationFundForm.data)
paymentForm = JSON.stringify(this.accumulationFundPaymentForm.data)
} else if(welfareType == "OTHER") {
baseForm = JSON.stringify(this.otherForm.data)
paymentForm = JSON.stringify(this.otherPaymentForm.data)
}
API.save({welfareType, baseForm, paymentForm}).then(res => {
if(res.status) {
message.success("保存成功", 1)
this.getTableDatas()
} else {
message.error(res.errormsg || "保存失败", 1)
}
})
}
// 导入模板下载
@action
exportTempateDownload = (params = {}) => {
API.exportCurData(params)
}
// 导入预览
@action
previewCurData = (params) => {
API.previewCurData(params).then(res => {
if(res.status) {
this.previewCurDataList = res.data
this.previewCurDataColumns = res.data.headers.map((item, index) => {
let column = {}
column.title = item;
column.dataIndex = "" + index;
column.key = index + ""
return column
})
this.previewCurDataDataSource = res.data.list.map((item) => {
let data = {}
item.map((i, index) => {
data[index + ''] = i
})
return data
})
} else {
message.error(res.errormsg || "获取失败", 1);
}
})
}
// 导入
@action
importBatch = (params) => {
return new Promise((resolve, reject) => {
API.importBatch(params).then(res => {
if(res.status) {
this.importResult = res.data
resolve();
} else {
message.error(res.errormsg || "导入失败", 1)
reject();
}
})
})
}
// 导出档案
@action
exportArchives = (ids = "") => {
API.exportArchives(ids)
}
}