<template>
    <el-drawer v-model="open" :title="`申领列表(${total})`" :before-close="handleClose" direction="rtl"
        class="demo-drawer" modal-class="el-subscribe-drawer" size="80%">
        <Index />
        <template #footer v-if="total > 0">
            <el-button plain @click="clearSparePartApplyDetails" v-if="total > 0">清 空</el-button>
            <el-button :disabled="disabled || total == 0" type="primary" @click="submit">提 交</el-button>
        </template>
    </el-drawer>
</template>

<script setup>
import { clearSparePartApplyDetails } from "@/utils/sparePartApplyDetails";
import Index from "@/components/SparePartApplyDetails/index";
const open = ref(false);
const disabled = ref(true);
const store = useStore();
const emit = defineEmits(["submit"]);

const total = computed(() => {
    let total = 0;
    Object.values(store.state.data.sparePartApplyDetails).map((item) => {
        total += item.sparePartApplyQuantity;
    });
    return total;
});


// 显示弹框
function show() {
    open.value = true;
    disabled.value = false;
}

// 关闭按钮
function handleClose() {
    open.value = false;
}

function submit() {
    emit("submit", store.state.data.sparePartApplyDetails)
}

defineExpose({
    show,
    handleClose,
});
</script>