Newer
Older
xc-business-system / src / views / business / taskMeasure / measureData / components / seventh / templateDetail.vue
dutingting on 2 Dec 23 KB 临时提交
<!-- 第7套:精密露点仪标准装置 -->
<!-- 检定数据管理详情模板 -->
<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 categoryNameDict from '/public/config/categoryNameDict.json'
import TemplateFormAndTable from '../templateFormAndTable.vue'
import { useSolveFormData } from '../useSolveFormData'
import type { IDetailMeasureList } from './seventh-interface'
// import templateTable 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 multiTable from '@/components/MultiHeaderTable/index.vue'
import templateTable from '@/views/business/measure/item/components/second/templateTable.vue'
import { useGroup } from '@/commonMethods/useGroup'
import { clearSymbol } from '@/utils/String'
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: '', // 标准装置名称
  appearanceRemark: '/',
  appearanceFunctionCheck: '1' as any, // 外观(1/0)
  appearance: '1',
  sealingTest: '1', // 标准器示值是否已通过软件
  outcome: '', // 结论
  remark: '', // 备注
})

// -------------------------------------------路由参数------------------------------------------
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 list = ref<IDetailMeasureList[]>([]) // 表格数据
const columns = ref<TableColumn[]>([])
const columns_mechanical = ref<TableColumn[]>([ // 机械式温湿度仪表
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '类型', value: 'typeDesc', align: 'center', required: false, type: 'text' },
  { text: '温度/湿度', value: 'dimension', align: 'center', width: '120', required: true, type: pageType.value === 'detail' ? 'text' : 'inputNumber', unit: 'dimensionPointUnit' },
  { text: '温度点/湿度点', value: 'dimensionPoint', align: 'center', width: '100', required: false, type: 'text' },
  {
    text: '第1次',
    value: '',
    align: 'center',
    required: false,
    children: [
      { text: '标准示值', value: 'measureValueOne', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
      { text: '被检示值', value: 'oneValue', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
    ],
  },
  {
    text: '第2次',
    value: '',
    align: 'center',
    required: false,
    children: [
      { text: '标准示值', value: 'measureValueTwo', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
      { text: '被检示值', value: 'twoValue', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
    ],
  },
  {
    text: '均值',
    value: '',
    align: 'center',
    required: false,
    children: [
      { text: '标准示值', value: 'averageMeasureValue', align: 'center', required: false, width: '110', type: 'text' },
      { text: '被检示值', value: 'averageValue', align: 'center', required: false, width: '110', type: 'text' },
    ],
  },
  { text: '误差', value: 'errorValue', align: 'center', width: '120', required: false, type: 'text' },
  { text: '最大误差', value: 'maxError', width: '120', align: 'center', required: false, type: 'text', needMark: true },
  { text: '最大允许误差', value: 'maximumError', width: '120', align: 'center', required: false, type: 'text' },
])
const columns_digital = ref<TableColumn[]>([ // 数字式/外置探头式温湿度仪表
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '类型', value: 'typeDesc', align: 'center', required: false, type: 'text' },
  { text: '温度/湿度', value: 'dimension', align: 'center', width: '120', required: true, type: pageType.value === 'detail' ? 'text' : 'inputNumber', unit: 'dimensionPointUnit' },
  { text: '温度点/湿度点', value: 'dimensionPoint', align: 'center', width: '100', required: false, type: 'text' },
  {
    text: '第1次',
    value: '',
    align: 'center',
    required: false,
    children: [
      { text: '标准示值', value: 'measureValueOne', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
      { text: '被检示值', value: 'oneValue', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
    ],
  },
  {
    text: '第2次',
    value: '',
    align: 'center',
    required: false,
    children: [
      { text: '标准示值', value: 'measureValueTwo', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
      { text: '被检示值', value: 'twoValue', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
    ],
  },
  {
    text: '第3次',
    value: '',
    align: 'center',
    required: false,
    children: [
      { text: '标准示值', value: 'measureValueThree', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
      { text: '被检示值', value: 'threeValue', align: 'center', required: true, width: '110', type: pageType.value === 'detail' ? 'text' : 'inputNumber' },
    ],
  },
  {
    text: '均值',
    value: '',
    align: 'center',
    required: false,
    children: [
      { text: '标准示值', value: 'averageMeasureValue', align: 'center', required: false, width: '110', type: 'text' },
      { text: '被检示值', value: 'averageValue', align: 'center', required: false, width: '110', type: 'text' },
    ],
  },
  { text: '误差', value: 'errorValue', align: 'center', width: '120', required: false, type: 'text' },
  { text: '最大误差', value: 'maxError', width: '120', align: 'center', required: false, type: 'text', needMark: true },
  { text: '最大允许误差', value: 'maximumError', width: '120', align: 'center', required: false, type: 'text' },
  { text: '不确定度', value: 'urel', align: 'center', width: '100', required: false, type: 'text' },
])
// 监听 外观检查 如果不合格 表格不可编辑数据置为'/'
watch(() => itemFormData.value.appearanceFunctionCheck, (newVal) => {
  // console.log(newVal, 'newVal')
  if (newVal === '1') {
    list.value = list.value.map((item: any) => ({
      ...item,
      editable: true,
      dimension: item.typeDesc.includes('温度') ? '  ' : ' ',
      measureValueOne: '',
      oneValue: '',
      measureValueTwo: '',
      twoValue: '',
      averageMeasureValue: '',
      averageValue: '',
      errorValue: '',
      maxError: '',
      measureValueThree: '',
      threeValue: '',
    }))

    const needInput = ['dimension', 'measureValueThree', 'threeValue', 'twoValue', 'measureValueTwo', 'measureValueOne', 'oneValue']
    columns.value.forEach((item: TableColumn | any) => {
      if (needInput.includes(item.value)) {
        item.type = 'inputNumber'
      }
      if (item.children) {
        item.children.forEach((citem: any) => {
          if (needInput.includes(citem.value)) {
            citem.type = 'inputNumber'
          }
        })
      }
    })
  }
  else if (newVal === '0') {
    list.value = list.value.map((item: any) => ({
      ...item,
      editable: false,
      dimension: item.typeDesc.includes('温度') ? '  /' : '/ ',
      measureValueOne: '/',
      oneValue: '/',
      measureValueTwo: '/',
      twoValue: '/',
      averageMeasureValue: '/',
      averageValue: '/',
      errorValue: '/',
      maxError: '/',
      measureValueThree: '/',
      threeValue: '/',
    }))
    columns.value.forEach((item: TableColumn | any) => {
      item.type = 'text'
      if (item.children) {
        item.children.forEach((citem: any) => {
          citem.type = 'text'
        })
      }
    })
  }
  list.value.forEach((item: any) => {
    for (const i in item) {
      if (i.includes('-span')) {
        delete item[i]
      }
    }
  })
})
// -------------------------------------------获取详情信息--------------------------------------------------
// 获取页面详情信息
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.appearanceRemark = `${res.data.appearanceRemark}` // 外观备注
    itemFormData.value.appearanceFunctionCheck = `${res.data.appearanceFunctionCheck}` // 外观(1/0)
    itemFormData.value.appearance = `${res.data.appearance}` // 外观(1/0)
    itemFormData.value.sealingTest = `${res.data.sealingTest}` // 标准器示值是否已通过软件
    itemFormData.value.outcome = `${res.data.outcome}` // 结论
    itemFormData.value.remark = `${res.data.remark}` // 结论
    // =======================================表单公共组件数据处理=======================================================
    useSolveFormData(res, templateFormAndTableRef.value)
    // ==================================检定数据========================================================================

    list.value = res.data.measureDataPointMeterList.map((item: any) => {
      return {
        ...item,
        editable: pageType.value !== 'detail',
        params: '示值测试',
        maximumError: item.maximumError.includes('±') ? item.maximumError : `${item.maximumError === '0' ? '' : '±'}${item.maximumError}`,
      }
    }) // 检定数据
    infoId.value = res.data.id
    emits('giveInfoId', infoId.value)
    loading.close()
  })
}

// 初始化输入数据
const initInputData = (data: any) => {
  list.value = data.map((item: any) => ({
    ...item,
    params: '示值测试',
    dimension: item.typeDesc.includes('温度') ? '  ' : ' ',
    // dimensionPoint: '',
    measureValueOne: '',
    oneValue: '',
    measureValueTwo: '',
    twoValue: '',
    measureValueThree: '',
    threeValue: '',
    averageMeasureValue: '',
    averageValue: '',
    errorValue: '',
    maxError: '',
    editable: true,
    typeDesc: `${item.typeDesc}/${item.dimensionPointUnit}`,
    maximumError: item.maximumError.includes('±') ? item.maximumError : `${item.maximumError === '0' ? '' : '±'}${item.maximumError}`,
  }))
  // 整理数据 温度 湿度
  list.value = [...list.value.filter((item: any) => item.typeDesc.includes('温度')), ...list.value.filter((item: any) => item.typeDesc.includes('湿度'))]
}

/**
 * 新增的时候获取检定项输入数据(获取检定项分类详情)
 * @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) => {
    if (Number(res.data.appearanceFunctionCheck)) {
      itemFormData.value.appearanceFunctionCheck = '1'
    }
    else {
      itemFormData.value.appearanceFunctionCheck = ''
    }
    if (Number(res.data.indicationError)) {
      initInputData(res.data.measureItemDataPointMeterList)
    }
    else {
      list.value = []
    }
  })
}

// ----------------------------------------点击保存时校验---------------------------------------
// 校验
const checkout = () => {
  let result = true
  // if (itemFormData.value.appearanceFunctionCheck === '') {
  //   return true
  // }
  // if (!list.value.length) {
  //   ElMessage.warning('该设备未配置检定项')
  //   result = false
  // }
  if (list.value.length) {
    if (!useCheckList(list.value, columns.value, '示值测试')) {
      result = false
    }
  }
  return result
}
// -----------------------------------------生成结果处理----------------------------------------
// 点击计算结果
const calculate = () => {
  if (!list.value.length) {
    ElMessage.warning('没有检定项数据,无法生成结果')
    return false
  }
  list.value.forEach((item: any) => {
    if (item.typeDesc.includes('温度')) {
      // console.log(list.value.filter((citem: any) => citem.typeDesc.includes('温度'))[0].dimension, '123')
      item.dimension = list.value.filter((citem: any) => citem.typeDesc.includes('温度'))[0].dimension
    }
    else if (item.typeDesc.includes('湿度')) {
      item.dimension = list.value.filter((citem: any) => citem.typeDesc.includes('湿度'))[0].dimension
    }
  })
  if (!useCheckList(list.value, columns.value, '示值测试')) {
    return false
  }

  if (list.value.filter((citem: any) => citem.typeDesc.includes('温度'))[0]?.dimension === list.value.filter((citem: any) => citem.typeDesc.includes('湿度'))[0]?.dimension) {
    ElMessage.warning('温度和湿度值不能一直')
    return false
  }
  const params = {
    belongStandardEquipment: itemFormData.value.belongStandardEquipment, // 检校标准装置
    itemCategoryName: itemFormData.value.itemCategoryName, // 检定项分类名称
    measureDataPointMeterList: list.value.map((item: any) => ({ ...item, maximumError: clearSymbol(item.maximumError) })),
  }
  calculateHandle(params).then((res) => {
    list.value = (res.data || list.value).map((item: any) => ({
      ...item,
      params: '示值测试',
      editable: true,
      dimensionPointUnit: item.typeDesc.includes('温度') ? '℃' : '%RH',
      maximumError: item.maximumError.includes('±') ? item.maximumError : `${item.maximumError === '0' ? '' : '±'}${item.maximumError}`,
    }))
  })
}

// 结论
watch(() => [itemFormData.value.appearanceFunctionCheck, list.value], () => {
  if (itemFormData.value.appearanceFunctionCheck === '1' && list.value.every((item: any) => Number(item.maxError) < Number(clearSymbol(item.maximumError)))) {
    itemFormData.value.outcome = '满足使用要求'
  }
  else {
    itemFormData.value.outcome = '不满足使用要求,建议停用或修正使用'
  }
}, {
  deep: true,
})
// ----------------------------------------------------------------------------------------
const isNeverDefineItemCategory = ref(false) // 检定项分类是否是从未定义过的
watch(() => itemFormData.value.itemCategoryName, (newValue) => {
  if (newValue) {
    // 判断是否是新增的检定项分类
    const index = categoryNameDict.findIndex((item: any) => item === newValue)
    if (index === -1) {
      isNeverDefineItemCategory.value = true
    }
    else {
      isNeverDefineItemCategory.value = false
    }
  }
})
// ------------------------------------------钩子----------------------------------------------
watch(() => itemFormData.value.itemCategoryName, (newValue) => {
  if (newValue) {
    switch (newValue) {
      case '机械式温湿度仪表':
        columns.value = columns_mechanical.value
        break
      case '数字式/外置探头式温湿度仪表':
        columns.value = columns_digital.value
        break
      default:
        break
    }
  }
}, { immediate: true, deep: true })

watch(() => props.infoId, (newValue) => {
  if (newValue) {
    infoId.value = newValue
  }
}, { immediate: true })
watch(() => pageType.value, (newValue) => {
  console.log(newValue, 'ageType.value')
  if (newValue) {
    if (newValue === 'detail') {
      columns.value.forEach((item: TableColumn | any) => {
        item.type = 'text'
        if (item.children) {
          item.children.forEach((citem: any) => {
            citem.type = 'text'
          })
        }
      })
      list.value = list.value.map((item: any) => ({ ...item, editable: false }))
    }
  }
})
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, list })
</script>

<template>
  <div class="measure-data-template-detail">
    <template-form-and-table ref="templateFormAndTableRef" :page-type="pageType" />
    <!-- 标签 -->
    <detail-block v-if="!isNeverDefineItemCategory" :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-show="current === 'measure-data' && itemFormData.appearanceFunctionCheck" ref="formRef"
        :model="itemFormData" label-width="140" label-position="right" style="margin-top: 20px;"
      >
        <el-row>
          <!-- 外观  -->
          <el-col v-if="`${itemFormData.appearanceFunctionCheck}` === '1'" :span="8">
            <el-form-item label="外观:" prop="appearance">
              <el-radio-group v-model="itemFormData.appearance" :disabled="pageType === 'detail'">
                <el-radio label="1">
                  合格
                </el-radio>
                <el-radio label="0">
                  不合格
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col v-if="`${itemFormData.appearance}` === '0'" :span="12">
            <el-form-item label="备注说明:" prop="appearanceRemark">
              <el-input
                v-model="itemFormData.appearanceRemark" class="full-width-input"
                :placeholder="pageType === 'detail' ? ' ' : '外观备注说明'" autosize type="textarea"
                :disabled="pageType === 'detail'"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <!-- 示值误差 -->
      <detail-block v-show="current === 'measure-data' && list.length" title="示值测试">
        <div style="display: flex; justify-content: space-between;">
          <el-form-item label="标准器示值是否已通过软件修正:" prop="sealingTest">
            <el-radio-group v-model="itemFormData.sealingTest" :disabled="pageType === 'detail'">
              <el-radio label="1">
                是
              </el-radio>
              <el-radio label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-button
            v-if="pageType !== 'detail' && itemFormData.appearanceFunctionCheck !== '0'" type="primary"
            @click="calculate"
          >
            计算结果
          </el-button>
        </div>
        <multi-table
          :table-data="list" :table-header="columns"
          :merge-rows="['maxError', 'maximumError', 'typeDesc', 'dimension']" :need-index="true"
        />
      </detail-block>
      <!-- ------------------------------------------------结论------------------------------------------------ -->
      <el-form
        v-show="current === 'measure-data'" ref="formRef" :model="itemFormData" label-width="140"
        label-position="right" style="margin-top: 20px;"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="结论:" prop="outcome">
              <el-input
                v-model="itemFormData.outcome" class="full-width-input"
                :placeholder="pageType === 'detail' ? ' ' : '结论'" autosize type="textarea"
                :disabled="pageType === 'detail'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注:" prop="remark">
              <el-input
                v-model="itemFormData.remark" class="full-width-input"
                :placeholder="pageType === 'detail' ? ' ' : '备注'" autosize type="textarea"
                :disabled="pageType === 'detail'"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <!-- 历史修改记录 -->
      <change-record v-if="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>