<template>
    <div id="ent_invoice_stock">
        <el-card v-loading="loading">
            <div slot="header">
                <span v-text="fmtIsvPlatform"></span>
                <el-button @click="handleRefresh" style="float: right; padding: 3px 0" type="text">刷新</el-button>
            </div>
            <el-table :data="invoiceInfoList" border style="width: 100%">
                <!-- <el-table-column prop="entTaxId" label="企业税号"> </el-table-column> -->
                <el-table-column prop="invoiceCategory" :formatter="fmtInvoiceCategory" label="发票种类" align="center">
                </el-table-column>
                <el-table-column prop="surplusTotalQuantity" label="剩余发票数" align="center"> </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
import { getEntPurchaseQuery } from '@/api/invoice_management'
export default {
    name: 'ent_invoice_stock',
    data() {
        return {
            loading: false,
            isvPlatform: '', // 平台信息
            invoiceInfoList: [],
        }
    },
    computed: {
        fmtIsvPlatform() {
            let result = '企业发票领用存信息';
            if (this.isvPlatform != null
                && this.isvPlatform != ''
                && this.isvPlatform != 'undefined') {
                result += ' - ' + this.isvPlatform;
            }
            return result;
        }
    },
    created() {
        this.callGetEntPurchaseQuery();
    },
    methods: {
        fmtInvoiceCategory(row, column, cellValue) {
            if (cellValue == 1) {
                return '增值税普通电子发票';
            } else if (cellValue == 2) {
                return '增值税电子专用发票';
            } else if (cellValue == 3) {
                return '增值税普通纸质发票';
            } else if (cellValue == 4) {
                return '增值税专用纸质发票';
            }
            return cellValue;
        },
        // 刷新企业发票领用存信息
        handleRefresh() {
            this.callGetEntPurchaseQuery();
        },
        // 企业发票领用存信息
        callGetEntPurchaseQuery() {
            this.loading = true;
            getEntPurchaseQuery().then(val => {
                this.loading = false;
                this.isvPlatform = val.data.isvPlatform;
                this.invoiceInfoList = val.data.purchaseDetailVOs;
            }).catch(err => {
                this.loading = false;
                this.$message.error(err);
            })
        }
    }
}
</script>
