import { FormSchema } from '/@/components/Form';
// import { uploadApi } from '/@/api/sys/upload';
import { Tinymce } from '/@/components/Tinymce/index';
import { h } from 'vue';
import { uploadApi } from '/@/api/advertisement/list';

export const padsSchemas: FormSchema[] = [
  {
    field: 'title',
    component: 'Input',
    label: '正文标题',
    componentProps: {
      placeholder: '轮播图正文标题',
    },
    required: true,
  },

  {
    field: 'orderNum',
    component: 'Input',
    label: '轮播排序',
    defaultValue: 0,
    componentProps: {
      placeholder: '轮播排序',
      type: 'number',
      min: 0,
    },
    required: true,
  },
  {
    field: 'connectId',
    component: 'Input',
    label: '链接ID',
    componentProps: {
      placeholder: '链接',
    },
    // required: true,
  },
  {
    field: 'image',
    component: 'Upload',
    label: '封面图',
    rules: [{ required: true, message: '请选择上传文件' }],
    componentProps: {
      api: uploadApi,
      maxNumber: 1,
      afterFetch: function (data) {
        console.log('data', data);
        return data;
      },
    },
    required: true,
  },
];
export const schemas: FormSchema[] = [
  {
    field: 'title',
    component: 'Input',
    label: '正文标题',
    componentProps: {
      placeholder: '轮播图正文标题',
    },
    required: true,
  },

  {
    field: 'orderNum',
    component: 'Input',
    label: '轮播排序',
    defaultValue: 0,
    componentProps: {
      placeholder: '轮播排序',
      type: 'number',
      min: 0,
    },
    required: true,
  },
  {
    field: 'link',
    component: 'Input',
    label: '链接',
    componentProps: {
      placeholder: '链接',
    },
    // required: true,
  },
  {
    field: 'image',
    component: 'Upload',
    label: '封面图',
    rules: [{ required: true, message: '请选择上传文件' }],
    componentProps: {
      api: uploadApi,
      maxNumber: 1,
      afterFetch(data) {
        // console.log('afterFetch1', data);
        // const covertData = [data.message];
        Reflect.set(data, 'url', data.message);
        // console.log('afterFetch2', data);
        return data;
      },
    },
    required: true,
  },
  {
    field: 'content',
    component: 'Input',
    label: '正文内容',
    defaultValue: '',
    rules: [{ required: true }],
    render: ({ model, field }) => {
      return h(Tinymce, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
];
