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

683 lines
18 KiB
JavaScript
Raw Normal View History

2022-03-23 19:38:10 +08:00
import { observable, action, toJS } from 'mobx';
import { message } from 'antd';
import { WeaForm, WeaTableNew } from 'comsMobx';
import * as API from '../apis/ledger'; // 引入API接口文件
2022-03-30 20:04:34 +08:00
import { tempateColumns } from '../pages/payroll/columns';
2022-04-06 14:26:16 +08:00
import { notNull } from '../util/validate';
2022-03-23 19:38:10 +08:00
const { TableStore } = WeaTableNew;
export class LedgerStore {
@observable tableStore = new TableStore(); // new table
@observable form = new WeaForm(); // nrew 一个form
@observable condition = []; // 存储后台得到的form数据
@observable hasRight = true; // 判断用户是有权限查看当前页面: 没有权限渲染无权限页面,有权限渲染数据
@observable showSearchAd = false; // 高级搜索面板显示
@observable loading = true; // 数据加载状态
2022-03-25 16:41:59 +08:00
@observable salarySobId = "";
@observable includeType=1; // 0排除、1包含
@observable userTableStore = {};
@observable addUserModalVisible = false;
2022-03-29 17:33:54 +08:00
@observable itemGroups = [
{
id:"default",
name: "未分类",
items: []
}
];
@observable salaryItemTableStore = new TableStore();
@observable empBrowserList = []
@observable empFields = []
@observable excludeIds = []
@observable addCategoryVisible = false; // 薪资项目-添加分类Modal
2022-03-30 20:04:34 +08:00
@observable ruleOptionList = []; // 第四步规则可选项目列表
@observable sobItemRuleDataSource = []; // 第四步规则列表
@observable ledgerRuleList = [];
@observable baseInfoRequest = {};
@observable userSelectedList = [];
2022-04-20 15:28:40 +08:00
// ** 薪资项目 **
// 添加薪资项目
@observable addSalaryItemColumns = [];
@observable addSalaryItemDataSource = [];
2022-04-27 19:27:23 +08:00
@observable addSalaryItemPageInfo = {}; // 分页信息
2022-04-20 15:28:40 +08:00
2022-03-30 20:04:34 +08:00
@action
initSlideData = () => {
this.salarySobId = "";
this.includeType = 1
this.userTableStore = {}
this.addUserModalVisible = false
this.itemGroups = [
{
id:"default",
name: "未分类",
items: []
}
];
this.empBrowserList = []
this.empFields = []
this.excludeIds = []
this.ruleOptionList = []
this.sobItemRuleDataSource = []; // 第四步规则列表
this.ledgerRuleList = [];
this.baseInfoRequest = {};
this.userSelectedList = [];
}
2022-04-27 19:27:23 +08:00
// 设置员工字段
@action
setEmpFields = (empFields) => this.empFields = empFields
2022-03-30 20:04:34 +08:00
@action
setUserSelectedList = userSelectedList => this.userSelectedList = userSelectedList
@action
setBaseInfoRequest = baseInfoRequest => this.baseInfoRequest = baseInfoRequest
@action
setSobItemRuleDataSource = sobItemRuleDataSource => this.sobItemRuleDataSource = sobItemRuleDataSource
2022-03-29 17:33:54 +08:00
@action
setAddCategoryVisible = addCategoryVisible => this.addCategoryVisible = addCategoryVisible
@action
setExcludeIds = excludeIds => this.excludeIds = excludeIds
@action
addExcludeIds = id => {
let excludeIds = [...this.excludeIds]
excludeIds.push(id)
this.excludeIds = excludeIds
}
@action
addEmpFields = (fieldId) => {
let sortedIndex = 1;
if(this.empFields.length > 0) {
let lastSortedIndex = this.empFields[this.empFields.length - 1].sortedIndex
sortedIndex = parseInt(lastSortedIndex) + 1
}
let item = {
fieldId,
2022-05-07 14:47:14 +08:00
sortedIndex,
canDelete: true
2022-03-29 17:33:54 +08:00
}
let result = [...this.empFields]
result.push(item)
this.empFields = result
2022-04-27 19:27:23 +08:00
this.userSelectedList = this.empFields.map(item => {
item = {...item}
item.key = item.fieldId
if(!item.showname || item.showname == "") {
this.empBrowserList.map(bitem => {
if(bitem.key == item.fieldId) {
item.showname = bitem.showname
}
})
}
return item;
})
2022-03-29 17:33:54 +08:00
}
@action
setItemGroups = itemGroups => this.itemGroups = itemGroups
@action
addItemGroup = name => {
2022-04-06 14:26:16 +08:00
if(!name || name == "" || name.trim() == "") {
message.warning("分类名称不能为空")
return
}
2022-03-29 17:33:54 +08:00
let itemGroups = [...this.itemGroups]
let flag = false;
itemGroups.map(item => {
if(item.name == name) {
flag = true;
}
})
if(flag) {
message.warning("分类已存在")
return
}
let item = {name, items: []}
itemGroups.unshift(item)
this.setItemGroups(itemGroups)
this.addCategoryVisible = false
}
@action
addItemsToGroup = (title, list) => {
let itemGroups = [...this.itemGroups]
itemGroups.map(item => {
if(item.name == title) {
item.items = item.items ? item.items.concat(list) : list
}
})
2022-04-20 15:28:40 +08:00
2022-03-29 17:33:54 +08:00
this.setItemGroups(itemGroups);
}
@action
addCategoryList = item => {
let list = [...this.categoryList]
list.push(item)
this.categoryList = list
}
@action
removeCategoryList = item => {
let list = [...this.categoryList]
list.filter(i => item.name != i.name)
this.categoryList = list;
}
2022-03-25 16:41:59 +08:00
@action
setAddUserModalVisible = addUserModalVisible => this.addUserModalVisible = addUserModalVisible;
@action
setUserTableStore = userTableStore => this.userTableStore = userTableStore;
@action
setIncludeType = includeType => this.includeType = includeType
@action
setSalarySobId = salarySobId => this.salarySobId = salarySobId;
2022-03-23 19:38:10 +08:00
// 初始化操作
@action
doInit = () => {
// this.getCondition();
this.getTableDatas({});
2022-03-30 20:04:34 +08:00
this.setBaseInfoRequest({
name: "",
taxableItems: "1",
salaryCycleType: "1",
salaryCycleFromDay: "1",
taxCycleType: "1",
attendCycleType: "1",
attendCycleFromDay: "1",
socialSecurityCycleType: "1",
description: ""
})
2022-03-23 19:38:10 +08:00
}
2022-03-31 21:03:17 +08:00
@action
initBaseInfoRequest = () => {
this.setBaseInfoRequest({
name: "",
taxableItems: "1",
salaryCycleType: "1",
salaryCycleFromDay: "1",
taxCycleType: "1",
attendCycleType: "1",
attendCycleFromDay: "1",
socialSecurityCycleType: "1",
description: ""
})
}
2022-03-23 19:38:10 +08:00
// 获得高级搜索表单数据
@action
getCondition = () => {
API.getCondition().then(action(res => {
if (res.api_status) { // 接口请求成功/失败处理
this.condition = res.condition;
this.form.initFormFields(res.condition); // 渲染高级搜索form表单
} else {
2022-03-24 10:32:14 +08:00
message.error(res.errormsg || '接口调用失败!')
2022-03-23 19:38:10 +08:00
}
}));
}
// 渲染table数据
@action
getTableDatas = (params) => {
this.loading = true;
API.getLedgerList(params).then(action(res => {
if (res.status) { // 接口请求成功/失败处理
this.tableStore.getDatas(res.data.datas); // table 请求数据
} else {
2022-03-24 10:32:14 +08:00
message.error(res.errormsg || '接口调用失败!')
2022-03-23 19:38:10 +08:00
}
this.loading = false;
}));
}
@action
setShowSearchAd = bool => this.showSearchAd = bool;
// 高级搜索 - 搜索
@action doSearch = () => {
this.getTableDatas();
this.showSearchAd = false;
}
// 复制
@action doCopy = (id, name) => {
2022-05-13 15:25:21 +08:00
return new Promise((resolve, reject) => {
API.duplicateLedger({id, name}).then(res => {
if(res.status) {
message.success("复制成功")
this.getTableDatas({});
resolve();
} else {
message.error(res.errormsg || "复制失败")
reject();
}
})
2022-03-23 19:38:10 +08:00
})
2022-05-13 15:25:21 +08:00
2022-03-23 19:38:10 +08:00
}
2022-03-24 10:32:14 +08:00
//启用/禁用薪资帐套
@action
changeLedgerStatus = (id, disable) => {
API.changeLedgerStatus({id, disable}).then(res => {
if(res.status) {
2022-03-24 16:58:57 +08:00
this.getTableDatas({});
2022-03-24 10:32:14 +08:00
message.success("修改成功")
} else {
message.error(res.errormsg || "修改失败")
}
})
}
2022-04-06 14:26:16 +08:00
validateBaseFrom(params) {
if(!notNull(params.name)) {
message.warning("名称不能为空");
return false
}
if(!notNull(params.taxableItems)) {
message.warning("薪资类型不能为空");
return false
}
if(!notNull(params.salaryCycleType)) {
message.warning("薪资周期不能为空");
return false
}
if(!notNull(params.salaryCycleFromDay)) {
message.warning("薪资周期不能为空");
return false
}
if(!notNull(params.taxCycleType)) {
message.warning("税款所属期不能为空");
return false
}
if(!notNull(params.attendCycleType)) {
message.warning("考勤周期不能为空");
return false
}
if(!notNull(params.attendCycleFromDay)) {
message.warning("考勤周期不能为空");
return false
}
if(!notNull(params.socialSecurityCycleType)) {
message.warning("福利台账月份不能为空");
return false
}
return true
}
2022-03-24 16:58:57 +08:00
//保存薪资帐套基本信息
@action
saveLedgerBasic = (params) => {
2022-04-06 14:26:16 +08:00
if(!this.validateBaseFrom(params)) {
return
}
2022-03-30 20:04:34 +08:00
return new Promise((resolve, reject) => {
API.saveLedgerBasic(params).then(res => {
if(res.status) {
this.salarySobId = res.data;
resolve()
this.getTableDatas({})
message.success("保存成功")
} else {
reject(res.errormsg || "保存失败")
message.error(res.errormsg || "保存失败")
}
})
2022-03-24 16:58:57 +08:00
})
2022-03-30 20:04:34 +08:00
2022-03-24 16:58:57 +08:00
}
//删除薪资帐套
@action
deleteLedger = (params) => {
API.deleteLedger(params).then(res => {
if(res.status) {
message.success("删除成功")
this.getTableDatas({});
} else {
message.error(res.errormsg || "删除失败")
}
})
}
2022-03-24 10:32:14 +08:00
2022-04-06 14:26:16 +08:00
validateLedgerPersonRange(params) {
if(!notNull(params.includeType)) {
message.warning("对象类型不能为空")
return false
}
if(!notNull(params.targetParams)) {
message.warning("对象类型不能为空")
return false
}
if(!notNull(params.employeeStatus)) {
message.warning("选择员工状态不能为空")
return false
}
return true
}
2022-03-25 16:41:59 +08:00
//保存薪资帐套人员范围
@action
saveLedgerPersonRange = (params) => {
2022-04-06 14:26:16 +08:00
if(!this.validateLedgerPersonRange(params)) {
return
}
2022-03-25 16:41:59 +08:00
API.saveLedgerPersonRange(params).then(res => {
if(res.status) {
if(this.includeType == 1) {
this.getLedgerPersonRangeInclude({salarySobId: this.salarySobId})
} else {
this.getLedgerPersonRangeExclude({salarySobId: this.salarySobId})
}
this.addUserModalVisible = false;
message.success("添加成功")
} else {
message.error(res.errormsg || "添加失败")
}
})
}
//薪资帐套人员范围(包含)列表
getLedgerPersonRangeInclude = (params) => {
API.getLedgerPersonRangeInclude(params).then(res => {
if(res.status) {
this.setUserTableStore(res.data)
} else {
message.error(res.errormsg || "获取失败")
}
})
}
//薪资帐套人员范围(排除)列表
getLedgerPersonRangeExclude = (params) => {
API.getLedgerPersonRangeExclude(params).then(res => {
if(res.status) {
this.setUserTableStore(res.data)
} else {
message.error(res.errormsg || "获取失败")
}
})
}
//删除薪资帐套人员范围
deleteLedgerPersonRange = (params) => {
API.deleteLedgerPersonRange(params).then(res => {
if(res.status) {
if(this.includeType == 1) {
this.getLedgerPersonRangeInclude({salarySobId: this.salarySobId})
} else {
this.getLedgerPersonRangeExclude({salarySobId: this.salarySobId})
}
message.success("删除成功")
} else {
message.error(res.errormsg || "删除失败")
}
})
}
2022-03-29 17:33:54 +08:00
// 薪资项目可选列表
@action
2022-04-27 19:27:23 +08:00
listSalaryItem = (searchValue = "", current = 1) => {
2022-03-29 17:33:54 +08:00
let excludeIds = []
this.itemGroups.map(item => {
2022-05-31 16:21:25 +08:00
item.items && item.items.map(i => {
2022-04-27 19:27:23 +08:00
excludeIds.push(i.salaryItemId)
2022-03-29 17:33:54 +08:00
})
})
2022-04-27 19:27:23 +08:00
this.loading = true
API.listSalaryItem({name:searchValue, excludeIds, current}).then(res => {
2022-03-29 17:33:54 +08:00
if(res.status) {
2022-05-10 15:31:13 +08:00
if(res.data.list) {
this.addSalaryItemDataSource = res.data.list.map(item => {
item = {...item}
item.key = item.id
return item;
});
} else {
this.addSalaryItemDataSource = []
}
2022-04-20 15:28:40 +08:00
this.addSalaryItemColumns = res.data.columns;
2022-04-27 19:27:23 +08:00
this.addSalaryItemPageInfo = res.data
2022-04-20 15:28:40 +08:00
// this.salaryItemTableStore.getDatas(res.data.datas);
2022-03-29 17:33:54 +08:00
} else {
message.error(res.errormsg || "获取数据失败")
}
2022-04-27 19:27:23 +08:00
this.loading = false
2022-03-29 17:33:54 +08:00
})
}
@action
empFieldList = () => {
API.empFieldList().then(res => {
if(res.status) {
this.empBrowserList = res.data.map(item => {return {showname: item.name, key: item.id, selected: false}})
} else {
message.error(res.errormsg || "获取失败")
}
})
}
@action
saveLedgerItem = () => {
let itemGroups = [...this.itemGroups]
itemGroups = itemGroups.map(item => {
let result = {...item}
2022-05-10 15:31:13 +08:00
if(result.items) {
result.items = result.items.map((i,index) => (
{
salaryItemId: i.salaryItemId,
sortedIndex: index + 1,
formulaId: i.formulaId
}
))
return result;
}
}).filter(item => item)
2022-03-29 17:33:54 +08:00
let params = {
salarySobId: this.salarySobId,
empFields: this.empFields,
itemGroups: itemGroups.filter(item => item.id != "default"),
items: itemGroups.filter(item => item.id == 'default')[0].items
}
2022-03-30 20:04:34 +08:00
return new Promise((resolve, reject) => {
API.saveLedgerItem(params).then(res => {
if(res.status) {
resolve()
message.success("保存成功");
} else {
reject()
message.error(res.errormsg || "保存失败")
}
})
})
}
// 调薪计薪规则可选的薪资项目列表
@action
listSalarySobItem = () => {
let params = {
salarySobId: this.salarySobId,
excludeSalaryItemIds: this.sobItemRuleDataSource.map(item => item.salaryItemId)
}
2022-03-31 21:03:17 +08:00
return new Promise((resolve, reject) => {
API.listSalarySobItem(params).then(res => {
if(res.status) {
this.ruleOptionList = res.data.map(item => {
return {
key: item.salaryItemId.toString(),
showname: item.salaryItemName,
selected: false
}
})
resolve()
} else {
reject()
message.error(res.errormsg || "获取失败")
}
})
2022-03-30 20:04:34 +08:00
})
}
// 调薪计薪规则保存
@action
saveAdjustmentRule = () => {
let params = {
salarySobId:this.salarySobId,
ruleParams:this.sobItemRuleDataSource
}
return new Promise((resolve, reject) => {
API.saveAdjustmentRule(params).then(res => {
if(res.status) {
resolve()
message.success("保存成功")
} else {
reject()
message.error(res.errormsg || "获取失败")
}
})
})
}
@action
listAdjustmentRule = () => {
let params = {
salarySobId: this.salarySobId
}
API.listAdjustmentRule(params).then(res => {
if(res.status) {
this.sobItemRuleDataSource = res.data
}
})
}
// 保存薪资帐套校验规则
@action
saveLedgerRule = (params) => {
params.salarySobId = this.salarySobId;
API.saveLedgerRule(params).then(res => {
if(res.status) {
this.getLedgerRuleList()
message.success("保存成功")
2022-03-29 17:33:54 +08:00
} else {
message.error(res.errormsg || "保存失败")
}
})
}
2022-03-30 20:04:34 +08:00
//薪资帐套校验规则列表
@action
getLedgerRuleList = (name = "") => {
let params = {
salarySobId: this.salarySobId,
name
}
API.getLedgerRuleList(params).then(res => {
if(res.status) {
this.ledgerRuleList = res.data
} else {
message.error(res.errormsg || "获取数据失败")
}
})
}
//删除薪资帐套校验规则
@action
deleteLedgerRule = (ids) => {
API.deleteLedgerRule(ids).then(res => {
if(res.status) {
message.success("删除成功")
this.getLedgerRuleList();
} else {
message.error(res.errormsg || "删除失败")
}
})
}
// 获取基本信息
@action
getLedgerBasicForm = () => {
API.getLedgerBasicForm(this.salarySobId).then(res => {
if(res.status) {
let basicForm = res.data.basicForm
Object.keys(basicForm).map(key => {
2022-04-18 11:42:45 +08:00
if(basicForm[key]) {
basicForm[key] = basicForm[key].toString();
}
2022-03-30 20:04:34 +08:00
})
this.baseInfoRequest = basicForm
} else {
messsage.error(res.errormsg || "获取失败")
}
})
}
2022-03-29 17:33:54 +08:00
2022-03-30 20:04:34 +08:00
//薪资帐套薪资项目详情
@action
getLedgerItemForm = () => {
API.getLedgerItemForm({salarySobId: this.salarySobId}).then(res => {
if(res.status) {
this.empFields = res.data.empFields
this.itemGroups = res.data.itemGroups
let defaultItems = {
id:"default",
name: "未分类",
items:res.data.items
}
this.itemGroups.unshift(defaultItems)
API.empFieldList().then(ires => {
if(res.status) {
this.empBrowserList = ires.data.map(item => {return {showname: item.name, key: item.id, selected: false}})
this.userSelectedList = this.empFields.map(item => {
item = {...item}
item.key = item.fieldId
this.empBrowserList.map(bitem => {
if(bitem.key == item.fieldId) {
item.showname = bitem.showname
}
})
return item;
})
2022-04-27 19:27:23 +08:00
console.log("this.userSelectedList: " ,toJS(this.userSelectedList));
2022-03-30 20:04:34 +08:00
} else {
message.error(res.errormsg || "获取失败")
}
})
} else {
message.error(res.errormsg || "获取失败")
}
})
}
2022-03-25 16:41:59 +08:00
2022-03-23 19:38:10 +08:00
}