salary-management-front/pc4mobx/hrmSalary/pages/datapush/components/PDDialog/index.js

136 lines
4.7 KiB
JavaScript

/*
* 数据推送
* 推送明细新增编辑
* @Author: 黎永顺
* @Date: 2024/11/20
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
import React, { Component } from "react";
import { inject, observer } from "mobx-react";
import { WeaDialog, WeaFormItem, WeaLocaleProvider, WeaSearchGroup, WeaTools } from "ecCom";
import CustomTreeSelect from "./customTreeSelect";
import { commonEnumList } from "../../../../apis/ruleconfig";
import * as API from "../../../../apis/datapush";
import { PDConditions } from "../../conditions";
import { WeaSwitch } from "comsMobx";
import { Button, message } from "antd";
const getLabel = WeaLocaleProvider.getLabel;
const getKey = WeaTools.getKey;
@inject("baseFormStore")
@observer
class Index extends Component {
constructor(props) {
super(props);
this.state = {
conditions: [], loading: false
};
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.visible !== this.props.visible && nextProps.visible) this.initForm(nextProps);
if (nextProps.visible !== this.props.visible && !nextProps.visible) this.props.baseFormStore.initFormExtra();
}
initForm = async (props) => {
const { detail = {} } = props;
const { data: fieldType } = await commonEnumList({ enumClass: "com.engine.salary.enums.push.PushItemFieldEnum" });
this.setState({
conditions: _.map(PDConditions, item => ({
...item, items: _.map(item.items, o => {
o = { ...o, label: getLabel(o.lanId, o.label), value: detail[getKey(o)] ? String(detail[getKey(o)]) : "" };
if (getKey(o) === "fieldType") {
return {
...o, value: detail[getKey(o)] ? String(detail[getKey(o)]) : "",
options: _.map(fieldType, o => ({ key: o.enum, showname: o.defaultLabel }))
};
}
return { ...o };
})
}))
}, () => {
props.baseFormStore.formExtra.initFormFields(this.state.conditions);
});
};
renderRuleForm = () => {
const { conditions } = this.state;
const { baseFormStore: { formExtra } } = this.props, { isFormInit } = formExtra;
const formParams = formExtra.getFormParams();
let group = [];
isFormInit && conditions && conditions.map(c => {
let items = [];
c.items.map(fields => {
items.push({
com: (
<WeaFormItem label={fields.label} labelCol={{ span: `${fields.labelcol}` }}
wrapperCol={{ span: `${fields.fieldcol}` }} error={formExtra.getError(fields)}
tipPosition="bottom">
{
getKey(fields) === "item" ?
<React.Fragment>
<CustomTreeSelect fieldConfig={fields} form={formExtra} formParams={formParams}/>
{
_.isEmpty(formParams.item) &&
<span className="wea-required-e9" style={{ verticalAlign: "middle" }}>
<img src="/images/BacoError_wev9.png" alt=""/>
</span>
}
</React.Fragment>
: <WeaSwitch fieldConfig={fields} form={formExtra} formParams={formParams}/>
}
</WeaFormItem>),
colSpan: 1,
hide: fields.hide
});
});
!_.isEmpty(items) && group.push(
<WeaSearchGroup col={1} needTigger={true} showGroup={c.defaultshow} items={items} center={false}
title={c.title}/>);
});
return group;
};
save = () => {
const { baseFormStore: { formExtra }, id, settingId } = this.props;
formExtra.validateForm().then(f => {
if (f.isValid) {
const payload = formExtra.getFormParams();
this.setState({ loading: true });
API.savePushItemList({ ...payload, settingId, id })
.then(({ status, errormsg }) => {
this.setState({ loading: false });
if (status) {
message.success(getLabel(30700, "操作成功"));
this.props.onCancel(this.props.onSearch());
} else {
message.error(errormsg);
}
}).catch(() => this.setState({ loading: false }));
} else {
f.showErrors();
}
});
};
render() {
const { loading } = this.state;
return (
<WeaDialog
{...this.props} style={{ width: 480, height: 174 }} initLoadCss className="Pdetail_dialog"
buttons={[
<Button onClick={this.props.onCancel}>{getLabel(111, "取消")}</Button>,
<Button type="primary" onClick={this.save} loading={loading}>{getLabel(111, "保存")}</Button>
]}
>
<div className="form-dialog-layout">{this.renderRuleForm()}</div>
</WeaDialog>
);
}
}
export default Index;