<template>
    <el-dialog title="开票" :visible.sync="dialogFormVisible">
        <el-form :model="forms">
            <el-form-item label="项目分类：" :label-width="labelWidth">
                <el-select v-model="forms.article" :filter-method="getindustry" filterable style="width: 100%;"
                    placeholder="餐饮">
                    <el-option :label="item.name" :value="item.name" v-for="(item, index) in getindustryList"
                        :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="数电发票：" :label-width="labelWidth">
                <el-select v-model="forms.type" style="width: 100%;" placeholder="">
                    <el-option :label="item" :value="item" v-for="(item, index) in digitalInvoiceList[0]"
                        :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="税率：" :label-width="labelWidth">
                <el-select v-model="forms.se_amount" @change="changeevent" style="width: 100%;" placeholder="">
                    <el-option :label="item" :value="item" v-for="(item, index) in digitalInvoiceList[1]"
                        :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="开票金额：" :label-width="labelWidth">
                <el-input v-model="forms.price" @change="changeevent" type="number" placeholder="请输入金额"></el-input>
            </el-form-item>
            <el-form-item label="开票人账号：" :label-width="labelWidth">
                <el-select v-model="forms.dlzh" style="width: 100%;" placeholder="">
                    <el-option :label="item.bsryxm" :value="item.dlzh" v-for="(item, index) in Binding"
                        :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="单价：" :label-width="labelWidth">
                <el-input v-model="forms.d_price" disabled placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="税额：" :label-width="labelWidth">
                <el-input v-model="forms.tax_amount" disabled placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="数量：" :label-width="labelWidth">
                <el-input v-model="forms.number" type="number" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="备注：" :label-width="labelWidth">
                <el-input v-model="forms.notes" type="text" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="规格型号：" :label-width="labelWidth">
                <el-input v-model="forms.notes" type="text" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="产品单位(桌)：" :label-width="labelWidth">
                <el-input v-model="forms.notes" type="number" placeholder=""></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" :loading="printloading" @click="SubmitEvent">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
import { getbinding, getindustry, getdigitalInvoice, getstoreSe, getsubInvoicing } from "@/api/application";

export default {
    data() {
        return {
            dialogFormVisible: false,
            forms: {},
            digitalInvoiceList: [],
            getindustryList: [],
            labelWidth: '120px',
            // 绑定人信息
            Binding: [],
            item: "",
            printloading: false,

        }
    },
    mounted() {
        this.getdigitalInvoice()
        this.getindustry()
    },
    methods: {
        show(d) {
            this.dialogFormVisible = !this.dialogFormVisible
            this.item = d
            this.getbinding()
        },
        async changeevent() {
            let obj = {
                se_amount: this.forms.se_amount.slice(0, -1),
                amount: this.forms.price
            }
            const res = await getstoreSe(obj)
            this.forms.d_price = res.d_amount
            this.forms.tax_amount = res.tx
        },
        async SubmitEvent() {
            this.printloading = true
            this.forms.se_amount = this.forms.se_amount.slice(0, -1)
            const res = await getsubInvoicing(this.forms)
            this.dialogFormVisible = !this.dialogFormVisible
            this.printloading = false
            this.$emit('qrcode', res.invoice_records)
        },
        // 获取项目分类
        async getindustry(d = '餐饮') {
            const res = await getindustry({ article: d })
            this.getindustryList = res.list
        },
        // 获取数电发票类型
        async getdigitalInvoice() {
            const res = await getdigitalInvoice()
            this.digitalInvoiceList = res
        },
        // 开票
        async getbinding(d = "") {
            const res = await getbinding(d)
            this.forms = {
                account: res.bindAccount,
                dlzh: res.taxation[0].dlzh,
                article: res.article,
                type: res.sdType,
                se_amount: res.taxAmount,
                number: 1,
                d_price: '',
                tax_amount: '',
                price: this.item.payAmount,
                cash_out: this.item.orderNo,
            }
            this.Binding = res.taxation
            this.changeevent()
        }
    }
}
</script>