Newer
Older
xc-business-system / src / views / equipement / standard / checkData / components / useStabilityCaculate.ts
dutingting on 11 Jan 2024 3 KB 多功能校准源稳定性完成
// 稳定性所使用的一些公共的方法
/**
 * 清空六个日期的值
 * @param item 清空的数据,Object
 */
export function clearDateValue(item: any) {
  item.testValueOne = ''
  item.testValueTwo = ''
  item.testValueThree = ''
  item.testValueFour = ''
  item.testValueFive = ''
  item.testValueSix = ''
  return item
}

/**
 * 处理详情表头
 * @param columns 表头
 * @param list 表格数据
 */
export function handleDetailTableTableHead(columns: any, list: any) {
  if (!list.length) { return false }
  console.log('------')

  console.log(columns)

  console.log('======')

  console.log(list)

  if (list[0].testValueOneDate !== '') {
    columns[5].children[0].text = list[0].testValueOneDate // 填表头
  }
  if (list[0].testValueTwoDate !== '') {
    columns[5].children[1].text = list[0].testValueTwoDate // 填表头
  }
  if (list[0].testValueThreeDate !== '') {
    columns[5].children[2].text = list[0].testValueThreeDate // 填表头
  }
  if (list[0].testValueFourDate !== '') {
    columns[5].children[3].text = list[0].testValueFourDate // 填表头
  }
  if (list[0].testValueFiveDate !== '') {
    columns[5].children[4].text = list[0].testValueFiveDate // 填表头
  }
  if (list[0].testValueSixDate !== '') {
    columns[5].children[5].text = list[0].testValueSixDate // 填表头
  }

  return columns
}

/**
 * 处理保存日期参数
 * @param columns 表头
 * @param list 表格数据
 */
export function handleSaveDateParams(columns: any, list: any) {
  if (!list.length) { return false }
  list = list.map((item: { testValueFiveDate: string; testValueFourDate: string; testValueThreeDate: string; testValueTwoDate: string; testValueOneDate: string }) => {
    return {
      ...item,
      testValueFiveDate: columns[5].children[4].text === '-' ? '' : columns[5].children[4].text, //	核查读数5日期(稳定性)
      testValueFourDate: columns[5].children[3].text === '-' ? '' : columns[5].children[3].text, //	核查读数4日期(稳定性)
      testValueThreeDate: columns[5].children[2].text === '-' ? '' : columns[5].children[2].text, //	核查读数3日期(稳定性)
      testValueTwoDate: columns[5].children[1].text === '-' ? '' : columns[5].children[1].text, //	核查读数2日期(稳定性)
      testValueOneDate: columns[5].children[0].text === '-' ? '' : columns[5].children[0].text, //	核查读数1日期(稳定性)
    }
  })
  return list
}

/**
 * 处理稳定性表格数据
 * @param value 所有查询到的稳定性历史数据
 * @param item 要处理的行数据
 * @param stabilityColumns 稳定性表头
 * @param num 控制表头日期从第几个开始填 ---查询历史日期从最后一个填,核查数据需要从倒数第二个填,因为最后一个要是本次核查日期
 * @returns itemData 处理完的行数据 columnsData 表头
 */
export function solveHistoryIndicationTableData(value: any, item: any, stabilityColumns: any, num = 4) {
  // 先找出此行数据的所有日期
  const list = value.filter((i: { checkPoint: string; params: string }) => i.params === item.params && i.checkPoint === item.checkPoint)
  // 按照时间倒序排序
  list.sort((i: { testValueDate: string }, j: { testValueDate: string }) => {
    const time1 = new Date(j.testValueDate).getTime()
    const time2 = new Date(i.testValueDate).getTime()
    return time1 - time2
  })

  list.forEach((e: { testValueDate: string; testValue: string; id: string }, index: number) => {
    stabilityColumns[5].children![num - index].text = e.testValueDate // 填表头
    stabilityColumns[5].children![num - index].checkDateDetailId = e.id // id用来查对应日期的详情
    item[stabilityColumns[5].children![num - index].value] = e.testValue // 填表格数据
  })

  return {
    itemData: item,
    columnsData: stabilityColumns,
  }
}