import { selectObj } from '@/utils/select'
import { C2InputKeyType, TypeC2Form } from './type'
import { TypeZ1dict } from '@/pages/Z_system/Z1dict/type'
import store from '@/store'
import { cascaderArr } from '../C1register/AddGoods/data'

export const C2baseFormData: TypeC2Form = {
  goodNumName: '',
  goodNum: '',
  goodName: '',
  fileName: '',
  effect: '',
  creatorName: '',
  startTime: '',
  endTime: '',
  pageNum: 1,
  pageSize: 10
}

// 级联数据平铺
let dictAll: TypeZ1dict[] = []

export const cascaderFu = (val: string) => {
  if (dictAll && dictAll.length === 0) {
    dictAll = store.getState().Z1dict.dictAll
  }

  let obj: any = {}
  if (dictAll && dictAll.length) {
    obj = cascaderArr(dictAll)
  }
  return obj[val]
}

export const C2InputKeyArr: {
  name: string
  key: C2InputKeyType
  type: '输入框' | '下拉框' | '级联'
  data?: any[]
}[] = [
  { name: '编号类型', key: 'goodNumName', type: '下拉框', data: selectObj['藏品编号类型'] },
  { name: '藏品编号', key: 'goodNum', type: '输入框' },
  { name: '藏品名称', key: 'goodName', type: '输入框' },
  { name: '附件名称', key: 'fileName', type: '输入框' },
  { name: '用途', key: 'effect', type: '级联', data: cascaderFu('附件用途') },
  { name: '上传人', key: 'creatorName', type: '输入框' }
]
