import * as Api from '../apis/importresource'; import { observable, action, extendObservable } from 'mobx'; import { WeaForm, WeaTableNew } from 'comsMobx'; import { message } from 'antd' import { i18n } from '../public/i18n'; const { TableStore } = WeaTableNew; // import { // HrmAdAreaSet // } from './adareaset'; // import { // HrmOfficeAddress // } from './officeaddress'; // import { // HrmPostSet // } from './postset'; // import { // HrmMajorSet // } from './majorset'; // const hrmAdAreaSet = new HrmAdAreaSet(); // const hrmOfficeAddress = new HrmOfficeAddress(); // const hrmPostSet = new HrmPostSet(); // const hrmMajorSet = new HrmMajorSet(); export class HrmImportCommon { sourceStore = null; @observable pageName = ''; @observable importType = ''; @observable importDialog = { visible: false, condition: [], form: new WeaForm(), title: '', loading: true, templetName: '', selectedValue: 'workcode', } @observable resultDialog = { title: observable.ref(i18n.label.importResult()), errorTip: observable.ref(i18n.message.selectImportTempleteError()), visible: false, index: 1, datas: [], importStatus: '', pId: '', interval: '', tableStore: new TableStore(), errorInfo: [], succnum: 0, failnum: 0, loading: true, component: '', } @observable recordDialog = { title: observable.ref(i18n.button.importHistoryQuery()), visible: false, tableStore: new TableStore(), } @observable logDialog = { title: observable.ref(i18n.button.getImportLog()), visible: false, tableStore: new TableStore(), isPanelShow: false, form: new WeaForm(), condition: [], loading: true, } @action getImportForm = () => { this.importDialog.loading = true; let params = { importType: this.importType } Api.getImportForm(params).then(rs => { const { status, condition = [], } = rs; if (status == '1') { this.importDialog.condition = condition; const copy = [...condition]; copy.splice(1); copy[0].items.splice(2); this.importDialog.form.initFormFields(copy); this.importDialog.loading = false; } else { // message.error(rs.message); } }).catch(error => { message.error(error); }); } @action getImportProcessInfo = () => { let params = { importType: this.importType, index: this.resultDialog.index, }; Api.getImportProcessLog(params).then(rs => { const { datas, index, pId = '', status } = rs; this.resultDialog.loading = false; if (status == '1') { const { importStatus, interval, errorInfo, component } = this.resultDialog; component.scrollToLast(); if (importStatus == 'over' || importStatus == 'error') { clearInterval(interval); if (!this.hasErrorInfo(errorInfo)) this.getResultInfo(); this.sourceStore && this.sourceStore.getTable(); //根据pageName判断刷新那个页面的列表 // switch (this.pageName) { // case 'adareaset': // hrmAdAreaSet.setOperation('getTable'); // hrmAdAreaSet.setFuncName('getCountryList'); // hrmAdAreaSet.getTable(); // break; // case 'officeaddress': // hrmOfficeAddress.getTableInfo(); // break; // case 'post': // hrmPostSet.initSet('getTableInfo', 'getJobGroupList'); // hrmPostSet.getTableInfo(); // break; // case 'major': // hrmMajorSet.setOperation('getTableInfo'); // hrmMajorSet.getTableInfo(); // break; // } return } if (rs.importStatus == 'over' || rs.importStatus == 'error') { this.resultDialog.loading = true; } this.resultDialog.importStatus = rs.importStatus; if (pId) this.resultDialog.pId = pId; if (this.resultDialog.datas.length == 0) { this.resultDialog.datas = datas; } else { this.resultDialog.datas = [...this.resultDialog.datas, ...datas] } this.resultDialog.index = index; } }); } @action getResultInfo = () => { let params = { pId: this.resultDialog.pId }; this.resultDialog.loading = true; Api.getImportResult(params).then(rs => { const { datas, status } = rs, { succnum, failnum, sessionkey = '' } = datas; if (status == '1') { this.resultDialog.succnum = succnum; this.resultDialog.failnum = failnum; sessionkey && this.resultDialog.tableStore.getDatas(sessionkey, 1); } this.resultDialog.loading = false; }); } @action getRecordTable = () => { let params = { importType: this.importType }; Api.getImportHistory(params).then(rs => { const { status, sessionkey, } = rs; if (status == '1') { this.recordDialog.tableStore.getDatas(sessionkey, 1); } else { message.error(rs.message); } }).catch(error => { message.error(error); }); } @action getLogTable = () => { let params = { importType: this.importType, ...this.logDialog.form.getFormParams(), }; if (this.resultDialog.pId) { params = { ...params, pId: this.resultDialog.pId } } Api.getImportLogDetail(params).then(rs => { const { status, sessionkey } = rs; if (status == '1') { this.logDialog.tableStore.getDatas(sessionkey, 1); } else { message.error(rs.message); } }).catch(error => { message.error(error); }); } @action submitImportInfo = () => { let params = { importType: this.importType, excelfile: this.importDialog.excelFileId, operateType: 'add' }; if (this.importType == 'group') { params = { ...params, ...this.importDialog.form.getFormParams() } } this.setResultInfoDialogVisible(true); Api.saveImport(params).then(rs => { const { status, errorInfo } = rs; if (status == '1') { if (this.hasErrorInfo(errorInfo)) { this.resultDialog.errorInfo = errorInfo; this.resultDialog.importStatus = 'error'; } } else { message.error(rs.message); } }).catch(error => { message.error(error); }); this.resultDialog.interval = setInterval(() => this.getImportProcessInfo(), 2000); } @action getLogSearchPanelCondition = () => { this.logDialog.loading = true; let params = { importType: this.importType }; Api.getImportLogSearchCondition(params).then(rs => { const { status, searchCondition } = rs; if (status == '1') { this.logDialog.condition = searchCondition; this.logDialog.form.initFormFields(searchCondition); } else { message.error(rs.message); } this.logDialog.loading = false; }).catch(error => { message.error(error); }); } @action setExcelFileNo = (id) => { extendObservable(this.importDialog, { excelFileId: id }); } @action submitExcel = () => { if (!this.importDialog.excelFileId) { message.warning(i18n.message.selectImportTemplete()); return; } this.submitImportInfo(); } @action queryRecord = () => { this.setRecordDialogVisible(true); } @action queryLog = () => { this.setLogDialogVisible(true); } @action jumpToImportResult = (id) => { this.resultDialog.pId = id; this.resultDialog.importStatus = 'over'; this.setResultInfoDialogVisible(true); this.getResultInfo(); } @action setImportDialogVisible = (bool) => { this.importDialog.visible = bool; if (bool) { this.getImportForm(); } else { this.importDialogReset(); } } //设置标识,标识当前是那个页面在导入 @action setImportPage = (pageName) => { this.pageName = pageName; } @action setResultInfoDialogVisible = (bool) => { this.resultDialog.visible = bool; if (!bool) { clearInterval(this.resultDialog.interval); this.resetResultDialogStatus(); } } @action importDialogReset = () => { this.importDialog.condition = []; this.importDialog.form = new WeaForm(); this.importDialog.selectedValue = 'workcode'; this.importDialog.excelFileId = ''; } @action resetResultDialogStatus = () => { this.resultDialog.index = 1; this.resultDialog.datas = []; this.resultDialog.importStatus = ''; this.resultDialog.pId = ''; this.resultDialog.interval = ''; this.resultDialog.errorInfo = ''; this.resultDialog.loading = true; } @action setRecordDialogVisible = (bool) => { this.recordDialog.visible = bool; bool && this.getRecordTable(); } @action setLogDialogVisible = (bool) => { this.logDialog.visible = bool; bool && this.getLogTable(); if (!bool) { this.logDialog.isPanelShow = false; this.logDialog.form = new WeaForm(); this.logDialog.condition = []; } } @action setLogPanelStatus = (bool) => { this.logDialog.isPanelShow = bool; bool && this.logDialog.condition.length == 0 && this.getLogSearchPanelCondition(); } @action searchLogInfo = () => { this.getLogTable(); } hasErrorInfo = (errorInfo) => { if (errorInfo.length == 0) return false; return true } @action setTempletName = (templetName) => { this.importDialog.templetName = templetName; } @action setImportDialogTitle = (title) => { this.importDialog.title = title; } @action setImportType = (type) => { this.importType = type; } @action setSelectedValue = (value) => { this.importDialog.selectedValue = value; } @action setScoll = (component) => { this.resultDialog.component = component; } setSourceStore = (store) => { this.sourceStore = store; } }