import { message } from 'ant-design-vue';
import { FormSchema } from '/@/components/Table';
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '问题项',
    field: 'problemItem',
    component: 'Input',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    dynamicDisabled: true,
  },
  {
    label: '问题描述',
    field: 'problemDes',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    dynamicDisabled: true,
    componentProps: {
      rows: 5
    }
  },
  {
    label: '负责部门',
    field: 'headDepCode',
    component: 'JSelectDept',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            formModel.headDepCode = null
            formModel.headCode = null
            updateSchema({
              field: 'headCode',
              componentProps: {
                onclick: (e:any) => {
                  if(!formModel.headDepCode){
                    message.warn("请先选择执行部门！")
                    return
                 }
                }
              },
            });
            return
          }
          if(formModel.headDepCode!=e[0]){
            formModel.headCode = null
          }
          updateSchema({
            field: 'headCode',
            componentProps: {
              dict: "listDuty",
              depCode: e[0],
              onclick: (e:any) => {
                if(!formModel.headDepCode){
                  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: 'headCode',
    component: 'JSearchSelectDuty',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "listDuty",
        onclick: (e:any) => {
          if(!formModel.headDepCode){
            formModel.headCode = 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: 'assinStatus',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'severity',
    component: 'Input',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    show: false
  },
  {
    label: '',
    field: 'priorityFlag',
    component: 'Input',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    show: false
  },
  {
    label: '',
    field: 'lateFinishTime',
    component: 'Input',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    show: false
  },
  {
	  label: '',
	  field: 'pid',
	  component: 'Input',
	  show: false
	},
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];


// 接收formData

//表单数据
export const formSchemaJs: FormSchema[] = [
  {
    label: '问题项',
    field: 'problemItem',
    component: 'Input',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    dynamicDisabled: true,
  },
  {
    label: '问题描述',
    field: 'problemDes',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    dynamicDisabled: true,
    componentProps: {
      rows: 5
    }
  },
  {
    label: '问题来源',
    field: 'actNo',
    component: 'Input',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,
  },
  {
    label: '严重程度',
    field: 'severity',
    component: 'JSearchSelect',
    componentProps:{
      dict: "severity"
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,
  },
  {
    label: '优先级',
    field: 'priorityFlag',
    component: 'JSearchSelect',
    componentProps:{
      dict: "priorityFlag"
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,
  },
  {
    label: '最晚完成时间',
    field: 'lateFinishTime',
    component: 'DatePicker',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,
  },
  {
    label: '是否接收',
    field: 'isReceive',
    component: 'JSearchSelect',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "isReceive",
        onChange: (e: any) => {
          const { updateSchema,clearValidate } = formActionType;
          if("1" == e){
            updateSchema({
              label: '整改策略',
              field: 'strategy',
              component: 'JSearchSelect',
              componentProps:{
                dict: "programme"
              },
              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: '请选择整改策略!'},
                ];
              }
            })
            updateSchema({
              label: '整改方案',
              field: 'programme',
              component: 'InputTextArea',
              itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
              dynamicRules: ({model,schema}) => {
                return [
                       { required: true, message: '请输入整改方案!'},
                ];
              },
              componentProps: {
                rows: 5
              }
            })
          }else{
            updateSchema({
              label: '整改策略',
              field: 'strategy',
              component: 'JSearchSelect',
              componentProps:{
                dict: "programme"
              },
              colProps: {lg: 12},
              itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
              dynamicRules: ({model,schema}) => {
                return []
              }
            })
            updateSchema({
              label: '整改方案',
              field: 'programme',
              component: 'InputTextArea',
              itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
              dynamicRules: ({model,schema}) => {
                return []
              },
              componentProps: {
                rows: 5
              }
            })
            clearValidate()
          }
        }
      }
    },
    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: 'strategy',
    component: 'JSearchSelect',
    componentProps:{
      dict: "programme"
    },
    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: 'programme',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请输入整改方案!'},
      ];
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'assinStatus',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'receiveStatus',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'problemSourceFlag',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'headDepCode',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'headCode',
    component: 'Input',
	  show: false
  },
  {
	  label: '',
	  field: 'pid',
	  component: 'Input',
	  show: false
	},
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

export const formSchemaEdit: FormSchema[] = [
  {
    label: '问题项',
    field: 'problemItem',
    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: 'problemDes',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请输入问题描述!'},
      ];
    },
    componentProps: {
      rows: 5
    }
  },
  // {
  //   label: '控制活动',
  //   field: 'actNo',
  //   slot: 'actNoSlot',
  //   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: 'problemSource',
    component: 'Input',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,
  },
  {
    label: '严重程度',
    field: 'severity',
    component: 'JSearchSelect',
    componentProps:{
      dict: "severity"
    },
    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: 'priorityFlag',
    component: 'JSearchSelect',
    componentProps:{
      dict: "priorityFlag"
    },
    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: 'lateFinishTime',
    component: 'DatePicker',
    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: '请选择最晚完成时间!'},
      ];
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'assinStatus',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'receiveStatus',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'problemSourceFlag',
    component: 'Input',
	  show: false
  },
  {
	  label: '',
	  field: 'actNo',
	  component: 'Input',
	  show: false
	},
  {
	  label: '',
	  field: 'pid',
	  component: 'Input',
	  show: false
	},
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
]

export const formSchemaDetail: FormSchema[] = [
  {
    label: '问题项',
    field: 'problemItem',
    component: 'Input',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
  },
  {
    label: '问题描述',
    field: 'problemDes',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    componentProps: {
      rows: 5
    }
  },
  // {
  //   label: '控制活动',
  //   field: 'actNo',
  //   slot: 'actNoSlot',
  //   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: 'problemSource',
    component: 'Input',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '严重程度',
    field: 'severity',
    component: 'JSearchSelect',
    componentProps:{
      dict: "severity"
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '优先级',
    field: 'priorityFlag',
    component: 'JSearchSelect',
    componentProps:{
      dict: "priorityFlag"
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '最晚完成时间',
    field: 'lateFinishTime',
    component: 'DatePicker',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '负责部门',
    field: 'headDepCode',
    component: 'JSelectDept',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            formModel.headDepCode = null
            formModel.headCode = null
            updateSchema({
              field: 'headCode',
              componentProps: {
                onclick: (e:any) => {
                  if(!formModel.headDepCode){
                    message.warn("请先选择执行部门！")
                    return
                 }
                }
              },
            });
            return
          }
          if(formModel.headDepCode!=e[0]){
            formModel.headCode = null
          }
          updateSchema({
            field: 'headCode',
            componentProps: {
              dict: "listDuty",
              depCode: e[0],
              onclick: (e:any) => {
                if(!formModel.headDepCode){
                  message.warn("请先选择执行部门！")
                  return
                }
              }
            },
          });
        }
      }
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '负责人',
    field: 'headCode',
    component: 'JSearchSelectDuty',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "listDuty",
        onclick: (e:any) => {
          if(!formModel.headDepCode){
            formModel.headCode = null
             message.warn("请先选择执行部门！")
             return
          }
       }
      }
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '是否接收',
    field: 'isReceive',
    component: 'JSearchSelect',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "isReceive",
        onChange: (e: any) => {
          const { updateSchema,clearValidate } = formActionType;
          if("1" == e){
            updateSchema({
              label: '整改策略',
              field: 'strategy',
              component: 'JSearchSelect',
              componentProps:{
                dict: "programme"
              },
              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: '请选择整改策略!'},
                ];
              }
            })
            updateSchema({
              label: '整改方案',
              field: 'programme',
              component: 'InputTextArea',
              itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
              componentProps: {
                rows: 5
              }
            })
          }else{
            updateSchema({
              label: '整改策略',
              field: 'strategy',
              component: 'JSearchSelect',
              componentProps:{
                dict: "programme"
              },
              colProps: {lg: 12},
              itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
            })
            updateSchema({
              label: '整改方案',
              field: 'programme',
              component: 'InputTextArea',
              itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
              componentProps: {
                rows: 5
              }
            })
          }
        }
      }
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '整改策略',
    field: 'strategy',
    component: 'JSearchSelect',
    componentProps:{
      dict: "programme"
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '整改方案',
    field: 'programme',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    componentProps: {
      rows: 5
    }
  },
	// TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'assinStatus',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'receiveStatus',
    component: 'Input',
	  show: false
  },
  {
    label: '',
    field: 'problemSourceFlag',
    component: 'Input',
	  show: false
  },
  {
	  label: '',
	  field: 'pid',
	  component: 'Input',
	  show: false
	},
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
]

export const formSchemaBatchFp : FormSchema[] = [
  {
	  label: '',
	  field: 'ids',
	  component: 'Input',
	  show: false
	},
  {
    label: '负责部门',
    field: 'headDepCode',
    component: 'JSelectDept',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            formModel.headDepCode = null
            formModel.headCode = null
            updateSchema({
              field: 'headCode',
              componentProps: {
                onclick: (e:any) => {
                  if(!formModel.headDepCode){
                    message.warn("请先选择执行部门！")
                    return
                 }
                }
              },
            });
            return
          }
          if(formModel.headDepCode!=e[0]){
            formModel.headCode = null
          }
          updateSchema({
            field: 'headCode',
            componentProps: {
              dict: "listDuty",
              depCode: e[0],
              onclick: (e:any) => {
                if(!formModel.headDepCode){
                  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: 'headCode',
    component: 'JSearchSelectDuty',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "listDuty",
        onclick: (e:any) => {
          if(!formModel.headDepCode){
            formModel.headCode = 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: '请选择负责人!'},
      ];
    },
  },
]

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