// 住院预交金

import React from 'react';
import { Select, Input, Row, Col, Button, Spin, Divider, Popconfirm, message, Icon, Form, DatePicker, Table, Tabs, Modal, Card, Pagination, Popover, Switch } from 'antd';
import { $http } from 'containers/config/https';
// import Moment from 'moment';
// import { Keup, ArraySome } from '../../../tools/index';
// import PubilcTablePagination from '../../common/PubilcTablePagination.jsx'; // 公共table组件
// import DatePickerFormat from '../../../components/datePicker/DatePickerFormat';
import TipHeader from './component/TipHeader'
import './style/style.less'
// import store from '../../../store';
import CommonPagination from 'components/pagination/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import store from 'store';

// 组件const
const { Option } = Select;
// const { RangePicker } = DatePicker;
const dateFormat = 'YYYY-MM-DD' || undefined;
// const { Search } = Input;

export default class AccDeposit extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            userInfo: {}, // 用户数据
            dataTableTop: [], // table数据 上列表table
            dataTable1: [], // table数据 主列表table
            dataTable2: [], // table数据 折扣记账系数配置列表
            dataTable3: [], // table数据 不属于折扣内明细
            selectListData1: [],
            selectListData2: [],
            selectListData3: [],
            totalTop: 0,
            pageTop: 1,
            pageSizeTop: 50,
            StartDateTop: undefined,  // //开始日期
            EndDateTop: undefined,  // //结束日期
            StartDate1: undefined,  // //开始日期
            EndDate1: undefined,  // //结束日期
            cardType: '', // 卡类型
            cardTypeData: [], // 卡类型
            cardNo: '', // 卡号
            patNo: '',
            select1: '',
            select2: '',
            select3: '',
            nameNo: '',
            execID: [],
            ordID: '',
            modalShow: false,
            columnsTop: [],
            columns1: [],
            selectedRowKeys: [],
            money: {},
            bqType: '',
            jsType: '',
            bqData: [],
            jsTypeData: [],
            time1: '1',
            allMoney: 0,
            accSubStatus: {}, //账户状态
            userPayData: {}, //账户状态
            patBillID: '',
            mark: '0',
            listArr: [],
            selectType: [],
            selectData: [],
            selectedRows: [],
            languageData: {}, // 国际化语言包
            language: {},   // 国际化语言
            languageCode: JSON.parse(window.sessionStorage.userData).language, // 国际化语言标识
            ColumnAuthority: '',

            propsAdmID: ""
        }

    }
    componentDidMount() {
        this.cloumTopData()
        this.setState({
            userInfo: this.props.userInfo || {},
            patBillID: this.props.patBillID || {}
        }, () => {
            this.tableData()
            this.selectData()
        })
        this.cloumTopData() //国际化
    }
    static getDerivedStateFromProps(nextProps, prevState) {
        //该方法内禁止访问this
        if (nextProps.admID !== prevState.propsAdmID) {
            //通过对比nextProps和prevState，返回一个用于更新状态的对象
            return {
                propsAdmID: nextProps.admID
            }
        }
        return null
    }
    componentDidUpdate(prevProps, prevState) {
        console.log(prevProps, prevState)
        if (prevProps.admID !== this.state.propsAdmID) {
            this.setState({ propsAdmID: prevProps.admID }, () => {
                this.tableData();
                this.selectData()
            })
        }
    }
    // 数据配置
    cloumTopData() {
        var data1 = {
            params: [{
                compontName: "HospPayRecodFindLift",
                type: 'C',
            }]
        }

        $http.post('urlS', this, {
            code: "01040073",
            data: data1,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    let resC = res.result.C

                    for (var i = 0; i < resC.length; i++) {
                        resC[i].key = i;
                    }

                    this.setState({
                        columnsTop: resC, // 费用类型table
                    }, () => {
                        this.columnsTop(this.state.columnsTop)
                    });
                }
            }
        });

    }
    columnsTop(resC) {

        let { languageCode } = this.state
        for (var i = 0; i < resC.length; i++) {
            resC[i].key = i;
        }
        if (languageCode === "EN") {
            resC.map((item, i) => {
                item.title = item.enDescripts
            })
        }

        if (languageCode === "CN") {
            resC.map((item, i) => {
                item.title = item.descripts
            })
        }

        this.setState({
            columnsTop: resC, // 费用类型table
        });
    }
    onColumnRef = (ref) => {
        this.columnRef = ref;
    }
    LanCNEN = (code) => {
        let { languageData } = this.state
        this.setState({
            language: languageData[code]
        })
    }

    tableData = () => {
        let data = {
            admID: this.state.propsAdmID ? this.state.propsAdmID : "",
            pagination: [{
                pageSize: this.state.pageSizeTop,
                currentPage: this.state.pageTop,
            }]
        }
        $http.post('urlS', this, {
            code: "05100369",
            data: data,
            success: function (res) {
                console.log(res, "123")
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    let resC = res.data
                    for (var i = 0; i < resC.length; i++) {
                        resC[i].key = i;
                    }
                    this.setState({
                        dataTable1: resC, // 列表数据
                        totalTop: res.totalCount,
                    });
                } else {
                    this.setState({
                        dataTable1: [], // 列表数据
                        totalTop: 0,
                    })
                }
            }
        });

    }

    // 显示分页总条数
    showTotal(total) {
        return `共 ${total} 条`;
    }
    onChangeTop = (page, pageSize) => {
        this.setState({ pageTop: page, pageSizeTop: pageSize }, () => {
            // 重新调用查询方法
            this.tableData();
        })
    }
    // 条数改变的回调
    onShowSizeChangeTop = (current, size) => {
        this.setState({ pageTop: 1, pageSizeTop: size }, () => {
            // 重新调用查询方法
            this.tableData();
        })

    }

    onChangeSwitch = (checked) => {
        if (checked) {
            this.setState({ mark: '0' })
        } else {
            this.setState({ mark: '1' })
        }

    }

    selectType = (e) => {
        this.setState({
            selectType: e, //账户状态
        });
    }

    selectData = () => {
        var data = {
            params: [{
                "patBillID": this.state.patBillID || '',
                "admID": this.state.propsAdmID ? this.state.propsAdmID : "",
            }],
        }
        $http.post('urlS', this, {
            code: "05100248",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {

                    this.setState({
                        selectData: res.result || [], //账户状态
                    });
                }
            }
        });

    }
    //数据导 出
    // DataoutputPresc = () => {
    //     let { userInfo, mark, selectType } = this.state
    //     window.open("http://172.18.100.87:18080/demo/reportJsp/showReport.jsp?rpx=HospOfListing.rpx&&patBillID=" + (this.state.patBillID || '') + "&mark=" + (this.state.mark || 0) + "&patNo=" + (userInfo.patNo || '') + "&name=" + (userInfo.patName || '') + "&sex=" + (userInfo.patSexDesc || ''))
    // }

    selectRowKeys(selectedRowKeys, selectedRows) {
        this.setState({
            selectedRowKeys: selectedRowKeys,
            selectedRows: selectedRows
        })
    }
    render() {
        const title = `预交金`;
        let isPersonalInformation = this.props.isPersonalInformation ? this.props.isPersonalInformation : "true";
        return (
            <div>
                <div style={{ display: isPersonalInformation === "false" ? "none" : "block" }}>
                    <TipHeader userInfo={this.state.userInfo} key={this.state.userInfo.patID + this.state.userInfo.accTSubID} />
                </div>
                <Row>
                    <Col span={24}>
                        <Card style={{ width: '100%', padding: '0' }} className='pd0' title={title}  >
                            <div>
                                <Row >
                                    <Col>
                                        <Row style={{ minHeight: '50px', padding: '0 24px 10px 24px' }}>
                                            <Button onClick={() => this.tableData()} style={{ margin: '12px 15px 0 30px', background: 'rgba(255,255,255,1)' }}>查询</Button>
                                        </Row>
                                    </Col>
                                    <Col span={24}>
                                        <Table
                                            pagination={false}
                                            bordered
                                            scroll={{ y: store.getState().tableHeight.y - 110, x: 1100 }}
                                            columns={this.state.columnsTop}
                                            dataSource={this.state.dataTable1}
                                            className="table-body-height"
                                        />
                                        <ColumnAuthoritysModel
                                            clientWidth='900px'
                                            compontName='HospPayRecodFindLift'
                                            configType="C"
                                            onRef={this.onColumnRef}
                                            reloadData={() => {
                                                this.cloumTopData()
                                            }}
                                        />
                                        <CommonPagination size="large" current={this.state.pageTop} total={this.state.totalTop} search='search'
                                            onShowSizeChange={this.onShowSizeChangeTop.bind(this)} complete={true} dataSource={this.state.dataTable1}
                                            onChange={this.onChangeTop.bind(this)} />
                                    </Col>
                                </Row>
                            </div >
                        </Card>
                    </Col>
                </Row>
            </div >


        )
    }
}