<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>
            <el-button plain @click="clearMaintenanceApplyDetails" 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 { clearMaintenanceApplyDetails } from "@/utils/maintenanceApplyDetails";
import Index from "@/components/MaintenanceApplyDetails/index";
const { ctx } = getCurrentInstance();
const open = ref(false);
const disabled = ref(true);
const store = useStore();
const emit = defineEmits(["submit"]);

const props = defineProps({
    sparePartAccessType: {
        type: [Number, String],
        default: null,
    },
});

const { sparePartAccessType } = toRefs(props);

const total = computed(() => {
    let total = 0;
    total += Object.values(store.state.data.maintenanceApplyDetails).length;
    total += store.state.data.maintenanceApplyDetailsCustomList.length;
    return total;
});


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

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

function submit() {
    emit("submit", sparePartAccessType.value == 10 ? store.state.data.sparePartAccessDetailsIn : store.state.data.sparePartAccessDetailsOut);
    // ctx.$emit("submit", sparePartAccessType.value == 10 ? store.state.data.sparePartAccessDetailsIn : store.state.data.sparePartAccessDetailsOut);
}

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