<script setup lang="ts">
import { shallowRef, shallowReactive } from "vue";
import SearchCheck from "./search-check.vue";
import SearchBatch from "./search-batch.vue";
import SearchBatchMain from "./search-batch-main.vue";

enum SearchMode {
  check,
  batch
}

const showModel = shallowRef(false);
const currentSearchMode = shallowRef(1);
const emit = defineEmits(["reload", "save-btn-click"]);

const payload = shallowReactive({
  companyNo: "",
  platform_type: "",
  is_comon: "0"
});

async function show(_companyNo, _platform_type) {
  showModel.value = true;
  payload.companyNo = _companyNo;
  payload.platform_type = _platform_type;
}

function handleConfirm(selected) {
  emit("save-btn-click", selected);
  showModel.value = false;
}

defineExpose({
  show
});
</script>

<template>
  <el-dialog
    top="5vh"
    center
    v-model="showModel"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    append-to-body
    destroy-on-close
    title="添加销售订单"
    :width="'1040px'"
  >

    <ElRadioGroup v-model="currentSearchMode">
      <ElRadio :label="1">勾选查找</ElRadio>
      <ElRadio :label="2">批量查找(销售订单编号)</ElRadio>
      <ElRadio :label="3">批量查找(销售订单主编号)</ElRadio>
    </ElRadioGroup>

    <template v-if="currentSearchMode === 1">
      <SearchCheck :payload="payload" @confirm="handleConfirm" />
    </template>

    <template v-if="currentSearchMode === 2">
      <SearchBatch :payload="payload" @confirm="handleConfirm" />
    </template>

    <template v-if="currentSearchMode === 3">
      <SearchBatchMain :payload="payload" @confirm="handleConfirm" />
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
:deep(.el-pagination) {
  justify-content: flex-start !important;
}

.search {
  padding: 0px !important;
}
</style>
