import {
  startStatus,
  frozenState,
  deviceState
} from '@/assets/js/blockSort'

export const incubator = () => {
  return [{
    field: 'selection',
    label: '多选',
    align: 'center',
  }, {
    field: 'T_devName',
    label: '名称',
    align: 'center',
  }]
}

export const employee = () => {
  return [{
    field: 'index',
    label: '序号',
    align: 'center',
  }, {
    field: 'name',
    label: '名称',
    align: 'center',
  }, {
    field: 'sn',
    label: 'SN',
    align: 'center',
  }, {
    field: 'status',
    label: '状态',
    align: 'center',
    options: startStatus()
  }, {
    field: 'monitorStatus',
    label: '监控状态',
    align: 'center',
    options: deviceState()
  }, {
    field: 'cold_temperatures',
    label: '预冷温度(℃)',
    align: 'center',
  }, {
    field: 'cold_spots',
    label: '预冷地点',
    align: 'center',
  }, {
    field: 'for_cold_cooler_time',
    label: '预冷要求',
    align: 'center',
  }, {
    field: 'deviceData.T_t',
    label: '最新温度',
    align: 'center',
  }, {
    field: 'deviceData.T_time',
    label: '最新记录时间',
    align: 'center',
  }, {
    field: 'action',
    label: '操作',
    align: 'center',
    colWidth: '350px',
    labelButton: [{
      type: 'record',
      label: '温湿度记录',
      icon: 'el-icon-s-order',
      style: 'primary',
    }, {
      type: 'logs',
      label: '详情',
      icon: 'el-icon-tickets',
      style: 'success',
    }, {
      type: 'edit',
      label: '编辑',
      icon: 'el-icon-edit',
      style: 'primary',
    }, {
      type: 'del',
      label: '删除',
      icon: 'el-icon-delete',
      style: 'danger',
    }]
  }]
}

export const formRules = () => {
  return [{
    field: 'name',
    label: '名称',
    placeholder: '请输入名称',
    type: 'input',
    colWidth: 24,
    rules: [{
      required: true,
      message: '请输入名称',
      trigger: 'blur'
    }]
  }, {
    field: 'sn',
    label: 'SN',
    placeholder: '请输入SN',
    type: 'input',
    colWidth: 24,
    rules: [{
      required: false,
      message: '请输入SN',
      trigger: 'blur'
    }]
  }, {
    field: 'cold_temperatures',
    label: '预冷温度(℃)',
    placeholder: '请输入预冷温度(℃)',
    type: 'input',
    colWidth: 24,
    unit: '℃',
    rules: [{
      required: false,
      message: '请输入预冷温度(℃)',
      trigger: 'blur'
    }]
  }, {
    field: 'cold_spots',
    label: '预冷地点',
    placeholder: '请输入预冷地点',
    type: 'input',
    colWidth: 24,
    rules: [{
      required: false,
      message: '请输入预冷地点',
      trigger: 'blur'
    }]
  }, {
    field: 'for_cold_cooler_time',
    label: '预冷要求',
    placeholder: '请输入预冷要求',
    type: 'input',
    colWidth: 24,
    unit: '小时',
    rules: [{
      required: false,
      message: '请输入预冷要求',
      trigger: 'blur'
    }, {
      required: false,
      validator: (rule, value, callback) => {
        if (!value && rule.required) {
          return callback(new Error('请输入预冷要求'));
        }
        if (value) {
          if (!/^(\d+)?(\.\d+)?$/.test(value)) {
            return callback(new Error('请输入有效的数值'));
          }
        }
        return callback();
      },
      trigger: ['blur', 'change']
    }]
  }, {
    field: 'status',
    label: '状态',
    placeholder: '状态',
    type: 'radio',
    colWidth: 24,
    rules: [{
      required: true,
      message: '选择状态',
      trigger: 'change'
    }],
    options: startStatus()
  }]
}

export const historyRecord = () => {
  return [{
    field: 'selection',
    label: '多选',
    align: 'center',
  }, {
    field: 'code',
    label: '编号',
    align: 'center',
  }, {
    field: 'status',
    label: '状态',
    align: 'center',
    options: frozenState()
  }, {
    field: 'inStorageTime',
    label: '入库时间',
    align: 'center',
  }, {
    field: 'outStorageTime',
    label: '出库时间',
    align: 'center',
  }, {
    field: 'multistage',
    label: '保温箱温湿度记录',
    children: [{
      field: 'reCheck.nickName',
      label: '开始时间',
      align: 'center',
    }, {
      field: 'reCheck.phone',
      label: '结束时间',
      align: 'center',
    }, ]
  }, {
    field: 'multistage',
    label: '冰排释冷',
    children: [{
      field: 'reCheck.nickName',
      label: '开始时间',
      align: 'center',
    }, {
      field: 'reCheck.phone',
      label: '结束时间',
      align: 'center',
    }, {
      field: 'reCheck.phone',
      label: '释冷时间',
      align: 'center',
    }, ]
  }, {
    field: 'location',
    label: '所在位置',
    align: 'center',
  }, {
    field: 'freezeClaim',
    label: '冷冻要求',
    align: 'center',
  }, {
    field: 'freezeDuration',
    label: '冷冻时间',
    align: 'center',
  }]
}
