import React,{Component} from 'react'

import { Form, Input, DatePicker,Row, Col,Button,Icon ,Select} from 'antd';

import TextArea from './ZTextArea'


import YBIC from './YBIC'

const FormItem = Form.Item;


export default class T50A extends Component
{

    name='50A'
    desp = "Currency/Instructed Amount"
    
    pattern = "3!a15d"
    tno = -1
    //注意值要格式化
    keys = [1,2]
    onChange=(index,value)=>
    {
        if(index==2)
            this.fisrt_temp = undefined
        let obj = {};
        if(!value)
            value = ""
        let objtemp =this.props.value
        
        objtemp = objtemp && objtemp.length? objtemp[0] : {}

        objtemp["s"+index] = value;

        this.keys.forEach(i=>{
            obj['s'+i] = objtemp['s'+i]
        });
        let mval = ''
        if(obj.s1)
             mval = `${obj.s1}\r\n`
        if(obj.s2 )
             mval = `${mval}${obj.s2}`

        this.props.onValue([obj,mval])
    }
    componentWillMount()
    {
        // if(this.props.action == 'edit')
        // {
        //     this.fisrt_temp = '1/(Name of Beneficiary Customer)\r2/(Address Line)\r3/(Country and Town)'
        // }
    }
    render()
    {
        let value =this.props.value

        let mval = value && value.length? value[1] : ''
        let errmsg = value && value.length==3?value[2]:{}

        value = value && value.length? value[0] : {}
        return (<div>
        <Row>
                    <Col style={{"minWidth":'100px'}} span={16}>
                        <FormItem
                            label="Party Identifier"
                            help={errmsg.s1}
                            validateStatus={errmsg.s1?'error':null}
                        >
                             <Input   value={value.s1} onChange={e=>this.onChange(1,e.target.value)}   maxLength={35} style={{imeMode:'disabled'}} placeholder="Party Identifier"/>
                                   
                        </FormItem>
                    </Col>
        </Row>
        <Row>
            <Col>
            <FormItem
                 label="Number/Name and Address"  
                 required={this.props.status=='M' || mval?'required':null}
                 help={errmsg.s2}
                 validateStatus={errmsg.s2?'error':null}
                >
                        <TextArea type="textarea"  onChange={e=>this.onChange(2,e.target.value)} value={value.s2} style={{imeMode:'disabled'}} placeholder="Number/Name and Address" rows={4} cols={35} maxLength={140}/> 
                </FormItem>
            </Col>
        </Row>
        {/*<SubItem value={value.s2} onValue={(val)=>this.onChange(2,val)} />*/}
        </div>)
    }
}

class SubItem extends Component
{

    constructor(props)
    {
        super(props)
        this.state={items:[{val1:""},{val1:""},{val1:""},{val1:""}]}
        this.keys=[1,2,3,4]
    }
    onChange=(index,value)=>
    {
        let obj = {};
        if(!value)
            value = ""
        let objtemp =this.props.value
        
        objtemp = objtemp && objtemp.length? objtemp[0] : {}

        objtemp["s"+index] = value;

        this.keys.forEach(i=>{
            obj['s'+i] = objtemp['s'+i]
        });
        
        
         let mval = `1/${obj.s1}\r\n2/${obj.s2}\r\n3/${obj.s3}\r\n4/${obj.s4}`.replace(/^\d\r\n/,'')
        this.props.onValue([obj,mval])
    }

    render()
    {
        let value =this.props.value

        value = value && value.length?value[0] : {}
        
        return (<div>

            {
            this.state.items.map((item,index)=>{
                return (<Row key={index}>
                        
                        <Col span={24}>
                            <FormItem
                            >  
                                    <Input value={value['s'+index]} onChange={e=>this.onChange(index,e.target.value)} addonBefore={index+1+'/'} type="text" maxLength={33} style={{imeMode:'disabled'}} placeholder="Narrative"/>
                            </FormItem>
                        </Col>
                    </Row>)
                        
                })
            }
        </div>)
    }
    
}