import { DICT_TYPE } from '@/utils/dict'

export interface ConstructionDailyReportRow {
  id?: number
  deptId?: number
  projectId?: number
  taskId?: number
  status?: number
  auditStatus?: number
  createTime?: number | string
  deptName?: string
  projectName?: string
  location?: string
  mainDeviceNum?: number | null
  wellName?: string
  wokDeviceNum?: number | null
  fiveStatusLabel?: string
  dailyWorkingLayers?: number | null
  dailySandVolume?: number | null
  dailyLiquidVolume?: number | null
  jingshu?: number | null
  cengshu?: number | null
  dailyFuel?: number | null
  nonProductionTime?: number | null
  accidentTime?: number | null
  repairTime?: number | null
  selfStopTime?: number | null
  complexityTime?: number | null
  relocationTime?: number | null
  rectificationTime?: number | null
  waitingStopTime?: number | null
  winterBreakTime?: number | null
  partyaDesign?: number | null
  partyaPrepare?: number | null
  partyaResource?: number | null
  otherNptTime?: number | null
  otherNptReason?: string
  nptReason?: string
  singleWellWorkload?: number | string | null
  productionStatus?: string
  planWorkingLayers?: number | null
  weather?: string
  temperature?: string
  deviceNames?: string
  customer?: string
  reportName?: string
  constructionEndDate?: string | number
  constructionStartDate?: string | number
  monthWorkingLayers?: number | null
  monthWorkingWells?: number | null
  fiveStatus?: string
}

export interface ConstructionDailyReportQuery {
  pageNo: number
  pageSize: number
  deptId?: number
  projectDeptId?: number
  teamId?: number
  projectName?: string
  wellName?: string
  createTime?: string[]
}

export interface ConstructionDailyReportField {
  prop: keyof ConstructionDailyReportRow
  label: string
  type?: 'text' | 'number' | 'textarea' | 'select'
  span?: 1 | 2
  precision?: number
  suffix?: string
  editableInEdit?: boolean
  dictType?: string
}

export interface ConstructionDailyReportSection {
  title: string
  columns?: 2 | 3
  fields: ConstructionDailyReportField[]
}

export interface ConstructionDailyReportTableColumnLeaf {
  prop: keyof ConstructionDailyReportRow
  label: string
  width?: number
  minWidth?: number
  fixed?: 'left' | 'right'
}

export interface ConstructionDailyReportTableColumnGroup {
  label: string
  children: ConstructionDailyReportTableColumnLeaf[]
}

export type ConstructionDailyReportTableColumn =
  | ConstructionDailyReportTableColumnLeaf
  | ConstructionDailyReportTableColumnGroup

export const tableColumns: ConstructionDailyReportTableColumn[] = [
  { prop: 'reportName', label: '日报名称', minWidth: 180, fixed: 'left' },
  { prop: 'createTime', label: '创建日期', width: 120 },
  { prop: 'projectName', label: '项目', minWidth: 160, fixed: 'left' },
  { prop: 'location', label: '施工区域', minWidth: 140 },
  { prop: 'deptName', label: '队伍', minWidth: 140 },
  { prop: 'mainDeviceNum', label: '主设备(泵车)数量', width: 130 },
  { prop: 'wellName', label: '生产任务', minWidth: 140 },
  { prop: 'wokDeviceNum', label: '作业泵车数量', width: 120 },
  { prop: 'fiveStatusLabel', label: '队伍状态', minWidth: 120 },
  { prop: 'dailyWorkingLayers', label: '当日主压层数', width: 120 },
  { prop: 'dailySandVolume', label: '当日加砂量(吨)', width: 130 },
  { prop: 'dailyLiquidVolume', label: '当日注液量(方)', width: 130 },
  { prop: 'monthWorkingWells', label: '当月作业井数', width: 120 },
  { prop: 'monthWorkingLayers', label: '当月作业层数', width: 120 },
  { prop: 'dailyFuel', label: '当日油耗(L)', width: 110 },
  {
    label: '非生产时间',
    children: [
      { prop: 'accidentTime', label: '工程质量', width: 110 },
      { prop: 'repairTime', label: '设备故障', width: 110 },
      { prop: 'selfStopTime', label: '设备保养', width: 110 },
      { prop: 'complexityTime', label: '技术受限', width: 110 },
      { prop: 'relocationTime', label: '生产配合', width: 110 },
      { prop: 'rectificationTime', label: '生产组织', width: 110 },
      { prop: 'waitingStopTime', label: '不可抗力', width: 110 },
      { prop: 'winterBreakTime', label: '待命', width: 110 },
      { prop: 'partyaDesign', label: '甲方设计', width: 110 },
      { prop: 'partyaPrepare', label: '甲方准备', width: 110 },
      { prop: 'partyaResource', label: '甲方资源', width: 110 },
      { prop: 'otherNptTime', label: '其它非生产时间', width: 130 }
    ]
  },
  { prop: 'otherNptReason', label: '其它非生产时间原因', minWidth: 180 },
  // { prop: 'nptReason', label: '造成非生产时间原因', minWidth: 180 },
  { prop: 'singleWellWorkload', label: '单井工作量', width: 120 },
  { prop: 'productionStatus', label: '施工动态', minWidth: 180 },
  { prop: 'planWorkingLayers', label: '本月计划层数', width: 120 },
  { prop: 'weather', label: '天气', width: 100 },
  { prop: 'temperature', label: '气温(℃)', width: 100 },
  { prop: 'deviceNames', label: '设备名称', minWidth: 180 },
  { prop: 'customer', label: '合同甲方', minWidth: 140 }
]

export const formSections: ConstructionDailyReportSection[] = [
  {
    title: '基础信息',
    fields: [
      { prop: 'reportName', label: '日报名称' },
      { prop: 'projectName', label: '项目' },
      { prop: 'location', label: '施工区域' },
      { prop: 'deptName', label: '队伍' },
      { prop: 'wellName', label: '生产任务' },
      { prop: 'customer', label: '合同甲方' },
      { prop: 'deviceNames', label: '设备名称', span: 2 }
    ]
  },
  {
    title: '生产数据',
    fields: [
      { prop: 'mainDeviceNum', label: '主设备数量', type: 'number', editableInEdit: true },
      { prop: 'wokDeviceNum', label: '作业泵车数量', type: 'number', editableInEdit: true },
      {
        prop: 'fiveStatus',
        label: '队伍状态',
        type: 'select',
        editableInEdit: true,
        dictType: DICT_TYPE.PMS_PROJECT_RD_STATUS
      },
      {
        prop: 'dailyWorkingLayers',
        label: '当日主压层数',
        type: 'number',
        editableInEdit: true
      },
      {
        prop: 'dailySandVolume',
        label: '当日加砂量(吨)',
        type: 'number',
        editableInEdit: true
      },
      {
        prop: 'dailyLiquidVolume',
        label: '当日注液量(方)',
        type: 'number',
        editableInEdit: true
      },
      { prop: 'monthWorkingWells', label: '当月作业井数', type: 'number' },
      { prop: 'monthWorkingLayers', label: '当月作业层数', type: 'number' },
      {
        prop: 'dailyFuel',
        label: '当日油耗(L)',
        type: 'number',
        editableInEdit: true
      },
      { prop: 'singleWellWorkload', label: '单井工作量', editableInEdit: true },
      { prop: 'planWorkingLayers', label: '本月计划层数', type: 'number' }
    ]
  },
  {
    title: '现场说明',
    fields: [
      // {
      //   prop: 'nptReason',
      //   label: '造成非生产时间原因',
      //   type: 'textarea',
      //   span: 2,
      //   editableInEdit: true
      // },
      {
        prop: 'productionStatus',
        label: '施工动态',
        type: 'textarea',
        span: 2,
        editableInEdit: true
      },
      { prop: 'weather', label: '天气', editableInEdit: true },
      { prop: 'temperature', label: '气温(℃)', editableInEdit: true }
    ]
  },
  {
    title: '非生产时间',
    columns: 3,
    fields: [
      {
        prop: 'accidentTime',
        label: '工程质量',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'repairTime',
        label: '设备故障',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'selfStopTime',
        label: '设备保养',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'complexityTime',
        label: '技术受限',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'relocationTime',
        label: '生产配合',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'rectificationTime',
        label: '生产组织',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'waitingStopTime',
        label: '不可抗力',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'winterBreakTime',
        label: '待命',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'partyaDesign',
        label: '甲方设计',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'partyaPrepare',
        label: '甲方准备',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'partyaResource',
        label: '甲方资源',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'otherNptTime',
        label: '其它非生产时间',
        type: 'number',
        suffix: '小时（H）',
        editableInEdit: true
      },
      {
        prop: 'otherNptReason',
        label: '其它非生产时间原因',
        type: 'textarea',
        span: 2,
        editableInEdit: true
      }
    ]
  }
]

export function createEmptyConstructionDailyReport(): ConstructionDailyReportRow {
  return {
    mainDeviceNum: null,
    wokDeviceNum: null,
    dailyWorkingLayers: null,
    dailySandVolume: null,
    dailyLiquidVolume: null,
    jingshu: null,
    cengshu: null,
    dailyFuel: null,
    nonProductionTime: null,
    accidentTime: null,
    repairTime: null,
    selfStopTime: null,
    complexityTime: null,
    relocationTime: null,
    rectificationTime: null,
    waitingStopTime: null,
    winterBreakTime: null,
    partyaDesign: null,
    partyaPrepare: null,
    partyaResource: null,
    otherNptTime: null,
    otherNptReason: '',
    singleWellWorkload: null,
    planWorkingLayers: null
  }
}
