import { message } from 'ant-design-vue';
import { FormSchema } from '/@/components/Table';
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '责任部门',
    field: 'depId',
    component: 'JSelectDept',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            formModel.depId = null
            formModel.dutyCode = null
            updateSchema({
              field: 'dutyCode',
              componentProps: {
                dict: "listDuty",
                onclick: (e:any) => {
                  if(!formModel.depId){
                    message.warn("请先选择责任部门！")
                    return
                 }
                }
              },
            });
            return
          }
           if(formModel.depId!=e[0]){
            formModel.dutyCode = null
          }
          updateSchema({
            field: 'dutyCode',
            componentProps: {
              dict: "listDuty",
              depCode: e[0],
              onclick: (e:any) => {
                if(!formModel.depId){
                  message.warn("请先选择责任部门！")
                  return
                }
              }
            },
          });
        }
      }
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请选择责任部门!'},
      ];
    },
  },
  {
    label: '责任人',
    field: 'dutyCode',
    component: 'JSearchSelectDuty',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "listDuty",
        onclick: (e:any) => {
          if(!formModel.depId){
            formModel.dutyCode = null
             message.warn("请先选择责任部门！")
             return
          }
       }
      }
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请选择责任人!'},
      ];
    },
  },
  {
    label: '备注',
    field: 'des',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
	  label: '',
	  field: 'projectCreId',
	  component: 'Input',
	  show: false
	},
  {
	  label: '',
	  field: 'ids',
	  component: 'Input',
	  show: false
	},
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

export const formSchemaUpFile: FormSchema[] = [
    {
      label: '上传文件',
      field: 'fileUploadPath',
      component: 'JUpload',
      itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
      componentProps: { desText:"支持扩展名: .rar .zip .doc .docx .pdf .jpg..."},
    },
	// TODO 主键隐藏字段，目前写死为ID
  {
	  label: '',
	  field: 'projectCreId',
	  component: 'Input',
	  show: false
	},
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

