import { message } from 'ant-design-vue';
import { BasicColumn, FormSchema } from '/@/components/Table';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '项目名称',
    align:"center",
    dataIndex: 'projectName',
    width:150
   },
   {
    title: '项目类型',
    align:"center",
    dataIndex: 'projectTypeName',
    width:150
   },
   {
    title: '执行部门',
    align:"center",
    dataIndex: 'execDepName',
    width:100
   },
   {
    title: '负责人',
    align:"center",
    dataIndex: 'headName',
    width:100
   },
   {
    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: 'statusName',
    width:100
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "项目名称",
      field: 'projectName',
      component: 'Input',
      colProps: {span: 6},
 	},
	{
      label: "项目类型",
      field: 'projectType',
      component: 'Input',
      colProps: {span: 6},
 	},
	{
      label: "执行部门",
      field: 'execDepCode',
      component: 'Input',
      colProps: {span: 6},
 	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '项目名称',
    field: 'projectName',
    component: 'Input',
    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: 'projectType',
    component: 'JSearchSelect',
    componentProps:{
      dict: "projecttype"
    },
    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: 'execDepCode',
    component: 'JSelectDept',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        multiple: false,
        allowClear: false,
        onChange: (e: any) => {
          const { updateSchema } = formActionType;
          if(e === undefined||e===''){
            formModel.execDepCode = null
            formModel.headCode = null
            updateSchema({
              field: 'headCode',
              componentProps: {
                onclick: (e:any) => {
                  if(!formModel.execDepCode){
                    message.warn("请先选择执行部门！")
                    return
                 }
                }
              },
            });
            return
          }
          if(formModel.execDepCode!=e[0]){
            formModel.headCode = null
          }
          updateSchema({
            field: 'headCode',
            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: ({model,schema}) => {
      return [
             { required: true, message: '请选择执行部门!'},
      ];
    },
  },
  {
    label: '负责人',
    field: 'headCode',
    component: 'JSearchSelectDuty',
    componentProps: ({ schema, tableAction, formActionType, formModel }) => {
      return {
        dict: "listDuty",
        onclick: (e:any) => {
          if(!formModel.execDepCode){
            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: 'planStartDate',
    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: '请选择计划开始日期!'},
      ];
    },
  },
  {
    label: '计划结束日期',
    field: 'planEndDate',
    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: '请选择计划结束日期!'},
      ];
    },
  },
  {
    label: '审核部门',
    field: 'approveDepCode',
    component: 'JSelectDept',
    componentProps: ({ schema, tableAction, 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: {
                dict: "listDuty",
                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
                }
              }
            },
          });
        }
      }
    },
    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: 'approveUser',
    component: 'JSearchSelectDuty',
    componentProps: ({ schema, tableAction, formActionType, 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: ({model,schema}) => {
      return [
             { required: true, message: '请选择审核人!'},
      ];
    },
  },
  {
    label: '项目描述',
    field: 'projectDesc',
    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: '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..."},
  },
  {
    label: '变更原因',
    field: 'optDes',
    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: 'approveDes',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    show: false,
    componentProps: {
      rows: 5
    }
  },
  {
	  label: '',
	  field: 'planCode',
	  component: 'Input',
	  show: false
	},
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];



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