// 新增用户信息
import React from 'react';
import { Form, Row, Col, Input, Select, Table, Switch, Button, Icon, message, Collapse, Modal, Spin } from 'antd';
// import reqwest from 'reqwest';
import { $http } from '../../../containers/config/https';
import { Util, ArraySome } from '../../../tools';
import Moment from 'moment';
import store from '../../../store';
import { withRouter } from 'react-router-dom';
import DatePickerFormat from '../../../components/datePicker/DatePickerFormat';
import UploadImg from './UploadImg';
import UploadPage from './UploadPage';
import '.././style/index.less';
// import { userInfo } from 'os';

// 组件const
const { Option } = Select;
const Panel = Collapse.Panel;
const { TextArea } = Input;
const formItemLayout = {    // label 和input宽度
    labelCol: { span: 14 },
    wrapperCol: { span: 8, offset: 2 },
};

const formItemSw = {    // label 和input宽度
    lg: { span: 3 },
};
class UserAdd extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            dataContact: [],   // 联系方式table数据
            contactCount: 0,   // 联系方式table数据Key
            depCount: 0,   // 联系方式table数据Key
            sexData: [], // 性别集合
            titleData: [], // 职称集合
            positionData: [], //职务集合
            languageData: [], // 语言集合
            credtypeData: [], // 证件类型集合
            hospitalData: [], // 医院集合
            groupData: [], // 角色集合
            deptDrData: [], // 科室集合
            contactMap: [],  //  联系方式select
            contactMapDisabled: [], //  联系方式select禁用数据
            contactHttp: [], //  联系方式请求数据
            // depHttp: [], // 登陆科室请求数据
            modalShow: false, //  弹框的显示
            contactId: [], // 删除联系方式数组
            firstLod: false, //  加载开关
            userInfo: {}, //  用户数据
            userID: '', //  用户id
            errorInput: [], //  错误input
            isCode: false,
            loading: false,
            imageUrl: '', // 图片地址
            faceValue: '', // 图片特征值
            errorImg: false, // 图片不通过
            fileList: '', // 图片
            userPicAddress1: '', // 图片服务器地址
            userPicAddress2: '', // 图片服务器地址
            typeName: '', // 图片上传名称
            image: '',
            loadingDom: false
        };

        // 联系方式table
        this.columnsContact = [{
            title: '联系方式',
            dataIndex: 'userContactTypeDesc',
            align: "center",
            key: '1',
            render: (text, record) => (
                <Select placeholder="请选择" defaultValue={record.userContactTypeDesc} style={{ width: '160px' }} onChange={this.contactMapChange.bind(this, record)} >
                    {this.state.contactMap.map(item => <Option key={item.descripts} value={item.descripts} disabled={this.state.contactMapDisabled.includes(item.descripts)}>{item.descripts}</Option>)}
                </Select>
            ),
        }, {
            title: '联系号码',
            dataIndex: 'userContactValue',
            align: "center",
            key: '2',
            render: (text, record) => (

                <Input placeholder="请输入" defaultValue={record.userContactValue} className={this.state.errorInput.includes(record.userContactTypeDesc) ? 'has-error' : ''} style={{ width: '160px' }} onBlur={this.contactMapBlur.bind(this, record)} />
            ),
        }, {
            title: '操作',
            dataIndex: 'operation',
            align: "center",
            key: '3',
            render: (text, record) => (
                <span>
                    <Icon type="delete" style={{ color: 'rgba(240,65,52,1)' }}></Icon>
                    <span className='span' onClick={() => this.dataContactDel(record.key)} style={{ color: 'rgba(240,65,52,1)' }}>删除</span>
                </span>
            ),
        }]
    }

    componentDidMount() {
        store.dispatch({
            type: 'userData',
            value: { userID: '', userCode: '' }
        })

        if (this.props.userID) {
            this.setState({
                userID: this.props.userID,
                isCode: true
            }, () => {
                this.userData() // 用户数据加载加载
            })
        }
        this.contactMapList() // 联系方式类型加载

        // 初始值下拉列表值
        let data = {
            "params": [
                {
                    code: '',
                }
            ]
        };

        $http.post('urlS', this, {
            code: "01040057",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    this.setState({
                        sexData: res.selectStore.sexAry, // 性别集合
                        languageData: res.selectStore.languageAry, // 语言集合
                        credtypeData: res.selectStore.credtypeAry, // 证件类型集合
                        titleData: res.selectStore.titleAry, // 职称集合
                        positionData: res.selectStore.positionAry, //职务集合
                        userPicAddress1: res.selectStore.userPicAddress || '', // 职称集合
                    })
                }
            }
        });
    }

    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }

    // 用户数据加载加载
    userData = () => {
        if (this.state.userID === '') {
            return false
        }
        let data = {
            "params": [{
                userID: this.state.userID,
            }]
        };

        $http.post('urlS', this, {
            code: "01040049",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    this.setState({
                        userInfo: res.result || '',
                        userPicAddress2: res.result.personImage || '', // 上传图片服务器地址
                        userPicAddress3: res.result.userImage || '', // 上传图片服务器地址
                    })
                }
            }
        });
    }

    // 联系方式类型加载
    contactMapList = () => {
        let data = {
            "params": [{
                code: '',
            }]
        };

        $http.post('urlS', this, {
            code: "01040034",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    this.setState({
                        contactMap: res.result
                    })
                }
            }
        });
    }

    // 弹框开启
    dataContactAddModal = () => {
        this.setState({
            modalShow: true,
        });

        this.contactAry() // 回显联系方式
        if (this.state.dataContact.length < 1) {
            // const { contactCount, dataContact, contactHttp } = this.state;
            this.dataContactAdd()
        }
    }
    // 解锁
    unLockUser = () => {
        let data = {
            "params": [{
                loginName: this.state.userInfo.userCode,
            }]
        };

        $http.post('urlS', this, {
            code: "01040310",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    message.success('解锁成功!')
                    this.userData();
                }
            }
        });

    }

    // 重置密码
    pwdModal = () => {
        const modal = Modal.confirm({
            title: '重置密码',
            content:
                (<div>
                    <Row style={{ textAlign: 'center' }}>
                        <Col span={24}>
                            <Button onClick={() => this.czPwd('userPassword')} style={{ marginBottom: '20px', }}>重置登录密码</Button>
                        </Col>
                        <Col span={24} >
                            <Button onClick={() => this.czPwd('userPin')} style={{ marginBottom: '20px', }} >重置签名密码</Button>
                        </Col>
                        <Col span={24}>
                            <Button onClick={() => this.czPwd('all')} style={{ marginBottom: '20px', }} >全部重置</Button>
                        </Col>
                    </Row>
                </div>),
            okText: '确认',
            onOk() {
                modal.destroy();
            },
        });

    }

    czPwd = (type) => {
        let data;
        // 全部重置
        if (type === 'all') {
            data = {
                "params": [{
                    "updateUserID": JSON.parse(window.sessionStorage.userData).userID || '',
                    "userID": this.state.userInfo.userID || '',
                    "hospID": JSON.parse(window.sessionStorage.userData).hospID || '',   // 当前医院
                    "userPassword": '',
                    "userPin": '',
                }]
            };
        }

        // 重置登录密码
        if (type === 'userPassword') {
            data = {
                "params": [{
                    "updateUserID": JSON.parse(window.sessionStorage.userData).userID || '',
                    "userID": this.state.userInfo.userID || '',
                    "hospID": JSON.parse(window.sessionStorage.userData).hospID || '',   // 当前医院
                    "userPassword": '',
                }]
            };
        }

        if (type === 'userPin') {
            // 重置签名密码
            data = {
                "params": [{
                    "updateUserID": JSON.parse(window.sessionStorage.userData).userID || '',
                    "userID": this.state.userInfo.userID || '',
                    "hospID": JSON.parse(window.sessionStorage.userData).hospID || '',   // 当前医院
                    "userPin": '',
                }]
            };
        }

        $http.post('urlADS', this, {
            code: "01040074",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    message.success(res.errorMessage)
                    Modal.destroyAll()
                }
            }
        });

    }

    contactAry = () => {   // 回显联系方式
        // 回显联系方式
        if (this.state.userInfo.userContactAry) {
            if (this.state.userInfo.userContactAry.length > 0 && this.state.firstLod === false) {
                let newdataContact = this.state.dataContact
                let newcontactMapDisabled = this.state.contactMapDisabled
                let newcontactCount = this.state.contactCount

                this.state.userInfo.userContactAry.map((item, i) => { //其他联系方式数组

                    const newData = {
                        key: i,
                        contactId: item.userContactID,
                        userContactID: item.userContactID,
                        userContactTypeID: item.userContactTypeID,
                        userContactTypeDesc: item.userContactTypeDesc,
                        userContactValue: item.userContactValue,
                    };
                    newcontactMapDisabled.push(item.userContactTypeDesc)
                    newdataContact.push(newData)
                })
                this.setState({
                    dataContact: newdataContact,   // 联系方式table数据
                    contactHttp: newdataContact, //  联系方式请求数据
                    contactCount: this.state.userInfo.userContactAry.length,   // 联系方式table数据Key
                    contactMapDisabled: newcontactMapDisabled, //  联系方式select禁用数据
                    firstLod: true, //  加载开关
                });
            }
        }
    }

    // 弹框关闭
    handleCancel = () => {
        if (this.state.errorInput.length > 0) {
            message.error('请输入正确的号码')
            // return false
        }
        this.setState({
            modalShow: false,
        });
    }

    // 联系方式table添加
    dataContactAdd = () => {
        let { contactCount, dataContact, contactHttp } = this.state;
        let newData = {
            key: contactCount,
            userContactTypeID: '',
            userContactTypeDesc: '',
            userContactValue: '',
        };

        this.setState({
            dataContact: [...dataContact, newData],
            contactCount: contactCount + 1,
            contactHttp: [...contactHttp, newData],
        });

    }

    // 联系方式table删除
    dataContactDel = (key) => {
        let dataContact = [...this.state.dataContact];
        let contactHttp = [...this.state.contactHttp];
        let contactId = [...this.state.contactId];
        let { contactMapDisabled, errorInput, contactCount } = this.state  //  联系方式select禁用数据

        // if (dataContact.length <= 1) {
        //     return false;
        // }

        contactMapDisabled.splice(key, 1)   // 删除不可选数组

        let newData = dataContact.filter((item, i) => {
            return item.key === key
        })

        if (newData[0].contactId) {  // 删除联系方式数组
            contactId.push(newData[0].contactId)
        }

        if (errorInput.length > 0) {

            let errorI = errorInput.indexOf(newData[0].userContactTypeDesc)

            if (errorI != -1) {
                errorInput.splice(errorI, 1);
            }


        }

        this.setState({
            dataContact: dataContact.filter(item => item.key !== key),
            // contactCount: contactCount - 1,

            contactMapDisabled: contactMapDisabled, //  联系方式select禁用数据
            contactHttp: contactHttp.filter(item => item.key !== key),
            contactId: contactId,
            errorInput: errorInput
        });
    }

    // 通过联系方式option的value获取对应的id
    contactOpptionId = (option) => {
        const { contactMap } = this.state
        let val = ''
        contactMap.map((item) => {
            if (option === item.descripts) {
                val = item.id
            }
        })

        return val
    }

    // 通过联系方式option的value获取对应的descripts
    contactOpptionDes = (option) => {
        const { contactMap } = this.state
        let val = ''
        contactMap.map((item) => {
            if (option === item.descripts) {
                val = item.descripts
            }
        })
        return val
    }

    // 联系方式变换
    contactMapChange = (t, value) => {
        let { contactHttp, contactMapDisabled, errorInput } = this.state
        let iH;
        contactHttp.map((item, i) => {
            if (item.key === t.key) {
                iH = i
            }
        })

        contactHttp[iH].userContactTypeID = this.contactOpptionId(value)  // 通过联系方式option的value获取对应的id
        contactHttp[iH].userContactTypeDesc = this.contactOpptionDes(value)   // 通过联系方式option的value获取对应的descripts


        if (this.state.dataContact.length === 1) {   //只有一个联系方式
            contactMapDisabled.length = 0;  //清空数组 保持只有一个值
            contactMapDisabled.push(value)
        } else {
            if (iH <= contactMapDisabled.length) {
                contactMapDisabled.splice(iH, 1, value)
            } else {
                if (!contactMapDisabled.includes(value)) {
                    contactMapDisabled.push(value)
                }
            }

        }

        if (errorInput.length > 0) {

            let errorI = errorInput.indexOf(contactHttp[iH].userContactTypeDesc)

            if (errorI == -1) {
                errorInput.splice(errorI, 1);
            }


        }

        this.setState({
            contactMapDisabled: contactMapDisabled,
            contactHttp: contactHttp,
            errorInput: errorInput
        });
    }

    // 联系方式文本失去焦点
    contactMapBlur = (t, value) => {

        let { contactHttp, errorInput } = this.state
        let iH;
        contactHttp.map((item, i) => {
            if (item.key === t.key) {
                iH = i
            }
        })

        contactHttp[iH].userContactValue = value.target.value

        this.setState({
            errorInput: errorInput
        });

        let regIdNo = /^1\d{10}$/;  // 自定义规则  手机号码
        let regexp = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\d{8}$)/;  // 自定义规则  固话座机号码

        if (contactHttp[iH].userContactTypeDesc === '办公电话') {
            if (!regexp.test(value.target.value)) {
                errorInput.push(contactHttp[iH].userContactTypeDesc)
                errorInput = ArraySome.ArrayWeigh(errorInput, 'remove') //将重复元素提取出到一个新数组或者单独数组去重

                this.setState({
                    errorInput: errorInput
                });
                message.error('请输入正确办公电话')
            } else {
                this.setState({
                    errorInput: []
                });
            }
        }

        if (contactHttp[iH].userContactTypeDesc === '手机') {
            if (!regIdNo.test(value.target.value)) {
                errorInput.push(contactHttp[iH].userContactTypeDesc)
                errorInput = ArraySome.ArrayWeigh(errorInput, 'remove') //将重复元素提取出到一个新数组或者单独数组去重
                this.setState({
                    errorInput: errorInput
                });
                message.error('请输入正确手机号')
            } else {
                this.setState({
                    errorInput: []
                });
            }
        }

        this.setState({
            contactHttp: contactHttp
        });
    }

    //证件号码的到出生日期
    getBirthdayFromIdCard = (event) => {
        let psidno = event.target.value;
        ///////////////////// 生日
        let birthdayno, birthdaytemp, birthday

        if (psidno.length == 18) {
            birthdayno = psidno.substring(6, 14)
        } else if (psidno.length == 15) {
            birthdaytemp = psidno.substring(6, 12)
            birthdayno = "19" + birthdaytemp
        } else {
            return false
        }
        birthday = birthdayno.substring(0, 4) + "-" + birthdayno.substring(4, 6) + "-" + birthdayno.substring(6, 8)
        if (birthday !== '') {
            this.props.form.setFieldsValue({
                'dOB': Moment(birthday, 'YYYY-MM-DD'),
            });
        }

        ///////////////////// 性别
        let sexno, sex
        if (psidno.length == 18) {
            sexno = psidno.substring(16, 17)
        } else if (psidno.length == 15) {
            sexno = psidno.substring(14, 15)
        } else {
            return false
        }
        let tempid = sexno % 2;
        if (tempid == 0) {
            sex = '2' //女
        } else {
            sex = '1' //男
        }
        this.props.form.setFieldsValue({
            'sexDr': sex,
        });

    }

    // 判断 身份证
    credNoIs = (rule, val, callback) => {
        if (!val) {
            callback();
        }
        let regIdNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;  // 自定义规则
        if (!regIdNo.test(val) && this.props.form.getFieldValue('credTypeDr') === '1') {
            callback('身份证号格式不正确');
        }
        callback();
    }

    // 医生护士互斥 医生
    doctorFlagChange = (event) => {

        let e = !event
        if (this.props.form.getFieldValue('nurseFlag')) {
            this.props.form.setFieldsValue({
                'nurseFlag': e,
            });
        }
    }

    // 医生护士互斥 护士
    nurseFlagChange = (event) => {
        let e = !event
        if (this.props.form.getFieldValue('doctorFlag')) {
            this.props.form.setFieldsValue({
                'doctorFlag': e
            });
        }
    }

    // 可用变化
    activeChange = (event) => {
        let e = event
        if (e) {
            this.props.form.setFieldsValue({
                'dateTo': undefined
            });
        } else {
            this.props.form.setFieldsValue({
                'dateTo': Moment(Moment().format('L'), 'YYYY-MM-DD')
            });
        }
    }

    ImgValue = (faceValue, imageUrl) => {
        this.setState({
            faceValue,
            imageUrl
        })
    }

    handleLoading = (status) => {
        this.setState({
            loadingDom: status
        })
    }

    ImgValue2 = (filePath) => {
        this.setState({
            image: filePath || ''
        })
    }

    ImgValue3 = (filePath) => {
        this.setState({
            publicImage: filePath || ''
        })
    }

    // 保存用户信息表单提交
    handleSubmit = (e, flag) => {
        e.preventDefault();
        this.contactAry() // 回显联系方式
        this.props.form.validateFields((err, values) => {

            if (!err) {  //!err

                let { contactHttp, contactId } = this.state //其他联系方式,科室state
                let newContactHttp = contactHttp.filter(value => Object.keys(value).length !== 0);
                let newContactHttp2 = []

                newContactHttp.map((item, i) => {
                    if (item.userContactValue !== '' && item.userContactTypeDesc !== '') {
                        newContactHttp2.push(item)
                    }
                })
                let stopDate = ""
                if (flag && flag === 'Y') {
                    stopDate = Moment().format('YYYY-MM-DD')
                } else {
                    stopDate = values.dateTo ? Moment(values.dateTo).utcOffset(480).format('YYYY-MM-DD') : ''
                }
                let data = {
                    "params": [{
                        userID: this.state.userInfo.userID || '',    //用户ID
                        userDesc: values.descripts || '',            //姓名                      
                        userCredTypeID: values.credTypeDr || '',     //证件类型
                        userCredNo: values.credNo || '',         // 证件号码
                        userSexID: values.sexDr || '',    //性别
                        userDOB: values.dOB ? Moment(values.dOB).utcOffset(480).format('YYYY-MM-DD') : '',                 //  出生日期                 
                        userCode: values.code || '',         // 工号                     
                        userName: values.userName || '',      // 用户名                         
                        userTitleID: values.titleDr || '', // 职称
                        userPositionID: values.positionDr || '', //行政职务
                        userCertNo: values.certNo || '',    //证书号
                        userLanguageID: values.languageDr || '',   // 默认语言
                        userPswActiveDate: values.pswActiveDate || '',     //密码有效天数
                        userMobile: values.mobile || '',   //手机号码
                        insuUserCode: values.insuUserCode || '',   //国家医保编码
                        userContactAry: newContactHttp2 || [],    //其他联系方式
                        // logonLocAry: depHttp || [],     //登陆科室
                        userIntroduce: values.introduce || '',   //简介
                        userDocFlag: Util.replaceTrueFalse(values.doctorFlag) || '',      //是否医师
                        userSurgeon: Util.replaceTrueFalse(values.surgeon) || '',             //外科医生
                        userAnaesthetist: Util.replaceTrueFalse(values.anaesthetist) || '',        // 麻醉医生
                        userNurFlag: Util.replaceTrueFalse(values.nurseFlag) || '',     // 护士
                        optometryFlag: Util.replaceTrueFalse(values.optometryFlag) || '',
                        superDocFlag: Util.replaceTrueFalse(values.superDocFlag) || '',     // 上级医师
                        attendDocFlag: Util.replaceTrueFalse(values.attendDocFlag) || '',     // 主治医师
                        // layoutManager: Util.replaceTrueFalse(values.layoutManager) || '',       //允许页面编辑
                        // columnManager: Util.replaceTrueFalse(values.columnManager) || '',       //允许列编辑
                        userActive: Util.replaceTrueFalse(values.active) || '',          //可用
                        financialAuthority: Util.replaceTrueFalse(values.financialAuthority) || '',  // 是否可以查看进价
                        userDateFrom: values.dateFrom ? Moment(values.dateFrom).utcOffset(480).format('YYYY-MM-DD') : '',        //生效日期
                        userDateTo: stopDate,          //失效日期
                        // userImage: values.image || '',           //图片
                        userUpdateUserID: JSON.parse(window.sessionStorage.userData).userID || '',        //更新人
                        currentUserHospID: JSON.parse(window.sessionStorage.userData).hospID || '',   // 当前医院
                        userContactRemoveAry: contactId || [],    //删除其他联系方式
                        requestFlag: 'N',
                        faceValue: this.state.faceValue || '',
                        userPicName: this.state.image === '' ? undefined : this.state.image,
                        publicImage: this.state.publicImage
                    }]
                };
                $http.post('urlADS', this, {
                    code: "01040024",
                    data: data,
                    success: function (res) {
                        let errorCode = res.errorCode;
                        if (errorCode === '0') {
                            message.success(res.errorMessage);
                            store.dispatch({
                                type: 'userData',
                                value: { userID: res.result[0].userID, userCode: res.result[0].userCode }
                            })
                            // this.setState({
                            //     typeName: res.result[0].userPicFiledName
                            // }, () => {
                            //     this.handleUpload() //图片上传
                            // })
                        }
                    }
                });
            }

        });
    }

    UploadImgClearn = () => {
        let data = {
            "params": [{
                userID: this.state.userInfo.userID || '',    //用户ID
            }]
        };
        $http.post('urlADS', this, {
            code: "01040193",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    message.success(res.errorMessage);
                    this.setState({
                        imageUrl: '', // 图片地址
                        faceValue: '', // 图片特征值
                        errorImg: false, // 图片不通过
                    }, () => {
                        this.childUploadImg.clearn()
                    })
                }
            }
        });

    }

    UploadImgClearLeftImg(e) {
        this.setState({
            publicImage: ''
        }, () => {
            this.childUploadPic.clearn()
            this.handleSubmit(e)
        })
    }

    onRefUploadImg = (ref) => {
        this.childUploadImg = ref
    }

    onUpload = (ref) => {
        this.childUploadPic = ref
    }

    render() {
        const { getFieldDecorator } = this.props.form;
        let userInfo = this.state.userInfo ? this.state.userInfo : {};
        let session = JSON.parse(window.sessionStorage.userData);
        // const uploadButton = (
        //     <div>
        //         <Icon type={this.state.loading ? 'loading' : 'plus'} />
        //         <div className="ant-upload-text">Upload</div>
        //     </div>
        // );
        // const { userPicAddress1, userPicAddress2 } = this.state;

        return (
            <div style={{ padding: 10, }}>
                <Spin spinning={this.state.loadingDom} tip="加载中...">
                    <Form layout="vertical" className="userForm" onSubmit={this.handleSubmit}  >
                        <Collapse defaultActiveKey={['1', '2']} >
                            <Panel header="基本信息" key="1" extra={this.state.userInfo.userLocked ? <span style={{ color: "red" }}>  用户密码多次失败，已被锁定!</span> : ''}>
                                <Row>
                                    <Col span={18}>
                                        {/* 第一行 */}
                                        <Row>
                                            <Col span={4}>
                                                <Form.Item label="姓名">
                                                    {getFieldDecorator('descripts', {
                                                        initialValue: userInfo.userDesc ? userInfo.userDesc : '',
                                                        rules: [{ required: true, message: '请输入姓名' }]
                                                    })(
                                                        <Input placeholder="请输入角色名称" className='input' />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="证件类型">
                                                    {getFieldDecorator('credTypeDr', {
                                                        initialValue: userInfo.userCredTypeID ? userInfo.userCredTypeID : '',
                                                        rules: [{ required: true, message: '请输入证件类型' }],
                                                    })(
                                                        <Select placeholder="请选择证件类型" >
                                                            {this.state.credtypeData.map(item => <Option key={item.id}>{item.descripts}</Option>)}
                                                        </Select>
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="证件号码">
                                                    {getFieldDecorator('credNo', {
                                                        initialValue: userInfo.userCredNo ? userInfo.userCredNo : '',
                                                        rules: [{ required: true, message: '请输入证件号码' }, {
                                                            validator: this.credNoIs
                                                        }],
                                                    })(
                                                        <Input placeholder="请输入证件号码" className='input' onBlur={this.getBirthdayFromIdCard} />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="性别">
                                                    {getFieldDecorator('sexDr', {
                                                        initialValue: userInfo.userSexID ? userInfo.userSexID : '',
                                                        rules: [{ required: true, message: '请选择性别' }]
                                                    })(
                                                        <Select placeholder="请选择性别">
                                                            {this.state.sexData.map(item => <Option key={item.id}>{item.descripts}</Option>)}
                                                        </Select>
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1} className="dpW100">
                                                <Form.Item label="出生日期">
                                                    {getFieldDecorator('dOB', {
                                                        initialValue: userInfo.userDOB ? Moment(userInfo.userDOB, 'YYYY-MM-DD') : undefined,
                                                        rules: [{ required: true, message: '请选择出生日期' }]
                                                    })(
                                                        <DatePickerFormat />
                                                    )}
                                                </Form.Item>
                                            </Col>

                                        </Row>
                                        {/* 第二行 */}
                                        <Row>
                                            <Col span={4}>
                                                <Form.Item label="人员工号">
                                                    {getFieldDecorator('code', {
                                                        initialValue: userInfo.userCode ? userInfo.userCode : '',
                                                        rules: [{ required: true, message: '请输入人员工号' }]
                                                    })(
                                                        <Input placeholder="请输入人员工号" className='input' disabled={this.state.isCode} />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="用户名">
                                                    {getFieldDecorator('userName', {
                                                        initialValue: userInfo.userName ? userInfo.userName : '',
                                                    })(
                                                        <Input placeholder="请输入用户名" className='input' allowClear />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="职称">
                                                    {getFieldDecorator('titleDr', {
                                                        initialValue: userInfo.userTitleID ? userInfo.userTitleID : '',

                                                    })(
                                                        <Select placeholder="请选择职称" allowClear>
                                                            {this.state.titleData.map(item => <Option key={item.id}>{item.descripts}</Option>)}
                                                        </Select>
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="证书号码">
                                                    {getFieldDecorator('certNo', {
                                                        initialValue: userInfo.userCertNo ? userInfo.userCertNo : '',
                                                    })(
                                                        <Input placeholder="请输入证书号码" className='input' allowClear />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="语言">
                                                    {getFieldDecorator('languageDr', {
                                                        initialValue: userInfo.userLanguageID ? userInfo.userLanguageID : '1',
                                                        rules: [{ required: true, message: '请选择语言' }],
                                                    })(
                                                        <Select placeholder="请选择语言">
                                                            {this.state.languageData.map(item => <Option key={item.id}>{item.descripts}</Option>)}
                                                        </Select>
                                                    )}
                                                </Form.Item>
                                            </Col>
                                        </Row>
                                        <Row>
                                            {/* <Col span={4}>
                                            <Form.Item label="登录密码">
                                                {getFieldDecorator('password', {
                                                    initialValue: userInfo.password ? userInfo.password : '',
                                                    rules: [{ required: true, message: '请输入登录密码' }]
                                                })(
                                                    <Input placeholder="请输入登录密码" className='input' />
                                                )}
                                            </Form.Item>
                                        </Col> */}
                                            <Col span={4} >
                                                <Form.Item label="密码有效天数">
                                                    {getFieldDecorator('pswActiveDate', {
                                                        initialValue: userInfo.userPswActiveDate ? userInfo.userPswActiveDate : '',
                                                        rules: [{ required: true, message: '请输入密码有效天数' }, { pattern: /([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])/, message: '有效天数至少1天' }]
                                                    })(
                                                        <Input placeholder="请输入密码有效天数" className='input' onKeyUp={(event) => { event.target.value = event.target.value.replace(/\D/g, '') }} />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            {/* <Col span={4} offset={1}>
                                            <Form.Item label="签名密码">
                                                {getFieldDecorator('pin', {
                                                    initialValue: userInfo.pin ? userInfo.pin : '',
                                                    rules: [{ required: true, message: '请输入签名密码' }]
                                                })(
                                                    <Input placeholder="请输入签名密码" className='input' />
                                                )}
                                            </Form.Item>
                                        </Col> */}
                                            <Col span={4} offset={1}>
                                                <Form.Item label="手机号码">
                                                    {getFieldDecorator('mobile', {
                                                        initialValue: userInfo.userMobile ? userInfo.userMobile : '',
                                                        rules: [{ required: true, message: '请输入手机号' }, { pattern: /^1\d{10}$/, message: '请输入正确的手机号' }],
                                                    })(
                                                        <Input placeholder="手机号码" className='input' />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="行政职务">
                                                    {getFieldDecorator('positionDr', {
                                                        initialValue: userInfo.userPositionID ? userInfo.userPositionID : '',

                                                    })(
                                                        <Select placeholder="请选择行政职务" allowClear>
                                                            {this.state.positionData.map(item => <Option key={item.id}>{item.descripts}</Option>)}
                                                        </Select>
                                                    )}
                                                </Form.Item>
                                            </Col>
                                            <Col span={4} offset={1}>
                                                <Form.Item label="国家医保编码">
                                                    {getFieldDecorator('insuUserCode', {
                                                        initialValue: userInfo.insuUserCode ? userInfo.insuUserCode : '',
                                                        rules: [{ required: false, message: '请输入国家医保编码' },],
                                                    })(
                                                        <Input placeholder="国家医保编码" className='input' />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                        </Row>
                                        <Row>
                                            <Col span={4} offset={1} >
                                                <span className="addHref" onClick={this.dataContactAddModal}>+添加其他联系方式</span>
                                            </Col>
                                            <Col span={4} offset={1} >
                                                <span className="addHref" onClick={this.pwdModal} style={{ display: this.state.isCode ? 'inline-block' : 'none' }}>重置密码</span>
                                            </Col>
                                            <Col span={4} offset={1} >
                                                <span className="addHref" onClick={this.unLockUser} style={{ display: userInfo.userLocked ? 'inline-block' : 'none' }}>手动解锁</span>
                                            </Col>

                                        </Row>
                                        <Row >
                                            <Col span={24}>
                                                <Form.Item label="简介">
                                                    {getFieldDecorator('introduce', {
                                                        initialValue: userInfo.userIntroduce ? userInfo.userIntroduce : '',
                                                    })(
                                                        <TextArea rows={2} maxLength="2000" placeholder="请输入简介" />
                                                    )}
                                                </Form.Item>
                                            </Col>
                                        </Row>
                                        {/* 第九行 */}
                                    </Col>
                                    <Col span={6} >
                                        <Row type="flex" justify="center">
                                            <Form.Item label="">
                                                <div style={{ textAlign: 'center' }}>
                                                    <span className="mB10" style={{ display: 'inline-block' }}>宣传照片</span>
                                                    <UploadPage onRef={this.onUpload} handThis={this} imageUrl={this.state.userPicAddress3} key={this.state.userPicAddress3}  ></UploadPage>
                                                    <Button onClick={this.UploadImgClearLeftImg.bind(this)} >清除</Button>
                                                </div>
                                            </Form.Item>
                                            <Form.Item label="">
                                                <div style={{ textAlign: 'center' }}>
                                                    <span className="mB10" style={{ display: 'inline-block' }}>登录照片</span>
                                                    <UploadImg onRef={this.onRefUploadImg} handThis={this} imageUrl={this.state.userPicAddress2} key={this.state.userPicAddress2}  ></UploadImg>
                                                    <Button onClick={() => this.UploadImgClearn()} >清除</Button>
                                                </div>
                                            </Form.Item>
                                        </Row>

                                    </Col>
                                </Row>
                            </Panel>
                            <Panel header="基本配置" key="2">
                                <Row>
                                    <Col className="textR" style={{ width: '80px', float: 'left' }}>
                                        <span >人员类型:</span>
                                    </Col>
                                    <Col {...formItemSw} style={{ marginLeft: '20px' }}>
                                        <Form.Item label="医师"  {...formItemLayout} className="labelR" >
                                            {getFieldDecorator('doctorFlag', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.userDocFlag === "Y" ? true : false,
                                            })(
                                                <Switch onChange={(event) => { this.doctorFlagChange(event) }} checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col {...formItemSw}>
                                        <Form.Item label="外科医师"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('surgeon', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.userSurgeon === "Y" ? true : false,
                                            })(
                                                <Switch checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col {...formItemSw}>
                                        <Form.Item label="麻醉医生"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('anaesthetist', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.userAnaesthetist === "Y" ? true : false,
                                            })(
                                                <Switch checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col {...formItemSw}>
                                        <Form.Item label="上级医师"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('superDocFlag', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.superDocFlag === "Y" ? true : false,
                                            })(
                                                <Switch checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col {...formItemSw}>
                                        <Form.Item label="主治医师"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('attendDocFlag', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.attendDocFlag === "Y" ? true : false,
                                            })(
                                                <Switch checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col {...formItemSw}>
                                        <Form.Item label="护士"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('nurseFlag', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.userNurFlag === "Y" ? true : false,
                                            })(
                                                <Switch onChange={(event) => { this.nurseFlagChange(event) }} checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col {...formItemSw}>
                                        <Form.Item label="验光师"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('optometryFlag', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.optometryFlag === "Y" ? true : false,
                                            })(
                                                <Switch checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                </Row>
                                {/* 第十行 */}
                                {/* <Row>
                                <Col className="textR" style={{ width: '80px', float: 'left' }}>
                                    <span >编辑权限:</span>
                                </Col>
                                <Col {...formItemSw} style={{ marginLeft: '20px' }}>
                                    <Form.Item label="界面编辑"  {...formItemLayout} className="labelR" >
                                        {getFieldDecorator('layoutManager', {
                                            valuePropName: 'checked',
                                            initialValue: userInfo.allowLayout === "Y" ? true : false,
                                        })(
                                            <Switch checkedChildren="是" unCheckedChildren="否" />
                                        )}
                                    </Form.Item>
                                </Col>
                                <Col {...formItemSw} >
                                    <Form.Item label="列编辑"  {...formItemLayout} className="labelR">
                                        {getFieldDecorator('columnManager', {
                                            valuePropName: 'checked',
                                            initialValue: userInfo.allowColumn === "Y" ? true : false,
                                        })(
                                            <Switch checkedChildren="是" unCheckedChildren="否" />
                                        )}
                                    </Form.Item>
                                </Col>
                            </Row> */}
                                <Row>
                                    <Col className="textR" style={{ width: '80px', float: 'left' }}>
                                        <span >其他:</span>
                                    </Col>
                                    <Col {...formItemSw} style={{ marginLeft: '20px' }}>
                                        <Form.Item label="用户可用"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('active', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.userEffective === "Y" ? true : false,
                                            })(
                                                <Switch onChange={(event) => { this.activeChange(event) }} checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col {...formItemSw}>
                                        <Form.Item label="查看进价"  {...formItemLayout} className="labelR">
                                            {getFieldDecorator('financialAuthority', {
                                                valuePropName: 'checked',
                                                initialValue: userInfo.financialAuthority === "Y" ? true : false,
                                            })(
                                                <Switch checkedChildren="是" unCheckedChildren="否" />
                                            )}
                                        </Form.Item>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col className="textR formRequired" style={{ width: '80px', float: 'left' }}>
                                        <span style={{ lineHeight: '30px' }}>生效日期:</span>
                                    </Col>
                                    <Col span={4} className="dpW100" style={{ marginLeft: '20px' }}>
                                        <Form.Item  >
                                            {getFieldDecorator('dateFrom', {
                                                rules: [{ required: true, message: '请输入生效日期' }],
                                                initialValue: userInfo.userDateFrom ? Moment(userInfo.userDateFrom, 'YYYY-MM-DD') : Moment(Moment().format('L'), 'YYYY-MM-DD')
                                            })(
                                                <DatePickerFormat />
                                            )}
                                        </Form.Item>
                                    </Col>
                                    <Col className="textR" span={1} style={{ width: '80px', float: 'left' }}>
                                        <span style={{ lineHeight: '30px' }} >失效日期:</span>
                                    </Col>
                                    <Col span={4} className="dpW100" style={{ marginLeft: '20px' }}>
                                        <Form.Item >
                                            {getFieldDecorator('dateTo', {
                                                initialValue: userInfo.userDateTo ? Moment(userInfo.userDateTo, 'YYYY-MM-DD') : undefined,
                                            })(
                                                <DatePickerFormat />
                                            )}
                                        </Form.Item>
                                    </Col>
                                </Row>
                            </Panel>
                        </Collapse>
                        <Row style={{ width: '100%', textAlign: 'center', margin: '5px 0' }}>
                            <Button hidden={session.hospCode != 'H20'} onClick={(e) => this.handleSubmit(e, "Y")} style={{ background: 'red', color: '#fff', marginRight: '5px' }}>暂停</Button>
                            <Button hidden={session.hospCode != 'H20'} onClick={(e) => this.handleSubmit(e, "Y")} style={{ background: 'red', color: '#fff', marginRight: '5px' }}>禁用</Button>
                            <Button onClick={this.handleSubmit} style={{ background: 'rgba(66,185,131,1)', color: '#fff' }}>保存</Button>
                        </Row>
                        <Modal
                            visible={this.state.modalShow}
                            title='添加联系方式'
                            onCancel={this.handleCancel}
                            onOk={this.handleCancel}
                        >
                            <Row>
                                <Col span={24} className="textR mB10" style={{ marginTop: '-10px' }}>
                                    <span icon="plus" onClick={this.dataContactAdd} style={{ cursor: 'pointer', color: 'rgb(66, 185, 131)' }}>添加联系方式</span>
                                </Col>
                            </Row>
                            <Table
                                bordered
                                dataSource={this.state.dataContact}
                                columns={this.columnsContact}
                                pagination={false}
                                style={{ minHeight: '200px' }}
                            />
                        </Modal>
                    </Form>
                </Spin>
            </div>
        )
    }
}

const UserAddFrom = Form.create()(UserAdd);


export default withRouter(UserAddFrom)