// 会议详情抽屉配置数据
// @ts-ignore: 忽略
import type { FormSchemaGetter } from '#/adapter/form';
// @ts-ignore: 忽略

import { ElMessage } from 'element-plus';

// @ts-ignore: 忽略
import { getMultipleImageUploadConfig } from '#/components/upload';

export const drawerFormSchema: any | FormSchemaGetter = () => [
  {
    component: 'SectionTitle',
    fieldName: '_section_title',
    hideLabel: true,
    componentProps: {
      title: '基本信息',
    },
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入会议主持',
    },
    fieldName: 'meetingHost',
    label: '会议主持',
    rules: 'required',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入会议地点',
    },
    fieldName: 'meetingLocation',
    label: '会议地点',
    rules: 'required',
  },
  {
    component: 'InputNumber',
    componentProps: (data: any) => {
      return {
        placeholder: '请输入参会人数',
        min: 0,
        max: undefined,
        onChange(val: number) {
          if (val && val > data.totalCount) {
            ElMessage({
              message: '参会人数不能大于总人数',
              type: 'warning',
            });
            data.attendeesCount = 0;
          }
        },
      };
    },
    fieldName: 'attendeesCount',
    label: '参会人数',
    rules: 'required',
  },
  {
    component: 'InputNumber',
    componentProps: {
      placeholder: '请输入总人数',
      min: 0,
      max: undefined,
      disabled: true,
    },
    fieldName: 'totalCount',
    label: '总人数',
  },
  {
    component: 'DatePicker',
    componentProps: {
      type: 'datetimerange',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
    },
    fieldName: 'firstMeetingTime',
    label: '首次会议时间',
    rules: 'required',
  },
  {
    component: 'DatePicker',
    componentProps: {
      type: 'datetimerange',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
    },
    fieldName: 'secondMeetingTime',
    label: '二次会议时间',
    // rules: 'required',
  },
  {
    component: 'SectionTitle',
    fieldName: '_section_title',
    hideLabel: true,
    componentProps: {
      title: '会议内容',
    },
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入通知通告',
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
    fieldName: 'noticeAnnouncement',
    label: '通知通告',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入业绩管理',
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
    fieldName: 'performanceManagement',
    label: '业绩管理',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入服务提升',
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
    fieldName: 'serviceImprovement',
    label: '服务提升',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入视觉形象',
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
    fieldName: 'visualImage',
    label: '视觉形象',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入运营管理',
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
    fieldName: 'operationManagement',
    label: '运营管理',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入安全合规',
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
    fieldName: 'securityCompliance',
    label: '安全合规',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入安全合规附件名称',
    },
    fieldName: 'securityComplianceAttachment',
    label: '安全合规附件名称',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入其它内容',
      type: 'textarea',
      rows: 3,
      maxlength: 200,
    },
    fieldName: 'otherContent',
    label: '其它',
  },
  {
    component: 'SectionTitle',
    fieldName: '_section_title',
    hideLabel: true,
    componentProps: {
      title: '会议照片',
    },
  },
  {
    component: 'Input',
    fieldName: 'meetingImages',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Upload',
    fieldName: 'meetingImagePaths',
    label: '会议记录和现场照片',
    rules: 'required',
    componentProps: (row: any) => {
      return {
        ...getMultipleImageUploadConfig(6),
        multiple: true,
        onSuccess: (res: any, uploadFile: any, uploadFiles: any) => {
          if (res.code === 200) {
            const paths: string[] = [];
            uploadFiles.forEach((item: any) => {
              if (item.response?.code === 200) {
                paths.push(item.response.data.fileName);
              }
            });
            row.meetingImages = paths.join(',');
            return res.data;
          }
        },
      };
    },
    renderComponentContent: () => {
      return {
        default: () => '点击上传',
      };
    },
    required: true,
  },
];
