Newer
Older
xc-business-system / src / views / business / taskMeasure / measureData / components / second / templateDetail.vue
<!-- 第2套:直流稳压电源标准装置 -->
<!-- 检定数据管理详情模板 -->
<script lang="ts" setup name="MeasureDataTemplateDetail">
import { ref } from 'vue'
import { ElLoading, ElMessage } from 'element-plus'
import dayjs from 'dayjs'
import changeRecord from '../changeRecord.vue'
import selectStandard from '../../dialog/selectStandardDialog.vue'
import TemplateFormAndTable from '../templateFormAndTable.vue'
import { useSolveFormData } from '../useSolveFormData'
import type { IDetailMeasureList } from './second-interface'
import templateTable1 from './templateTable.vue'
import useUserStore from '@/store/modules/user'
import type { dictType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { calculateHandle, getInfo } from '@/api/business/taskMeasure/measureData'
import { getInfo as getItemInfo } from '@/api/business/measure/item'
import { useCheckList } from '@/commonMethods/useCheckList'
import { calc } from '@/utils/useCalc'
import templateTable from '@/views/business/measure/item/components/second/templateTable.vue'
import { initTableRow } from '@/commonMethods/useMergeTableRow'
const props = defineProps({
  infoId: String, // id
  dataNo: String, // 检定数据编号
})
const emits = defineEmits(['giveInfoId'])
const user = useUserStore() // 用户信息
const $router = useRouter() // 关闭页面使用
const $route = useRoute() // 路由参数
const ruleFormRef = ref() // 表单ref
const templateFormAndTableRef = ref() // 表单和被检设备、测量设备表格公共组件ref
const itemFormData = ref({ // 有关于检定项的数据
  itemId: '', // 检定项id
  itemCategoryName: '', // 设备检定项分类名称
  itemCategoryId: '', // 设备检定项分类名称id
  belongStandardEquipment: '', // 标准装置code
  belongStandardEquipmentName: '', // 标准装置名称
  appearance: '外观完好,工作正常', // 外观(1/0)
  appearanceFunctionCheck: 0, // 外观
  voltageRegulation: 0, // 电源电压调整率
  loadRegulation: 0, // 负载调整率
  voltageRepresentError: 0, // 电压表示值误差
  currentRepresentErrorDirect: 0, // 电流表示值误差(直接测量)
  currentRepresentErrorIndirect: 0, // 电流表示值误差(间接测量)
  rippleVoltage: 0, // 纹波电压
  voltageOutputStability: 0, // 输出电压短期稳定性
  remark: '无', // 情况说明
  conclusion: '1', // 检验结论
})
// -------------------------------------------路由参数------------------------------------------
const pageType = ref('add') // 页面类型: add, edit, detail
const infoId = ref('') // 列表id
if ($route.params && $route.params.type) {
  pageType.value = $route.params.type as string

  if ($route.params.id) {
    infoId.value = $route.params.id as string
  }
}

// ------------------------------------------标签----------------------------------------------------------
const radioMenus = ref([ // 标签内容
  { name: '检定数据', value: 'measure-data' },
  { name: '历史修改记录', value: 'change-record' },
])
const current = ref('measure-data') // 选择的tab 默认基本信息

// ---------------------------------------检定项数据表格----------------------------------------------------
const lineVoltageRegulationList = ref<IDetailMeasureList[]>([]) // 电源电压调整率
const loadRegulationList = ref<IDetailMeasureList[]>([]) // 负载调整率
const voltageRepresentationValueErrorList = ref<IDetailMeasureList[]>([]) // 电压表示值误差
const ammeterDirectList = ref<IDetailMeasureList[]>([]) // 电流表示值误差(直接测量)
const ammeterIndirectList = ref<IDetailMeasureList[]>([]) // 电流表示值误差(间接测量)
const rippleVoltageList = ref<IDetailMeasureList[]>([]) // 纹波电压
const outputVoltageStabilityList = ref<IDetailMeasureList[]>([]) // 输出电压短期稳定性

const columns_line_voltage_regulation = ref<TableColumn[]>([ // 电源电压调整率
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  { text: '调压器输出值', value: 'voltageRegulatorOutputValue', align: 'center', required: true, type: 'text' },
  { text: '被检电源输出电压值', value: 'voltageOutputValue', align: 'center', required: true, type: 'input' },
  { text: '被检电源输出电压最大差值', value: 'voltageMaxDifference', align: 'center', required: false, type: 'text' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'text' },
  { text: '电源电压调整率', value: 'voltageRegulation', align: 'center', required: false, type: 'text' },
])

const columns_load_regulation = ref<TableColumn[]>([ // 负载调整率
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  { text: '负载情况', value: 'loadSituation', align: 'center', required: true, type: 'text' },
  { text: '被检电源输出电压值', value: 'voltageOutputValue', align: 'center', required: true, type: 'input' },
  { text: '电压差值', value: 'voltageDifference', align: 'center', required: true, type: 'text' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'text' },
  { text: '负载调整率', value: 'loadRegulation', align: 'center', required: true, type: 'text' },
])

// 电压表示值误差
const columns_voltage_representation_value_error = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' },
  { text: '标准值', value: 'standardValue', align: 'center', required: true, type: 'input' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'text' },
  { text: '绝对误差', value: 'absoluteError', align: 'center', required: true, type: 'text' },
])

// 电流表示值误差(间接测量)
const columns_ammeter_indirect = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' },
  { text: '标准电压值', value: 'standardVoltageValue', align: 'center', required: true, type: 'input' },
  { text: '标准值', value: 'standardValue', align: 'center', required: true, type: 'text' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'text' },
  { text: '绝对误差', value: 'absoluteError', align: 'center', required: true, type: 'text' },
])

// 纹波电压
const columns_ripple_voltage = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'text' },
  { text: '纹波电压', value: 'rippleVoltage', align: 'center', required: true, type: 'input' },
])

// 输出电压短期稳定性
const columns_output_voltage_stability = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  { text: '被测电源输出电压', value: 'voltageOutputValue', align: 'center', required: true, type: 'input' },
  { text: '输出电压最大变化值', value: 'outputVoltageMaxChange', align: 'center', required: true, type: 'text' },
  { text: '仪器技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'text' },
  { text: '短期稳定性', value: 'shortTermStability', align: 'center', required: true, type: 'text' },
])
// 增加行 - 输出电压短期稳定性
const addRow = () => {
  outputVoltageStabilityList.value.push(outputVoltageStabilityList.value[outputVoltageStabilityList.value.length - 1])
  outputVoltageStabilityList.value = initTableRow(outputVoltageStabilityList.value)
  // outputVoltageStabilityList.value = outputVoltageStabilityList.value.map((item) => {
  //   const obj = {}
  //   for (const i in item) {
  //     if (!i.includes('-span')) {
  //       obj[i] = item[i]
  //     }
  //   }
  //   console.log(obj, 'obj')
  //   return obj
  // })
}
// -------------------------------------------获取详情信息--------------------------------------------------
// 获取页面详情信息
const fetchInfo = () => {
  const loading = ElLoading.service({
    lock: true,
    background: 'rgba(255, 255, 255, 0.8)',
  })
  getInfo({
    id: infoId.value,
    belongStandardEquipment: itemFormData.value.belongStandardEquipment,
    // 我的任务跳转过来如果已经配置过检定项了,到编辑页面,且用一下三个字段替代传id请求详情
    itemId: $route.query.itemId, // 检定项id
    orderId: $route.query.orderId, // 任务单id
    sampleId: $route.query.sampleId, // 被检设备id
  }).then((res) => {
    // 有关于检定项的数据
    itemFormData.value.itemId = res.data.itemId // 检定项id
    itemFormData.value.itemCategoryName = res.data.itemCategoryName // 设备检定项分类名称
    itemFormData.value.itemCategoryId = res.data.itemCategoryId ? res.data.itemCategoryId : itemFormData.value.itemCategoryId // 设备检定项分类名称id
    itemFormData.value.appearance = `${res.data.appearance}` // 外观(1/0)

    // =======================================表单公共组件数据处理=======================================================
    useSolveFormData(res, templateFormAndTableRef.value)
    // ==================================检定数据========================================================================

    // list.value = res.data.measureDataPistonGaugeList.map((item: IDetailMeasureList) => {
    //   return {
    //     ...item,
    //     editable: pageType.value !== 'detail',
    //   }
    // }) // 检定数据

    infoId.value = res.data.id
    emits('giveInfoId', infoId.value)
    loading.close()
  })
}

// 初始化输入数据
const initInputData = (data: any) => {
  console.log(data, 'data')
  data.forEach((item: any) => {
    console.log(item, 'item')
    switch (item.dataType) {
      case '1':
        // 电源电压调整率
        lineVoltageRegulationList.value.push({ ...item, params: '电源电压调整率' })
        break
      case '2':
        // 负载调整率
        loadRegulationList.value.push({ ...item, params: '负载调整率' })
        break
      case '3':
        // 电压表示值误差
        voltageRepresentationValueErrorList.value.push({ ...item, params: '电压表示值误差' })
        break
      case '4':
        // 电流表示值误差(直接测量)
        ammeterDirectList.value.push({ ...item, params: '电流表示值误差(直接测量)' })
        break
      case '5':
        // 电流表示值误差(间接测量)
        ammeterIndirectList.value.push({ ...item, params: '电流表示值误差(间接测量)' })
        break
      case '6':
        // 纹波电压
        rippleVoltageList.value.push({ ...item, params: '纹波电压' })
        break
      case '7':
        // 纹波电压
        outputVoltageStabilityList.value.push({ ...item, params: '输出电压短期稳定性' })
        break
    }
  })
}

/**
 * 新增的时候获取检定项输入数据(获取检定项分类详情)
 * @param itemId  检定项id
 * @param itemCategoryName 检定项分类名字
 * @param belongStandardEquipment 检校标准装置字典
 */
const fetchItemInfo = (itemId: string, itemCategoryName: string, belongStandardEquipment = '') => {
  const params = {
    id: itemId,
    itemCategoryName, // 检定项分类名字
    belongStandardEquipment, // 检校标准装置字典code
  }
  getItemInfo(params).then((res) => {
    console.log(res.data, '鉴定项')
    itemFormData.value.appearanceFunctionCheck = res.data.appearanceFunctionCheck // 外观及功能检查
    itemFormData.value.voltageRegulation = res.data.voltageRegulation // 电源电压调整率
    itemFormData.value.loadRegulation = res.data.loadRegulation // 负载调整率
    itemFormData.value.voltageRepresentError = res.data.voltageRepresentError // 电压表示值误差
    itemFormData.value.currentRepresentErrorDirect = res.data.currentRepresentErrorDirect // 电流表示值误差(直接测量)
    itemFormData.value.currentRepresentErrorIndirect = res.data.currentRepresentErrorIndirect // 电流表示值误差(间接测量)
    itemFormData.value.rippleVoltage = res.data.rippleVoltage // 纹波电压
    itemFormData.value.voltageOutputStability = res.data.voltageOutputStability // 输出电压短期稳定性
    initInputData(res.data.measureItemDataDcPowerList)
  })
}
// -----------------------------------------字典----------------------------------------
const RegulatorOutputValue = ref<{ value: string;name: string;id: string }[]>([]) // 调压器输出值
const fetchDict = async () => {
  const res1 = await getDictByCode('voltageRegulatorOutputValue')
  RegulatorOutputValue.value = res1.data
}
fetchDict()
// 调压器输出值
// ----------------------------------------点击保存时校验---------------------------------------
// 校验
const checkout = () => {
}
// -----------------------------------------生成结果处理----------------------------------------
// 点击计算结果
const calculate = (title: string) => {
  console.log(title, 'title')
  switch (title) {
    case '电源电压调整率':
      // lineVoltageRegulationList.value.forEach((item: any) => {
      //   // 计算 被检电源输出电压最大差值 调压器输出值的最大值与最小值的被检电源输出电压值差的绝对值
      //   const voltageRegulatorOutputValue = RegulatorOutputValue.value.map(item => Number(item.name))
      //   // console.log(Math.max(...voltageRegulatorOutputValue))
      //   console.log(Math.max(...voltageRegulatorOutputValue), Math.min(...voltageRegulatorOutputValue))
      //   item.voltageMaxDifference = Math.abs(Math.max(...voltageRegulatorOutputValue) - Number(item.voltageOutputValue)) - Math.abs(Math.min(...voltageRegulatorOutputValue) - Number(item.voltageOutputValue))
      // })
      break
  }
  // ElMessage.info('敬请期待')
  // return false
  // if (!list.value.length) {
  //   ElMessage.warning('没有检定项数据,无法生成结果')
  //   return false
  // }
  // if (!useCheckList(list.value, measureColumns.value, '检定数据')) {
  //   return false
  // }
  // const params = {
  //   belongStandardEquipment: itemFormData.value.belongStandardEquipment, // 检校标准装置
  //   itemCategoryName: itemFormData.value.itemCategoryName, // 检定项分类名称
  //   measureDataCalibratorList: list.value,
  // }
  // calculateHandle(params).then((res) => {
  //   if (res.data && res.data.length) {
  //     resultList.value = res.data.map((item: IDetailMeasureList) => {
  //       return {
  //         ...item,
  //       }
  //     }) // 检定数据
  //   }
  //   else {
  //     list.value = res.data
  //   }
  // })
}

// ------------------------------------------钩子----------------------------------------------

watch(() => props.infoId, (newValue) => {
  if (newValue) {
    infoId.value = newValue
  }
}, { immediate: true })

onMounted(() => {
  if (pageType.value === 'add') { // 从我的任务跳转过来(新增)
    itemFormData.value.itemId = $route.query.itemId as string// 检定项id
    itemFormData.value.itemCategoryName = $route.query.itemCategoryName as string// 设备检定项分类名称
    itemFormData.value.itemCategoryId = $route.query.itemCategoryId as string// 设备检定项分类名称id
    itemFormData.value.belongStandardEquipment = $route.query.belongStandardEquipment as string// 标准装置code
    itemFormData.value.belongStandardEquipmentName = $route.query.belongStandardEquipmentName as string// 标准装置名称
    // 查输入值(查检定项管理的详情)
    fetchItemInfo($route.query.itemId! as string, $route.query.itemCategoryName! as string, $route.query.belongStandardEquipment as string)
  }
  else {
    itemFormData.value.itemCategoryName = $route.query.itemCategoryName as string // 设备检定项分类名称
    itemFormData.value.itemCategoryId = $route.query.itemCategoryId as string// 设备检定项分类名称id
    itemFormData.value.belongStandardEquipment = $route.query.belongStandardEquipment as string// 标准装置code
    itemFormData.value.belongStandardEquipmentName = $route.query.belongStandardEquipmentName as string// 标准装置名称
    fetchInfo()
  }
})

defineExpose({ checkout, itemFormData, templateFormAndTableRef, pageType })
</script>

<template>
  <div class="measure-data-template-detail">
    <template-form-and-table ref="templateFormAndTableRef" :page-type="pageType" />
    <!-- 标签 -->
    <detail-block :title="pageType !== 'detail' ? '检定数据' : ''" :class="pageType === 'detail' ? 'setBottom' : ''">
      <el-radio-group v-if="pageType === 'detail'" v-model="current">
        <el-radio-button v-for="item in radioMenus" :key="item.value" :label="item.value">
          {{ item.name }}
        </el-radio-button>
      </el-radio-group>

      <el-form
        v-if="current === 'measure-data'"
        ref="formRef"
        :model="itemFormData"
        label-width="140"
        label-position="right"
        style="margin-top: 20px;"
      >
        <el-row v-if="itemFormData.appearanceFunctionCheck">
          <!-- 外观  -->
          <el-col :span="12">
            <el-form-item label="外观及功能性检查:" prop="appearance">
              <el-input
                v-model="itemFormData.appearance"
                class="full-width-input"
                autosize
                type="textarea"
                :disabled="pageType === 'detail'"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <!-- 电源电压调整率 -->
      <template-table
        v-if="itemFormData.voltageRegulation" title="电源电压调整率" :data="lineVoltageRegulationList" :columns="columns_line_voltage_regulation"
        index="1" :show-btn="false" :calc-btn="true" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel', 'voltageMaxDifference', 'technicalIndex', 'voltageRegulation']"
        @calculate-result="calculate"
      />
      <!-- 负载调整率 -->
      <template-table
        v-if="itemFormData.loadRegulation" title="负载调整率" :data="loadRegulationList" :columns="columns_load_regulation"
        index="2" :show-btn="false" :calc-btn="true" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel', 'voltageDifference', 'technicalIndex', 'loadRegulation']" @calculate-result="calculate"
      />

      <!--  电压表示值误差 -->
      <template-table
        v-if="itemFormData.voltageRepresentError" title="电压表示值误差" :data="voltageRepresentationValueErrorList" :columns="columns_voltage_representation_value_error"
        index="3" :show-btn="false" :calc-btn="true" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel']" @calculate-result="calculate"
      />

      <!-- 电流表示值误差(直接测量) -->
      <template-table
        v-if="itemFormData.currentRepresentErrorDirect" title="电流表示值误差(直接测量)" :data="ammeterDirectList" :columns="columns_voltage_representation_value_error"
        index="4" :show-btn="false" :calc-btn="true" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel']" @calculate-result="calculate"
      />

      <!-- 电流表示值误差(间接测量) -->
      <template-table
        v-if="itemFormData.currentRepresentErrorIndirect" title="电流表示值误差(间接测量)" :data="ammeterIndirectList" :columns="columns_ammeter_indirect"
        index="5" :show-btn="false" :calc-btn="true" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel']" @calculate-result="calculate"
      />

      <!--  纹波电压 -->
      <template-table
        v-if="itemFormData.rippleVoltage" title="纹波电压" :data="rippleVoltageList" :columns="columns_ripple_voltage"
        index="6" :show-btn="false" :calc-btn="true" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel']" @calculate-result="calculate"
      />

      <!--  输出电压短期稳定性 -->
      <template-table
        v-if="itemFormData.voltageOutputStability" title="输出电压短期稳定性" :data="outputVoltageStabilityList" :columns="columns_output_voltage_stability"
        index="7" :show-btn="true" :calc-btn="true" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel', 'outputVoltageMaxChange', 'technicalIndex', 'shortTermStability']" @calculate-result="calculate"
        @addRow="addRow"
      />

      <!-- 历史修改记录 -->
      <change-record v-show="pageType === 'detail' && current === 'change-record'" :info-id="infoId" />
    </detail-block>
  </div>
</template>

<style lang="scss">
.measure-data-template-detail {
  .el-radio__label {
    display: block !important;
  }
}
</style>