import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '任务名称',
    align: 'left',
    dataIndex: 'taskname',
  },
  {
    title: '模板名称',
    align: 'left',
    dataIndex: 'tplname',
  },

  {
    title: '审批状态',
    align: 'center',
    dataIndex: 'appSta',
    customRender: ({ text }) => {
      if(!text||text===0) {
        return render.renderTag("待审批", "blue");
      }
      if(!text||text===1) {
        return render.renderTag("通过", "green");
      }
      if(!text||text===2) {
        return render.renderTag("未通过", "red");
      }
      if(!text||text===9) {
        return render.renderTag("归档", "gray");
      }

      const color = text == 'L' ? 'blue' : text == 'M' ? 'yellow' : 'red';
      return render.renderTag(render.renderDict(text, 'priority'), color);
    },
    ifShow: true,
  },

  {
    title: '审批人',
    align: 'center',
    dataIndex: 'appUser',
    ifShow: false,
  },
  {
    title: '审批说明',
    align: 'center',
    dataIndex: 'appDes',
    ifShow: true,
  },
  {
    title: '审批时间',
    align: 'center',
    dataIndex: 'appTime',
    customRender: ({ text }) => {
      return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
    },
    ifShow: true,
  },
  {
    title: '',
    align: 'center',
    dataIndex: 'id',
    ifShow: false,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '任务名称',
    field: 'taskname',
    component: 'Input',
  },
  {
    label: '模板名称',
    field: 'tplname',
    component: 'Input',
  },
  {
    label: '审批状态',
    field: 'appSta',
    component: 'InputNumber',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '任务ID',
    field: 'taskid',
    component: 'InputNumber',
  },
  {
    label: '审批状态',
    field: 'appSta',
    component: 'InputNumber',
  },
  {
    label: '审批人',
    field: 'appUser',
    component: 'Input',
    show: false,
  },
  {
    label: '审批说明',
    field: 'appDes',
    component: 'Input',
    show: false,
  },
  {
    label: '审批时间',
    field: 'appTime',
    component: 'DatePicker',
    show: false,
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
//审批表单
export const formSchemaApprove: FormSchema[] = [
  {
    label: '是否通过',
    field: 'appSta',
    required: true,
    defaultValue: 1,
    component: 'RadioGroup',
    componentProps: ({}) => {
      return {
        options: [
          { label: '通过', value: 1 },
          { label: '否决', value: 2 },
        ],
      };
    },
  },
  {
    label: '审批意见',
    field: 'appDes',
    component: 'InputTextArea',
    componentProps: {
      rows: 8,
      placeholder: '请输入审批意见，不超过500字',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: false }, { min: 0, max: 500, message: '长度最大500个字符', trigger: 'blur' }];
    },
  },
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'taskid',
    component: 'Input',
    show: false,
  },
];

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