<template>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span class="text-bold">申购列表</span>
        <span class="text-bold" v-if="applyPurchaseNumTotal != 0">({{ applyPurchaseNumTotal }})</span>
      </div>
    </template>
    <Index />
    <div class="flex justify-end margin-top">
      <el-button plain @click="clearApplyPurchaseDetails">清 空</el-button>
      <el-button :disabled="applyPurchaseNumTotal == 0" type="primary" @click="submit">提 交</el-button>
    </div>
  </el-card>
</template>

<script setup>
import { clearApplyPurchaseDetails } from "@/utils/applyPurchaseDetails";
import Index from "./index";
const store = useStore();
const { ctx } = getCurrentInstance();
const emit = defineEmits(["submit"]);

const applyPurchaseNumTotal = computed(() => {
  let total = 0;
  Object.values(store.state.data.applyPurchaseDetails).map((item) => {
    total += item.applyPurchaseNum;
  });
   store.state.data.applyPurchaseDetailsCustomList.map((item) => {
    total += item.applyPurchaseNum;
  });
  return total;
});

function submit() {
  emit("submit", store.state.data.applyPurchaseDetails)
  // ctx.$emit("submit", store.state.data.applyPurchaseDetails);
}

</script>