/*
 * Creator:     ML
 * CreatDate:   2019-12-24
 * descripts：  治疗工作站 资源类型
 * */
import React from 'react';
import {
    Card, Table, Input, Form, Select, Row, Col, DatePicker, Button, Pagination,
    Popconfirm, Divider, Icon, message, Checkbox, Badge,
} from 'antd';
import './style/index.less';
import { $http } from 'containers/config/https';
import { Util } from 'tools/index';
import { dayFormat } from 'tools/index';
import CommonPagination from 'components/pagination/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
// import DigitalKeyboard from 'pages/common/DigitalKeyboard';
import moment from 'moment';
import store from 'store';
const formItemLayout = { // label 和input宽度
    labelCol: { span: 5 },
    wrapperCol: { span: 10 },
}
const paddRightCol = {
    paddingRight: "0px"
}
const formItemLayoutSearch = {
    labelCol: { span: 7 },
    wrapperCol: { span: 17 },
}
const formItemLayoutTT = {
    labelCol: { span: 9 },
    wrapperCol: { span: 15 },
}
const formItemLayoutLoc = {
    labelCol: { span: 5 },
    wrapperCol: { span: 19 },
}
const FormItem = Form.Item;
const Option = Select.Option;
class SourceType extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        this.state = {
            total: 0,
            page: 1,
            pageSize: 10,
            userData: userData,
            size: 'small',
            sizeHos: "small",
            search: "",
            pageSizeHos: 10,
            pageHos: 1,
            showkey:false,
            sss:false
        }
    }
    
    componentDidMount() {
        var x = document.querySelectorAll(".locDom .ant-table-body");
        for (var i = 0; i < x.length; i++) {
            x[i].style.height = store.getState().tableHeight.y - 338 + 'px';
            x[i].style.overflow = "auto";
        }
        document.querySelector('.listDom .ant-table-body').style.height = store.getState().tableHeight.y - 272 + 'px';
        document.querySelector('.hosDom .ant-table-body').style.height = store.getState().tableHeight.y - 462 + 'px';
        document.querySelector('.hosDom .ant-table-body').style.overflow = "auto";
        this.getMainTableColumns();//资源类型表头
        this.getMainTableColumnsHos();
        this.getMainTableColumnsLoc();
        this.getHopSelect()
        this.getLocType()
        this.findData();//资源类型表数据
    }
    //获取医院下拉框
    getHopSelect = () => {
        let data = {
            params: [{
                hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
                logonGroupID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID : "",
                logonHospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
            }],
        }
        $http.post('urlS', this, {
            code: '01040001',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        hosData: res.result
                    })
                }
            }
        })
    }
     //获取科室类型下拉框
     getLocType = () => {
        let data = {
            params: [{
               
            }],
        }
        $http.post('urlS', this, {
            code: '05100225',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        locTypeData: res.result.Data
                    })
                }
            }
        })
    }
    
    onColumnRef = (ref) => {
        this.columnRef = ref;
    }
    onColumnRefHos = (ref) => {
        this.columnRefHos = ref;
    }
    onColumnRefLoc = (ref) => {
        this.columnRefLoc = ref;
    }
    // 获取主列表columns---资源类型列表
    getMainTableColumns = () => {
        let data = {
            params: [{
                compontName: "ResourceTypeAssociatedHospital",
                reactCode: ['ResourceTypeAssociatedHospital'],
                type: 'C',
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map(item => {
                        return {
                            align: item.align,
                            widthNum: parseInt(item.width),
                            width: item.width,
                            dataIndex: item.dataIndex,
                            title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{this.state.userData.language == 'EN' ? item.descripts:item.title}</div>,
                            display: item.display,
                            key: item.seqNo,
                            // render: (text, record) => {
                            //    if (item.code == "status") {
                            //      return (
                            //      <span>{record.status=="Y"?"生效":"失效"}</span>
                            //      )
                            //    }
                            //    return text
                            //  }
                        }
                    }) : '';
                    let filterArr = arr.filter(function (item) { return item.display === 'Y' });
                    let seqArr = {
                        align: "center",
                        widthNum: 140,
                        width: "50px",
                        code: "edit",
                        dataIndex: "edit",
                        title: this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocOperating?this.setMessage('ResTypeLinkLocOperating', 'descripts'):"操作",
                        display: "Y",
                        render: (value, row, index) => {
                            return (
                                <span>
                                    {/* <Divider type="vertical" /> */}
                                    <Popconfirm title={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocWhetherToDelete?this.setMessage('ResTypeLinkLocWhetherToDelete', 'descripts'):"是否要删除"} onConfirm={(e) => this.toggleEditable(e,row)}>
                                        <a style={{ color: "red" }} >{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDelete?this.setMessage('ResTypeLinkLocDelete', 'descripts'):"删除"}</a>
                                    </Popconfirm>
                                </span>
                            )
                        },
                    }
                    filterArr.push(seqArr)
                    this.setState({ columns: filterArr, widthTotal: res.totalWidth })
                    // console.log("res.totalWidth",res.totalWidth)
                }
            }
        })
    }

    // 获取主列表columns---科室列表
    getMainTableColumnsLoc = () => {
        let data = {
            params: [{
                compontName: "ResTypeLinkLoc",
                reactCode: ['ResTypeLinkLoc'],
                type: 'C',
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map(item => {
                        return {
                            align: item.align,
                            widthNum: parseInt(item.width),
                            width: item.width,
                            dataIndex: item.dataIndex,
                            title: <div onDoubleClick={() => this.columnRefLoc.onOpenModel()}>{this.state.userData.language == 'EN' ? item.descripts:item.title}</div>,
                            display: item.display,
                            key: item.seqNo,
                            // render: (text, record) => {
                            //    if (item.code == "status") {
                            //      return (
                            //      <span>{record.status=="Y"?"生效":"失效"}</span>
                            //      )
                            //    }
                            //    return text
                            //  }
                        }
                    }) : '';
                    let filterArr = arr.filter(function (item) { return item.display === 'Y' });
                    this.setState({
                        localeProvider: this.state.userData.language == 'EN' ? res.result.language.EN : res.result.language.CN,
                         colcolumnsLeftTab: filterArr, 
                         widthTotalHos: res.totalWidth 
                        },()=>{
                            // console.log("localeProvider",this.state.localeProvider)
                        })
                    // console.log("res.totalWidth",res.totalWidth)
                }
            }
        })
    }
    // 获取主列表columns---医院列表
    getMainTableColumnsHos = () => {
        let data = {
            params: [{
                compontName: "ResourceTypeHospitalList",
                reactCode: ['ResourceTypeHospitalList'],
                type: 'C',
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map(item => {
                        return {
                            align: item.align,
                            widthNum: parseInt(item.width),
                            width: item.width,
                            dataIndex: item.dataIndex,
                            title: <div onDoubleClick={() => this.columnRefHos.onOpenModel()}>{this.state.userData.language == 'EN' ? item.descripts:item.title}</div>,
                            display: item.display,
                            key: item.seqNo,
                            // render: (text, record) => {
                            //    if (item.code == "status") {
                            //      return (
                            //      <span>{record.status=="Y"?"生效":"失效"}</span>
                            //      )
                            //    }
                            //    return text
                            //  }
                        }
                    }) : '';
                    let filterArr = arr.filter(function (item) { return item.display === 'Y' });
                    let seqArr = {
                        align: "center",
                        widthNum: 140,
                        width: "50px",
                        code: "edit",
                        dataIndex: "edit",
                        title: this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocOperating?this.setMessage('ResTypeLinkLocOperating', 'descripts'):"操作",
                        display: "Y",
                        render: (value, row, index) => {
                            return (
                                <span>
                                    {/* <Divider type="vertical" /> */}
                                    <Popconfirm title={this.state.localeProvider&&
                                    this.state.localeProvider.ResTypeLinkLocWhetherToDelete?
                                        this.setMessage('ResTypeLinkLocWhetherToDelete', 'descripts'):
                                        "是否要删除"}
                                         onConfirm={(e) => this.toggleEditableHos(e,row)}
                                         >
                                        <a style={{ color: "red" }} >{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDelete?this.setMessage('ResTypeLinkLocDelete', 'descripts'):"删除"}</a>
                                    </Popconfirm>
                                </span>
                            )
                        },
                    }
                    filterArr.push(seqArr)
                    this.setState({ columnsHos: filterArr, widthTotalHos: res.totalWidth })
                    // console.log("res.totalWidth",res.totalWidth)
                }
            }
        })
    }
    //查询资源类型列表
    getFindListDate = (e) => {
        let { page, pageSize, } = this.state;
        let data = {
            params: [{
                Input: this.props.form.getFieldValue("searchType") || "",
                Status: this.props.form.getFieldValue("status") || "ALL",
            }],
            pagination: [{
                pageSize: pageSize,
                currentPage: page,
            }]
        }
        $http.post('urlS', this, {
            code: '01040149',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        search: e,
                        sourceListData: res.result.data,
                        total: res.result.TotalCount,
                    },()=>{
                    })
                }
            }
        })
    }
    //查询btn---资源类型列表
    findData = () => {
        this.props.form.setFieldsValue({code:undefined,descripts:undefined,dateFrom:undefined,dateTo:undefined})
        this.setState({
            page: 1,
            pageSize: this.state.pageSize,
            search: "search",
            rowIds: "",
            info: {},
        }, () => {
            this.handAllClear()
            this.getFindListDate()
        })
    }
    //获取医院列表
    getToHos = (id) => {
        const { pageSizeHos, pageHos } = this.state
        let data = {}
        data = {
            params: [{
                Id: id,
                groupID:sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID : "",
                logonHospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
            }],
            pagination: [{
                pageSize: pageSizeHos,
                currentPage: pageHos,
            }]
        }
        $http.post('urlS', this, {
            code: '01040150',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        sourceHosData: res.result.data,
                        totalHos: res.result.TotalCount,
                        rowIdHos: res.result.data&&res.result.data.length>0?res.result.data[0].Id:"",
                    },()=>{
                        if(res.result.data&&res.result.data.length>0){
                            this.getAuthorizationList(res.result.data&&res.result.data[0].Id)
                            this.getOtherLoc(res.result.data&&res.result.data[0].Id)
                        }
                       
                    })
                }
            }
        })
    }
    handleRest = () => {
        this.props.form.setFieldsValue({ code: undefined, descripts: undefined, dateFrom: undefined, dateTo: undefined });
    }

    // 修改page和pageSize 跳转至---
    onChange = (e, pageSize) => {
        this.setState({ page: e, pageSize: this.state.pageSize }, () => {
            // 重新调用查询方法
            let { values } = this.state;
            this.getFindDate(values);
        })
    }
    //下拉选择页数
    onShowSizeChange = (page, pageSize) => {
        this.setState({ page: 1, pageSize: pageSize }, () => {
            // 重新调用查询方法
            this.getFindListDate()
        })
    }
    // 显示分页总条数
    showTotalHos(total) {
        return `共 ${total} 条`;
    }
    // 修改page和pageSize 跳转至---
    onChangeHos = (e, pageSize) => {
        this.setState({ page: e, pageSize: this.state.pageSizeHos }, () => {
            // 重新调用查询方法
            this.getToHos(this.state.rowIds)
        })
    }
    //下拉选择页数
    onShowSizeChangeHos = (page, pageSize) => {
        this.setState({ page: 1, pageSize: pageSize, searchHos: "search" }, () => {
            // 重新调用查询方法
            this.getToHos(this.state.rowIds)
        })
    }
    // 显示分页总条数
    showTotal(total) {
        return `共 ${total} 条`;
    }
    setRowClassNames = (record) => {
        return record.id === this.state.rowIds ? 'clickRowStyle' : '';
    }
    //点击Row----资源类型列表
    onClickRow = (record) => {
        return {
            onClick: () => {
                if (this.state.rowIds === "") {
                    this.setState({
                        rowIds: record.id,
                        info: record,
                    });
                    this.getToHos(record.id)
                    this.handleSet(record)
                } else {
                    if (this.state.rowIds !== record.id) {
                        this.setState({
                            rowIds: record.id,
                            info: record,
                        });
                        this.getToHos(record.id)
                        this.handRightClear()
                        this.handleSet(record)
                    } else {
                        this.setState({
                            rowIds: "",
                            info: {},
                        },()=>{
                            this.handleRest()
                            this.handAllClear()
                        });
                        
                    }
                }
            },
        };
    }
    handleCancel = () => {
            this.setState({
                rowIds:""
            },()=>{
                this.handAllClear()
                this.handleRest()
            })
          
    }
    handleSet=(info)=>{
        this.props.form.setFieldsValue({
            code:info.code,
            descripts:info.descripts,
            dateFrom:moment(info.startDate, "YYYY-MM-DD"),
            dateTo:info.stopDate&&info.stopDate?moment(info.stopDate, "YYYY-MM-DD"):undefined,
        })
    }
    handAllClear=()=>{
        this.setState({
            info:{},
        })
        this.handRightClear()
    }
    handRightClear=()=>{
        this.props.form.setFieldsValue({hos:undefined,})
        this.setState({
            sourceHosData:[],
        })
        this.handBottomClear()
    }
    handBottomClear=()=>{
        this.props.form.setFieldsValue({searchRightLoc:undefined,LocDr:undefined,searchLoc:undefined})
        this.setState({
            rowIdHos:"",
            leftLocData:[],
            rightLocData:[],
            rowSelection_right:[],
            rowSelection:[],
            selectedRows:[], 
            selectedRowKeys:[],
            selectedRow_right:[], 
            selectedRowKeys_right:[],
        })
    }
    handleOk = () => {
        this.props.form.validateFields((err, values) => {
            let data = {}
            data = {
                params: [{
                    updateUserID: JSON.parse(sessionStorage.userData).userID || '',
                    descripts: values.descripts || "",
                    code: values.code || "",
                    id: this.state.rowIds,
                    startDate: values.dateFrom ? moment(values.dateFrom).format('YYYY-MM-DD') : "",//生效日期
                    stopDate: values.dateTo ? moment(values.dateTo).format('YYYY-MM-DD') : "",//失效日期
                }],
            }
            $http.post('urlS', this, {
                code: '01040151',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        if (this.state.rowIds) {
                            message.success(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocEditedSuccessfully?this.setMessage('ResTypeLinkLocEditedSuccessfully', 'descripts'):"编辑成功");
                            this.getFindListDate()
                        } else {
                            message.success(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocAddedsSuccessfully?this.setMessage('ResTypeLinkLocAddedsSuccessfully', 'descripts'):"添加成功");
                            let lastPage = Math.ceil((this.state.total + 1) / this.state.pageSize)
                            this.setState({
                                page: lastPage,
                            }, () => {
                                this.handleCancel()
                                this.getFindListDate()
                            })
                        }

                    }
                }
            })
        })

    }
    //删除资源类型
    toggleEditable = (e,row) => {
        e.stopPropagation()
        let data = {}
        data = {
            params: [{
                updateUserID: JSON.parse(sessionStorage.userData).userID || '',
                ID: row.id,
            }],
        }
        $http.post('urlS', this, {
            code: '01040148',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    message.success(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSuccessfullyDeleted?this.setMessage('ResTypeLinkLocSuccessfullyDeleted', 'descripts'):"删除成功");
                    this.handleCancel()
                    this.getFindListDate()
                }
            }
        })
    }
    //加入医院
    addHos = () => {
        if (this.props.form.getFieldValue("hos") && this.props.form.getFieldValue("hos")) {
            let data = {}
            data = {
                params: [{
                    updateUserID: JSON.parse(sessionStorage.userData).userID || '',
                    hospId: this.props.form.getFieldValue("hos") || '',
                    ResTypeId: this.state.rowIds || "",
                }],
            }
            $http.post('urlS', this, {
                code: '01040152',
                data: data,
                success: function (res) {
                    if (+res.errorCode === 0) {
                        message.success(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocJoinedSuccessfully?this.setMessage('ResTypeLinkLocJoinedSuccessfully', 'descripts'):"加入成功");
                        this.props.form.setFieldsValue({ hos: undefined })
                        this.getToHos(this.state.rowIds)
                    }
                }
            })
        } else {
            message.warning(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocPleaseHospital?this.setMessage('ResTypeLinkLocPleaseHospital', 'descripts'):"请选择医院")
        }
    }
    setRowClassNamesHos = (record) => {
        return record.Id === this.state.rowIdHos ? 'clickRowStyle' : '';
    }
    //点击Row----医院列表
    onClickRowHos = (record) => {
        return {
            onClick: () => {
                if (this.state.rowIdHos === "") {
                    this.setState({
                        rowIdHos: record.Id,
                    });
                    // this.handleBaseHosp(record.Id)
                    this.getAuthorizationList(record.Id)
                    this.getOtherLoc(record.Id)
                } else {
                    if (this.state.rowIdHos !== record.Id) {
                        this.setState({
                            rowIdHos: record.Id,
                        });
                        // this.handleBaseHosp(record.Id)
                        this.getAuthorizationList(record.Id)
                        this.getOtherLoc(record.Id)
                    } else {
                        this.setState({
                            rowIdHos: "",
                        });
                        this.handBottomClear()
                    }
                }
            },
        };
    }
    //删除医院
    toggleEditableHos = (e,record) => {
        e.stopPropagation()
        let data = {}
        data = {
            params: [{
                updateUserID: JSON.parse(sessionStorage.userData).userID || '',
                // ResTypeId:this.state.rowIds,
                ID: record.Id,
            }],
        }
        $http.post('urlS', this, {
            code: '01040147',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    message.success(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSuccessfullyDeleted?this.setMessage('ResTypeLinkLocSuccessfullyDeleted', 'descripts'):"删除成功");
                    this.getToHos(this.state.rowIds)
                    this.setState({
                        rowIdHos: "",
                        rightLocData:[]
                    },()=>{
                        this.handBottomClear()
                    })   
                }
            }
        })
    }
    //医院选择带出科室
    handleBaseHosp = (id) => {
        this.props.form.setFieldsValue({ LocDr: undefined })
        if (id) {
            this.setState({
                hosID: id
            }, () => {
                this.getPublicBaseLocSelect()
            })
        } else {
            this.setState({
                hosID: "",
                publicBaseLocArr: []
            }, () => {
                this.getPublicBaseLocSelect()
            })
        }
    }
    //获取科室下拉框
    getPublicBaseLocSelect = () => {
        let data = {}
        data = {
            params: [{
                hospID: this.state.hosID || "",
                locTypeID: this.state.LocDr || ""
            }],
        }
        $http.post('urlS', this, {
            code: '01050029',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.result.Data) {
                    let arr = res.result.Data && res.result.Data.map((item, index) => {
                        res.result.Data[index].key = Number(index)
                    })
                    this.setState({
                        publicBaseLocArr: res.result.Data,
                    })
                } else {

                }
            }
        })
    }
    handelAdd = () => {
        if (this.state.selectedRows.length > 0) {
                let data = {
                    params: [{
                        updateUserID: JSON.parse(sessionStorage.userData).userID || '',
                        ID: "",
                        resTypeHospId: this.state.rowIdHos,
                        locId: this.state.selectedRowKeys,
                        createDate: moment().format('YYYY-MM-DD') || undefined,//创建日期
                        startDate: moment().format('YYYY-MM-DD') || undefined,//开始日期
                        stopDate: undefined,
                    }]
                }
                // this.state.selectedRows.map((item) => {
                //     return data.params[0].MenuDetail.push({
                //         MenuDetailDr: item.id,
                //         SeqNo: '',
                //         LocDr: '',
                //         PreMenuGroupDr: this.state.selectrow,
                //         UpdateUserDr: user.userID
                //     });
                // })
                $http.post('urlS', this, {
                    code: "01040145",
                    data: data,
                    success: (res) => {
                        if (+res.errorCode === 0) {
                            message.success(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocAddedSuccessfully?this.setMessage('ResTypeLinkLocAddedSuccessfully', 'descripts'):"新增成功");
                            this.getAuthorizationList(this.state.rowIdHos);
                            this.getOtherLoc(this.state.rowIdHos)
                            this.setState({ selectedRowKeys: [], selectedRowKeys_right: [], selectrow: '', selectedRows: '' });
                        }
                    },
                    error: (error) => {
                        message.error(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocAddFailed?this.setMessage('ResTypeLinkLocAddFailed', 'descripts'):"新增失败" + error);
                    }
                })
        } else {
            message.error(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocPleaseCheck?this.setMessage('ResTypeLinkLocPleaseCheck', 'descripts'):"请勾选后再点击增加");
        }
    }
    // mapDataToKey = arr => {
    //     const that = this
    //     return arr.map(item => {
    //         if (item.children && item.children.length > 0) {
    //             that.mapDataToKey(item.children)
    //         }
    //         return { ...item, key: item.ID }
    //     })
    // }
     //查询科室列表
    getOtherLoc=(id)=>{
        let data = {
            params: [{
                resTypeHospId: id,
                input: this.props.form.getFieldValue("searchLoc"),
                locTypeId:this.props.form.getFieldValue("LocDr")
            }]
        }

        $http.post('urlS', this, {
            code: "01040153",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    res.result.data.map((item, index) => {
                        res.result.data[index].key = index;
                        return res.result.data;
                    })
                    this.setState({
                        // rightLocData: this.mapDataToKey(res.result.data),
                        leftLocData: res.result.data,
                        //  total: res.result.TotalCount,
                        // rightTabLoading: false
                    })
                }
            }

        })
    }
    //查询已选科室
    getAuthorizationList = (hosId, input) => {
        let data = {
            params: [{
                resTypeHospId: hosId,
                input: this.props.form.getFieldValue("searchRightLoc"),
            }]
        }

        $http.post('urlS', this, {
            code: "01040144",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    res.result.data.map((item, index) => {
                        res.result.data[index].key = index;
                        return res.result.data;
                    })
                    this.setState({
                        // rightLocData: this.mapDataToKey(res.result.data),
                        rightLocData:res.result.data,
                        // data: res.result.Data,
                        //  total: res.result.TotalCount,
                        // rightTabLoading: false
                    })
                }
            }

        })
    }
    findLeftLocData = () => {
        this.getOtherLoc(this.state.rowIdHos)
    }
    findRightLocData=()=>{
        this.getAuthorizationList(this.state.rowIdHos)
    }
    //批量删除
    moreDel = () => {
        let data = {
            params: [{
                ID: this.state.selectedRowKeys_right,
                updateUserID: JSON.parse(sessionStorage.userData).userID || '',
            }]
        }
        $http.post('urlS', this, {
            code: "01040146",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                   message.success(this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSuccessfullyDeleted?this.setMessage('ResTypeLinkLocSuccessfullyDeleted', 'descripts'):"删除成功")
                   this.getAuthorizationList(this.state.rowIdHos)
                   this.getOtherLoc(this.state.rowIdHos)
                   this.setState({
                    selectedRowKeys_right:[]
                   })
                }
            }
        })
    }
     //国际化
     setMessage(name, message) {
        return this.state.localeProvider ? this.state.localeProvider[name][message] : ''
      }
      handleMousedowns=(e,Id)=>{
        //   console.log("e",e)
        this.onBoardRefChild.showCheckBoard(e)
        let dom = document.getElementById(Id)
        this.onBoardRefChild.setCaret(dom)
      }
      onBoardRef = (refs) => {
        this.onBoardRefChild = refs
    }

    onDurRef = (refs) => {
        this.onDurRefChild = refs
    }

    onQtyRef = (refs) => {
        this.onQtyRefChild = refs
    }
      //input框值改变赋值
      handleChange=(e)=>{
        this.setState({
            InputValue:e.target.value
        })
      }
      setValue=(v,Id)=>{
          this.props.form.setFieldsValue({
              [Id]:v
            })
      }
    render() {
        let { getFieldDecorator } = this.props.form;
        const { info, hosData, columns, columnsHos, colcolumnsLeftTab } = this.state
        var date = new Date();
        let statusData = [
            {
                descriptsSPCode: "QB",
                descripts: "全部",
                id: "ALL",
                descriptsEN:"All"
            }, {
                descriptsSPCode: "SX",
                descripts: "生效",
                id: "Y",
                descriptsEN:"Take effect"
            }, {
                descriptsSPCode: "SX",
                descripts: "失效",
                id: "N",
                descriptsEN:"Invalid"
            },
        ]
        //状态
        let statusOp = [];
        statusData && statusData.map((item, index) => {
            statusOp.push(<Option key={index} code={item.descriptsSPCode} value={item.id} title={item.descripts + '^' + item.id}>{this.state.userData.language == 'EN' ? item.descriptsEN : item.descripts}</Option>)
        })
        //医院
        let hosOp = [];
        hosData && hosData.map((item, index) => {
            hosOp.push(<Option key={index} onClick={(e, ) => this.handleBaseHosp(item.id)} code={item.descriptsSPCode} value={item.id} title={item.descripts + '^' + item.descriptsSPCode}>{item.descripts}</Option>)
        })
        //科室
        let locOp = []
        this.state.publicBaseLocArr && this.state.publicBaseLocArr.map(item => {
            locOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
        })
        //科室类型
        let locTypeOp = []
        this.state.locTypeData && this.state.locTypeData.map(item => {
            locTypeOp.push(<Option key={item.id} role={item.descripts + '^' + item.descriptsSPCode} title={item.descripts} value={String(item.id)}>{item.descripts}</Option>)
        })
        const { selectedRowKeys, selectedRow_right } = this.state
        const rowSelection = {
            selectedRowKeys,
            onChange: (selectedRowKeys, selectedRows) => {
                // console.log("selectedRowKeys",selectedRowKeys)
                this.setState({ selectedRows, selectedRowKeys });
            },
            onSelect: (record, selected, selectedRows) => {
                this.setState({ selectedRows });
            },
            onSelectAll: (selected, selectedRows, changeRows) => {
                this.setState({ selectedRows });
            }
        };
        const rowSelection_right = {
            selectedRowKeys: this.state.selectedRowKeys_right,
            onChange: (selectedRowKeys, selectedRows) => {
                let btnStatus = 'active';
                let selectrow = "";
                if (selectedRowKeys.length === 0) {
                    btnStatus = 'default';
                } else {
                    selectrow = selectedRowKeys[selectedRowKeys.length - 1];
                }
                this.setState({ btnStatus: btnStatus, selectrow: selectrow, selectedRow_right: selectedRows, selectedRowKeys_right: selectedRowKeys });
            },
            onSelectAll: (selected, selectedRows, changeRows) => {
                if (selectedRows.length > 0) {
                    this.setState({
                        btnStatus: 'active'
                    })
                } else {
                    this.setState({
                        btnStatus: 'default'
                    })
                }
                this.setState({ selectedRow_right: selectedRows });
            }
        };
        const numberStyle= {
            width: "60px",
            height: "60px",
            display: "inline-block",
            textAlign: "center",
            lineHeight: "60px",
            borderRadius: "4px",
            background: "#7d7876",
            color: "#ffffff",
            fontSize: "30px",
        }
      
        return (
            <div className='sourceDom'>
                <Row>
                    <Col span={8}>
                        <Card style={{position:"relative"}} title={this.state.rowIds && this.state.rowIds ? this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocEditResourceTypes?this.setMessage('ResTypeLinkLocEditResourceTypes', 'descripts'):"编辑资源类型" : this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocAddResourceTypes?this.setMessage('ResTypeLinkLocAddResourceTypes', 'descripts'):"添加资源类型"} > 
                        <Divider className="leftLine" type="vertical"></Divider>
                            <Form>
                                <Row gutter={12} style={{ paddingLeft: "52px" }}>
                                    <Col span={24} style={{paddingRight: "0px",}} >
                                        <FormItem label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSourceCode?this.setMessage('ResTypeLinkLocSourceCode', 'descripts'):"资源代码"} {...formItemLayout}>
                                            {getFieldDecorator('code', {
                                                initialValue: info && info.code ? info.code : undefined,
                                                rules: [{ required: true, message: this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSourceCode?this.setMessage('ResTypeLinkLocSourceCode', 'message'):"请输入资源代码"}],
                                            })(
                                                   <Input  /> 
                                            )}
                                        </FormItem>
                                        {/* onClick={(e)=>this.handleMousedowns(e,"code")} */}
                                        {/* <DigitalKeyboard integer={true} ref={this.onBoardRef} setValue={this.setValue}></DigitalKeyboard> */}
                                    </Col>
                                    <Col span={24} style={{paddingRight: "0px",position:"relative"}}>
                                        <FormItem label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocResourceName?this.setMessage('ResTypeLinkLocResourceName', 'descripts'):"资源名称"} {...formItemLayout}>
                                            {getFieldDecorator('descripts', {
                                                initialValue: info && info.descripts ? info.descripts : undefined,
                                                rules: [{ required: true, message: this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocResourceName?this.setMessage('ResTypeLinkLocResourceName', 'message'):"请输入资源名称"}],
                                            })(
                                                <Input />
                                            )}
                                        </FormItem>
                                        {/* onClick={(e)=>this.handleMousedowns(e,"descripts")} */}
                                        {/* <DigitalKeyboard  ref={this.onBoardRef} setValue={this.setValue}></DigitalKeyboard> */}
                                    </Col>
                                    <Col span={24} style={paddRightCol}>
                                        <FormItem label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocStartDate?this.setMessage('ResTypeLinkLocStartDate', 'descripts'):"生效日期"} {...formItemLayout}>
                                            {getFieldDecorator('dateFrom', {
                                                initialValue: info && info.startDate ? moment(info.startDate, "YYYY-MM-DD") : moment(),
                                                rules: [{ required: true, message: this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocStartDate?this.setMessage('ResTypeLinkLocStartDate', 'message'):"请选择生效日期"}],
                                            })(
                                                <DatePicker style={{ width: '100%' }} disabledDate={(curDate) => {
                                                    return curDate && curDate > moment().endOf('day');
                                                }} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={24} style={paddRightCol}>
                                        <FormItem label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocStopDate?this.setMessage('ResTypeLinkLocStopDate', 'descripts'):"失效日期"} {...formItemLayout}>
                                            {getFieldDecorator('dateTo', {
                                                initialValue: info && info.stopDate ? moment(info.stopDate, "YYYY-MM-DD") : undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <DatePicker style={{ width: '100%' }} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={24} style={{ textAlign: "center", }}>
                                        <Button key="submitc" type="primary" style={{ marginRight: "10px" }} onClick={this.handleCancel}>
                                        {this.state.rowIds && this.state.rowIds ? this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocCanel?this.setMessage('ResTypeLinkLocCanel', 'descripts'):"取消" : this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocEmpty?this.setMessage('ResTypeLinkLocEmpty', 'descripts'):"清空"}
                                        </Button>
                                        <Button key="submits" type="primary" disabled={this.state.canSave} onClick={this.handleOk}>{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSave?this.setMessage('ResTypeLinkLocSave', 'descripts'):"保存"}</Button>
                                    </Col>
                                </Row>
                            </Form>
                        </Card>
                       {/* <span style={{color:"red"}}></span> */}
                        <Card style={{position:"relative"}} title={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocListOfResourceTypes?this.setMessage('ResTypeLinkLocListOfResourceTypes', 'descripts'):"资源类型列表"} className="joinDom">
                        <Divider className="leftLine" type="vertical"></Divider>
                            <Form>
                                <Row>
                                    <Col span={11} style={paddRightCol}>
                                        <FormItem {...formItemLayoutTT} label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocResourceTypes?this.setMessage('ResTypeLinkLocResourceTypes', 'descripts'):"资源类型"}>
                                            {getFieldDecorator('searchType', {
                                                initialValue: undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Input  placeholder={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDescriptionCode?this.setMessage('ResTypeLinkLocDescriptionCode', 'descripts'):"描述/代码回车搜索"} onPressEnter={this.findData}></Input>
                                            )} 
                                        </FormItem>
                                        {/* <DigitalKeyboard  ref={this.onBoardRef} setValue={this.setValue}></DigitalKeyboard> */}
                                    </Col>
                                    <Col span={9} style={paddRightCol}>
                                        <FormItem {...formItemLayoutSearch} label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocState?this.setMessage('ResTypeLinkLocState', 'descripts'):"状态"}>
                                            {getFieldDecorator('status', {
                                                initialValue: "ALL",
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Select
                                                    allowClear
                                                >
                                                    {statusOp}
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={2} style={{ paddingLeft: "10px", paddingRight: "0px", width: "5%" }}>
                                        <FormItem  {...formItemLayout}>
                                            {getFieldDecorator('searchBtn', {
                                                initialValue: undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Button onClick={this.findData} style={{ background: 'rgba(66,185,131,1)', color: '#fff' }}>{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSearch?this.setMessage('ResTypeLinkLocSearch', 'descripts'):"查询"}</Button>
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <div className="listDom joinDom">
                                    <Table
                                        // scroll={{ x: 1160, y: store.getState().tableHeight.y + 156 }}
                                        columns={columns}
                                        dataSource={this.state.sourceListData}
                                        pagination={false}
                                        rowKey={record => record.key}
                                        onRow={this.onClickRow}
                                        rowClassName={this.setRowClassNames}
                                        bordered
                                        style={{ height: store.getState().tableHeight.y - 266 + 'px', overflow: "auto" }}
                                    />
                                    <CommonPagination size={this.state.size} page={this.state.page} current={this.state.page} total={this.state.total} search={this.state.search}
                                        onShowSizeChange={this.onShowSizeChange.bind(this)} complete={true} dataSource={this.state.sourceListData}
                                        onChange={this.onChange.bind(this)} />
                                    <ColumnAuthoritysModel
                                        clientWidth='800px'
                                        compontName='ResourceTypeAssociatedHospital'
                                        configType="C"
                                        onRef={this.onColumnRef}
                                        reloadData={this.getMainTableColumns}
                                    />
                                </div>
                            </Form>
                        </Card>
                    </Col>
                    <Col span={16}>
                        <Card style={{position:"relative"}} title={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocReferToTheHospital?this.setMessage('ResTypeLinkLocReferToTheHospital', 'descripts'):"引用医院"} className="joinDom">
                        <Divider className="leftLine" type="vertical"></Divider>
                            <Form>
                                <Row>
                                    <Col span={9} style={paddRightCol}>
                                        <FormItem {...formItemLayoutSearch} label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocChooseHospital?this.setMessage('ResTypeLinkLocChooseHospital', 'descripts'):"选择医院"}>
                                            {getFieldDecorator('hos', {
                                                initialValue: undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Select
                                                    allowClear
                                                    onChange={this.handleBaseHosp}
                                                >
                                                    {hosOp}
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={2} style={{ paddingLeft: "10px", paddingRight: "0px", width: "5%" }}>
                                        <FormItem  {...formItemLayout}>
                                            {getFieldDecorator('searchBtn', {
                                                initialValue: undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Button onClick={this.addHos} disabled={!this.state.rowIds} style={{ background: 'rgba(66,185,131,1)', color: '#fff' }}>{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocJoin?this.setMessage('ResTypeLinkLocJoin', 'descripts'):"加入"}</Button>
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <div className="hosDom">
                                    <Table
                                        // scroll={{ x: 1160, y: store.getState().tableHeight.y + 156 }}
                                        columns={columnsHos}
                                        dataSource={this.state.sourceHosData}
                                        pagination={false}
                                        rowKey={record => record.key}
                                        onRow={this.onClickRowHos}
                                        rowClassName={this.setRowClassNamesHos}
                                        bordered
                                        style={{ height: store.getState().tableHeight.y - 460 + 'px' }}
                                    />
                                    <CommonPagination size={this.state.sizeHos} page={this.state.pageHos} current={this.state.pageHos} total={this.state.totalHos} search={this.state.searchHos}
                                        onShowSizeChange={this.onShowSizeChangeHos.bind(this)} complete={true} dataSource={this.state.sourceHosData}
                                        onChange={this.onChangeHos.bind(this)} />
                                </div>
                                <ColumnAuthoritysModel
                                    clientWidth='800px'
                                    compontName='ResourceTypeHospitalList'
                                    configType="C"
                                    onRef={this.onColumnRefHos}
                                    reloadData={this.getMainTableColumnsHos}
                                />

                            </Form>
                        </Card>
                        <Card style={{position:"relative"}} title={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocReferenceDepartment?this.setMessage('ResTypeLinkLocReferenceDepartment', 'descripts'):"引用科室"}>
                        <Divider className="leftLine" type="vertical"></Divider>
                            <div className={"flexBox locDom"}>
                                <div className={"leftTbale"}>
                                    <Row>
                                        <Col span={24}>
                                            <ul style={{ paddingLeft: '15px' }}>
                                                <li style={{ color: '#F7805D' }}><span style={{ color: 'green', fontSize: '16px' }}>{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocTheSectionList?this.setMessage('ResTypeLinkLocTheSectionList', 'descripts'):"科室列表"}</span></li>
                                            </ul>

                                        </Col>
                                    </Row>
                                    <Row>
                                        <Col span={12} style={paddRightCol}>
                                            <FormItem {...formItemLayoutTT} label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocTheSectionType?this.setMessage('ResTypeLinkLocTheSectionType', 'descripts'):"科室类型"}>
                                                {getFieldDecorator('LocDr', {
                                                    initialValue: undefined,
                                                    rules: [{ required: false, message: '' }],
                                                })(
                                                    <Select
                                                    allowClear
                                                    style={{width:"100%"}}
                                                    >
                                                        {locTypeOp}
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={12} style={paddRightCol}>
                                            <FormItem {...formItemLayoutLoc} label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDepartment?this.setMessage('ResTypeLinkLocDepartment', 'descripts'):"科室"}>
                                                {getFieldDecorator('searchLoc', {
                                                    initialValue: undefined,
                                                    rules: [{ required: false, message: '' }],
                                                })(
                                                    <Input   placeholder={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDescriptionCode?this.setMessage('ResTypeLinkLocDescriptionCode', 'descripts'):"描述/代码回车搜索"} onPressEnter={this.findLeftLocData}></Input>
                                                )}
                                            </FormItem>
                                            {/* <DigitalKeyboard  ref={this.onBoardRef} setValue={this.setValue}></DigitalKeyboard> */}
                                        </Col>
                                    </Row>
                                    <Row style={{textAlign:"right",marginTop:"-10px"}}>
                                    <Col span={24} style={{marginBottom:"4px",}}>
                                            <Button type="primary" onClick={this.findLeftLocData}>{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocSearch?this.setMessage('ResTypeLinkLocSearch', 'descripts'):"查询"}</Button>
                                        </Col>
                                    </Row>
                                    <Table
                                        // style={{ height: this.state.windowheight - 380 + 'px' }}
                                        bordered
                                        // loading={this.state.leftTabLoading}
                                        // components={this.components}
                                        columns={colcolumnsLeftTab}
                                        dataSource={this.state.leftLocData}
                                        rowKey={(row) => {
                                            return row.id
                                        }}
                                        pagination={false}
                                        style={{ height: store.getState().tableHeight.y - 336 + 'px', overflow: "auto" }}
                                        // scroll={{ x: 240, y: this.state.windowheight - 380 - 40 }}
                                        rowSelection={rowSelection}
                                    />
                                    <ColumnAuthoritysModel
                                        clientWidth='800px'
                                        compontName='ResTypeLinkLoc'
                                        configType="C"
                                        onRef={this.onColumnRefLoc}
                                        reloadData={this.getMainTableColumnsLoc}
                                    />
                                </div>
                                < Icon type="right-circle" style={{ fontSize: '30px', display: 'flex', alignItems: 'center' }} size="small" onClick={this.handelAdd} />
                                <div className={"rightTbale"} style={{ overflow: 'hidden', padding: "0 20px 20px 20px", margintop: '4px' }}>
                                    <Row>
                                        <Col span={24}>
                                            <ul style={{ paddingLeft: '15px' }}>
                                                <li style={{ color: '#42B983' }}><span style={{ color: 'green', margintop: '1rem', fontSize: '16px' }}>{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocListDepartmentsAdded?this.setMessage('ResTypeLinkLocListDepartmentsAdded', 'descripts'):"已添加科室列表"}</span></li>
                                            </ul>

                                        </Col>
                                    </Row>
                                    <Row>
                                        <Col span={12} style={paddRightCol}>
                                            <FormItem {...formItemLayoutLoc} label={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDepartment?this.setMessage('ResTypeLinkLocDepartment', 'descripts'):"科室"}>
                                                {getFieldDecorator('searchRightLoc', {
                                                    initialValue: undefined,
                                                    rules: [{ required: false, message: '' }],
                                                })(
                                                    <Input placeholder={this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDescriptionCode?this.setMessage('ResTypeLinkLocDescriptionCode', 'descripts'):"描述/代码回车搜索"} onPressEnter={this.findRightLocData}></Input>
                                                )}
                                            </FormItem>
                                        </Col>
                                    </Row>
                                    <Row style={{textAlign:"left",}}>
                                    <Col span={24} style={{marginBottom:"4px",marginTop:"-10px"}}>
                                            <Button disabled={this.state.selectedRowKeys_right&&this.state.selectedRowKeys_right.length==0} 
                                            style={{background: "#fff",border: "0",  color: this.state.selectedRowKeys_right&&this.state.selectedRowKeys_right.length==0?"#cfcfcf":"#40a9ff"}} 
                                            type="primary" onClick={this.moreDel} >{this.state.localeProvider&&this.state.localeProvider.ResTypeLinkLocDeleteInBatches?this.setMessage('ResTypeLinkLocDeleteInBatches', 'descripts'):"批量删除"}</Button>
                                        </Col>
                                    </Row>
                                    <Table
                                        // style={{ height: this.state.windowheight - 380 + 'px', marginTop: '1.18rem' }}
                                        columns={colcolumnsLeftTab}
                                        bordered
                                        // loading={this.state.rightTabLoading}
                                        indentSize={15}
                                        dataSource={this.state.rightLocData}
                                        rowKey={(row) => {
                                            return row.id
                                        }}
                                        rowClassName={this.setRowClassName}
                                        // onRow={this.onClickRow}
                                        pagination={false}
                                        rowSelection={rowSelection_right}
                                        style={{ height: store.getState().tableHeight.y - 336 + 'px', overflow: "auto" }}
                                    // scroll={{ x: 440, y: this.state.windowheight - 380 - 40 }}
                                    />
                                </div>
                            </div>
                        </Card>
                    </Col>
                </Row>
            </div>
        )
    }
}

export default Form.create()(SourceType);