// 通用的一些 数据 和类型
import { FileListType } from '@/components/Z3upFiles/data'
import { getDictFu, selectObj } from '@/utils/dataChange'

// 列表字段
export const baseFormData = (can?: { [x: string]: string }) => {
  const obj: any = {
    pageSize: 10,
    pageNum: 1,

    businessStartTime: '',
    businessEndTime: '',
    searchKey: '',
    startTime: '',
    endTime: '',
    status: ''
  }
  // 修改给后端的字段
  if (can) {
    for (const key in can) {
      if (obj[key] !== undefined) {
        obj[can[key]] = obj[key]
        delete obj[key]
      }
    }
  }
  return obj
}

// 顶部筛选
export const topSearch = (txt: string, can?: { [x: number]: string | string[] }) => {
  // const txtObj = {
  //   征集: '或线索名称',
  //   登记: '、藏品编号或名称',
  //   入馆: '、藏品编号或名称'
  // }
  // const txt2Res = Reflect.get(txtObj, txt)

  const txt2Res = txt === '征集' ? '或线索名称' : '、藏品编号或名称'

  const canArr = [
    ['businessStartTime', 'businessEndTime'],
    'searchKey',
    ['startTime', 'endTime'],
    'status'
  ]

  // 修改给后端的字段
  if (can) {
    for (const key in can) {
      canArr[key] = can[key]
    }
  }

  return [
    {
      type: 'time',
      key: canArr[0],
      placeholder: [`${txt}日期开始`, `${txt}日期结束`]
    },
    {
      type: 'input',
      key: canArr[1],
      placeholder: `请输入申请编号、发起人${txt2Res}`
    },
    {
      type: 'time',
      key: canArr[2],
      placeholder: ['发起日期开始', '发起日期结束']
    },
    {
      type: 'select',
      key: canArr[3],
      placeholder: '申请状态',
      options: selectObj['订单审批状态'],
      style: { width: 200 }
    }
  ]
}

// 查看页面顶部字段 通用部分
export const rowArrTemp = (txt: string, can?: { [x: number]: string }, txt2?: string) => {
  const canArr = ['date', 'num', 'dictIdApply', 'reason', 'remark']

  if (can) {
    for (const key in can) {
      canArr[key] = can[key]
    }
  }

  return [
    {
      name: `藏品${txt}`,
      type: 'txt'
    },
    {
      name: `${txt}日期`,
      must: true,
      key: canArr[0],
      type: 'DatePicker'
    },
    {
      name: '申请编号',
      must: true,
      key: canArr[1],
      type: 'Input',
      noNull: true //不允许输入空格
    },
    {
      name: '申请类型',
      key: canArr[2],
      type: 'Cascader',
      options: getDictFu(txt2 ? txt2 : `藏品${txt}`)
    },
    {
      name: '事由说明',
      full: true,
      key: canArr[3],
      type: 'TextArea'
    },
    {
      name: '备注',
      full: true,
      key: canArr[4],
      type: 'TextArea'
    }
  ]
}

export type TypetableAuditList = {
  auditTime?: any
  auditorId?: any
  auditorName?: any
  createTime: string
  creatorId: number
  creatorName: string
  flowId: number
  handler?: any
  id: number
  isAuto: number
  isUse: number
  moduleIds?: any
  name: string
  orderId: number
  processId: number
  rtfOpinion?: any
  sort: number
  status: number
  type?: any
  updateTime: string
}
// 列表type
export type Typetable = {
  auditUserIds: string
  audits: TypetableAuditList[]
  createTime: string
  creatorId: number
  creatorName: string
  currentAuditUserIds: string
  currentProcessId: number
  date: string
  dictIdApply?: any
  fileIds?: any
  files: FileListType[]
  files2: FileListType[]
  goodIds: string
  id: number
  nodeProcessId: number
  num: string
  reason: string
  remark: string
  snapName?: any
  snapNum?: any
  snaps: any[]
  status: number
  type: string
  updateTime: string
  deptName: string

  // 藏品鉴定
  member: string

  // 库房列表
  name: string

  // 附件归档
  filing: FileListType[]
}

// 上传的附近路径和文件夹名字
export type FileUpInfoType = {
  myUrl: string
  dirCode: string
}
