trunk/pc4mobx/organization/stores/companyextend.js

193 lines
5.0 KiB
JavaScript

import { observable, action, toJS } from "mobx";
import { WeaForm } from "comsMobx";
import { WeaTableNew } from "comsMobx";
import { Modal, message } from "antd";
import { i18n } from "../public/i18n";
export class CompanyExtendStore {
@observable form = new WeaForm();
@observable tableInfo = []
@observable conditions = [];
@observable isEditor = false;
@observable isNew = true;
@observable loading = true;
@observable tabInfo = [];
@observable selectedKey = 0;
@observable detailSelectedKey = 0;
@observable buttons = {}
@observable date;
@observable personalEditTables;
@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.tabkey = '0';
}
init = () => {
//this.tabkey = '0';
this.isEditor = false;
}
save = () => {
if(this.loading)
return;
this.loading = true;
this.form.validateForm().then(f => {
if (f.isValid) {
if(this.personalEditTables){
// const targetDatas = this.tableInfo[this.tabkey].tabinfo.datas,
// isPass = (targetDatas.length > 0) ? this.personalEditTables.refs.edit.doRequiredCheck().pass : true
let isPass = 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({ ...{
// operation: 'editpersonalinfo',
// id: this.hrmId
// },
// ...pDatas,
// ...this.getTableEditParams()
// }).
// then(data => {
// if (data.status == '1') {
// message.success(i18n.message.saveSuccess());
// this.init();
// this.getData();
// this.selectedRowKeys = [];
// } else {
// message.warning(data.message);
// }
// this.loading = false;
// }, error => {
// message.warning(error.message);
// 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 = (params={}) => {
// this.loading = true;
// params.id=this.hrmId;
// params.viewAttr=this.isEditor?2:1;
// params.is_multilang_set=this.isEditor;
// params.operation = 'getResourcePesonalView';
// API.getResourceCard(params).then((data) => {
// this.hasRight = has(data, 'hasRight') ? data.hasRight : true;
// this.loading = false;
// this.form.initFormFields(data.result.conditions);
// this.conditions = data.result.conditions;
// this.tableInfo = this.handleTable(data.result.tables);
// this.getTabInfo();
// this.buttons = data.result.buttons;
// this.hrmId = data.result.id;
// this.isEditor && this.getSelectedRows();
// })
}
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.tabkey = this.tabInfo[0].key;
}
setLoading(val) {
this.loading(false);
}
updateDetailSelectedKey = (key) => {
this.detailSelectedKey = key;
}
updateSelectedKey = (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;
}
}