trunk/pc4mobx/organization/stores/staff.js

367 lines
9.5 KiB
JavaScript
Raw Normal View History

2022-05-25 14:58:27 +08:00
import {
observable,
action
} from 'mobx';
import * as mobx from 'mobx';
2022-09-06 18:53:08 +08:00
import * as Api from '../apis/staff'; // 引入API接口文件
2022-05-25 14:58:27 +08:00
import {
WeaForm
} from 'comsMobx';
import {
WeaTableNew
} from 'comsMobx';
2022-06-24 14:38:54 +08:00
import {
2022-05-25 14:58:27 +08:00
Modal,
message,
} from 'antd'
import {
i18n
} from '../public/i18n';
const toJS = mobx.toJS;
const {
TableStore
} = WeaTableNew;
export class StaffStore {
@observable tableStore = new TableStore();
@observable topMenu = []
@observable rightMenu = [];
@observable condition = [];
2022-08-17 15:13:26 +08:00
fcondition = [];
2022-06-24 14:38:54 +08:00
@observable leftCondition = [];
2022-05-25 14:58:27 +08:00
@observable searchCondition = [];
@observable isEdit = true;
@observable isNew = true;
@observable isPanelShow = false; //高级搜索面板
@observable form2 = new WeaForm();
@observable form = new WeaForm();
@observable form1 = new WeaForm();
@observable staffName = '';
2022-05-26 13:55:26 +08:00
@observable conditionNum = 10;
2022-05-25 14:58:27 +08:00
@observable ids = ''; //选择行id
@observable searchConditionLoading = true;
@observable nEdialogTitle = '';
@observable visible = false;
@observable dialogLoading = true;
@observable staffId = '';
@observable date = '';
2022-06-07 16:52:12 +08:00
@observable hasRight = '';
2022-06-07 17:56:29 +08:00
@observable operateType = ''; //1 编辑 2 变更
2022-06-23 11:53:57 +08:00
@observable companysId = 1;
2022-05-25 14:58:27 +08:00
2022-06-24 14:38:54 +08:00
@observable planId = '';
@observable selectTreeNodeInfo;
2022-05-25 14:58:27 +08:00
@action
2022-09-02 11:00:27 +08:00
getTableInfo(isOnChange = false) {
2022-06-24 14:38:54 +08:00
let params = {
planId: this.planId,
...this.selectTreeNodeInfo,
}
2022-09-02 11:00:27 +08:00
const {current} = this.tableStore;
2022-05-25 14:58:27 +08:00
if (this.isEmptyObject(this.form2.getFormParams())) {
params = {
2022-06-24 14:38:54 +08:00
...params,
staffName: this.staffName,
2022-05-25 14:58:27 +08:00
};
} else {
params = {
2022-06-24 14:38:54 +08:00
...this.form2.getFormParams(),
...params,
2022-05-25 14:58:27 +08:00
};
}
Api.getSearchList(params).then(res => {
if (res.code === 200) {
2022-06-07 16:52:12 +08:00
this.setHasRight(res.data.hasRight);
2022-10-21 17:51:28 +08:00
if(res.data.hasRight) {
isOnChange ? this.tableStore.getDatas(res.data.datas, current) : this.tableStore.getDatas(res.data.datas,1);
}
2022-05-25 14:58:27 +08:00
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
//删除
delete() {
let params = {
ids: this.ids
};
Api.deleteTableData(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
message.success(i18n.message.deleteSuccess());
this.getTableInfo();
} else {
message.warning(data.msg);
}
})
.catch(error => {
message.warning(error.msg);
})
}
save() {
let params = {
...this.form.getFormParams()
};
this.form.validateForm().then(f => {
if (f.isValid) {
Api.add(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
message.success(data.msg);
this.getTableInfo();
this.setVisible(false);
} else {
message.warning(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
} else {
f.showErrors();
this.setDate(new Date());
}
});
}
edit() {
let params = { ...this.form.getFormParams(), id: this.staffId };
this.form.validateForm().then(f => {
if (f.isValid) {
Api.edit(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
message.success(data.msg);
2022-09-02 11:00:27 +08:00
this.getTableInfo(true);
2022-05-25 14:58:27 +08:00
this.setVisible(false);
} else {
message.warning(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
} else {
f.showErrors();
this.setDate(new Date());
}
});
}
2022-06-24 14:38:54 +08:00
@action("leftTree事件")
doSearch(params) {
this.selectTreeNodeInfo = params;
this.getTableInfo();
}
2022-05-25 14:58:27 +08:00
getForm() {
let params = this.isNew ? {} : {
2022-06-07 18:11:10 +08:00
id: this.staffId,
operateType: this.operateType
2022-05-25 14:58:27 +08:00
}
this.setDialogLoadingStatus(true);
2022-05-26 13:55:26 +08:00
Api.getForm(params).then(res => {
2022-05-25 14:58:27 +08:00
if (res.code === 200) {
this.setDialogLoadingStatus(false);
2022-08-17 15:13:26 +08:00
res.data.condition && this.setFcondition(res.data.condition);
2022-05-25 14:58:27 +08:00
res.data.condition && this.setCondition(res.data.condition);
res.data.condition && this.form.initFormFields(res.data.condition);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
2022-08-17 15:13:26 +08:00
}
2022-05-25 14:58:27 +08:00
2022-08-17 15:13:26 +08:00
updateConditions(data) {
this.form.updateFields({
2022-11-17 11:34:05 +08:00
ecCompany: {
2022-08-17 15:13:26 +08:00
value: ''
},
2022-11-17 11:34:05 +08:00
ecDepartment: {
2022-08-17 15:13:26 +08:00
value: ''
},
jobId: {
value: ''
}
});
const type = data.planId.valueObj[0].control_dimensions;
this.condition = this.fcondition;
switch(type) {
case '分部':
this.condition[0].items = this.condition[0].items.filter(item => {
2022-09-06 18:53:08 +08:00
return (item.domkey[0] != 'ecDepartment' && item.domkey[0] != 'jobId')
2022-08-17 15:13:26 +08:00
});
break;
case '部门':
this.condition[0].items = this.condition[0].items.filter(item => {
2022-11-17 11:34:05 +08:00
return item.domkey[0] != 'ecCompany' && item.domkey[0] != 'jobId'
2022-08-17 15:13:26 +08:00
})
break;
case '岗位':
2022-11-17 11:34:05 +08:00
this.condition[0].items = this.condition[0].items.filter(item => {
return item.domkey[0] != 'ecCompany' && item.domkey[0] != 'ecDepartment'
})
2022-08-17 15:13:26 +08:00
}
this.setCondition(this.condition);
this.form.initFormFields(this.condition);
2022-05-25 14:58:27 +08:00
}
getSearchCondition() {
this.setScLoadingStatus(false);
Api.getAdvanceSearchCondition().then(res => {
if (res.code === 200) {
this.setScLoadingStatus(false);
res.data.conditions && this.setSearchCondition(res.data.conditions);
res.data.conditions && this.form2.initFormFields(res.data.conditions);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
@action
getHasRight() {
Api.getHasRight().then(res => {
if (res.code === 200) {
res.data.rightMenu && this.setRightMenu(res.data.rightMenu);
res.data.topMenu && this.setTopMenu(res.data.topMenu);
2022-06-24 14:38:54 +08:00
res.data.condition && this.setLeftCondition(res.data.condition);
res.data.condition && this.form1.initFormFields(res.data.condition);
2022-05-25 14:58:27 +08:00
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
updateFields(val) {
this.form2.updateFields({
staffName: {
value: val
}
});
}
setSearchCondition(condition) {
this.searchCondition = condition;
}
setScLoadingStatus(bool) {
this.searchConditionLoading = bool;
}
setPanelStatus(bool) {
this.isPanelShow = bool;
bool && this.getSearchCondition();
if (!bool) {
this.scLoadingReset();
}
}
setStaffName(staffName) {
this.staffName = staffName;
}
isEmptyObject(obj) {
for (let key in obj) {
return false;
}
return true;
}
setIds(ids) {
this.ids = ids;
}
scLoadingReset() {
this.searchConditionLoading = true;
}
formReset() {
this.form = new WeaForm();
}
dialogLoadingReset() {
this.dialogLoading = true;
}
setVisible(bool) {
this.visible = bool;
this.formReset();
!bool && this.dialogLoadingReset();
}
setDialogLoadingStatus(bool) {
this.dialogLoading = bool;
}
setNeDialogTitle(title) {
this.nEdialogTitle = title;
}
setIsNew(bool) {
this.isNew = bool;
}
setCondition(condition) {
this.condition = condition;
}
setStaffId(staffId) {
this.staffId = staffId;
}
@action
setDate(date) {
this.date = date;
}
setTopMenu(topMenu) {
this.topMenu = topMenu;
}
setRightMenu(rightMenu) {
this.rightMenu = rightMenu;
}
2022-06-07 16:52:12 +08:00
setHasRight(bool) {
this.hasRight = bool;
}
2022-06-07 17:56:29 +08:00
setOperateType(operateType) {
this.operateType = operateType;
}
2022-06-24 14:38:54 +08:00
setLeftCondition(leftCondition) {
this.leftCondition = leftCondition;
}
setPlanId(planId) {
this.planId = planId;
this.getTableInfo();
}
2022-08-17 15:13:26 +08:00
setFcondition(condition) {
this.fcondition = condition;
}
2022-06-07 17:56:29 +08:00
2022-05-25 14:58:27 +08:00
}