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

346 lines
9.9 KiB
JavaScript
Raw Normal View History

2022-07-28 17:16:40 +08:00
import { action, observable } from "mobx";
import { message } from "antd";
import { WeaForm, WeaTableNew } from "comsMobx";
2022-03-12 17:07:11 +08:00
2022-07-28 17:16:40 +08:00
import * as API from "../apis/welfareScheme"; // 引入API接口文件
import { notNull } from "../util/validate";
2022-03-12 17:07:11 +08:00
const { TableStore } = WeaTableNew;
export class ProgrammeStore {
@observable tableStore = new TableStore(); // new table
@observable condition = []; // 存储后台得到的form数据
@observable hasRight = true; // 判断用户是有权限查看当前页面: 没有权限渲染无权限页面,有权限渲染数据
@observable showSearchAd = false; // 高级搜索面板显示
@observable loading = true; // 数据加载状态
2023-02-13 16:38:15 +08:00
@observable deleteLoading = false; // 删除加载状态
2022-03-12 17:07:11 +08:00
@observable selectedKey = "SOCIAL_SECURITY";
2023-02-13 16:38:15 +08:00
@observable customSelectkey = "";
2022-03-21 17:43:26 +08:00
@observable defaultPersonDataSource = []; // 默认新增列表DataSource
@observable defaultCompanyDataSource = [];
@observable requestParams = {
schemeName: "",
remarks: "",
2022-08-25 17:54:18 +08:00
paymentArea: "1",
sharedType: "",
2023-02-13 16:38:15 +08:00
taxAgentIds: ""
};
2022-07-28 17:16:40 +08:00
@observable form = new WeaForm();
2022-03-22 16:53:39 +08:00
@observable formCondition = []; // 存储后台得到的form数据
2022-04-24 14:50:44 +08:00
@observable customNewVisible = false;
2023-02-13 16:38:15 +08:00
@observable customRequest = {};
2022-03-28 10:53:19 +08:00
2022-04-22 17:00:10 +08:00
// 福利方案列表
@observable tableDataSource = [];
@observable tableColumns = [];
2022-04-24 14:50:44 +08:00
@observable tablePageInfo = {};
2022-04-22 17:00:10 +08:00
2022-05-30 17:30:53 +08:00
@action
2023-02-13 16:38:15 +08:00
setCustomSelectkey = customSelectkey => this.customSelectkey = customSelectkey;
2022-07-28 17:16:40 +08:00
2022-03-28 10:53:19 +08:00
@action
2023-02-13 16:38:15 +08:00
setCustomRequest = customRequest => this.customRequest = customRequest;
2022-03-28 10:53:19 +08:00
@action
setCustomNewVisible = customNewVisible => this.customNewVisible = customNewVisible;
2022-03-21 17:43:26 +08:00
@action
2022-03-21 19:54:16 +08:00
setRequestParams = requestParams => this.requestParams = requestParams;
2022-03-21 17:43:26 +08:00
@action
setDefaultPersonDataSource = defaultPersonDataSource => this.defaultPersonDataSource = defaultPersonDataSource;
@action
setDefaultCompanyDataSource = defaultCompanyDataSource => this.defaultCompanyDataSource = defaultCompanyDataSource;
2022-03-28 10:53:19 +08:00
@action
initSlideParms = () => {
this.requestParams = {
schemeName: "",
remarks: "",
2022-08-25 17:54:18 +08:00
paymentType: "SCHEME_TOWN",
sharedType: "",
2023-02-13 16:38:15 +08:00
taxAgentIds: ""
};
2022-03-28 10:53:19 +08:00
this.defaultPersonDataSource = [];
this.defaultCompanyDataSource = [];
2023-02-13 16:38:15 +08:00
};
2022-03-28 10:53:19 +08:00
2022-03-12 17:07:11 +08:00
@action
setSelectedKey = selectedKey => this.selectedKey = selectedKey;
// 初始化操作
@action
doInit = () => {
this.getTableDatas();
// this.getCustomCategoryList();
2023-02-13 16:38:15 +08:00
};
2022-03-12 17:07:11 +08:00
// 获得高级搜索表单数据
2022-03-22 16:53:39 +08:00
// @action
// getCondition = () => {
// API.getForm().then(action(res => {
// if (res.status) { // 接口请求成功/失败处理
// this.condition = res.condition;
// this.form.initFormFields(res.condition); // 渲染高级搜索form表单
// } else {
// message.error(res.msg || '接口调用失败!')
// }
// }));
// }
2022-03-12 17:07:11 +08:00
// 渲染table数据
@action
getTableDatas = (selectKey = "SOCIAL_SECURITY", params) => {
this.loading = true;
const formParams = this.form.getFormParams() || {};
params = params || formParams;
2023-02-13 16:38:15 +08:00
params.welfareTypeEnum = selectKey;
2022-03-12 17:07:11 +08:00
API.getTable(params).then(action(res => {
if (res.status) { // 接口请求成功/失败处理
2022-04-22 17:00:10 +08:00
// this.tableStore.getDatas(res.data.datas); // table 请求数据
this.tableDataSource = res.data.list ? res.data.list : [];
this.tableColumns = res.data.columns;
2022-04-24 14:50:44 +08:00
this.tablePageInfo = res.data;
2022-03-12 17:07:11 +08:00
} else {
2023-02-13 16:38:15 +08:00
message.error(res.errormsg || "接口调用失败!");
2022-03-12 17:07:11 +08:00
}
this.loading = false;
}));
2023-02-13 16:38:15 +08:00
};
2022-03-12 17:07:11 +08:00
// 渲染自定义福利
@action
2022-04-01 10:39:01 +08:00
getCustomCategoryList = (selectKey = "", params) => {
2022-03-12 17:07:11 +08:00
this.loading = true;
const formParams = this.form.getFormParams() || {};
params = params || formParams;
2023-02-13 16:38:15 +08:00
params.welfareTypeEnum = selectKey;
2022-03-12 17:07:11 +08:00
API.getCustomCategoryList(params).then(action(res => {
if (res.status) { // 接口请求成功/失败处理
} else {
2023-02-13 16:38:15 +08:00
message.error(res.errormsg || "接口调用失败!");
2022-03-12 17:07:11 +08:00
}
this.loading = false;
}));
2023-02-13 16:38:15 +08:00
};
2022-03-12 17:07:11 +08:00
@action
setShowSearchAd = bool => this.showSearchAd = bool;
// 高级搜索 - 搜索
@action doSearch = () => {
this.getTableDatas();
this.showSearchAd = false;
2023-02-13 16:38:15 +08:00
};
2022-03-12 17:07:11 +08:00
2022-03-21 17:43:26 +08:00
// 获取form, 获取获取详情
@action getForm = (params) => {
2023-02-13 16:38:15 +08:00
return new Promise((resolve, reject) => {
API.getForm(params).then(res => {
if (res.status) {
let resultList = res.data.form.schemeDetailList;
resultList = _.map(resultList, it => ({
...it,
rententionRule: it.rententionRule ? it.rententionRule : "2",
validNum: !_.isNil(it.validNum) ? it.validNum : "2"
}));
this.defaultPersonDataSource = resultList.filter(item => item.paymentScope == "个人");
this.defaultCompanyDataSource = resultList.filter(item => item.paymentScope == "公司");
let defaultRequest = {
schemeName: "",
remarks: "",
paymentArea: "1"
};
this.requestParams = { ...defaultRequest, ...res.data.form.schemeBatch };
resolve();
} else {
reject();
2022-03-21 19:54:16 +08:00
}
2023-02-13 16:38:15 +08:00
}).catch(() => reject());
});
};
2022-03-21 17:43:26 +08:00
2022-04-06 14:26:16 +08:00
valideForm(params) {
2023-02-13 16:38:15 +08:00
if (!notNull(params.insuranceScheme.paymentType)) {
message.warning("缴纳类型不能为空");
return false;
2022-04-06 14:26:16 +08:00
}
2023-02-13 16:38:15 +08:00
if (!notNull(params.insuranceScheme.schemeName)) {
message.warning("方案名称不能为空");
return false;
2022-04-06 14:26:16 +08:00
}
2022-08-25 17:54:18 +08:00
2023-02-13 16:38:15 +08:00
if (this.requestParams.sharedType === "1" && !notNull(params.insuranceScheme.taxAgentIds)) {
message.warning("可见性范围不能为空");
return false;
2022-08-25 17:54:18 +08:00
}
2022-04-06 14:26:16 +08:00
return true;
}
2022-03-21 17:43:26 +08:00
@action createScheme = (params) => {
2022-05-18 17:10:12 +08:00
params.insuranceScheme.paymentArea = params.insuranceScheme.paymentType;
2023-02-13 16:38:15 +08:00
return new Promise((resolve, reject) => {
if (!this.valideForm(params)) {
2022-08-25 17:54:18 +08:00
reject("新建失败");
2023-02-13 16:38:15 +08:00
return;
2022-03-21 17:43:26 +08:00
}
2022-08-25 17:54:18 +08:00
API.createScheme(params).then(res => {
2023-02-13 16:38:15 +08:00
if (res.status) {
resolve(res);
2022-08-25 17:54:18 +08:00
message.success("新建成功");
this.getTableDatas(this.selectedKey);
} else {
reject("新建失败");
2023-02-13 16:38:15 +08:00
message.error(res.errormsg || "新建失败");
2022-08-25 17:54:18 +08:00
}
2023-02-13 16:38:15 +08:00
});
});
};
2022-03-21 17:43:26 +08:00
2022-03-21 19:54:16 +08:00
@action updateScheme = (params) => {
2022-05-18 17:10:12 +08:00
params.insuranceScheme.paymentArea = params.insuranceScheme.paymentType;
2023-02-13 16:38:15 +08:00
return new Promise((resolve, reject) => {
if (!this.valideForm(params)) {
2022-08-25 17:54:18 +08:00
reject("新建失败");
2023-02-13 16:38:15 +08:00
return;
2022-03-21 19:54:16 +08:00
}
2022-08-25 17:54:18 +08:00
API.updateScheme(params).then(res => {
2023-02-13 16:38:15 +08:00
if (res.status) {
resolve(res);
2022-08-25 17:54:18 +08:00
message.success("更新成功");
this.getTableDatas(this.selectedKey);
} else {
2023-02-13 16:38:15 +08:00
reject("更新失败");
message.error(res.errormsg || "更新失败");
2022-08-25 17:54:18 +08:00
}
2023-02-13 16:38:15 +08:00
});
});
};
2022-03-21 19:54:16 +08:00
2022-09-09 10:29:12 +08:00
@action("复制福利方案")
copyScheme = (params) => {
2023-02-13 16:38:15 +08:00
return new Promise((resolve, reject) => {
API.copyScheme(params).then(res => {
2023-02-13 16:38:15 +08:00
if (res.status) {
resolve("复制成功");
message.success("复制成功");
this.getTableDatas(this.selectedKey);
} else {
2023-02-13 16:38:15 +08:00
reject(res.errormsg || "复制失败");
message.error(res.errormsg || "复制失败");
}
2023-02-13 16:38:15 +08:00
});
});
};
2022-07-28 17:16:40 +08:00
@action("删除社保数据")
deleteScheme = (params) => {
2023-02-13 16:38:15 +08:00
this.deleteLoading = true;
2022-07-28 17:16:40 +08:00
API.deleteScheme(params).then(res => {
2023-02-13 16:38:15 +08:00
this.deleteLoading = false;
if (res.status) {
message.success("刪除成功");
2022-07-28 17:16:40 +08:00
this.getTableDatas(this.selectedKey);
} else {
2023-02-13 16:38:15 +08:00
message.error(res.errormsg || "刪除失败");
2022-07-28 17:16:40 +08:00
}
2023-02-13 16:38:15 +08:00
});
};
2022-03-21 19:54:16 +08:00
2022-03-22 16:53:39 +08:00
@action getCustomForm = (params) => {
API.getCustomCategoryForm(params).then(res => {
2023-02-13 16:38:15 +08:00
if (res.status) {
2022-03-22 16:53:39 +08:00
let condition = res.data.item;
let items = Object.keys(condition).map(item => {
2023-02-13 16:38:15 +08:00
return condition[item];
});
let fieldCondtion = items;
2022-03-22 16:53:39 +08:00
this.formCondition = fieldCondtion;
2022-03-23 19:38:10 +08:00
} else {
2023-02-13 16:38:15 +08:00
message.error(res.errormsg || "获取失败");
2022-03-22 16:53:39 +08:00
}
2023-02-13 16:38:15 +08:00
});
};
2022-03-28 10:53:19 +08:00
2022-04-06 14:26:16 +08:00
validateCustomRequest() {
let flag = true;
2022-06-16 20:58:54 +08:00
try {
this.formCondition.forEach(item => {
2023-02-13 16:38:15 +08:00
if (item.rules == "required") {
if (!notNull(this.customRequest[item.domkey[0]])) {
message.warning(item.label + "不能为空");
throw new Error(item.label + "不能为空");
2022-06-16 20:58:54 +08:00
}
2022-04-06 14:26:16 +08:00
}
2023-02-13 16:38:15 +08:00
});
} catch (e) {
flag = false;
}
2022-04-06 14:26:16 +08:00
return flag;
}
2022-03-28 10:53:19 +08:00
// 新增自定义福利
@action createSICategory = (params) => {
2022-04-01 15:02:18 +08:00
return new Promise((resolve, reject) => {
2023-02-13 16:38:15 +08:00
if (!this.validateCustomRequest()) {
reject();
2023-02-13 16:38:15 +08:00
return;
}
2023-02-13 16:38:15 +08:00
API.createSICategory({ ...params, paymentScope: params.paymentScope.split(",") }).then(res => {
if (res.status) {
message.success("新增成功");
resolve();
2022-04-01 15:02:18 +08:00
} else {
2023-02-13 16:38:15 +08:00
reject();
message.error(res.errormsg || "新增失败");
2022-04-01 15:02:18 +08:00
}
2023-02-13 16:38:15 +08:00
}).catch(() => {
message.error("新增失败");
});
});
2022-07-28 17:16:40 +08:00
2023-02-13 16:38:15 +08:00
};
2022-03-28 10:53:19 +08:00
// 自定义福利启用、停用
@action
2022-04-01 09:28:05 +08:00
updateCustomCategoryStatus = (id, isUse) => {
let params = {
id,
isUse: isUse ? 1 : 0
2023-02-13 16:38:15 +08:00
};
2022-03-28 10:53:19 +08:00
API.updateCustomCategoryStatus(params).then(res => {
2023-02-13 16:38:15 +08:00
if (res.status) {
message.success("修改成功");
this.getCustomCategoryList();
2022-03-28 10:53:19 +08:00
} else {
2023-02-13 16:38:15 +08:00
message.error(res.errormsg || "修改失败");
2022-03-28 10:53:19 +08:00
}
2023-02-13 16:38:15 +08:00
});
};
2022-03-28 10:53:19 +08:00
2022-04-01 15:02:18 +08:00
// 自定义福利编辑
@action
updateCustomCategory = (params) => {
return new Promise((resolve, reject) => {
API.updateCustomCategory({
..._.pick(params, ["id", "insuranceName"]),
paymentScope: _.pick(params, ["paymentScope"]).paymentScope.split(",")
}).then(res => {
2023-02-13 16:38:15 +08:00
if (res.status) {
message.success("编辑成功");
resolve();
2022-04-01 15:02:18 +08:00
} else {
2023-02-13 16:38:15 +08:00
reject();
message.error(res.errormsg || "编辑失败");
2022-04-01 15:02:18 +08:00
}
2023-02-13 16:38:15 +08:00
});
});
2022-07-28 17:16:40 +08:00
2023-02-13 16:38:15 +08:00
};
2022-04-01 15:02:18 +08:00
2022-07-28 17:16:40 +08:00
}