import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { message } from 'ant-design-vue';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '问题项',
    align:"center",
    dataIndex: 'problemItem',
    width:150
   },
   {
    title: '整改策略',
    align:"center",
    dataIndex: 'strategy',
    customRender:({text}) =>{
      let m = {"0001":"立即整改","0002":"短期整改","0003":"长期整改"}
      return m[text]
    },
    width:150
   },
   {
    title: '整改方案',
    align:"center",
    dataIndex: 'programme',
    width:150
   },
   {
    title: '计划开始日期',
    align:"center",
    dataIndex: 'planStartDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
    width:130
   },
   {
    title: '计划结束日期',
    align:"center",
    dataIndex: 'planEndDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
    width:130
   },
   {
    title: '执行部门',
    align:"center",
    dataIndex: 'execDepName',
    width:100
   },
   {
    title: '执行人',
    align:"center",
    dataIndex: 'execUserName',
    width:100
   },
   {
    title: '编制状态',
    align:"center",
    dataIndex: 'editFlag',
    customRender:({text}) =>{
      let m = {"0":"未编制","1":"已编制"}
      return m[text]
    },
    width:100
   }
];
//查询数据
export const searchFormSchema: FormSchema[] = [

  {
    label: "问题项",
    field: 'problemItem',
    component: 'Input',
    colProps: {span: 5},
 },
 {
  label: '整改策略',
  field: 'strategy',
  component: 'JSearchSelect',
  componentProps:{
    dict: "programme"
  },
  colProps: {lg: 5},
  itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
},
{
    label: "编制状态",
    field: 'editFlag',
    component: 'JSearchSelect',
    componentProps:{
      dict: "editFlag"
    },
    colProps: {span: 5},
 },
];
//表单数据
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: 'programme',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    dynamicDisabled: true,
    componentProps: {
      rows: 5
    }
  },
  {
    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},}},
    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: 'execDepCode',
    component: 'JSelectDept',
    componentProps: ({ formActionType, formModel }) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            //formModel.execDepCode = null
            formModel.execUser = null
            updateSchema({
              field: 'execUser',
              componentProps: {
                onclick: (e:any) => {
                  if(!formModel.execDepCode){
                    message.warn('请先选择执行部门！')
                    return
                 }
                }
              },
            });
            return
          }
          if(formModel.execDepCode!=e[0]){
            formModel.execUser = null
          }
          updateSchema({
            field: 'execUser',
            componentProps: {
              dict: "listDuty",
              depCode: e[0],
              onclick: (e:any) => {
                if(!formModel.execDepCode){
                  message.warn('请先选择执行部门')
                  return
                }
              }
            },
          });
        }
      }
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({values}) => {
      if(values.showFooter){        
        return [        
             { required: true, message: '请选择执行部门'},
        ];
      }
      return [];
    },
  },
  {
    label: '执行人',
    field: 'execUser',
    component: 'JSearchSelectDuty',
    componentProps: ({  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: ({values}) => {
      if(values.showFooter){        
        return [        
             { required: true, message: '请选择执行人'},
        ];
      }
      return [];
    },
  },
  {
    label: '审核部门',
    field: 'approveDepCode',
    component: 'JSelectDept',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({values}) => {
      if(values.showFooter){        
        return [        
             { required: true, message: '请选择审核部门'},
        ];
      }
      return [];
    },
    componentProps: ({ formActionType, formModel}) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            //formModel.approveDepCode = null
            formModel.approveUser = null
            updateSchema({
              field: 'approveUser',
              componentProps: {
                onclick: (e:any) => {
                  if(!formModel.approveDepCode){
                    //message.warn('请先选择审核部门')
                    return
                 }
                }
              },
            });
            return
          }
          if(formModel.approveDepCode!=e[0]){
            formModel.approveUser = null
          }
          updateSchema({
            field: 'approveUser',
            componentProps: {
              dict: "listDuty",
              depCode: e[0],
              onclick: (e:any) => {
                if(!formModel.approveDepCode){
                 //message.warn('请先选择审核部门')
                  return
                }
              }
            },
          });
        }
      }
    },
  },
  {
    label: '审核人',
    field: 'approveUser',
    component: 'JSearchSelectDuty',
    componentProps: ({formModel}) => {
      return {
        dict: "listDuty",
        onclick: (e:any) => {
          if(!formModel.approveDepCode){
            formModel.approveUser = null;
            // message.warn("请先选择执行部门！");
             return;
          }
       }
      }
    },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({values}) => {
      if(values.showFooter){        
        return [        
             { required: true, message: '请选择审核人'},
        ];
      }
      return [];
    },
  },
  {
    label: '计划开始日期',
    field: 'planStartDate',
    component: 'DatePicker',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({values}) => {
      if(values.showFooter){        
        return [        
             { required: true, message: '请选择计划开始日期'},
        ];
      }
      return [];
    },
  },  {
    label: '计划结束日期',
    field: 'planEndDate',
    component: 'DatePicker',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({values}) => {
      if(values.showFooter){        
        return [        
             { required: true, message: '请选择计划结束日期'},
        ];
      }
      return [];
    },
  },
  
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
  {
	  label: '',
	  field: 'problemTaskId',
	  component: 'Input',
	  show: false
	},
  {
    label: '',
    field: 'showFooter',
    component: 'Input',
    show: false,
  },
];



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