trunk/pc4mobx/organization/stores/jobextend.js

383 lines
11 KiB
JavaScript

import { observable, action, toJS } from "mobx";
import { WeaForm } from "comsMobx";
import isEmpty from 'lodash/isEmpty'
import { WeaTableNew } from "comsMobx";
import { Modal, message } from "antd";
import { i18n } from "../public/i18n";
import * as Api from '../apis/job'; // 引入API接口文件
import {
findIndex, forEach
} from 'lodash';
export class JobExtendStore {
@observable form = new WeaForm();
@observable tableInfo = []
@observable condition = [];
@observable isEditor = false;
@observable isNew = true;
@observable loading = true;
@observable tabInfo = [];
@observable selectedKey = '0';
@observable detailSelectedKey = '0';
@observable topTab = [];
@observable buttons = {};
@observable id = ''; //岗位id
@observable date = '';
@observable personalEditTables;
@observable tabkey = '0'
@observable selectedRowKeys = [];
@observable selectedRows = [];
@action onRowSelect = (keys) => {
this.setSelectedRowKeys(keys);
}
@action setSelectedRowKeys = (keys) => {
this.selectedRowKeys = keys;
}
@action
edit = () => {
this.isEditor = true;
this.getData();
this.getTabInfo();
this.detailSelectedKey = '0'
}
init = () => {
this.detailSelectedKey = '0'
this.isEditor = false;
}
save = () => {
if (this.loading)
return;
this.form.validateForm().then(f => {
if (f.isValid) {
this.loading = true;
if (this.personalEditTables) {
const targetDatas = this.tableInfo[this.detailSelectedKey].tabinfo.datas,
isPass = (targetDatas.length > 0) ? this.personalEditTables.refs.edit.doRequiredCheck().pass : true
if (isPass) {
this.editResource()
} else {
this.loading = false;
}
} else {
this.editResource();
}
} else {
f.showErrors();
this.setDate(new Date());
this.loading = false;
}
})
}
editResource = () => {
let pDatas = this.form.getFormParams();
Api.editResource({
...{
id: this.id
},
...pDatas,
...this.getTableEditParams()
}).then(data => {
if (data.code == 200) {
message.success(i18n.message.saveSuccess());
this.init();
this.getData();
this.selectedRowKeys = [];
} else {
message.warning(data.msg);
}
this.loading = false;
}, error => {
message.warning(error.msg);
this.loading = false;
})
}
getTableEditParams = () => {
const params = {};
this.tableInfo && this.tableInfo.forEach(t => {
t.tabinfo.datas = t.tabinfo.datas || [];
params[t.tabinfo.rownum] = t.tabinfo.datas.length;
t.tabinfo && t.tabinfo.datas && t.tabinfo.datas.forEach((item, index) => {
!isEmpty(item) && forEach(item, (value, key) => {
Object.assign(params, {
[`${key}_${index}`]: value
});
})
})
})
return params
}
getData = () => {
this.setLoading(true);
let params = {
viewAttr: this.isEditor ? 2 : 1,
id: this.id,
viewCondition: this.selectedKey
}
Api.getJobExtendForm(params).then((res) => {
if (res.code === 200) {
//默认职级职等范围
let conditions = res.data.result.conditions;
if(this.isEditor == true && this.selectedKey == '0'){
let currenttime = 1657247378274;
let key0 = `scheme_id_${currenttime}`;
let key1 = `level_id_${currenttime}`;
let key2 = `scheme_id_${currenttime}`;
let label = "职级"
const index1 = findIndex(conditions[1].items, { label });
label = "职等"
const index2 = findIndex(conditions[1].items, { label });
let schemeId = conditions[1].items[1].browserConditionParam.replaceDatas.length > 0 && conditions[1].items[1].browserConditionParam.replaceDatas[0].id;
let levelIds = res.data.levelIds;
this.rangeLimit(key0,schemeId,index1,currenttime,conditions);
this.rangeLimitLevel(key1,key2,index2,levelIds,currenttime,conditions)
}
res.data.result.conditions && this.form.initFormFields(conditions);
res.data.result.conditions && this.setCondition(conditions);
this.tableInfo = this.handleTable(res.data.result.tables);
this.getTabInfo();
res.data.result.buttons && this.setButtons(res.data.result.buttons);
res.data.result.tabInfo && this.setTopTab(res.data.result.tabInfo);
this.isEditor && this.getSelectedRows();
this.setLoading(false);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
handleTable = (datas) => {
return datas && datas.map(data => {
const { tabinfo: { columns } } = data;
const length = columns.length;
columns.map(c => {
c.width = `${95 / length}%`
})
return data
})
}
getTabInfo = () => {
this.tabInfo = [];
this.tableInfo && this.tableInfo.forEach((c, idx) => {
if (!c.hide) {
this.tabInfo.push({
key: `${idx}`,
title: c.tabname,
})
}
})
if (!isEmpty(this.tabInfo)) this.detailSelectedKey = this.tabInfo[0].key;
}
updateConditions(data) {
if (data.sequence_id) {
if (data.sequence_id.valueObj.length > 0) {
let label = "岗位序列";
const item = findIndex(this.condition[1].items, { label });
this.condition[1].items[item].browserConditionParam.replaceDatas = [{ name: data.sequence_id.valueObj[0].sequence_names, id: data.sequence_id.value }];
this.condition[1].items[2].browserConditionParam.replaceDatas = [{ name: "", id: "" }];
this.condition[1].items[3].browserConditionParam.replaceDatas = [{ name: "", id: "" }];
label = "等级方案"
const index = findIndex(this.condition[1].items, { label });
const schemeId = data.sequence_id.valueObj[0].scheme_values;
this.condition[1].items[index].browserConditionParam.replaceDatas = [{ name: data.sequence_id.valueObj[0].scheme_ids, id: schemeId }];
//清空职级并限制范围
label = "职级"
const index1 = findIndex(this.condition[1].items, { label });
let currenttime = 1657247378274
let key = `scheme_id_${currenttime}`;
let condition = this.rangeLimit(key,schemeId,index1,currenttime,this.condition);
this.form.updateFields({
scheme_id: {
value: schemeId
},
level_id: {
value: ''
},
grade_id: {
value: ''
}
});
this.setCondition(condition);
this.form.initFormFields(condition);
}
} else if (data.grade_id) {
let condition = this.condition;
//清空职等并限制范围
let label = "职等"
const index2 = findIndex(this.condition[1].items, { label });
this.condition[1].items[index2].browserConditionParam.replaceDatas = [{ name: "", id: "" }];
label = "职级";
const item = findIndex(this.condition[1].items, { label });
let grade_names = data.grade_id.valueObj.length > 0 ? data.grade_id.valueObj[0].grade_names : "";
let value = data.grade_id.valueObj.length > 0 ? data.grade_id.value : "";
this.condition[1].items[item].browserConditionParam.replaceDatas = [{ name: grade_names, id: value }];
if (data.grade_id.valueObj.length > 0) {
let currenttime = 1657247378274;
let key1 = `level_id_${currenttime}`;
let key2 = `scheme_id_${currenttime}`;
let params = {
id:data.grade_id.value
};
Api.getLevelId(params).then(res => {
if (res.code === 200) {
const levelId = res.data;
condition = this.rangeLimitLevel(key1,key2,index2,levelId,currenttime,this.condition);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
this.form.updateFields({
level_id: {
value: ''
}
});
this.setCondition(condition);
this.form.initFormFields(condition);
}
}
rangeLimit(key,value,index,currenttime,condition) {
condition[1].items[index].browserConditionParam.completeParams = {
...condition[1].items[index].browserConditionParam.completeParams,
[key]: value,
currenttime: currenttime
}
condition[1].items[index].browserConditionParam.conditionDataParams = {
...condition[1].items[index].browserConditionParam.conditionDataParams,
[key]: value,
currenttime: currenttime
}
condition[1].items[index].browserConditionParam.dataParams = {
...condition[1].items[index].browserConditionParam.dataParams,
[key]: value,
currenttime: currenttime
}
condition[1].items[index].browserConditionParam.destDataParams = {
...condition[1].items[index].browserConditionParam.destDataParams,
[key]: value,
currenttime: currenttime
}
return condition;
}
rangeLimitLevel(key1,key2,index,value,currenttime,condition) {
condition[1].items[index].browserConditionParam.completeParams = {
...condition[1].items[index].browserConditionParam.completeParams,
[key1]: value,
[key2]: "''",
currenttime: currenttime
}
condition[1].items[index].browserConditionParam.conditionDataParams = {
...condition[1].items[index].browserConditionParam.conditionDataParams,
[key1]: value,
[key2]: "''",
currenttime: currenttime
}
condition[1].items[index].browserConditionParam.dataParams = {
...condition[1].items[index].browserConditionParam.dataParams,
[key1]: value,
[key2]: "''",
currenttime: currenttime
}
condition[1].items[index].browserConditionParam.destDataParams = {
...condition[1].items[index].browserConditionParam.destDataParams,
[key]: value,
[key2]: "''",
currenttime: currenttime
}
return condition;
}
setLoading(val) {
this.loading = val;
}
updateTabKey = (key) => {
this.tabKey = key;
}
updateDetailSelectedKey = (key) => {
this.detailSelectedKey = key;
}
updateTableInfo = (data) => {
this.tableInfo = data
}
setSelectedKey = (key) => {
this.selectedKey = key;
}
getSelectedRows = () => {
const selectedRows = [];
this.tableInfo.forEach(t => {
const singleTableRows = [];
t.tabinfo.datas.forEach((data, i) => {
if (data.viewAttr === 1) {
singleTableRows.push(i);
}
});
selectedRows.push(singleTableRows);
})
this.selectedRows = selectedRows;
}
setTopTab(topTab) {
this.topTab = topTab;
}
changeData(key) {
this.setSelectedKey(key);
this.getData();
}
setId(id) {
this.id = id;
}
setPersonalEditTables = (ref) => {
this.personalEditTables = ref;
}
setCondition(condition) {
this.condition = condition;
}
setButtons(buttons) {
this.buttons = buttons;
}
setDate(date) {
this.date = date;
}
}