trunk/pc4mobx/organization/stores/resource.js

495 lines
12 KiB
JavaScript
Raw Normal View History

2022-06-20 17:08:10 +08:00
import {
observable,
2023-01-06 18:01:46 +08:00
action,
computed
2022-06-20 17:08:10 +08:00
} from 'mobx';
import * as mobx from 'mobx';
import * as Api from '../apis/resource'; // 引入API接口文件
import {
2023-01-06 18:01:46 +08:00
WeaForm,WeaTableNew
2022-06-20 17:08:10 +08:00
} from 'comsMobx';
import {
Modal,
message,
2023-01-05 18:02:33 +08:00
Button
2022-06-20 17:08:10 +08:00
} from 'antd'
2023-01-06 18:01:46 +08:00
import {
WeaSelect,
WeaInputSearch,
WeaLocaleProvider,
} from 'ecCom';
2022-06-20 17:08:10 +08:00
import {
i18n
} from '../public/i18n';
2023-01-06 18:01:46 +08:00
import trim from 'lodash/trim';
2022-06-29 18:37:25 +08:00
import {getSecondPath} from '../util/index'
2023-01-06 18:01:46 +08:00
import cloneDeep from 'lodash/cloneDeep';
2022-06-20 17:08:10 +08:00
const toJS = mobx.toJS;
const {
TableStore
} = WeaTableNew;
export class ResourceStore {
@observable tableStore = new TableStore();
@observable topMenu = []
@observable rightMenu = [];
@observable condition = [];
@observable searchCondition = [];
2023-01-06 18:01:46 +08:00
@observable defaultCondition = [];
@observable templates=[];
2022-06-20 17:08:10 +08:00
@observable isEdit = true;
@observable isNew = true;
@observable isPanelShow = false; //高级搜索面板
@observable form2 = new WeaForm();
@observable form = new WeaForm();
2022-10-21 17:51:28 +08:00
@observable lastName = '';
2022-06-22 10:28:25 +08:00
@observable conditionNum = 8;
2022-06-20 17:08:10 +08:00
@observable ids = ''; //选择行id
@observable searchConditionLoading = true;
@observable nEdialogTitle = '';
@observable visible = false;
@observable dialogLoading = true;
2022-10-25 17:50:10 +08:00
@observable userId = '';
2022-06-20 17:08:10 +08:00
@observable date = '';
@observable defaultShowLeft = true;
@observable companysId = 1
2022-10-21 17:51:28 +08:00
@observable hasRight = '';
@observable selectTreeNodeInfo;
2022-06-20 17:08:10 +08:00
2023-01-05 18:02:33 +08:00
@action("列表") getTableInfo() {
2022-06-20 17:08:10 +08:00
let params;
this.tableStore = new TableStore();
if (this.isEmptyObject(this.form2.getFormParams())) {
params = {
2022-10-21 17:51:28 +08:00
...this.selectTreeNodeInfo,
lastName: this.lastName
2022-06-20 17:08:10 +08:00
};
} else {
params = {
2022-10-21 17:51:28 +08:00
...this.selectTreeNodeInfo,
2022-06-20 17:08:10 +08:00
...this.form2.getFormParams()
};
}
Api.getSearchList(params).then(res => {
if (res.code === 200) {
res.data.datas && this.tableStore.getDatas(res.data.datas, 1);
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
2022-10-21 17:51:28 +08:00
}
2022-06-20 17:08:10 +08:00
2022-10-21 17:51:28 +08:00
@action("nodetree事件") doSearch(params) {
this.selectTreeNodeInfo = params;
this.getTableInfo();
2022-06-20 17:08:10 +08:00
}
2023-01-05 18:02:33 +08:00
@action("保存") save() {
2022-06-20 17:08:10 +08:00
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());
}
});
}
2023-01-05 18:02:33 +08:00
@action("新增表单") getForm() {
2022-06-20 17:08:10 +08:00
let params = this.isNew ? {} : {
2022-10-25 17:50:10 +08:00
id: this.userId
2022-06-20 17:08:10 +08:00
}
this.setDialogLoadingStatus(true);
Api.getSchemeForm(params).then(res => {
if (res.code === 200) {
this.setDialogLoadingStatus(false);
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);
})
}
2023-01-05 18:02:33 +08:00
@action("高级搜索表单") getSearchCondition() {
2023-01-06 18:01:46 +08:00
this.setScLoadingStatus(true);
const params = {
selectKeys:this.transfer.transferKeys
}
Api.getAdvanceSearchCondition(params).then(res => {
2022-06-20 17:08:10 +08:00
if (res.code === 200) {
this.setScLoadingStatus(false);
res.data.conditions && this.setSearchCondition(res.data.conditions);
2023-01-06 18:01:46 +08:00
res.data.defaultcondition && this.setDefaultCondition(res.data.defaultcondition);
res.data.defaultcondition && this.form2.initFormFields(res.data.defaultcondition);
res.data.templates && this.setTemplates(res.data.templates);
2022-06-20 17:08:10 +08:00
} else {
message.warning(res.msg);
}
}, error => {
message.warning(error.msg);
})
}
2023-01-05 18:02:33 +08:00
@action("顶部按钮") getHasRight() {
2022-06-20 17:08:10 +08:00
Api.getHasRight().then(res => {
if (res.code === 200) {
2022-10-21 17:51:28 +08:00
this.setHasRight(res.data.hasRight);
2022-06-20 17:08:10 +08:00
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);
})
}
2023-01-05 18:02:33 +08:00
@action("导出") export(){
2022-06-29 18:37:25 +08:00
const params = {
...this.form.getFormParams()
}
Api.exportResource(toJS(this.tableStore.selectedRowKeys).toString());
2022-06-30 17:14:04 +08:00
this.tableStore.selectedRowKeys = [];
2022-06-29 18:37:25 +08:00
}
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);
})
2023-01-05 18:02:33 +08:00
}
2023-01-06 18:01:46 +08:00
/** ====================================================================================== */
2023-01-05 18:02:33 +08:00
@observable searchDialog = {
visible: false,
title: '常用条件定制',
}
SEARCHDIALOG = {
hasScroll: false,
icon: 'icon-coms-hrm',
iconBgcolor: '#217346',
onCancel: () => this.closeSearchDialog(),
style: {
width: 700,
height: 450
},
moreBtn: {
datas: []
},
buttons: [<Button type='primary' onClick={()=>this.saveHrmSearchUserDefine()}>保存</Button>],
}
2023-01-06 18:01:46 +08:00
TRANSFER = {
height: 350,
renderItem: (items) => this.renderItem(items),
filterLeft: (items) => this.filterLeft(items),
filterRight: (items) => this.filterRight(items),
onChange: (v) => this.updateTransferKeys(v)
}
@observable transfer = {
transferDatas: [],
transferKeys: [],
transferOptions: [],
transferSelectedKey: '0',
transferleftIptVal: '',
transferRightIptVal: ''
}
2023-01-05 18:02:33 +08:00
@action("常用条件定制保存") saveHrmSearchUserDefine = () => {
2023-01-06 18:01:46 +08:00
this.closeSearchDialog();
this.getSearchCondition();
}
@action("常用条件定制") formatTransfer = () => {
const transferDatas = []
const transferKeys = []
const transferOptions = [{
key: "",
showname: ""
}]
this.transfer.transferSelectedKey = '0';
this.transfer.transferleftIptVal = '';
this.transfer.transferRightIptVal = '';
this.searchCondition.forEach((c, idx) => {
transferOptions.push({
key: `${idx}`,
showname: c.title,
})
c.items.forEach((i) => {
transferDatas.push({
id: i.domkey[0],
label: i.label,
title: c.title,
idx: `${idx}`
})
})
})
this.defaultCondition.forEach((c, idx) => {
c.items.forEach((i) => {
transferKeys.push(i.domkey[0]);
})
})
this.transfer.transferDatas = transferDatas;
this.transfer.transferKeys = transferKeys;
this.transfer.transferOptions = transferOptions;
}
2023-01-05 18:02:33 +08:00
2023-01-06 18:01:46 +08:00
inputSearchStyle = {
width:"105px",
float:"right",
marginTop:"5px",
marginLeft:"10px"
2023-01-05 18:02:33 +08:00
}
2023-01-06 18:01:46 +08:00
selectStyle={
marginTop:"-1px",
width:"85px",
float:"right"
}
@computed get leftHeader() {
const {
transferleftIptVal,
transferOptions,
transferSelectedKey
} = this.transfer;
return (
<div className="trasfer-header">
<span>待选</span>
<WeaInputSearch
style={this.inputSearchStyle}
value={transferleftIptVal}
onSearchChange={this.updateTransferleftIptVal}
/>
<WeaSelect
style={this.selectStyle}
options={transferOptions}
value={transferSelectedKey}
onChange={this.updateTransferSelectedKey}
/>
</div>
)
}
@computed get rightHeader() {
const {
transferRightIptVal
} = this.transfer;
return (
<div className="trasfer-header">
<span>已选</span>
<WeaInputSearch
style={this.inputSearchStyle}
value={transferRightIptVal}
onSearchChange={ this.updateTransferRightptVal}
/>
</div>
)
}
renderItem = (item) => {
const {
label,
title
} = item;
return (<div className="trasfer-list-item" style={{"padding":"10px 20px","borderBottom":"1px solid #ddd"}}>
<div className="top text-overflow" style={{"marginBottom":"4px"}} title={label}>{label}</div>
<div className="bottom text-overflow" style={{"color":"#999"}} title={title}>{title}</div>
</div>)
};
filterLeft = (items) => {
let leftItems = cloneDeep(items);
const {
transferleftIptVal,
transferSelectedKey
} = this.transfer;
if (transferSelectedKey) {
leftItems = leftItems.filter((item) => item.idx == transferSelectedKey)
}
if (trim(transferleftIptVal)) {
leftItems = leftItems.filter((item) => item.label.indexOf(trim(transferleftIptVal)) > -1)
}
return leftItems
}
filterRight = (items) => {
let rightItems = cloneDeep(items);
const {
transferRightIptVal
} = this.transfer;
if (trim(transferRightIptVal)) {
rightItems = rightItems.filter((item) => item.label.indexOf(trim(transferRightIptVal)) > -1)
}
return rightItems
}
@action("穿梭框变化回调") updateTransferKeys = (v) => {
this.transfer.transferKeys = v;
}
@action updateTransferleftIptVal = (v) => {
this.transfer.transferleftIptVal = v;
}
@action updateTransferSelectedKey = (v) => {
this.transfer.transferSelectedKey = v;
}
@action updateTransferRightptVal = (v) => {
this.transfer.transferRightIptVal = v;
}
2023-01-05 18:02:33 +08:00
@action openSearchDialog = () => {
this.searchDialog.visible = true;
2023-01-06 18:01:46 +08:00
this.formatTransfer();
2023-01-05 18:02:33 +08:00
}
@action closeSearchDialog = () => {
this.searchDialog.visible = false;
}
2022-12-09 14:47:19 +08:00
2022-06-20 17:08:10 +08:00
updateFields(val) {
this.form2.updateFields({
2022-10-21 17:51:28 +08:00
lastName: {
2022-06-20 17:08:10 +08:00
value: val
}
});
}
setSearchCondition(condition) {
this.searchCondition = condition;
}
2023-01-06 18:01:46 +08:00
setDefaultCondition(defaultcondition) {
this.defaultCondition = defaultcondition;
}
setTemplates(templates) {
this.templates = templates;
}
2022-06-20 17:08:10 +08:00
setScLoadingStatus(bool) {
this.searchConditionLoading = bool;
}
setPanelStatus(bool) {
this.isPanelShow = bool;
bool && this.getSearchCondition();
if (!bool) {
this.scLoadingReset();
}
}
2022-10-21 17:51:28 +08:00
setLastName(val) {
this.lastName = val;
2022-06-20 17:08:10 +08:00
}
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;
}
2022-10-25 17:50:10 +08:00
setUserId(userId) {
this.userId = userId;
2022-06-20 17:08:10 +08:00
}
setDate(date) {
this.date = date;
}
setTopMenu(topMenu) {
this.topMenu = topMenu;
}
setRightMenu(rightMenu) {
this.rightMenu = rightMenu;
}
setHasRight(bool) {
this.hasRight = bool;
}
}