salary-management-front/pc4mobx/hrmSalary/pages/calculate/baseFormModal.js

130 lines
3.5 KiB
JavaScript

import React from "react";
import { Button, Col, message, Modal, Row, Select } from "antd";
import RequiredLabelTip from "../../components/requiredLabelTip";
import { inject, observer } from "mobx-react";
import { WeaDatePicker, WeaInput } from "ecCom";
import { notNull } from "../../util/validate";
import "./index.less";
const { Option } = Select;
@inject("calculateStore")
@observer
export default class baseFormModal extends React.Component {
constructor(props) {
super(props);
this.state = {
salaryMonthStr: "",
inited: false,
selectOptions: [],
salarySob: "",
description: ""
};
}
componentWillMount() {
const { calculateStore } = this.props;
const { salaryacctGetForm } = calculateStore;
salaryacctGetForm().then(data => {
this.setState({
inited: true,
selectOptions: data.salarySobs
});
});
}
handleSelectChange(value) {
this.setState({
salarySob: value
});
}
// 保存回调
handleSave() {
if (!this.validate()) {
return;
}
let params = {
salaryMonthStr: this.state.salaryMonthStr,
salarySobId: this.state.salarySob,
description: this.state.description
};
const { calculateStore: { saveBasic } } = this.props;
saveBasic(params).then((id) => {
this.props.onCancel();
this.props.onRefresh();
window.open("/spa/hrmSalary/static/index.html#/main/hrmSalary/calculateDetail?id=" + id);
});
}
validate() {
if (!notNull(this.state.salaryMonthStr)) {
message.warning("薪酬所属月不能为空");
return false;
} else if (!notNull(this.state.salarySob)) {
message.warning("核算账套不能为空");
return false;
}
return true;
}
render() {
const { salaryMonthStr, salarySobId, description } = this.state;
return (
<Modal
title="核算"
wrapClassName="dataList-wrapper"
visible={this.props.visible}
width={600}
onCancel={() => {
this.props.onCancel();
}}
footer={<Button type="primary" onClick={() => {
this.handleSave();
}}>保存</Button>}
>
<Row style={{ lineHeight: "40px" }}>
<Col span={8}>薪酬所属月<RequiredLabelTip/></Col>
<Col span={16}>
<WeaDatePicker
style={{ width: "100%" }}
format="yyyy-MM"
value={this.state.salaryMonthStr}
onChange={value => {
this.setState({
salaryMonthStr: value
});
}}
/>
</Col>
</Row>
<Row style={{ lineHeight: "40px" }} className="formItem">
<Col span={8}>核算账套<RequiredLabelTip/></Col>
<Col span={16}>
{
this.state.inited && <Select
defaultValue={this.state.salarySob} value={this.state.salarySob} style={{ width: "100%" }}
onChange={(value) => this.handleSelectChange(value)}>
{this.state.selectOptions.map(item => (
<Option value={item.id} key={item.id}>{item.name}</Option>
))}
</Select>
}
</Col>
</Row>
<Row style={{ lineHeight: "40px" }}>
<Col span={8}>备注</Col>
<Col span={16}>
<WeaInput value={description} onChange={(value) => this.setState({ description: value })}/>
</Col>
</Row>
</Modal>
);
}
}