trunk/pc4mobx/organization/stores/managerDetach.js

347 lines
9.2 KiB
JavaScript
Raw Normal View History

2022-10-21 14:35:06 +08:00
import {
observable,
action
} from 'mobx';
import * as mobx from 'mobx';
import * as Api from '../apis/managerDetach';
import {
WeaForm
} from 'comsMobx';
import {
WeaTableNew
} from 'comsMobx';
import {
Modal,
message,
} from 'antd'
import {
i18n
} from '../public/i18n';
const toJS = mobx.toJS;
const {
TableStore
} = WeaTableNew;
export class ManagerDetachStore {
@observable tableStore = new TableStore();
@observable topMenu = []
@observable rightMenu = [];
@observable condition = [];
2024-08-20 15:27:34 +08:00
fcondition = [];
2022-10-21 14:35:06 +08:00
@observable searchCondition = [];
@observable isEdit = true;
@observable isNew = true;
@observable isPanelShow = false; //高级搜索面板
@observable form2 = new WeaForm();
@observable form = new WeaForm();
@observable managerName = '';
@observable conditionNum = 2;
@observable ids = ''; //选择行id
@observable searchConditionLoading = true;
@observable nEdialogTitle = '';
@observable visible = false;
@observable dialogLoading = true;
@observable detachId = '';
@observable date = '';
@observable hasRight = '';
2022-10-28 17:45:47 +08:00
@observable isDetach = '';
2022-10-21 14:35:06 +08:00
@action("列表数据加载") getTableInfo(isOnChange = false) {
let params;
const { current } = this.tableStore;
if (this.isEmptyObject(this.form2.getFormParams())) {
params = {
2022-10-27 14:27:44 +08:00
ecManager: this.managerName
2022-10-21 14:35:06 +08:00
};
} else {
params = {
...this.form2.getFormParams()
};
}
Api.getSearchList(params).then(res => {
if (res.code === 200) {
this.setHasRight(res.data.hasRight);
2022-11-03 14:33:55 +08:00
if(res.data.hasRight) {
this.isDetach = res.data.isDetach;
isOnChange ? this.tableStore.getDatas(res.data.datas, current) : this.tableStore.getDatas(res.data.datas,1);
}
2022-10-21 14:35:06 +08:00
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2022-10-21 14:40:47 +08:00
@action("批量删除") delete() {
2022-10-21 14:35:06 +08:00
let params = {
ids: this.ids
};
Api.deleteTableData(params).then(response => {
return response.json()
}).then(data => {
if (data.code === 200) {
this.getTableInfo();
message.success(i18n.message.deleteSuccess());
} else {
message.warning(data.msg);
}
})
.catch(error => {
message.warning(error.msg);
})
}
2024-08-20 15:27:34 +08:00
@action("新建保存") save() {
2022-10-21 14:35:06 +08:00
let params = {
...this.form.getFormParams()
};
2024-08-20 15:27:34 +08:00
if (params.managerType == "0" && params.ecManager == "") {
return message.error("管理员字段必填");
}
if (params.managerType == "1" && params.roleId == "") {
return message.error("角色字段必填");
}
2022-10-21 14:35:06 +08:00
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());
}
});
}
@action("编辑保存") edit() {
let params = { ...this.form.getFormParams(), id: this.detachId };
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);
this.getTableInfo(true);
this.setVisible(false);
} else {
message.warning(data.msg);
}
}).catch(error => {
message.warning(error.msg);
})
} else {
f.showErrors();
this.setDate(new Date());
}
});
}
@action("新建编辑表单") getForm() {
let params = this.isNew ? {} : {
id: this.detachId
}
this.setDialogLoadingStatus(true);
2022-10-28 17:45:47 +08:00
Api.getForm(params).then(res => {
2022-10-21 14:35:06 +08:00
if (res.code === 200) {
this.setDialogLoadingStatus(false);
2024-08-20 15:27:34 +08:00
res.data.condition && this.setFcondition(res.data.condition);
2022-10-21 14:35:06 +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);
})
}
@action("高级搜索") 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);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2022-10-28 17:45:47 +08:00
@action("分权设置") setDetach(checked) {
Api.doDetachSwitch({idDetach:checked}).then(res => {
if (res.code === 200) {
this.isDetach = res.data;
message.success(res.msg);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2022-10-21 14:35:06 +08:00
updateFields(val) {
this.form2.updateFields({
2022-10-27 14:27:44 +08:00
ecManager: {
2022-10-21 14:35:06 +08:00
value: val
}
});
}
2024-08-20 15:27:34 +08:00
updateConditions(data) {
this.form.updateFields({
ecManager: {
value: ''
},
roleId: {
value: ''
}
});
const type = data.managerType.value;
debugger
this.condition = this.fcondition;
switch(type) {
case '0':
this.condition[0].items = this.condition[0].items.filter(item => {
if(item.domkey[0] == 'ecManager'){
item.viewAttr = 3;
}
return item.domkey[0] != 'roleId';
});
break;
case '1':
this.condition[0].items = this.condition[0].items.filter(item => {
if(item.domkey[0] == 'roleId'){
item.viewAttr = 3;
}
return item.domkey[0] != 'ecManager';
})
}
this.setCondition(this.condition);
this.form.initFormFields(this.condition);
}
2022-10-21 14:35:06 +08:00
setSearchCondition(condition) {
this.searchCondition = condition;
}
setScLoadingStatus(bool) {
this.searchConditionLoading = bool;
}
setPanelStatus(bool) {
this.isPanelShow = bool;
bool && this.getSearchCondition();
if (!bool) {
this.scLoadingReset();
}
}
setManagerName(val) {
this.managerName = val;
}
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;
}
setDetachId(detachId) {
this.detachId = detachId;
}
setDate(date) {
this.date = date;
}
setTopMenu(topMenu) {
this.topMenu = topMenu;
}
setRightMenu(rightMenu) {
this.rightMenu = rightMenu;
}
setHasRight(bool) {
this.hasRight = bool;
}
2024-08-20 15:27:34 +08:00
setFcondition(condition) {
this.fcondition = condition;
}
2022-10-21 14:35:06 +08:00
}