/*
* Creator:     HLH
* CreatDate:   2019-1-15
* descripts：治疗工作站工作量统计报表
 * */
import React from 'react';
import { Card, Row, Radio, Col, Form, DatePicker, Select, Button, Input } from 'antd';
import { $http } from '../../../containers/config/https';
import Reports from '../../raqSoft/reportsEmbed';
import '../../scheduling/style/index.less';
import Moment from 'moment';
import store from 'store';
import PublicModalTable from './../../common/PublicModalTable';
const { Option } = Select;
const FormItem = Form.Item;
const formItemLayout = {    // label 和input宽度
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
};
const formItemItem = {
    labelCol: { span: 10 },
    wrapperCol: { span: 14 }
};

const WorkloadAccount = Form.create()(
    class extends React.Component {
        constructor() {
            super();
            const userInfo = sessionStorage.userData ? JSON.parse(sessionStorage.userData) : {}
            this.state = {
                selectData: {},
                userInfo: userInfo, //表单数据详情
                outPutListData: [],//输出信息列表
                pageSize: 10,
                page: 1,
                total: 0,
                language: JSON.parse(window.sessionStorage.userData),
                ChineseEnglishSize: [],
                raqName: '治疗工作站工作量统计表',
                params: {},
                stockID: '',
                hospID: '',
                session: {},
                input: ''
            };
            this.locDesc = userInfo.locDesc;
            this.typeDesc = '';
            this.modalColumns = [
                {
                    key: 1,
                    title: this.state.userInfo.language == 'EN' ? 'Hosptal' : '医院',
                    dataIndex: 'hospDesc',
                    align: "center",
                    width: '22%'
                },
                {
                    key: 2,
                    title: this.state.userInfo.language == 'EN' ? 'Departments' : '科室',
                    dataIndex: 'locDesc',
                    align: "center",
                    width: '24%',
                },
                {
                    key: 3,
                    title: this.state.userInfo.language == 'EN' ? 'doctor' : '医生',
                    dataIndex: 'docDesc',
                    align: "center",
                    width: '16%',
                },
                {
                    key: 4,
                    title: this.state.userInfo.language == 'EN' ? 'Treatment program' : '治疗项目',
                    dataIndex: 'medDesc',
                    align: "center",
                    width: '12%',
                },
                {
                    key: 5,
                    title: this.state.userInfo.language == 'EN' ? 'count' : '数量(总)',
                    dataIndex: 'cureNum',
                    align: "center",
                    width: '12%',
                },
                {
                    key: 6,
                    title: this.state.userInfo.language == 'EN' ? ' unit price' : '单价',
                    dataIndex: 'price',
                    align: "center",
                },
                {
                    key: 7,
                    title: this.state.userInfo.language == 'EN' ? ' count price' : '金额(总)',
                    dataIndex: 'curePrice',
                    align: "center",
                },
                {
                    key: 8,
                    title: this.state.userInfo.language == 'EN' ? ' count price' : '数量(已做)',
                    dataIndex: 'cureFNum',
                    align: "center",
                },
                {
                    key: 9,
                    title: this.state.userInfo.language == 'EN' ? ' count price' : '金额(已做)',
                    dataIndex: 'cureFPrice',
                    align: "center",
                }

            ]
        }
        componentDidMount() {
            // 初始化数据
            this.getHopSelect();
            this.getLocSelect();
            this.getDocSelect();
            this.getMedDescSelect();
            this.getAdmTypeSelect();
            this.searchInformation();
        }
        componentWillUnmount() {
            // 组件销毁前将静止让setState修改state的状态，防止内存泄漏
            this.setState = (state, callback) => { return; }
        }

        //清空表格内容
        resetFields = () => {
            this.props.form.resetFields();
            this.setState({ userInfo: {}, rowKey: '', rowData: '', stockID: '' });
        };
        handleReset = () => {
            this.resetFields();
        }
        //获取医院下拉框
        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({
                            hospArr: res.result
                        })
                    }
                }
            })
        }
        //获取科室下拉框
        getLocSelect = () => {
            let data = {

                params: [{
                    hospID: this.state.userInfo.hospID ? this.state.userInfo.hospID : "",
                    logonGroupID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID : "",
                    logonHospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
                }],
            }
            $http.post('urlS', this, {
                code: '01050029',
                data: data,
                success: function (res) {
                    if (res.errorCode == 0) {
                        this.setState({
                            locArr: res.result.Data
                        })
                    }
                }
            })
        }
        //获取医生下拉框
        getDocSelect = () => {
            let data = {
                params: [{
                    input: this.state.userInfo.input ? this.state.userInfo.input : '',
                    hospID: this.state.userInfo.hospID ? this.state.userInfo.hospID : "",
                    logonGroupID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID : "",
                    logonHospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
                }],
                pagination: [{
                    currentPage: 1,
                    pageSize: 100
                }],
            }
            $http.post('urlS', this, {
                code: '01040003',
                data: data,
                success: function (res) {
                    if (res.errorCode == 0) {
                        this.setState({
                            docArr: res.Data
                        })
                    }
                }
            })
        }

        //获取就诊类型下拉框
        getAdmTypeSelect = () => {
            let data = {
                params: [{
                }],
                session: [{
                    language: this.state.userInfo.language ? this.state.userInfo.language : 'CN',
                }],
            }
            $http.post('urlS', this, {
                code: '03050088',
                data: data,
                success: function (res) {
                    if (res.errorCode == 0) {
                        this.setState({
                            admTypeArr: res.result.Data
                        })
                    }
                }
            })
        }

        //获取治疗项目下拉框
        getMedDescSelect = () => {
            let data = {
                params: [{
                    hospID: this.state.userInfo.hospID ? this.state.userInfo.hospID : "",
                    logonGroupID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).groupID : "",
                    logonHospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
                }],
            }
            $http.post('urlS', this, {
                code: '01040183',
                data: data,
                success: function (res) {
                    if (res.errorCode == 0) {
                        this.setState({
                            medArr: res.result.dataArr
                        })
                    }
                }
            })
        }
        // 根据表单获取列表数据
        searchInformation = () => {
            this.props.form.validateFields((err, values) => {
                if (err) {
                    return;
                }
                const params = {
                    locID: values.locID ? values.locID : '',
                    hospID: values.hospID ? values.hospID : '',
                    dateFrom: values.dateFrom ? Moment(values.dateFrom).format("YYYY-MM-DD") : undefined,
                    dateTo: values.dateTo ? Moment(values.dateTo).format("YYYY-MM-DD") : '',
                    admTypeID: values.admTypeID ? values.admTypeID : "",
                    doctorID: values.doctorID ? values.doctorID : "",
                    medID: values.medID ? values.medID : "",
                }
                const raqName = values.reportType ? values.reportType : this.state.raqName;
                this.setState({ params: params, raqName: raqName });
            })
        };
        onRef = (ref) => {
            this.child = ref;
        };
        // 当描述失去焦点的时候
        stastockDescOnBlure = (e) => {
            if (this.state.ModalRowData && (e.target.value !== this.state.ModalRowData.stockDesc)) {
                this.props.form.setFieldsValue({ stockDesc: undefined });
            }
        };

        // 操作弹框
        onClickRowPublic = (record) => {
            return {
                onDoubleClick: () => {
                    this.confirmSelection(record);
                }
            }
        };
        // 双击选中行数据的回调
        confirmSelection = (record) => {
            // this.resetFields();
            this.setState({ ModalRowData: record }, () => {
                this.setState({ stockID: record.stockID });
                this.props.form.setFieldsValue({ stockDesc: record.stockDesc });
                // 关闭弹窗
                this.child.handleCancel();
            })
        };

        onchangeStock = (val) => {
            if (!val.target.value) {
                this.setState({ stockID: '' });
            }
        };
        render() {
            const { getFieldDecorator } = this.props.form;
            const { userInfo, params, ChineseEnglishSize, selectData } = this.state;
            let param = {
                width: '600px',
                top: this.state.top,
                left: this.state.left,
                columns: this.modalColumns,
                data: this.state.modalData,
                isOnRow: true,
                TableClassName: 'tab-placeholder',
            };
            //医院
            let hosOp = []
            this.state.hospArr && this.state.hospArr.map((item) => {
                hosOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
            })
            //科室
            let locOp = []
            this.state.locArr && this.state.locArr.map((item) => {
                locOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
            })
            //医生
            let docOp = []
            this.state.docArr && this.state.docArr.map((item) => {
                docOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
            })
            //就诊类型
            let admTypeOp = []
            this.state.admTypeArr && this.state.admTypeArr.map((item) => {
                admTypeOp.push(<Option key={item.admTypeID} value={String(item.admTypeID)}>{item.admDesc}</Option>)
            })
            //治疗项目
            let medItemOp = []
            this.state.medArr && this.state.medArr.map((item) => {
                medItemOp.push(<Option key={item.ID} value={String(item.ID)}>{item.descripts}</Option>)
            })
            return (
                <div className="WorkloadAccount">
                    <Row>
                        <Col span={5}>
                            <Row>
                                <Card
                                    size="small"
                                    title={<div className="card-title-left-icon"><div></div>按钮操作</div>}
                                >
                                    <Col >
                                        <Row >
                                            <Col style={{ textAlign: 'center' }} >
                                                <Button onClick={this.searchInformation}>查询</Button>
                                                <Button type="primary" onClick={this.handleReset} style={{ marginLeft: '20px' }}>清屏</Button>
                                            </Col>
                                        </Row>
                                    </Col>
                                </Card>
                            </Row>
                            <Row>
                                <Form >
                                    <Card
                                        title={<div className="card-title-left-icon"><div></div>查询条件</div>}
                                        size="small"
                                        className='checkAll'
                                    >
                                        <section className="ant-form-list">
                                            <div className='scrollbar' style={{ height: store.getState().tableHeight.y + 83 + 'px' }}>
                                                <Row >
                                                    <Col >
                                                        <FormItem label="医院" {...formItemItem} >
                                                            {getFieldDecorator('hospID', {
                                                                initialValue: userInfo && userInfo.hospID ? userInfo.hospID : "",
                                                                rules: [
                                                                    {
                                                                        required: true,
                                                                        message: '请选择医院',
                                                                    }
                                                                ],
                                                            })(
                                                                <Select
                                                                    placeholder="请选择"

                                                                    onSelect={this.handleStatus}
                                                                >
                                                                    {hosOp}
                                                                </Select>
                                                            )}
                                                        </FormItem>
                                                    </Col>
                                                    <Col >
                                                        <FormItem label="科室" {...formItemItem}>
                                                            {getFieldDecorator('locID', {

                                                                rules: [
                                                                    {
                                                                        required: false,
                                                                    }
                                                                ],
                                                            })(
                                                                <Select
                                                                    placeholder="请选择"
                                                                    onSelect={this.handleStatus}
                                                                >
                                                                    {locOp}
                                                                </Select>
                                                            )}
                                                        </FormItem>
                                                    </Col>
                                                    <Col >
                                                        <FormItem label="医生" {...formItemItem}>
                                                            {getFieldDecorator('doctorID', {
                                                                initialValue: userInfo.doctorID ? userInfo.doctorID : "",
                                                                rules: [
                                                                    {
                                                                        required: false,
                                                                    }
                                                                ],
                                                            })(
                                                                <Select
                                                                    placeholder="请选择"
                                                                    onSelect={this.handleStatus}
                                                                >
                                                                    {docOp}
                                                                </Select>
                                                            )}
                                                        </FormItem>
                                                    </Col>
                                                    <Col span={24}>
                                                        <FormItem label="日期从" {...formItemItem}>
                                                            {getFieldDecorator('dateFrom', {
                                                                initialValue: Moment(new Date()),
                                                                rules: [{ required: true, message: '请选择生效日期' }]
                                                            })(
                                                                <DatePicker
                                                                    format="YYYY-MM-DD"
                                                                    style={{ width: '100%' }}
                                                                >
                                                                </DatePicker>
                                                            )}
                                                        </FormItem>
                                                    </Col>
                                                    <Col span={24}>
                                                        <FormItem label="日期到" {...formItemItem}>
                                                            {getFieldDecorator('dateTo', {
                                                                initialValue: undefined,
                                                                rules: [{ required: false }]
                                                            })(
                                                                <DatePicker
                                                                    format="YYYY-MM-DD"
                                                                    style={{ width: '100%' }}
                                                                >
                                                                </DatePicker>
                                                            )}
                                                        </FormItem>
                                                    </Col>
                                                    <Col span={24}>
                                                        <FormItem label="治疗项目" {...formItemItem}>
                                                            {getFieldDecorator('medID', {
                                                                initialValue: userInfo.medID ? userInfo.medID : "",
                                                                rules: [{ required: false, message: '请选择' }]
                                                            })(
                                                                <Select
                                                                    placeholder="请选择"
                                                                    onSelect={this.handleStatus}
                                                                >
                                                                    {medItemOp}
                                                                </Select>
                                                            )}
                                                        </FormItem>
                                                    </Col>
                                                    <Col span={24}>
                                                        <FormItem label="就诊类型" {...formItemItem}>
                                                            {getFieldDecorator('admTypeID', {
                                                                initialValue: userInfo.admTypeID ? userInfo.admTypeID : "",
                                                                rules: [{ required: false, message: '请选择' }]
                                                            })(
                                                                <Select
                                                                    placeholder="请选择"
                                                                    onSelect={this.handleStatus}
                                                                >
                                                                    {admTypeOp}
                                                                </Select>
                                                            )}
                                                        </FormItem>
                                                    </Col>
                                                </Row>
                                            </div>
                                        </section>
                                    </Card>
                                </Form>
                            </Row>
                        </Col>
                        <Col span={19}>
                            <div style={{ height: store.getState().tableHeight.y + 200 + 'px' }}>
                                <Reports
                                    raqName={this.state.raqName}
                                    params={this.state.params}
                                />
                            </div>
                        </Col >
                    </Row>
                    <PublicModalTable param={param} onRef={this.onRef} />
                </div>
            )
        }
    }
);
export default WorkloadAccount;