<route lang="json">
{
  "style": {
    "navigationBarTitleText": "编辑基本信息",
    "navigationBarBackgroundColor": "#ffffff"
  }
}
</route>
<script setup lang="ts">
import {
  getDesignerBasicInfo,
  updateDesignerBasicInfo,
} from '../../../../../core/libs/agent-requests'
import { messages } from '../../../../../core/libs/messages'
import BottomAppBar from '@/components/bottom-app-bar.vue'
import DataForm from '@/components/data-form.vue'
import { DataFormSchema } from '../../../../../components/data-form'
import { DesignerBasicInfo } from '@designer-hub/app/src/core/libs/models'
import { requestToast } from '@designer-hub/app/src/core/utils/common'
import { omit } from 'radash'

const tab = ref('basic')
// 基础信息 家庭信息 奖项信息 销售信息 游学/活动信息
const tabs = [
  { label: '基础信息', value: 'basic' },
  { label: '家庭信息', value: 'family' },
  { label: '奖项信息', value: 'award' },
  { label: '销售信息', value: 'sale' },
  { label: '游学/活动信息', value: 'activity' },
  { label: '其他活动信息', value: 'events' },
]
const id = ref()
const { data: basicData, run: setBasicData } = useRequest(() => getDesignerBasicInfo(id.value))
const formData = ref({})
const schema = ref<
  DataFormSchema<
    Pick<
      DesignerBasicInfo,
      | 'companyAddress'
      | 'idCardNumber'
      | 'passportNumber'
      | 'householdAddress'
      | 'cooperationTime'
      | 'circle'
      | 'hobbies'
      | 'sharingIntent'
      // | 'imageUrl'
      // | 'maritalStatus'
      | 'maritalStatusStr'
    >
  >
>({
  companyAddress: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.companyAddress,
    labelWidth: 120,
    props: undefined,
  },
  idCardNumber: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.idCardNumber,
    labelWidth: 120,
  },
  passportNumber: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.passportNumber,
    labelWidth: 120,
  },
  householdAddress: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.householdAddress,
    labelWidth: 120,
  },
  cooperationTime: {
    type: 'TimePick',
    label: messages.objects.designerBasiceInfo.cooperationTime,
    labelWidth: 120,
    props: {
      type: 'date',
    },
  },
  circle: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.circle,
    labelWidth: 120,
  },
  hobbies: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.hobbies,
    labelWidth: 120,
  },
  sharingIntent: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.sharingIntent,
    labelWidth: 120,
  },
  // imageUrl: {
  //   type: 'ImageUploader',
  //   label: messages.objects.designerBasiceInfo.imageUrl,
  // },
  maritalStatusStr: {
    type: 'TextField',
    label: messages.objects.designerBasiceInfo.maritalStatusStr,
    labelWidth: 120,
    props: {
      // columns: [
      //   { label: '未婚', value: 1 },
      //   { label: '已婚', value: 2 },
      //   { label: '离婚', value: 3 },
      //   { label: '丧偶', value: 4 },
      // ],
    },
  },
})
const eventsQuery = computed(() => ({ type: '3' }))
const handleSubmit = async () => {
  console.log(formData.value)
  const { code } = await requestToast(
    () =>
      updateDesignerBasicInfo({
        ...formData.value,
        userId: id.value,
        id: basicData.value.id,
      }),
    {
      success: true,
      successTitle: '保存成功',
    },
  )
  if (code === 0) {
    await setBasicData()
    await uni.navigateBack()
  }
}
onLoad(async (query: { id: string }) => {
  id.value = query.id
  await setBasicData()
  formData.value = {
    ...omit(basicData.value, ['sex']),
  }
})
</script>
<template>
  <div class="flex-grow bg-white p-4">
    <DataForm :schema="schema" v-model="formData" :direction="'horizontal'"></DataForm>
    <BottomAppBar fixed placeholder>
      <wd-button block :round="false" @click="handleSubmit">保存</wd-button>
    </BottomAppBar>
  </div>
</template>
