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';
import { BrandListApi } from '/@/api/order/list';

export const padsSchemas: FormSchema[] = [
  {
    field: 'image',
    component: 'Upload',
    label: '封面',
    rules: [{ required: true, message: '请选择上传文件' }],
    itemProps: {
      validateTrigger: 'blur',
    },
    componentProps: {
      api: uploadApi,
      maxNumber: 1,
      accept: ['jpg', 'jpeg', 'gif', 'png'],
      afterFetch: function (data) {
        console.log('data', data);
        Reflect.set(data, 'url', data.message);
        return data;
      },
    },
    required: true,
  },
  {
    field: 'title',
    component: 'Input',
    label: '标题',
    componentProps: {
      placeholder: '标题',
      maxLength: 15,
    },
    required: true,
  },
  {
    field: 'connectId',
    label: '直播间名称',
    component: 'ApiSelect',
    required: true,
    itemProps: {
      validateTrigger: 'blur',
    },
    componentProps: {
      api: BrandListApi,
      // resultField: 'list',
      // numberToString: true,
      labelField: 'name',
      valueField: 'id',
      immediate: true,
      params: {
        page: 1,
        limit: 1000,
      },
    },
  },
  {
    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,
  // },
];
export const schemas: FormSchema[] = [
  {
    field: 'image',
    component: 'Upload',
    label: '封面图',
    rules: [{ required: true, message: '请选择上传文件' }],
    itemProps: {
      validateTrigger: 'blur',
    },
    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: 'title',
    component: 'Input',
    label: '正文标题',
    componentProps: {
      placeholder: '轮播图正文标题',
      maxLength: 15,
    },
    required: true,
  },

  {
    field: 'orderNum',
    component: 'Input',
    label: '轮播排序',
    defaultValue: 0,
    componentProps: {
      placeholder: '轮播排序',
      type: 'number',
      min: 0,
    },
    required: true,
  },
  // {
  //   field: 'url',
  //   component: 'Input',
  //   label: '链接',
  //   componentProps: {
  //     placeholder: '链接',
  //   },
  // },

  // {
  //   field: 'content',
  //   component: 'Input',
  //   label: '正文内容',
  //   defaultValue: '',
  //   rules: [{ required: true }],
  //   render: ({ model, field }) => {
  //     return h(Tinymce, {
  //       value: model[field],
  //       onChange: (value: string) => {
  //         model[field] = value;
  //       },
  //     });
  //   },
  // },
];
