/*
 * Creator:     ML
 * CreatDate:   2019-08-20
 * descripts：  个人信息  修改用户名 
*/
import React from 'react';
import { Form, Row, Col, Input, Button, message,  } from 'antd';
import { $http } from '../../../containers/config/https';
const { TextArea } = Input;
const ModifyUserName = Form.create()(
    class ModifyUserName extends React.Component {
        constructor(props) {
            super(props)
            this.state = {
                userName:"",//原名
                name: "",//新名
                // userIntroduce:"",//简介
            }
        }
        componentDidMount() {
            // this.getUserName();
            this.props.onModifyUserName(this)
        }
        getUserName=()=>{
            let data = {
                params: [{
                    userID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID:"",
                    locID: sessionStorage.userData ?JSON.parse(sessionStorage.userData).locID:"",
                }],
                // pagination: [{
                //     pageSize: 10,
                //     currentPage: 1,
                //     sortColumn: 'code',
                //     sortOrder: 'asc'
                // }]
            };
            $http.post('urlS', this, {
                code: "01040051",
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        this.setState({
                            userName:res.result.userName,
                            // name:res.result.userName,
                            userIntroduce:res.result.userIntroduce,
                        })
                    }
                }
            })
        }
        handleChangeName = (e) => {
            this.setState({
                name: e.target.value
            })
        }
        handSave = () => {
            if(this.state.name&&this.state.name){
                let data = {}
                data = {
                    params: [{
                        userID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID:"",
                        updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID:"",
                        power: "userName",
                        userName: this.state.name || '',
                        // userIntroduce:this.state.userIntroduce || "",
                    }],
                };
                $http.post('urlS', this, {
                    code: "01040090",
                    data: data,
                    success: function (res) {
                        if (+res.errorCode === 0) {
                            message.success(
                                this.props.localeProvider&&this.props.localeProvider.PersonalInformationSuccessfullyModified?this.setMessage('PersonalInformationSuccessfullyModified', 'descripts'):"修改成功"
                            );
                            this.setState({
                                name:""
                            })
                            this.getUserName();
                        }
                    }
                });
            }else{
                message.warning("请填写用户名")
            }
            
        }
        //国际化
        setMessage(name, message) {
            return this.props.localeProvider ? this.props.localeProvider[name][message] : ''
        }
       
        render() {
            const {name,userName,userIntroduce} = this.state
            let localeData = this.props.localeProvider
            return (
                <div className="nameTitle">
                    <p><span>{localeData&&localeData.PersonalInformationCurrentUsername?this.setMessage('PersonalInformationCurrentUsername', 'descripts'):"当前用户名："}</span>{userName}</p>
                    <Row>
                    <Col span={10}>
                        <Input value={name} style={{ width: "100%",}} autoFocus placeHolder={localeData&&localeData.PersonalInformationUserNamePlaceHolder?this.setMessage('PersonalInformationUserNamePlaceHolder', 'message'):"请输入新用户名，不能超过15个字"} maxLength={15} onPressEnter={this.handSave} onChange={this.handleChangeName}></Input>
                        </Col>
                    </Row>
                    {/* <p style={{margin:"12px 0"}}><span>个人简介</span></p>
                    <Row>
                    <Col span={10}>
                       <TextArea maxLength="2000" 
                       placeholder="请输入个人简介，不能超过2000个字"
                       style={{
                           minHeight:"266px"
                       }}  value={userIntroduce} onChange={(e) => this.handleFieldChange(e, 'userIntroduce', )} />
                    </Col>
                    </Row> */}
                    <Row>
                        <Col span={10} style={{textAlign:"right"}}>
                            <Button  style={{ marginTop: "12px" }} key="submits" type="primary" onClick={this.handSave} >{localeData&&localeData.PersonalInformationsave?this.setMessage('PersonalInformationsave', 'descripts'):"保存："}</Button>
                        </Col>
                    </Row>
                </div>
            )
        }
    })
export default ModifyUserName    