From 45466976d272c7b406b0e3d8b8fba92f3eb20524 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 07 一月 2020 17:55:13 +0800 Subject: [PATCH] 2020-01-07 --- src/templates/tableshare/verifycard/billcodeform/index.jsx | 203 +++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 157 insertions(+), 46 deletions(-) diff --git a/src/templates/tableshare/verifycard/billcodeform/index.jsx b/src/templates/tableshare/verifycard/billcodeform/index.jsx index c88deb9..34674b5 100644 --- a/src/templates/tableshare/verifycard/billcodeform/index.jsx +++ b/src/templates/tableshare/verifycard/billcodeform/index.jsx @@ -1,14 +1,78 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Form, Row, Col, Input, Select, Button, InputNumber } from 'antd' +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, // 瀛楀吀椤� - billCode: PropTypes.object, // 琛ㄥ崟 - billCodeChange: PropTypes.func // 琛ㄥ崟 + 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 : '' + }) } @@ -17,11 +81,46 @@ this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { values.uuid = this.state.editItem ? this.state.editItem.uuid : '' - values.field = values.field.join(',') + // 涓�绾ц彍鍗曞�间负20190203125926873D6029A9C511041719420鏃禩ypeCharTwo=TableCode锛屽叾浠栫敤BillCode + if (values.ModularCode === '20190203125926873D6029A9C511041719420') { + values.TypeCharTwo = 'TableCode' + } else { + values.TypeCharTwo = 'BillCode' + } + // 璁剧疆绫诲瀷鍚嶇О锛岀敤浜庡垪琛ㄦ樉绀� + let billType = { + Y: '鍗曞彿', + n: '缂栫爜', + Lp: '琛屽彿', + BN: '鎵规', + } + values.billType = billType[values.TypeCharOne] - this.props.uniqueChange(values) + // 璁剧疆鍑瘉绫诲瀷涓枃鍚� + 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: '' }) } }) @@ -29,41 +128,48 @@ render() { const { getFieldDecorator } = this.props.form - const { billCode } = this.props const formItemLayout = { labelCol: { xs: { span: 24 }, - sm: { span: 8 } + sm: { span: 10 } }, wrapperCol: { xs: { span: 24 }, - sm: { span: 16 } + sm: { span: 14 } } } return ( - <Form {...formItemLayout} className="custom-verify-form"> + <Form {...formItemLayout} className="verify-form"> <Row gutter={24}> <Col span={6}> <Form.Item label={'瀛楁'}> {getFieldDecorator('field', { - initialValue: billCode.ModularDetailCode || '', + initialValue: '', rules: [ { required: true, - message: this.props.dict['form.required.input'] + '鍑瘉鏍囪瘑!' + 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={'鍗曞彿绫诲瀷'}> + <Form.Item label={'绫诲瀷'}> {getFieldDecorator('TypeCharOne', { - initialValue: billCode.TypeCharOne || 'Y', + initialValue: 'Y', rules: [ { required: true, - message: this.props.dict['form.required.select'] + '鍗曞彿绫诲瀷!' + message: this.props.dict['form.required.select'] + '绫诲瀷!' } ] })( @@ -77,57 +183,62 @@ </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: billCode.ModularDetailCode || '', + initialValue: this.state.modularDetail[0] ? this.state.modularDetail[0].ModularDetailCode : '', rules: [ { required: true, message: this.props.dict['form.required.input'] + '鍑瘉鏍囪瘑!' } ] - })(<Input placeholder="" autoComplete="off" />)} - </Form.Item> - </Col> - <Col span={6}> - <Form.Item label={'娴佹按鐮佷綅鏁�'}> - {getFieldDecorator('Type', { - initialValue: billCode.Type || 4, - rules: [ - { - required: true, - message: this.props.dict['form.required.input'] + '娴佹按鐮佷綅鏁�!' - } - ] - })(<InputNumber defaultValue={4} min={1} max={10} precision={0} />)} - </Form.Item> - </Col> - <Col span={6}> - <Form.Item label={'绫诲瀷'}> - {getFieldDecorator('TypeCharTwo', { - initialValue: billCode.TypeCharTwo || 'BillCode', - rules: [ - { - required: true, - message: this.props.dict['form.required.select'] + '绫诲瀷!' - } - ] })( - <Select> - <Select.Option value="BillCode"> 涓氬姟 </Select.Option> - <Select.Option value="TableCode"> 涓绘暟鎹� </Select.Option> + <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={'鎶ラ敊淇℃伅'}> + <Form.Item label={'鎻愮ず淇℃伅'}> {getFieldDecorator('errmsg', { initialValue: '', rules: [ { required: true, - message: this.props.dict['form.required.input'] + '鎶ラ敊淇℃伅!' + message: this.props.dict['form.required.input'] + '鎻愮ず淇℃伅!' } ] })(<Input placeholder="" autoComplete="off" />)} -- Gitblit v1.8.0