import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getAllRolesList, queryUserByDepId } from '/@/views/system/user/user.api';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '报表名称',
    align: 'left',
    dataIndex: 'name',
    width: "20%",
    resizable:true
  },
  {
    title: '报表类型',
    align: 'left',
    dataIndex: 'tp',
    customRender: ({ text }) => {
      return render.renderDict(text, 'report_tp');
    },
    width: "7%",
    resizable:true
  },
  {
    title: '填报角色',
    align: 'left',
    dataIndex: 'enterRole',
    width:0,
    ifShow: false,
    resizable:true
  },
  {
    title: '负责人',
    align: 'left',
    dataIndex: 'respUser_dictText',
    width: "7%",
    resizable:true
  },
  {
    title: '联系电话',
    align: 'left',
    dataIndex: 'enterTel',
    width: "9%",
    resizable:true
  },
  {
    title: '截至日期',
    align: 'left',
    dataIndex: 'enterDate',
    customRender: ({ text }) => {
      return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
    },
    width: "9%",
    resizable:true
  },
  {
    title: '开始日期',
    align: 'center',
    dataIndex: 'startDate',
    customRender: ({ text }) => {
      return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
    },

    ifShow: false,
    resizable:true
  },
  {
    title: '结束日期',
    align: 'center',
    dataIndex: 'endDate',
    customRender: ({ text }) => {
      return !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
    },
    ifShow: false,
    resizable:true
  },
  {
    title: '报告状态',
    align: 'left',
    dataIndex: 'staText',
    ifShow: true,
    width: "8%",
    resizable:true
    // customRender: ({ text }) => {
    //   return render.renderDict(text, 'fxc_report_sta');
    // },
  },
  {
    title: '已分配数',
    align: 'left',
    dataIndex: 'allocNum',
    ifShow: true,
    width: "6%",
    resizable:true
  },
  {
    title: '总节点',
    align: 'left',
    dataIndex: 'tplItemNum',
    ifShow: true,
    width: "6%",
    resizable:true
  },
  {
    title: '填报数',
    align: 'left',
    dataIndex: 'fillStaNum',
    ifShow: true,
    width: "6%",
    resizable:true
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '报表名称',
    field: 'name',
    component: 'Input',
    // helpMessage: '前后输入*号可以实现模糊查询',
  },{

  //   label: '状态',
  //   field: 'sta',
  //   component: 'JDictSelectTag',
  //   componentProps: {
  //     dictCode: 'fxc_report_sta',
  //     placeholder: '选择状态',
  //   },
  // },
  // {
    label: '报表类型',
    field: 'tp',
    component: 'JDictSelectTag',
    colProps: { lg: 5 },
    // itemProps:{labelCol:{xs: {span: 24},sm: {span: 12},},wrapperCol:{xs: {span: 24},sm: {span: 16},}},
    componentProps: {
      dictCode: 'report_tp',
      placeholder: '请选择',
      stringToNumber: true,
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '报表名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
  {
    label: '报表类型',
    field: 'tp',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'report_tp',
      placeholder: '请选择',
      stringToNumber: true,
    },
    required: true,
  },
  {
    label: '填报角色',
    field: 'enterRole',
    component: 'ApiSelect',
    componentProps: {
      mode: 'radio',
      api: getAllRolesList,
      labelField: 'roleName',
      valueField: 'id',
    },
    required: true,
  },

  {
    label: '填报部门',
    field: 'respDepart',
    required: true,
    component: 'JSelectDept',
    componentProps: ({ formActionType, formModel }) => {
   
      return {
        sync: false,
        checkStrictly: true,
        defaultExpandLevel: 2,
        multiple:false,
        onSelect: async (options, values) => {
      
          const depId = values.value[0]
          if(depId.length==32){
            const users = await queryUserByDepId({id:depId});
            const newArray = users.map(user => ({
              label: user.realname,
              value: user.id
            }));
            const { updateSchema } = formActionType;
            updateSchema([
              {
                field: 'respUser',
                componentProps: { options: newArray },
              },
            ]);
          }
        },
      };
    },
  },
  {
    label: '负责人',
    field: 'respUser',
    component: 'Select',
    componentProps: {
      options:[]
    },
    required: false,
  },

  {
    label: '联系电话',
    field: 'enterTel',
    component: 'Input',
    required: false,
  },
  {
    label: '填报日期',
    field: 'enterDate',
    component: 'DatePicker',
    required: false,
  },

  {
    label: '开始日期',
    field: 'startDate',
    component: 'DatePicker',
    required: false,
  },
  {
    label: '结束日期',
    field: 'endDate',
    component: 'DatePicker',
    required: false,
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];


//表单数据
export const formImportDataSchema: FormSchema[] = [
  {
    label: 'XML目录',
    field: 'folderPath',
    component: 'Input',
    required: true,
  },
]

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