import { message } from 'ant-design-vue';
import { BasicColumn, FormSchema } from '/@/components/Table';

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '一级分类名称',
    align: 'left',
    dataIndex: 'pclassifyName',
    width: 150,
    //  customRender:({text}) =>{
    //    return !fClassify_map[text]?'':fClassify_map[text]
    //  },
  },
  {
    title: '二级分类名称',
    align: 'left',
    dataIndex: 'sclassifyName',
    width: 150,
    //  customRender:({text}) =>{
    //    return !sClassify_map[text]?'':sClassify_map[text]
    //  },
  },
  {
    title: '标签名称',
    align: 'left',
    dataIndex: 'lableName',
    width: 150,
  },
  {
    title: '标签说明',
    align: 'left',
    dataIndex: 'lableDesc',
    width: 200,
  },
  {
    title: '更新时间',
    align: 'left',
    dataIndex: 'updatedTime',
    width: 140,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '标签名称',
    field: 'lableName',
    component: 'JInput',
  },
  {
    label: '一级分类代码',
    field: 'pclassifyCode',
    component: 'ApiSelect',
  },
  {
    label: '二级分类代码',
    field: 'sclassifyCode',
    component: 'ApiSelect',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '一级分类',
    field: 'pclassifyCode',
    component: 'JSearchSelect',
    colProps: { lg: 12 },
    itemProps: { labelCol: { xs: { span: 24 }, sm: { span: 6 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 18 } } },
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "st_classify,classify_name,classify_code,level1='1' and has_child='1' order by sort_no desc",
        placeholder: '请选择等级',
        allowClear: true,
        // xxxx props
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          formModel.pclassifyCode = null;
          updateSchema({
            field: 'sclassifyCode',
            componentProps: {
              dict: "st_classify,classify_name,classify_code,level1='2' and upper_classify_code='0' order by sort_no desc",
              onclick: (e: any) => {
                if (!formModel.pclassifyCode) {
                  message.warn('请先选择一级分类！');
                  return;
                }
              },
            },
          });
          if (e === undefined) {
            return;
          }
          updateSchema({
            field: 'sclassifyCode',
            componentProps: {
              dict: "st_classify,classify_name,classify_code,level1='2' and upper_classify_code='" + e + "' order by sort_no desc",
              onclick: (e: any) => {
                if (!formModel.pclassifyCode) {
                  message.warn('请先选择一级分类！');
                  return;
                }
              },
            },
          });
        },
      };
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: false, message: '请选择一级分类!' }];
    },
  },
  {
    label: '二级分类',
    field: 'sclassifyCode',
    component: 'JSearchSelect',
    colProps: { lg: 12 },
    itemProps: { labelCol: { xs: { span: 24 }, sm: { span: 6 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 18 } } },
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "st_classify,classify_name,classify_code,level1='2' and upper_classify_code='" + formModel.pclassifyCode + "' order by sort_no desc",
        placeholder: '请选择二级分类',
        allowClear: true,
        onclick: (e: any) => {
          if (!formModel.sclassifyCode) {
            message.warn('请先选择一级分类！');
            return;
          }
        },
      };
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: false, message: '请选择二级分类!' }];
    },
  },
  {
    label: '标签名称',
    field: 'lableName',
    component: 'Input',
    itemProps: { labelCol: { xs: { span: 24 }, sm: { span: 3 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 21 } } },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入标签名称!' }];
    },
  },
  {
    label: '标签说明',
    field: 'lableDesc',
    component: 'InputTextArea',
    itemProps: { labelCol: { xs: { span: 24 }, sm: { span: 3 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 21 } } },
    componentProps: {
      rows: 5,
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
