trunk/pc4mobx/organization/stores/department.js

564 lines
12 KiB
JavaScript
Raw Normal View History

2022-06-02 16:51:21 +08:00
import {
2022-06-06 16:48:19 +08:00
observable,
action
} from 'mobx';
import * as mobx from 'mobx';
import * as Api from '../apis/department'; // 引入API接口文件
import {
WeaForm
} from 'comsMobx';
import {
WeaTableNew
} from 'comsMobx';
import {
Modal,
message,
} from 'antd'
import {
i18n
} from '../public/i18n';
2022-06-24 17:58:51 +08:00
import {
findIndex
} from 'lodash';
2022-06-06 16:48:19 +08:00
const toJS = mobx.toJS;
const {
TableStore
} = WeaTableNew;
export class DepartmentStore {
@observable tableStore = new TableStore();
@observable topMenu = []
@observable rightMenu = [];
@observable dataSource = [];
@observable columns = [];
@observable loading = true;
@observable dialogLoading = true;
@observable isEdit = true;
@observable nEdialogTitle = '';
@observable searchCondition = [];
@observable condition = [];
@observable copyCondition = [];
@observable isPanelShow = false; //高级搜索面板
@observable form = new WeaForm();
@observable form1 = new WeaForm(); //新增主表表单
@observable form2 = new WeaForm(); //复制表单
@observable departmentName = '';
2022-12-08 18:06:21 +08:00
@observable conditionNum = 4;
2022-06-06 16:48:19 +08:00
@observable ids = ''; //选择行id
@observable id = ''; //页面跳转参数id
@observable searchConditionLoading = true;
@observable visible = false;
@observable newVisible = false; //新增弹窗
@observable departmentId = '';
2022-06-24 14:38:54 +08:00
@observable selectedRowKeys = [];
2022-06-06 16:48:19 +08:00
@observable date = '';
@observable init = true; //是否首次加载
@observable total = '';
@observable current = 1;
@observable pageSize = 10;
2022-06-24 14:38:54 +08:00
@observable sortParams = [];
2022-06-06 16:48:19 +08:00
@observable defaultShowLeft = true;
@observable companysId = 1 //集团id
@observable postionDataSource = [];
@observable postionColumns = [];
@observable confirmVisible = false;
@observable confirmLoading = true;
@observable isMerge = true;
2022-06-07 16:52:12 +08:00
@observable hasRight = '';
2024-05-08 16:35:18 +08:00
@observable exSpinning = false;
2022-06-06 16:48:19 +08:00
2022-06-23 11:53:57 +08:00
@observable selectTreeNodeInfo;
2022-06-24 14:38:54 +08:00
saveAndSetting = false;
2022-06-23 11:53:57 +08:00
2022-06-06 16:48:19 +08:00
2022-12-08 18:06:21 +08:00
@action getTableInfo() {
2022-06-06 16:48:19 +08:00
this.setLoading(true);
2022-06-23 11:53:57 +08:00
let params = {
...this.selectTreeNodeInfo,
2022-06-06 16:48:19 +08:00
current: this.current,
2022-06-24 14:38:54 +08:00
pageSize: this.pageSize,
sortParams: this.sortParams
2022-06-06 16:48:19 +08:00
}
if (this.isEmptyObject(this.form.getFormParams())) {
2022-06-02 16:51:21 +08:00
params = {
...params,
2022-06-06 16:48:19 +08:00
departmentName: this.departmentName
};
} else {
params = {
...params,
...this.form.getFormParams(),
};
}
Api.getSearchList(params).then(response => {
return response.json()
}).then(res => {
if (res.code === 200) {
2022-06-07 16:52:12 +08:00
this.setHasRight(res.data.hasRight);
2022-06-06 16:48:19 +08:00
res.data.pageInfo.columns && this.setColumns(res.data.pageInfo.columns);
this.setTotal(res.data.pageInfo.total);
res.data.pageInfo.list && this.setDataSource(res.data.pageInfo.list);
this.setLoading(false);
this.setInit(false);
} else {
message.warning(res.msg);
2022-06-02 16:51:21 +08:00
}
2022-06-06 16:48:19 +08:00
}).catch(error => {
message.warning(error.msg);
})
}
2022-12-08 18:06:21 +08:00
@action("nodetree事件") doSearch(params) {
2022-06-23 11:53:57 +08:00
this.selectTreeNodeInfo = params;
this.setCurrent(1);
this.setPageSize(10);
2022-06-06 16:48:19 +08:00
this.setInit(true);
2022-06-23 11:53:57 +08:00
this.getTableInfo();
2022-06-06 16:48:19 +08:00
}
2022-12-08 18:06:21 +08:00
@action("联查岗位") getPostionTable(id) {
2022-06-06 16:48:19 +08:00
let params = {
parentDept: id
}
2022-06-07 09:34:25 +08:00
Api.getPostionTable(params).then(res => {
2022-06-06 16:48:19 +08:00
if (res.code === 200) {
res.data.list && this.setPostionDataSource(res.data.list);
res.data.columns && this.setPostionColumns(res.data.columns);
this.setDialogLoadingStatus(false);
2022-06-02 16:51:21 +08:00
} else {
2022-06-06 16:48:19 +08:00
message.warning(res.msg);
2022-06-02 16:51:21 +08:00
}
2022-06-24 14:38:54 +08:00
}, error => {
2022-06-06 16:48:19 +08:00
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());
2022-06-24 14:38:54 +08:00
this.setSelectedRowKeys([]);
2022-06-06 16:48:19 +08:00
this.getTableInfo();
} else {
message.warning(data.msg);
2022-06-02 16:51:21 +08:00
}
2022-06-06 16:48:19 +08:00
}).catch(error => {
message.warning(error.msg);
})
}
2022-06-02 16:51:21 +08:00
2022-06-06 16:48:19 +08:00
updateForbiddenTag(checked, id) {
let params = {
2023-07-31 09:28:22 +08:00
canceled: checked,
2022-06-06 16:48:19 +08:00
id: id
}
Api.updateForbiddenTag(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
message.success(data.msg, 1);
2022-06-22 10:28:25 +08:00
this.getTableInfo();
2022-06-06 16:48:19 +08:00
} else {
message.warning(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
}
2022-06-02 16:51:21 +08:00
2022-06-06 16:48:19 +08:00
getSearchCondition() {
this.setScLoadingStatus(true);
Api.getAdvanceSearchCondition().then(res => {
if (res.code === 200) {
this.setScLoadingStatus(false);
res.data.conditions && this.setSearchCondition(res.data.conditions);
res.data.conditions && this.form.initFormFields(res.data.conditions);
} else {
message.warning(res.msg);
2022-06-02 16:51:21 +08:00
}
2022-06-06 16:48:19 +08:00
}, error => {
message.warning(error.msg);
})
}
getDeptForm() {
this.setDialogLoadingStatus(true);
2022-12-08 18:06:21 +08:00
let params = {
...this.selectTreeNodeInfo,
addType:'normal',
viewattr:'2'
}
Api.getDeptForm(params).then(res => {
2022-06-06 16:48:19 +08:00
if (res.code === 200) {
this.setDialogLoadingStatus(false);
res.data.condition && this.setCondition(res.data.condition);
res.data.condition && this.form1.initFormFields(res.data.condition);
} else {
message.warning(res.msg);
2022-06-02 16:51:21 +08:00
}
2022-06-06 16:48:19 +08:00
}, error => {
message.warning(error.msg);
})
}
2022-10-21 17:51:28 +08:00
@action("合并部门") getMergeForm(id) {
2022-06-06 16:48:19 +08:00
let params = {
2022-06-24 14:38:54 +08:00
id: id
2022-06-06 16:48:19 +08:00
};
this.setConfirmLoading(true);
Api.getMergeForm(params).then(res => {
if (res.code === 200) {
this.setConfirmLoading(false);
res.data && this.setCondition(res.data);
res.data && this.form1.initFormFields(res.data);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2022-10-21 17:51:28 +08:00
@action("转移部门") getTransferForm(id) {
2022-06-06 16:48:19 +08:00
let params = {
2022-06-24 14:38:54 +08:00
id: id
2022-06-06 16:48:19 +08:00
};
this.setConfirmLoading(true);
Api.getTransferForm(params).then(res => {
if (res.code === 200) {
this.setConfirmLoading(false);
res.data && this.setCondition(res.data);
res.data && this.form1.initFormFields(res.data);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2022-10-21 17:51:28 +08:00
@action("复制表单") getCopyForm() {
2022-06-06 16:48:19 +08:00
let params = {};
Api.getCopyForm(params).then(res => {
if (res.code === 200) {
res.data && this.setCopyCondition(res.data);
res.data && this.form2.initFormFields(res.data);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
save() {
let params = {
...this.form1.getFormParams()
};
this.form1.validateForm().then(f => {
if (f.isValid) {
2022-12-08 18:06:21 +08:00
Api.add(params).then(data => {
2022-06-06 16:48:19 +08:00
if (data.code === 200) {
message.success(data.msg);
this.getTableInfo();
this.setNewVisible(false);
2022-06-24 14:38:54 +08:00
this.saveAndSetting && window.open(`/spa/organization/static/index.html#/main/organization/departmentExtend/${data.data}`, "_blank")
2022-06-06 16:48:19 +08:00
} else {
message.warning(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
} else {
f.showErrors();
this.setDate(new Date());
}
});
}
2022-12-08 18:06:21 +08:00
@action("合并") merge() {
2022-06-06 16:48:19 +08:00
let params = {
2022-06-24 14:38:54 +08:00
id: this.ids,
2022-06-06 16:48:19 +08:00
...this.form1.getFormParams()
};
this.form1.validateForm().then(f => {
if (f.isValid) {
Api.merge(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
message.success(data.msg);
this.getTableInfo();
this.setConfirmVisible(false);
} else {
message.warning(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
} else {
f.showErrors();
this.setDate(new Date());
}
});
}
2022-12-08 18:06:21 +08:00
@action("转移") transfer() {
2022-06-06 16:48:19 +08:00
let params = {
2022-06-24 14:38:54 +08:00
id: this.ids,
2022-06-06 16:48:19 +08:00
...this.form1.getFormParams()
};
this.form1.validateForm().then(f => {
if (f.isValid) {
Api.transfer(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
message.success(data.msg);
this.getTableInfo();
this.setConfirmVisible(false);
} else {
message.warning(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
} else {
f.showErrors();
this.setDate(new Date());
}
});
}
2022-12-08 18:06:21 +08:00
@action("复制") copy() {
2022-06-06 16:48:19 +08:00
let params = {
ids: this.ids,
...this.form2.getFormParams()
};
Api.copy(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
message.success(data.msg);
this.getTableInfo();
2022-06-24 14:38:54 +08:00
this.setSelectedRowKeys([]);
2022-06-06 16:48:19 +08:00
} else {
message.error(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
}
2022-10-21 17:51:28 +08:00
@action getHasRight() {
2022-06-06 16:48:19 +08:00
Api.getHasRight().then(res => {
if (res.code === 200) {
res.data.rightMenu && this.setRightMenu(res.data.rightMenu);
res.data.topMenu && this.setTopMenu(res.data.topMenu);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2022-12-14 16:17:15 +08:00
@action("另存为版本") version(id) {
Api.version({id:id}).then(res => {
2022-12-09 14:47:19 +08:00
if (res.code === 200) {
message.success(res.msg);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2024-05-08 16:35:18 +08:00
@action("全部导出") async exportData() {
this.exSpinning = true;
await Api.exportData();
this.exSpinning = false;
2023-09-22 10:41:23 +08:00
}
2022-06-24 14:38:54 +08:00
2022-06-06 16:48:19 +08:00
updateFields(val) {
this.form.updateFields({
2022-06-23 11:53:57 +08:00
departmentName: {
2022-06-06 16:48:19 +08:00
value: val
}
});
}
setSearchCondition(condition) {
this.searchCondition = condition;
}
setScLoadingStatus(bool) {
this.searchConditionLoading = bool;
}
setPanelStatus(bool) {
this.isPanelShow = bool;
bool && this.getSearchCondition();
if (!bool) {
this.scLoadingReset();
2022-06-02 16:51:21 +08:00
}
2022-06-06 16:48:19 +08:00
}
setDepartmentName(val) {
this.departmentName = val;
}
2022-06-02 16:51:21 +08:00
2022-06-06 16:48:19 +08:00
isEmptyObject(obj) {
for (let key in obj) {
return false;
2022-06-02 16:51:21 +08:00
}
2022-06-06 16:48:19 +08:00
return true;
}
setIds(ids) {
this.ids = ids;
}
setId(id) {
this.id = id;
}
scLoadingReset() {
this.searchConditionLoading = true;
}
formReset() {
this.form1 = new WeaForm();
}
setVisible(bool) {
this.visible = bool;
}
setDialogLoadingStatus(bool) {
this.dialogLoading = bool;
}
setSearchCondition(searchCondition) {
this.searchCondition = searchCondition;
}
setDepartmentId(departmentId) {
this.departmentId = departmentId;
}
setDate(date) {
this.date = date;
}
setTopMenu(topMenu) {
this.topMenu = topMenu;
}
setRightMenu(rightMenu) {
this.rightMenu = rightMenu;
}
setDataSource(dataSource) {
this.dataSource = dataSource;
}
setColumns(columns) {
this.columns = columns
}
setSelectedRowKeys(selectedRowKeys) {
this.selectedRowKeys = selectedRowKeys;
}
setLoading(bool) {
this.loading = bool;
}
setNeDialogTitle(title) {
this.nEdialogTitle = title
}
setCondition(condition) {
this.condition = condition;
}
setCopyCondition(copyCondition) {
this.copyCondition = copyCondition;
}
setNewVisible(bool) {
this.formReset();
this.newVisible = bool;
}
setTotal(total) {
this.total = total;
}
setCurrent(current) {
this.current = current;
}
setPageSize(pageSize) {
this.pageSize = pageSize;
}
setInit(bool) {
this.init = bool;
}
setConfirmVisible(confirmVisible) {
this.formReset();
this.confirmVisible = confirmVisible;
}
setConfirmLoading(confirmLoading) {
this.confirmLoading = confirmLoading;
}
setPostionDataSource(postionDataSource) {
this.postionDataSource = postionDataSource;
}
setPostionColumns(postionColumns) {
this.postionColumns = postionColumns;
}
setIsMerge(bool) {
this.isMerge = bool;
}
2022-06-07 16:52:12 +08:00
setHasRight(bool) {
this.hasRight = bool;
2022-06-24 14:38:54 +08:00
}
setSortParams(sorter) {
this.sortParams = [];
sorter.order && this.sortParams.push({
orderkey: sorter.field,
sortOrder: sorter.order
})
}
setSaveAndSetting(bool) {
this.saveAndSetting = bool;
}
2022-06-06 16:48:19 +08:00
}