<script lang="ts" setup>
import { message } from 'ant-design-vue'
import { getIndustryCategoryApi } from 'API/common'
import { CUR_STATUS } from '@/enums/common'
import { submitCompanyApi, getCompanyInfoApi } from 'API/user'
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
const visible = defineModel('visible', { default: false })
const emit = defineEmits(['success'])

const checkedList = ref([])
const checkOther = ref(false)
const otherContent = ref()

const plainOptions = ['海外资讯、出海信息、方法论案例等', '出海会员俱乐部和圈层活动', '海外游学、考察、资源对接等', '出海/营销等具体项目咨询']
const postForm = ref<any>({
  busLicense: '',
  name: '',
  account: '',
  regCode: '',
  legalMan: '',
  address: '',
  contactName: '',
  contactMobile: '',
  contactPosition: '',
  wxNumber: '',
  contactEmail: '',
  category: '',
  categoryTemporaryArr: null,
  purpose: '',
})
const activeTab = ref('name')
const companyName = ref()

const options = ref<any>([])

watch(
  () => checkOther.value,
  (value) => {
    if (!value) {
      otherContent.value = ''
    }
  }
)

const handleUploadSuccess = (fileList: any) => {
  if (fileList.length) {
    const data = fileList[0].response.result
    postForm.value.address = data.address
    postForm.value.name = data.companyName
    postForm.value.legalMan = data.legalMan
    postForm.value.regCode = data.regCode
  }
}
const getCompanyInfo = async () => {
  try {
    if (!companyName.value) {
      return message.error('请输入企业名称查询')
    }
    const res = await getCompanyInfoApi({ companyName: companyName.value })
    if (res.data.success) {
      postForm.value.address = res.data.result.address
      postForm.value.name = res.data.result.companyName
      postForm.value.legalMan = res.data.result.legalMan
      postForm.value.regCode = res.data.result.regCode
    }
  } catch (error) {
    console.log(error)
  }
}
const handleOther = () => {
  let otherStr = otherContent.value ? (checkedList.value.length ? '&' + otherContent.value : otherContent.value) : ''
  let checkedListStr = checkedList.value.length ? checkedList.value.join('&') : ''
  return checkedListStr + otherStr
}

const onSubmit = async () => {
  try {
    postForm.value.account = userStore.userInfo.accountEmail || userStore.userInfo.phoneNumber
    const params = {
      ...postForm.value,
    }
    const res = await submitCompanyApi(params)
    if (res.data.success) {
      emit('success')
    }
  } catch (error) {
    console.log('error---', error)
  }
}
const getCategoryList = async () => {
  const res = await getIndustryCategoryApi({ async: 0, pcode: 'C05' })
  if (res.data.success) {
    options.value = res.data.result || []
  }
  // const res = await apiCategory({ all: false, code: 'C05' })
  // if (res.data.success) {
  //   options.value = res.data.result || []
  // }
}
getCategoryList()
</script>

<template>
  <div class="p-40px">
    <div class="text-32px fw-700 text-#3d3d3d text-center">Improve Account Information</div>
    <div class="text-14px text-#999 text-center my-10px">Improve information to ensure that commissions are received normally</div>
    <div>
      <div>撒噶时光给</div>
    </div>
  </div>
</template>

<style lang="less" scoped>
</style>
