<script setup lang="ts">
import { ref } from "vue";

import QR from "./query/qr.vue";
import CG from "./query/cg.vue";
import SINGLE from "./query/single.vue";

const emit = defineEmits(['add']);
defineProps(['companyNo', 'supplierNo']);

const singleRef = ref<InstanceType<typeof SINGLE> | null>(null);

const isBatch = ref("1");
const selected = ref([]);
const visible = ref(false);


function open() {
  visible.value = true;
  singleRef.value.onSearch();
}


function close() {
  selected.value = [];
}


function confirm(list) {
  emit('add', list)
  visible.value = false;
}


defineExpose({ open })
</script>

<template>
  <el-dialog v-model="visible" title="发货运单" center @close="close" :close-on-click-modal="false"
  :close-on-press-escape="false">
    <div>
      <el-radio-group v-model="isBatch">
        <el-radio label="1">勾选查找</el-radio>
        <el-radio label="2">批量查找(采购单号)</el-radio>
        <el-radio label="3">批量查找(销售单号)</el-radio>
      </el-radio-group>

      <QR v-if="isBatch === '3'" @add="confirm" :supplier-no="supplierNo" :company-no="companyNo" />

      <CG  v-else-if="isBatch === '2'" @add="confirm" :supplier-no="supplierNo" :company-no="companyNo"/>

      <SINGLE v-else-if="isBatch === '1'" ref="singleRef" @add="confirm" :supplier-no="supplierNo" :company-no="companyNo" />
      </div>
    </el-dialog>
</template>
