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: 'projectName',
    width:150
   },
   {
    title: '项目类型',
    align:"left",
    dataIndex: 'projectType',
    customRender:({text}) =>{
      return render.renderDict(text, 'projecttype')
    },
    width:100
   },
   {
    title: '执行部门',
    align:"left",
    dataIndex: 'execDepName',
    width:100
   },
   {
    title: '负责人',
    align:"left",
    dataIndex: 'headName',
    width:100
   },
   {
    title: '归档部门',
    align:"center",
    dataIndex: 'recordDepName',
    width:100
   },
   {
    title: '归档人',
    align:"center",
    dataIndex: 'recordName',
    width:100
   },
   {
    title: '归档日期',
    align:"center",
    dataIndex: 'recordDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
    width:130
   },
   {
    title: '归档状态',
    align:"center",
    dataIndex: 'recordFlag',
    customRender:({text}) =>{
      const color =  text == '1' ?"red":"green";
      const temptext =  text == '1' ?"待归档":"已归档";
      return render.renderTag(temptext, color);

    },
    width:100
   },
  
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '项目名称',
    field: 'projectName',
    component: 'Input',
  },
  {
    label: '项目类型',
    field: 'projectType',
    component: 'JSearchSelect',
    componentProps:{
      dict: "projecttype"
    },
    colProps: {lg: 5},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},  },
    {
      label: '执行部门',
      field: 'execDepCode',
      component: 'JSelectDept',
    },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '项目名称',
    field: 'projectName',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,

    component: 'Input',
  },
  {
    label: '项目类型',
    field: 'projectType',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,
    component: 'Input',
  },
  {
    label: '执行部门',
    field: 'execDepName',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,

    component: 'Input',
  },
  {
    label: '负责人',
    field: 'headName',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicDisabled: true,

    component: 'Input',
  },
  {
    label: '开始日期',
    field: 'planStartDate',
    dynamicDisabled: true,
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    component: 'DatePicker',
  },
  {
    label: '结束日期',
    field: 'planEndDate',
    dynamicDisabled: true,
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    component: 'DatePicker'
  },
  {
    label: '项目描述',
    field: 'projectDesc',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    component: 'InputTextArea'
  },
  {
    label: '归档部门',
    field: 'recordDepCode',
    component: 'JSelectDept',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            formModel.recordDepCode = null
            formModel.recordUser = null
            updateSchema({
              field: 'recordUser',
              componentProps: {
                onclick: (e:any) => {
                  if(!formModel.recordDepCode){
                    //message.warn("请先选择归档部门！")
                    return
                 }
                }
              },
            });
            return
          }
          if(formModel.recordDepCode!=e[0]){
            formModel.recordUser = null
          }
          updateSchema({
            field: 'recordUser',
            componentProps: {
              dict: "listDuty",
              depCode: e[0],
              onclick: (e:any) => {
                if(!formModel.recordDepCode){
                  //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===undefined||values.showFooter){
        return [
          { required: true, message: '请选择归档部门'},
        ];
      }
      return [];
    },
  },
  {
    label: '归档人',
    field: 'recordUser',
    component: 'JSearchSelectDuty',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "listDuty",
        onclick: (e:any) => {
          if(!formModel.recordDepCode){
            formModel.recordUser = 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===undefined||values.showFooter){
        return [
          { required: true, message: '请选择归档人'},
        ];
      }
      return [];
    },
  },
  {
    label: '归档日期',
    field: 'recordDate',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    component: 'DatePicker',
    dynamicRules: ({values}) => {
      if(values.showFooter===undefined||values.showFooter){
        return [
          { required: true, message: '请选择归档日期'},
        ];
      }
      return [];
    },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
  {
	  label: '',
	  field: 'projectCreId',
	  component: 'Input',
	  show: false
	},
  {
	  label: '',
	  field: 'showFooter',
	  component: 'Input',
	  show: false
	},
];



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