export interface IListQuery {
  supplierNo: string
  supplierName: string
  director: string
  supplierType: string
  createTimeStart: string
  createTimeEnd: string
  approvalStatus: string
  formId: string
  offset: number
  limit: number
  sort?: string
  order?: string
}

export interface IDictType {
  name: string
  id: string
  value: string
}

export interface ITableColumn {
  text: string // 标题
  value: string // 值
  align?: 'left' | 'center' | 'right' // 排列
  width?: string | number // 宽度,px值
  show?: boolean // 是否显示列
  showOverflow?: boolean // 是否溢出为省略号
  filter?: Function // 字段过滤器
  styleFilter?: Function // 文字过滤器
  fixed?: boolean // 固定列
  filters?: { text: string; value: string }[] // 列筛选
  isFilters?: boolean // 是否有列筛选
  required?: boolean // 是否必填
}

export interface ISupplierInfo {
  id: string
  supplierNo: string
  supplierName: string
  briefName?: string
  supplierType: string
  supplierTypeName: string
  taxNumber?: string
  bankAccount?: string
  bankName?: string
  bankAccountNumber?: string
  postalCode?: string
  director?: string
  phone: string
  fax?: string
  mailbox?: string
  website?: string
  companyAddress?: string
  supplierContent: string
  remark?: string
  minioFileName?: string
  approvalStatus?: string
  approvalStatusName?: string
  processId?: string
  taskId?: string
  createUserId?: number
  createUserName?: string
  createTime?: string
  decisionItem?: number
}

export interface ISupplierInfoStaff {
  id: string
  supplierId: string
  name: string
  department: string
  job?: string
  phone?: string
  editable: boolean
}

// 验证手机
export const phoneValidator = (rule: any, value: string, callback: any) => {
  const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  if (reg.test(value.trim()) === true || value.trim() === '') {
    callback()
  }
  else {
    callback(new Error('验证失败'))
  }
}

export const phoneReg = (val: string) => {
  const reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  return reg.test(val)
}

// 邮编校验
export const postalCodeValidator = (rule: any, value: string, callback: any) => {
  const reg = /^[0-9]{6}$/
  if (reg.test(value.trim()) === true || value.trim() === '') {
    callback()
  }
  else {
    callback(new Error('验证失败'))
  }
}

// 邮箱校验
export const mailboxValidator = (rule: any, value: string, callback: any) => {
  const reg = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/
  if (reg.test(value.trim()) === true || value.trim() === '') {
    callback()
  }
  else {
    callback(new Error('邮箱校验失败'))
  }
}

// 网址校验
export const websiteValidator = (rule: any, value: string, callback: any) => {
  const reg = /^(http|https):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/\S*)?$/
  if (reg.test(value.trim()) === true || value.trim() === '') {
    callback()
  }
  else {
    callback(new Error('网址校验失败'))
  }
}
