<template>
  <!-- 传承人作品采集 -->
  <Form 
    :formModel="formModel"
    :formOptions="formOptions"
    :load="loadData"
    :model="InheritorWorkInfo"
    basicTabText="作品/产品信息"
    :save="handleSave"
  />
</template>

<script setup lang="ts">
import { ref, type Ref } from 'vue';
import Form from './form.vue';
import InheritorContent, { InheritorWorkInfo } from '@/api/collect/InheritorContent';
import CommonContent from '@/api/CommonContent';
import type { IDynamicFormOptions } from '@/components/dynamic';
import { useAuthStore } from '@/store/auth';
import { useLoadQuerys } from '@/common/composeabe/LoadQuerys';

const authStore = useAuthStore();
const formModel = ref(new InheritorWorkInfo()) as Ref<InheritorWorkInfo>;
const formOptions = ref<IDynamicFormOptions>({
  formItems: [
      {
        type: 'flat-group', label: '作品/产品信息', name: 'baseInfo',
        childrenColProps: { span: 24 },
        children: [
          { label: '作品/产品名称', name: 'title', type: 'text', additionalProps: { placeholder: '请输入标题' } },
          { 
            label: '所属区域', name: 'region', type: 'select-id', 
            additionalProps: { 
              placeholder: '请选择地区', 
              loadData: async () => (await CommonContent.getCategoryList(1)).map(p => ({ text: p.title, value: p.id, raw: p })) 
            } 
          },
          { label: '类型', name: 'type', type: 'select', 
            additionalProps: { 
              placeholder: '请选择类型', 
              columns: [[
                { text: '文字', value: 1 }, 
                { text: '音频', value: 2 }, 
                { text: '视频', value: 3 }, 
                { text: '相册', value: 4 }, 
                { text: '其他类型', value: 5 }
              ]], 
            } 
          },
          { 
            label: '缩略图', name: 'image', type: 'uploader', 
            additionalProps: { 
              placeholder: '请上传图片', 
              //upload: useAliOssUploadCo('inheritor/images'), 
              name: 'file', 
              accept: 'image/*' 
            }
          },
          { label: '图片说明', name: 'imageDesc', type: 'text', additionalProps: { placeholder: '请输入图片说明' } },
          { 
            label: '组图', name: 'images', type: 'uploader', 
            show: { callback: (_, model) => (model as InheritorWorkInfo).type == 4 },
            additionalProps: { 
              placeholder: '请上传组图', 
              accept: 'image/*',
              // beforeUpload: useBeforeUploadImageChecker(),
              // upload: useAliOssUploadCo('inheritor/images'), name: 'file', maxCount: 20 
            } 
          },
          { label: '作品/产品介绍', name: 'content', type: 'richtext', additionalProps: { placeholder: '请输入内容介绍' } },
          { 
            label: '音频', name: 'audio', type: 'uploader', 
            show: { callback: (_, model) => (model as InheritorWorkInfo).type == 2 },
            additionalProps: { 
              placeholder: '请上传音频', 
              accept: 'audio/*',
              // beforeUpload: useBeforeUploadAudioChecker(),
              // upload: useAliOssUploadCo('inheritor/audios'), 
              name: 'file' 
            } 
          },
          { 
            label: '相关视频', name: 'video', type: 'uploader', 
            show: { callback: (_, model) => (model as InheritorWorkInfo).type === 3 },
            additionalProps: { 
              // beforeUpload: useBeforeUploadVideoChecker(),
              // placeholder: '请上传视频', upload: useAliOssUploadCo('inheritor/videos'), name: 'file' 
            } 
          },
          { 
            label: '数字档案', name: 'archives', type: 'uploader', 
            show: { callback: (_, model) => (model as InheritorWorkInfo).type === 5 },
            additionalProps: { 
              placeholder: '请上传数字档案', 
              //upload: useAliOssUploadCo('inheritor/archives'), 
              name: 'file', 
              maxCount: 100 
            } 
          },
          { 
            label: '审核人员', name: 'text1', type: 'static-text', 
            additionalProps: {
              text: '黄念旭，李向群，卢志明',
              style: { color: '#999', }
            }
          },
          { 
            label: '审核状态', name: 'text2', type: 'static-text', 
            additionalProps: {
              text: '暂未审核',
              style: { color: '#999', }
            }
          },
          { 
            label: '填报人', name: 'text3', type: 'static-text', 
            additionalProps: {
              text: authStore.userInfo?.nickname ,
            }
          },
        ]
      },
    ],
  formRules: {
    title: [{ required: true, message: '请输入标题' }],
    region: [{ required: true, message: '请选择地区' }],
    image: [{ required: true, message: '请上传图片' }],
    type: [{ required: true, message: '请选择类型' }],
    content: [{ required: true, message: '请输入内容介绍' }],
  }
});

const { querys } = useLoadQuerys({
  id: 0,
  inheritorId: 0,
})

async function loadData() {
  const id = querys.value.id;
  if (id)
    formModel.value = await InheritorContent.getIchWorksDetail(id);
}
async function handleSave(data: InheritorWorkInfo) {
  data.ichId = querys.value.id;
  data.inheritorId = querys.value.inheritorId;
  return data;
}

</script>