<script setup lang="ts">
import { shallowRef, ref, nextTick } from "vue"
import Single from "./single.vue";
import Batch from "./batch.vue"


const emit = defineEmits(['list']);
defineProps<{ platform_type: string }>();

const isBatch = shallowRef('1');

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

const visible = shallowRef(false);

const customerNo = shallowRef("");
const companyNo = shallowRef("");


const list = (e: any) => {
  emit('list', e);
  visible.value = false;
}

defineExpose({
  onDisplay: (_customerNo: string, _companyNo: string) => {
    customerNo.value = _customerNo; 
    companyNo.value = _companyNo; 
    visible.value = true; 
    nextTick(() => isBatch.value === '1' && singleRef.value.search())
  }
})
</script>


<template>
  <ElDialog v-model="visible" title="通用订单列表" center width="1024px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-radio-group v-model="isBatch">
      <el-radio label="1">勾选查找</el-radio>
      <el-radio label="2">批量查找(销售单号)</el-radio>
    </el-radio-group>


    <Single v-if="isBatch === '1'" ref="singleRef" :customerNo="customerNo" :companyNo="companyNo"
      :platformType="platform_type" @list="list" />


    <Batch v-else :customerNo="customerNo" :companyNo="companyNo" :platformType="platform_type" @list="list" />
  </ElDialog>
</template>
