<template>
  <ChooseFile @upload="fileUpload" v-if="mode === 'upload'" />

  <ExcelOperate v-else-if="mode === 'operate'" />
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { getOrderFileById } from '@/api/order'
import { useCommentExcel } from '@/stores/commentExcel'
import ChooseFile from './components/ChooseFile/ChooseFile.vue'
import ExcelOperate from './components/ExcelOperate/ExcelOperate.vue'

const route = useRoute()
const { setFileInfo } = useCommentExcel()
const mode = ref('upload')
const fileUpload = () => {
  mode.value = 'operate'
}

// 获取文件信息及客户信息
const queryFileInfo = async () => {
  const { data } = await getOrderFileById(route.query.fileId as string)
  setFileInfo(data.result)
  mode.value = 'operate'
}

onMounted(() => {
  route.query?.fileId && queryFileInfo()
})
</script>
<style lang="scss" scoped></style>
