<template>
    <el-drawer v-model="open" :title="`${warehouseAccessType == 10 ? '入库' : '出库'}列表(${total})`"
        :before-close="handleClose" direction="rtl" class="demo-drawer" modal-class="el-subscribe-drawer" size="80%">
        <Index :warehouseAccessType="warehouseAccessType" />
        <template #footer>
            <el-button plain @click="clearWarehouseAccessDetailsIn" v-if="warehouseAccessType == 10 && total > 0">清 空
            </el-button>
            <el-button plain @click="clearWarehouseAccessDetailsOut" v-else-if="warehouseAccessType == 20 && total > 0">
                清 空
            </el-button>
            <el-button :disabled="disabled || total == 0" type="primary" @click="submit" v-if="total > 0">提
                交</el-button>
        </template>
    </el-drawer>
</template>

<script setup>
import { clearWarehouseAccessDetailsOut } from "@/utils/warehouseAccessDetailsOut";
import { clearWarehouseAccessDetailsIn } from "@/utils/warehouseAccessDetailsIn";
import Index from "@/components/WarehouseAccessDetails/index";
const { ctx } = getCurrentInstance();
const open = ref(false);
const disabled = ref(true);
const store = useStore();
const emit = defineEmits(["submit"]);

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

const { warehouseAccessType } = toRefs(props);

const total = computed(() => {
    let total = 0;
    Object.values(warehouseAccessType.value == 10 ? store.state.data.warehouseAccessDetailsIn : store.state.data.warehouseAccessDetailsOut).map((item) => {
        total += item.warehouseRetrievalQuantity;
    });
    return total;
});


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

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

function submit() {
    emit("submit", warehouseAccessType.value == 10 ? store.state.data.warehouseAccessDetailsIn : store.state.data.warehouseAccessDetailsOut);
    // ctx.$emit("submit", warehouseAccessType.value == 10 ? store.state.data.warehouseAccessDetailsIn : store.state.data.warehouseAccessDetailsOut);
}

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