import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Form, Row, Col, Input, Select, Button, notification } from 'antd'
|
import './index.scss'
|
|
|
class UniqueForm extends Component {
|
static propTpyes = {
|
dict: PropTypes.object, // 字典项
|
modular: PropTypes.array, // 表单
|
modularDetail: PropTypes.array, // 表单
|
orderChange: PropTypes.func, // 表单
|
orderCheck: PropTypes.func // 表单
|
}
|
|
state = {
|
editItem: null,
|
modularDetail: []
|
}
|
|
UNSAFE_componentWillMount() {
|
if (this.props.modular.length > 0) {
|
this.setState({
|
modularDetail: this.props.modularDetail.filter(item => item.BID === this.props.modular[0].ID)
|
})
|
}
|
}
|
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
if (!is(fromJS(this.props.modular), fromJS(nextProps.modular))) {
|
let _detail = nextProps.modularDetail.filter(item => item.BID === nextProps.modular[0].ID)
|
|
this.setState({
|
modularDetail: _detail
|
})
|
|
this.props.form.setFieldsValue({
|
ModularCode: nextProps.modular[0].ID,
|
ModularDetailCode: _detail[0] ? _detail[0].ModularDetailCode : ''
|
})
|
}
|
}
|
|
edit = (record) => {
|
let _detail = this.props.modularDetail.filter(item => item.BID === record.ModularCode)
|
let _modularDetailCode = ''
|
|
if (_detail.filter(item => item.ModularDetailCode === record.ModularDetailCode).length > 0) {
|
_modularDetailCode = record.ModularDetailCode
|
}
|
|
this.setState({
|
editItem: record,
|
modularDetail: _detail
|
})
|
this.props.form.setFieldsValue({
|
field: record.field,
|
TypeCharOne: record.TypeCharOne,
|
ModularCode: record.ModularCode,
|
ModularDetailCode: _modularDetailCode,
|
errmsg: record.errmsg,
|
errorCode: record.errorCode
|
})
|
}
|
|
voucherChange = (value) => {
|
let _detail = this.props.modularDetail.filter(item => item.BID === value)
|
|
this.setState({
|
modularDetail: _detail
|
})
|
this.props.form.setFieldsValue({
|
ModularDetailCode: _detail[0] ? _detail[0].ModularDetailCode : ''
|
})
|
}
|
|
|
handleConfirm = () => {
|
// 表单提交时检查输入值是否正确
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
|
// 一级菜单值为20190203125926873D6029A9C511041719420时TypeCharTwo=TableCode,其他用BillCode
|
if (values.ModularCode === '20190203125926873D6029A9C511041719420') {
|
values.TypeCharTwo = 'TableCode'
|
} else {
|
values.TypeCharTwo = 'BillCode'
|
}
|
// 设置类型名称,用于列表显示
|
let billType = {
|
Y: '单号',
|
n: '编码',
|
Lp: '行号',
|
BN: '批次',
|
}
|
values.billType = billType[values.TypeCharOne]
|
|
// 设置凭证类型中文名
|
let ModularCode = this.props.modular.filter(item => item.ID === values.ModularCode)[0]
|
values.ModularCodeName = ModularCode.NameNO
|
|
// 设置流水号位数
|
let _detail = this.state.modularDetail.filter(item => item.ModularDetailCode === values.ModularDetailCode)[0]
|
values.Type = _detail.Type
|
let _vaild = this.props.orderCheck(values)
|
|
if (!_vaild) {
|
notification.warning({
|
top: 92,
|
message: '字段值不可重复',
|
duration: 10
|
})
|
return
|
}
|
|
this.props.orderChange(values)
|
this.setState({
|
editItem: null
|
})
|
this.props.form.setFieldsValue({
|
field: '',
|
errmsg: ''
|
})
|
}
|
})
|
}
|
|
render() {
|
const { getFieldDecorator } = this.props.form
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 10 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 14 }
|
}
|
}
|
return (
|
<Form {...formItemLayout} className="verify-form">
|
<Row gutter={24}>
|
<Col span={6}>
|
<Form.Item label={'字段'}>
|
{getFieldDecorator('field', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + '字段!'
|
},
|
{
|
pattern: /^[0-9a-zA-Z_]*$/,
|
message: '名称只允许包含数字、字母和下划线,且以指定字符开始。'
|
},
|
{
|
max: 50,
|
message: '名称不超过50个字符。'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" />)}
|
</Form.Item>
|
</Col>
|
<Col span={6}>
|
<Form.Item label={'类型'}>
|
{getFieldDecorator('TypeCharOne', {
|
initialValue: 'Y',
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.select'] + '类型!'
|
}
|
]
|
})(
|
<Select>
|
<Select.Option value="Y"> 单号 </Select.Option>
|
<Select.Option value="n"> 编码 </Select.Option>
|
<Select.Option value="Lp"> 行号 </Select.Option>
|
<Select.Option value="BN"> 批次 </Select.Option>
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={6}>
|
<Form.Item label={'凭证类型'}>
|
{getFieldDecorator('ModularCode', {
|
initialValue: this.props.modular[0] ? this.props.modular[0].ID : '',
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + '凭证类型!'
|
}
|
]
|
})(
|
<Select
|
showSearch
|
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
onChange={(value) => {this.voucherChange(value)}}
|
>
|
{this.props.modular.map(option =>
|
<Select.Option id={option.ID} key={option.ID} value={option.ID}>
|
{option.NameNO}
|
</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={6}>
|
<Form.Item label={'凭证标识'}>
|
{getFieldDecorator('ModularDetailCode', {
|
initialValue: this.state.modularDetail[0] ? this.state.modularDetail[0].ModularDetailCode : '',
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + '凭证标识!'
|
}
|
]
|
})(
|
<Select
|
showSearch
|
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
>
|
{this.state.modularDetail.map(option =>
|
<Select.Option id={option.ModularDetailCode} key={option.ModularDetailCode} value={option.ModularDetailCode}>
|
{option.CodeName}
|
</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={6}>
|
<Form.Item label={'提示信息'}>
|
{getFieldDecorator('errmsg', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + '提示信息!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" />)}
|
</Form.Item>
|
</Col>
|
<Col span={6}>
|
<Form.Item label={'报错编码'}>
|
{getFieldDecorator('errorCode', {
|
initialValue: 'E',
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.select'] + '报错编码!'
|
}
|
]
|
})(
|
<Select>
|
<Select.Option value="E"> E </Select.Option>
|
<Select.Option value="N"> N </Select.Option>
|
<Select.Option value="F"> F </Select.Option>
|
<Select.Option value="NM"> NM </Select.Option>
|
<Select.Option value="S"> S </Select.Option>
|
<Select.Option value="-1"> -1 </Select.Option>
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={2}>
|
<Button onClick={this.handleConfirm} type="primary" className="add-row">
|
确定
|
</Button>
|
</Col>
|
</Row>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(UniqueForm)
|