<template>
  <ContentWrap v-loading="formLoading">
    <el-tabs v-model="activeName">
      <el-tab-pane label="基础信息" name="info">
        <SupplierInfoForm
          ref="infoRef"
          v-model:activeName="activeName"
          :is-detail="isDetail"
          :propFormData="formData"
          :supplierId="{ id }"
          @sendParam="handleParamTransfer"
        />
      </el-tab-pane>
    </el-tabs>
  </ContentWrap>
</template>
<script lang="ts" setup>
import SupplierInfoForm from '@/views/supplier/base/form/SupplierInfoForm.vue'
import {Api, Supplier, SupplierApprovalVO, SupplierVO} from '@/api/supplier/base'


defineOptions({ name: 'SupplierApprovalInfo' })
const props = defineProps<{ id?: number }>()
const supplierId = ref(0) // 供应商id
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const { params, name } = useRoute() // 查询参数
const sharedParam = ref(params.id as unknown as number); // 用于存储从 Tab 1 传递到 Tab 2 的参数
// 处理参数传递的方法
const handleParamTransfer = (param) => {
  sharedParam.value = param.id;
};
const loading = ref(true) // 加载中
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const infoRef = ref() // 供应商基本信息 Ref
const activeName = ref('info')
const supplier = ref<Supplier>({} as Supplier) // 详情
const isDetail = ref(true)

// 供应商基本信息 表单数据
const formData = ref({
  id: undefined,
  code: undefined,
  name: undefined,
  classification: undefined,
  type: undefined,
  nature: undefined,
  creditCode: undefined,
  tin: undefined,
  corporation: undefined,
  incorporationDate: undefined,
  address: undefined,
  bizScope: undefined,
  registeredCapital: undefined,
  annualTurnove: undefined,
  size: undefined,
  status: undefined,
  remark: undefined,
})

/** 获取供应商基本信息详情 */
const getSupplierData = async () => {
  loading.value = true
  formLoading.value = true
  try {
    // supplier.value = await Api.get(supplierId.value)
    formData.value = await Api.get(supplierId.value)
    console.log("供应商数据:" + formData.value.name)
  } finally {
    loading.value = false
    formLoading.value = false
  }
}

/** 初始化 */
onMounted(async () => {
  const id = props.id || params.id
  if (!id) {
    message.warning('参数错误，合同不能为空！')
    close()
    return
  }
  supplierId.value = id as unknown as number
  console.log("供应商id:" + supplierId.value)
  await getSupplierData()
})
</script>
