<template>
    <div id="ent_invoice_stock">
        <el-card v-loading="loading">
            <div slot="header">
                <span>企业发票领用存信息</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="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/ent_init";

export default {
    name: "ent_invoice_stock",
    props: {
        // 税号
        entTaxId: {
            type: String,
            default: null,
        },
        // 设备类型  1：软证书  2：税控盘  3：金税盘  4：税控ukey  5：税控服务器
        deviceType: {
            type: Number,
            default: null,
        },
        // 设备编号
        taxDiscId: {
            type: String,
            default: null,
        },
    },
    data() {
        return {
            loading: false,
            invoiceInfoList: [],
        };
    },
    watch: {
        entTaxId(val) {
            this.entTaxId = val;
            this.callGetEntPurchaseQuery();
        },
        deviceType(val) {
            this.deviceType = val;
            this.callGetEntPurchaseQuery();
        },
        taxDiscId(val) {
            this.taxDiscId = val;
            this.callGetEntPurchaseQuery();
        },
    },
    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.invoiceInfoList = null;
            if (
                this.entTaxId != null &&
                this.entTaxId != "" &&
                this.deviceType != null &&
                this.deviceType != ""
            ) {
                this.loading = true;
                GetEntPurchaseQuery(
                    this.entTaxId,
                    this.deviceType,
                    this.taxDiscId
                )
                    .then((val) => {
                        this.loading = false;
                        this.invoiceInfoList = val.data.purchaseDetailVOs;
                    })
                    .catch((err) => {
                        this.loading = false;
                        this.$message.error(err);
                    });
            }
        },
    },
};
</script>
