//票据号码段查询
import React from 'react'
import { Button, Row, Col, Input, Table } from 'antd'
import { $http } from '../../../containers/config/https'
import store from '../../../store';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';

const { TextArea } = Input;
export default class BillNumberSection extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            data: [],
            Tabledata: [],
            startInvNo: '',
            endInvNo: '',
            allAmt: '',
            allNum: '',
            normalNum: '',
            normalAmt: '',
            AbortNum: '',
            AbortAmt: '',
            StrikeNum: '',
            StrikeAmt: '',
            invNoSection: '',

            columns: [],
            languageTable1: {}, // 国际化Table1
            languageTable2: {}, // 国际化Table2
            languageData: {}, // 国际化语言包
            language: {},   // 国际化语言
            languageCode: JSON.parse(window.sessionStorage.userData).language, // 国际化语言标识
        }
        // this.columns = [
        //     {
        //         title: '发票号',
        //         dataIndex: 'invNo',
        //         width: '100px',
        //         align: 'center',
        //     },
        //     {
        //         title: '收费员',
        //         dataIndex: 'userID',
        //         width: '100px',
        //         align: 'center'
        //     },
        //     {
        //         title: '打印时间',
        //         dataIndex: 'printDate',
        //         width: '100px',
        //         align: 'center'
        //     },
        //     {
        //         title: '病人ID',
        //         dataIndex: 'patNo',
        //         width: '100px',
        //         align: 'center'
        //     },
        //     {
        //         title: '姓名',
        //         dataIndex: 'name',
        //         width: '100px',
        //         align: 'center'
        //     },
        //     {
        //         title: '费别',
        //         dataIndex: 'admReasonID',
        //         width: '100px',
        //         align: 'center'
        //     },
        //     {
        //         title: '状态',
        //         dataIndex: 'statusID',
        //         width: '100px',
        //         align: 'center'
        //     },
        // ]
    }

    onColumnRef = (ref) => {
        console.log(ref)
        this.columnRef = ref;
    }

    // 获取主列表columns
    tableList = (reactCode, compontName) => {
        var data = {
            params: [{
                "reactCode": ["InvBillNumberSection"],
                "compontName": "InvBillNumberSection",
                "type": "C"
            }]
        }
        console.log(1, data)
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    let resC = res.result.C
                    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
                        })
                    }
                    let arr = res.result && resC.length > 0 ? JSON.parse(JSON.stringify(resC)).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,
                        languageTable1: res.result.B || {},  // 国际化Table1
                        languageTable2: res.result.C || {},  // 国际化Table2
                        languageData: res.result.language || {},  // 国际化语言包
                    }, () => {
                        this.LanCNEN(this.state.languageCode)
                    })
                }
            }
        })
    }

    LanCNEN = (code) => {
        let { languageData } = this.state
        this.setState({
            language: languageData[code]
        })
    }

    componentDidMount() {
        this.tableList();
    }

    // 查询条件 --- 开始号码
    onChangeStartInvNo = (e) => {
        this.setState({ startInvNo: e.target.value });
    }
    // 查询条件 --- 结束号码段
    onChangeEndInvNo = (e) => {
        this.setState({ endInvNo: e.target.value });
    }
    //基础数据
    handleQuery = () => {
        let { startInvNo, endInvNo } = this.state;
        let data = {}
        data = {
            params: [{
                "startInvNo": startInvNo,
                "endInvNo": endInvNo
            }]
        }
        $http.post('urlDeanlt', this, {
            code: '05100165',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0 && res.result) {
                    for (var i = 0; i < res.result.length; i++) {
                        res.result[i].key = i;
                    }
                    for (var i = 0; i < res.payMentArr.length; i++) {
                        res.payMentArr[i].key = i;
                    }
                    this.setState({ data: res.result[0], total: res.result.length, loading: false })
                    this.setState({ Tabledata: res.payMentArr, total: res.payMentArr.length, loading: false })
                } else {
                    this.setState({ data: [], total: 0, loading: false })
                    this.setState({ Tabledata: [], total: 0, loading: false })
                }
            }
        })
    }
    render() {
        let { language } = this.state
        return (
            <div style={{ width: '100%', height: '100%' }}>
                <div className="department-header">
                    <Row style={{ minHeight: '80px', padding: '0 24px' }}>
                        <Col span={24} style={{ marginTop: '24px' }}>
                            {language.InvBillNumberSectioninvoiceInterval && language.InvBillNumberSectioninvoiceInterval.descripts}：<Input placeholder={language.InvBillNumberSectioninvoiceInterval && language.InvBillNumberSectioninvoiceInterval.message} style={{ width: '150px', marginRight: '20px' }} value={this.state.startInvNo} onChange={this.onChangeStartInvNo} /> —— <Input placeholder="区分大小写" style={{ width: '150px', marginRight: '20px' }} value={this.state.endInvNo} onChange={this.onChangeEndInvNo} />
                            <Button style={{ marginRight: '10px' }} onClick={this.handleQuery}>{language.InvBillNumberSectionquery && language.InvBillNumberSectionquery.descripts}</Button>
                        </Col>
                    </Row>
                </div>
                <div style={{ widht: '100%', height: '10px', background: '#f0f2f5' }}></div>
                <div style={{ padding: 12 }}>
                    <Row>
                        <Col span={18} style={{ marginTop: '24px' }}>
                            <Col span={6}>
                                {language.InvBillNumberSectiontotalAmount && language.InvBillNumberSectiontotalAmount.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.allAmt} />
                            </Col>
                            <Col span={6}>
                                {language.InvBillNumberSectionnormalAmount && language.InvBillNumberSectionnormalAmount.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.normalAmt} />
                            </Col>
                            <Col span={6}>
                                {language.InvBillNumberSectionredAmount && language.InvBillNumberSectionredAmount.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.strikeAmt} />
                            </Col>
                            <Col span={6}>
                                {language.InvBillNumberSectionabandonedAmount && language.InvBillNumberSectionabandonedAmount.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.abortAmt} />
                            </Col>
                        </Col>
                        <Col span={18} style={{ marginTop: '24px' }}>
                            <Col span={6}>
                                {language.InvBillNumberSectiontotalInvoice && language.InvBillNumberSectiontotalInvoice.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.allNum} />
                            </Col>
                            <Col span={6}>
                                {language.InvBillNumberSectionnormalInvoice && language.InvBillNumberSectionnormalInvoice.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.normalNum} />
                            </Col>
                            <Col span={6}>
                                {language.InvBillNumberSectionredInvoice && language.InvBillNumberSectionredInvoice.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.strikeNum} />
                            </Col>
                            <Col span={6}>
                                {language.InvBillNumberSectionabandonedInvoice && language.InvBillNumberSectionabandonedInvoice.descripts}：<Input disabled style={{ width: '200px' }} value={this.state.data.abortNum} />
                            </Col>
                        </Col>
                        <Col span={18} style={{ marginTop: '24px' }}>
                            <TextArea rows={4} disabled style={{ width: '1200px' }} value={this.state.data.invNoSection} />
                        </Col>
                    </Row>
                </div>
                <div style={{ padding: 12 }}>
                    {/* <Table columns={this.columns} dataSource={this.state.Tabledata} bordered></Table> */}
                    <Table
                        dataSource={this.state.Tabledata}
                        columns={this.state.columns}
                        className='TableA'
                        //rowClassName="editable-row"
                        pagination={false}
                        scroll={{ x: 900, y: store.getState().tableHeight.y }}
                        bordered
                        loading={this.state.loading}
                    />
                    <ColumnAuthoritysModel
                        clientWidth='900px'
                        compontName='InvBillNumberSection'
                        configType="C"
                        onRef={this.onColumnRef}
                        reloadData={this.tableList}
                    />

                </div>
            </div>
        )
    }
}