/*
 * Creator:     HLH
 * CreatDate:   2019-1-15
 * descripts：  治疗项目评估
 * */
import React from 'react';
import { Form, Input, Select, Button, message, Switch, Row, Icon, Divider, Popconfirm, DatePicker, Table, Col, Card } from 'antd';
import { $http } from 'containers/config/https';
import moment from 'moment';
import store from 'store';
import CommonPagination from 'components/pagination';
import CureItemEvaluationDetails from './CureItemEvaluationDetails';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import '../../basicdata/style/index.less'
const FormItem = Form.Item;
const Option = Select.Option;
const paddRightCol = {
    paddingRight: "0px"
}
const formItemLayoutType = {
    labelCol: { span: 5 },
    wrapperCol: { span: 18 }
}
const formItemLayout = { // label 和input宽度
    labelCol: { span: 8 },
    wrapperCol: { span: 14 },
}
class CureltemEvaluation extends React.Component {
    constructor() {
        super();
        this.state = {
            tableData: [], // 列表数据
            total: 0,
            page: 1,
            pageSize: 10,
            size: "big",
            search: "",
            ICD: "",
            diaID: "",
            size: "small",
            search: "",
            rowIds: "",
            columns: []
        };
    }
    componentDidMount() {
        document.querySelector('.ant-table-body').style.height = store.getState().tableHeight.y + 60 + 'px';
        if (this.state.size == "small") {
            this.setState({
                pageSize: 10
            })
        } else {
            this.setState({
                pageSize: 50
            })
        }
        this.getFindDate()
        this.getMainTableColumns()
    }
    componentWillReceiveProps(nextProps) {
    } //动态表头
    onColumnRef = (ref) => {
        this.columnRef = ref;
    }
    // 获取主列表columns
    getMainTableColumns = () => {
        let data = {
            params: [{
                compontName: "MaintenanceOfTreatmentItems",
                reactCode: ['MaintenanceOfTreatmentItems'],
                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()}>{item.title}</div>,
                            display: item.display,
                            key: item.seqNo,
                        }
                    }) : '';
                    let filterArr = arr.filter(function (item) { return item.display === 'Y' });
                    this.setState({ columns: filterArr, widthTotal: res.totalWidth })
                }
            }
        })
    }
    //调子组件
    onAttRef = (ref) => {
        this.childAtt = ref
    }
    onRef = (ref) => {
        this.onChildRef = ref
    }
    ondiaRef = (ref) => {
        this.onChilddiaRef = ref
    }
    searchICD = (e) => {
        this.onChildRef.showModal(e.target.value)
    }
    changeICD = (e) => {
        if (e && e.target.value.length == 0) {
            this.setState({
                ICD: ""
            })
        }
    }
    changediaICD = (e) => {
        if (e && e.target.value.length == 0) {
            this.setState({
                diaID: ""
            })
        }
    }
    searchdiaICD = (e) => {
        this.onChilddiaRef.showModal(e.target.value)
    }
    handleParms = (data) => {
        this.setState({
            ICD: data.id,
        })
        this.props.form.setFieldsValue({ ICDID: data.descripts, })
    }
    handlediaParms = (data) => {
        this.setState({
            diaID: data.id
        })
        this.props.form.setFieldsValue({ diaICDID: data.descripts })
    }
    handleClear = () => {
        if (this.state.ICD && this.state.ICD) {
            this.setState({
            })
        } else {
            this.setState({ ICD: "" })
            this.props.form.setFieldsValue({ ICDID: undefined })
        }
    }
    handlediaClear = () => {
        if (this.state.diaID && this.state.diaID) {
            this.setState({
                // diaID,
            })
        } else {
            this.setState({ diaID: "" })
            this.props.form.setFieldsValue({ diaICDID: undefined })
        }
    }
    // 点击查询
    handleQuery = () => {
        this.props.form.validateFields((err, values) => {
            if (!err) {
                this.setState({
                    values,
                    rowIds: "",
                }, () => {
                    //详情页面内容清空
                    this.childAtt.initDeatail()
                    this.onShowSizeChange("1", this.state.pageSize)
                })
            }
        })
    }
    //查询
    getFindDate = (values, e) => {
        let { page, pageSize, diaID, ICD } = this.state;
        let data = {
            params: [{
            }],
            pagination: [{
                pageSize: pageSize,
                currentPage: page,
            }]
        }
        $http.post('urlS', this, {
            code: '01040183',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        search: e,
                        tableData: res.result.dataArr,
                        total: res.result.TotalCount,
                    })
                }
            }
        })
    }
    // 修改page和pageSize 跳转至---
    onChange = (e) => {
        this.setState({ page: e, pageSize: this.state.pageSize, }, () => {
            // 重新调用查询方法
            let { values } = this.state;
            this.getFindDate(values);
        })
    }
    //下拉选择页数
    onShowSizeChange = (page, pageSize) => {
        this.setState({ page: 1, pageSize: pageSize }, () => {
            // 重新调用查询方法
            let { values } = this.state;
            this.getFindDate(values, "search");
        })
    }
    // 显示分页总条数
    showTotal(total) {
        return `共 ${total} 条`;
    }
    //点击Row
    onClickRow = (record) => {
        return {
            onClick: () => {
                this.setState({
                    parms: record,
                })
                this.childAtt.clearInfo()
                if (this.state.rowIds === "") {
                    this.setState({
                        rowIds: record.ID,
                    })
                    this.childAtt.getInfo(record)
                } else {
                    if (this.state.rowIds !== record.ID) {
                        this.setState({
                            rowIds: record.ID,
                        });
                        this.childAtt.getInfo(record)
                        this.childAtt.restCheck()
                    } else {
                        this.setState({
                            rowIds: "",
                        });
                        this.childAtt.initDeatail()
                    }
                }
            },
        };
    }
    //点击查询后 表格行
    setRowClassNames = (record) => {
        return record.ID === this.state.rowIds ? 'clickRowStyle' : '';
    }
    render() {
        const { columns } = this.state;
        const { getFieldDecorator } = this.props.form;
        return (
            <div className="majorCategoriesDom">
                <Row>
                    <Col span={8}>
                        <Card title="治疗项目" className="titleDom">
                            <Table
                                columns={columns}
                                dataSource={this.state.tableData}
                                pagination={false}
                                rowKey={record => record.key}
                                onRow={this.onClickRow}
                                rowClassName={this.setRowClassNames}
                                bordered
                                style={{ height: store.getState().tableHeight.y + 60 + 'px', overflow: "auto" }}
                            />
                            <CommonPagination size={this.state.size} current={this.state.page} total={this.state.total} search={this.state.search}
                                onShowSizeChange={this.onShowSizeChange.bind(this)} complete={true} dataSource={this.state.tableData}
                                onChange={this.onChange.bind(this)} />
                        </Card>
                    </Col>
                    <Col span={16} style={{ marginLeft: "-1px" }}>
                        <Card title="治疗项目评估" className="titleDom">
                            <CureItemEvaluationDetails onAttRef={this.onAttRef} handleQuery={this.handleQuery}></CureItemEvaluationDetails>
                        </Card>
                    </Col>
                </Row>
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName='CureItemEvaluation'
                    configType="C"
                    onRef={this.onColumnRef}
                    reloadData={this.getMainTableColumns}
                />
            </div>
        )
    }
};
const CureltemEvaluations = Form.create()(CureltemEvaluation);
export default CureltemEvaluations;