import { observable, action, toJS } from 'mobx'; import { message } from 'antd'; import { WeaForm, WeaTableNew } from 'comsMobx'; import * as API from '../apis/welfareArchive'; // 引入API接口文件 const { TableStore } = WeaTableNew; export class ArchivesStore { @observable tableStore = new TableStore( // {dataHandle: (datas) => { // return dataSource; // }} ); @observable form = new WeaForm(); // nrew 一个form @observable condition = []; // 存储后台得到的form数据 @observable hasRight = true; // 判断用户是有权限查看当前页面: 没有权限渲染无权限页面,有权限渲染数据 @observable showSearchAd = false; // 高级搜索面板显示 @observable loading = true; // 数据加载状态 @observable dataSource = []; // Slide 表单 @observable baseFormData = {} @observable socialSecurityForm = {} // 社保表单 @observable accumulationFundForm = {} // 公积金表单 @observable otherForm = {}; // 其他福利表单 // 基数表单 @observable socialSecurityPaymentForm = {}; // 社保表单 @observable accumulationFundPaymentForm = {}; // 公积金表单 @observable otherPaymentForm = {}; // 其他福利表单 @observable pageInfo = {}; // 社保表单 @action setSocialSecurityForm = socialSecurityForm => this.socialSecurityForm = socialSecurityForm; // 公积金表单 @action setAccumulationFundForm = accumulationFundForm => this.accumulationFundForm = accumulationFundForm // 其他福利表单 @action setOtherForm = otherForm => this.otherForm = otherForm // 社保表单 @action setSocialSecurityPaymentForm = socialSecurityPaymentForm => this.socialSecurityPaymentForm = socialSecurityPaymentForm // 公积金表单 @action setAccumulationFundPaymentForm = accumulationFundPaymentForm => this.accumulationFundPaymentForm = accumulationFundPaymentForm // 其他福利基数表单 @action setOtherPaymentForm = otherPaymentForm => this.otherPaymentForm = otherPaymentForm // 初始化操作 @action doInit = () => { // this.getCondition(); this.getTableDatas(); } // 获得高级搜索表单数据 @action getCondition = () => { API.getSaCondition().then(action(res => { if (res.status) { // 接口请求成功/失败处理 this.condition = res.data.condition; this.form.initFormFields(res.data.condition); // 渲染高级搜索form表单 } else { message.error(res.msg || '接口调用失败!') } })); } // 渲染table数据 @action getTableDatas = (params) => { this.loading = true; const formParams = this.form.getFormParams() || {}; params = params || formParams; API.getTable(params).then(action(res => { if (res.status) { // 接口请求成功/失败处理 this.dataSource = res.data.datas; // this.columns = res.data.columns; this.tableStore.getDatas(res.data.dataKey.datas) this.pageInfo = res.data.pageInfo } else { message.error(res.msg || '接口调用失败!') } this.loading = false; })); } @action setShowSearchAd = bool => this.showSearchAd = bool; // 高级搜索 - 搜索 @action doSearch = () => { this.getTableDatas(); this.showSearchAd = false; } // 查询档案基本信息表单 @action getBaseForm = (employeeId, welfareTypeEnum ="") => { API.getBaseForm({employeeId, welfareTypeEnum}).then(action(res => { if(res.status) { if(welfareTypeEnum == "") { this.baseFormData = res.data.data } else if(welfareTypeEnum == "SOCIAL_SECURITY"){ this.socialSecurityForm = res.data } else if(welfareTypeEnum == "ACCUMULATION_FUND") { this.accumulationFundForm = res.data } else if(welfareTypeEnum == "OTHER") { this.otherForm = res.data } if(res.data && res.data.data && res.data.data.id) { this.getPaymentForm(employeeId, welfareTypeEnum, res.data.data.id) } } else { message.error(res.errormsg || "获取失败") } })) } // 查询档案缴纳基数表单 @action getPaymentForm = (employeeId, welfareTypeEnum, schemeId) => { API.getPaymentForm({employeeId, welfareTypeEnum, schemeId}).then(res => { if(welfareTypeEnum == "SOCIAL_SECURITY") { this.socialSecurityPaymentForm = res.data } else if(welfareTypeEnum == "ACCUMULATION_FUND") { this.accumulationFundPaymentForm = res.data } else if(welfareTypeEnum == "OTHER") { this.otherPaymentForm = res.data } }) } // 保存表单 @action save = (welfareType) => { let baseForm = "" let paymentForm = "" if(welfareType == "SOCIAL_SECURITY") { baseForm = JSON.stringify(this.socialSecurityForm.data) paymentForm = JSON.stringify(this.socialSecurityPaymentForm.data) } else if(welfareType == "ACCUMULATION_FUND") { baseForm = JSON.stringify(this.accumulationFundForm.data) paymentForm = JSON.stringify(this.accumulationFundPaymentForm.data) } else if(welfareType == "OTHER") { baseForm = JSON.stringify(this.otherForm.data) paymentForm = JSON.stringify(this.otherPaymentForm.data) } API.save({welfareType, baseForm, paymentForm}).then(res => { if(res.status) { message.success("保存成功") } else { message.error(res.errormsg || "保存失败") } }) } }