Newer
Older
xc-business-system / src / views / equipement / standard / checkData / components / fourth / checkDataCom.vue
dutingting on 29 Nov 16 KB 解决冲突
<!-- 核查数据管理详情--核查项 -->
<script lang="ts" setup name="checkDataDetail">
import { ref } from 'vue'
import { ElLoading, ElMessage } from 'element-plus'
import saveCheckRecord from '../../dialog/saveCheckRecord.vue'
import type { IList } from './fourth-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import useUserStore from '@/store/modules/user'
import type { dictType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import multiTable from '@/components/MultiHeaderTable/index.vue'
import { useCheckList } from '@/commonMethods/useCheckList'
import { getCheckItemDetail, getJobInstructionList } from '@/api/equipment/standard/book'
import { addCheckData, calculateHandle, getInfo, updateCheckData } from '@/api/equipment/standard/checkData'
const props = defineProps({
  pageType: { // 页面类型
    type: String,
  },
})
const emits = defineEmits(['isConfigCheck'])
const user = useUserStore() // 用户信息
const $router = useRouter() // 关闭页面使用
const $route = useRoute() // 路由参数
const infoId = ref('')
const ruleFormRef = ref() // 表单ref
const form = ref({
  conclusion: '1', // 结论
  remark: '/', // 备注
})
const belongStandardEquipment = ref('1')
const itemCategoryId = ref('')
const itemCategoryName = ref('')
const tableLoading = ref(false) // 表格loading
// ----------------------------------路由参数------------------------------------------------
if ($route.params && $route.params.id) {
  infoId.value = $route.params.id as string
}
// ------------------------------------------字典----------------------------------------------
const conclusionList = ref<dictType[]>([]) // 结论
const checkItemElectricalSignalMap = ref({}) as any // 核查项目
const maximumErrorAbsoluteElectricalSignalMap = ref({}) as any // 最大允许误差电信号
const maximumErrorAbsolutePressureMap = ref({}) as any // 最大允许误差压力值

async function getDict() {
  // 结论
  getDictByCode('conclusion').then((response) => {
    conclusionList.value = response.data
  })
  // 核查项目
  getDictByCode('checkItemElectricalSignal').then((response) => {
    response.data.forEach((item: { value: string; name: string }) => {
      checkItemElectricalSignalMap.value[`${item.value}`] = item.name
    })
  })
  // 最大允许误差绝对值(压力值)
  const res = await getDictByCode('maximumErrorAbsolutePressure')
  res.data.forEach((item: { value: string; name: string }) => {
    maximumErrorAbsolutePressureMap.value[`${item.value}`] = item.name
  })

  // 最大允许误差绝对值(电信号)
  const resElectricalSignal = await getDictByCode('maximumErrorAbsoluteElectricalSignal')
  resElectricalSignal.data.forEach((item: { value: string; name: string }) => {
    maximumErrorAbsoluteElectricalSignalMap.value[`${item.value}`] = item.name
  })
}
getDict()
// ----------------------------------------核查数据----------------------------------------------
const list = ref<IList[]>([]) // 核查项数据
const columns = ref<TableColumn[]>([])
const columns_pressure = ref<TableColumn[]>([ // 压力值表头
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  { text: '核查点', value: 'checkPoint', align: 'center', required: true, type: 'text' },
  {
    text: '第一次',
    value: 'firstStroke',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '正行程', value: 'firstForwardStroke', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '反行程', value: 'firstReverseStroke', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '第二次',
    value: 'secondStroke',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '正行程', value: 'secondForwardStroke', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '反行程', value: 'secondReverseStroke', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '第三次',
    value: 'thirdStroke',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '正行程', value: 'thirdForwardStroke', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '反行程', value: 'thirdReverseStroke', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  { text: '均值', value: 'averageValue', align: 'center', required: false, type: 'text' },
  { text: '最大示值误差绝对值', value: 'maxIndicatingError', align: 'center', required: false, type: 'text' },
  { text: '最大回程误差绝对值', value: 'maxReturnError', align: 'center', required: false, type: 'text' },
  { text: '最大允许误差绝对值', value: 'maximumError', align: 'center', required: true, type: 'text' },
])

const columns_electrical_signal = ref<TableColumn[]>([ // 电信号表头
  { text: '核查项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '核查点', value: 'checkPoint', align: 'center', required: true, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
  {
    text: '第一次',
    value: 'first',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '核查标准示值', value: 'testValueOne', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '测量标准示值', value: 'measureValueOne', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '第二次',
    value: 'second',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '核查标准示值', value: 'testValueTwo', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '测量标准示值', value: 'measureValueTwo', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '第三次',
    value: 'third',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '核查标准示值', value: 'testValueThree', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '测量标准示值', value: 'measureValueThree', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '第四次',
    value: 'fourth',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '核查标准示值', value: 'testValueFour', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '测量标准示值', value: 'measureValueFour', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '第五次',
    value: 'fifth',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '核查标准示值', value: 'testValueFive', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '测量标准示值', value: 'measureValueFive', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '第六次',
    value: 'sixth',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '核查标准示值', value: 'testValueSix', align: 'center', required: true, width: '180', type: 'inputNumber' },
      { text: '测量标准示值', value: 'measureValueSix', align: 'center', required: true, width: '180', type: 'inputNumber' },
    ],
  },
  {
    text: '平均值',
    value: 'average',
    align: 'center',
    required: false,
    width: '180',
    children: [
      { text: '核查标准示值', value: 'averageValue', align: 'center', required: false, type: 'text' },
      { text: '测量标准示值', value: 'measureAverageValue', align: 'center', required: false, type: 'text' },
    ],
  },
  { text: '最大示值误差', value: 'maxIndicatingError', align: 'center', required: false, type: 'text' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'text' },
])

// 获取配置详情
async function fetchCheckItemDetail(equipmentId: string, belongStandardEquipmentParam: string, itemCategoryIdParam: string, itemCategoryNameParam: string) {
  belongStandardEquipment.value = belongStandardEquipmentParam // 检校标准库
  itemCategoryId.value = itemCategoryIdParam // 核查分类id
  itemCategoryName.value = itemCategoryNameParam // 核查分类名称
  const loading = ElLoading.service({
    lock: true,
    background: 'rgba(255, 255, 255, 0.8)',
  })
  const params = {
    equipmentId, // 智能模型id
    belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置code
    itemCategoryId: itemCategoryId.value, // 核查项分类id
    itemCategoryName: itemCategoryName.value, // 核查项分类名称
  }
  getDict().then(() => {
    getCheckItemDetail(params).then((res) => {
      loading.close()
      if (!res.data) {
        emits('isConfigCheck', false)
      }
      else {
        list.value = res.data.checkItemDataPistonGaugeList.map((item: { id: string; checkItem: string; standardIndication: string; maximumErrorAbsolute: string }) => {
          return {
            ...item,
            dataId: item.id, /// /	核查数据管理基础信息表id
            params: checkItemElectricalSignalMap.value[`${item.checkItem}`], // 核查项目
            testValueOne: item.standardIndication, //	核查标准示值1
            testValueTwo: item.standardIndication, //	核查标准示值2
            testValueThree: item.standardIndication, //	核查标准示值3
            testValueFour: item.standardIndication, //	核查标准示值4
            testValueFive: item.standardIndication, //	核查标准示值5
            testValueSix: item.standardIndication, //	核查标准示值6
            measureValueFive: undefined, //	测量标准示值5
            measureValueFour: undefined, //	测量标准示值4
            measureValueOne: undefined, //	测量标准示值1
            measureValueSix: undefined, //	测量标准示值6
            measureValueThree: undefined, //	测量标准示值3
            measureValueTwo: undefined, //	测量标准示值2
            secondForwardStroke: undefined, //	第二次正行程
            secondReverseStroke: undefined, //	第二次反行程
            thirdForwardStroke: undefined, //	第三次正行程
            thirdReverseStroke: undefined, //	第三次反行程
            firstForwardStroke: undefined, //	第一次正行程
            firstReverseStroke: undefined, //	第一次反行程
            maximumError: itemCategoryName.value === '压力值' ? maximumErrorAbsolutePressureMap.value[`${item.maximumErrorAbsolute}`] : maximumErrorAbsoluteElectricalSignalMap.value[`${item.maximumErrorAbsolute}`], // 最大允许误差绝对值
            editable: props.pageType !== 'detail',
          }
        })
      }
    })
  })
}

// 点击生成结果处理
const createResult = () => {
  if (!list.value.length) {
    ElMessage.warning('核查数据表格不能为空,是否未配置?请检查')
    return false
  }
  if (itemCategoryName.value === '压力值' && !useCheckList(list.value, columns_pressure.value, '核查数据')) {
    return false
  }

  if (itemCategoryName.value === '电信号' && !useCheckList(list.value, columns_electrical_signal.value, '核查数据')) {
    return false
  }

  const params = {
    belongStandardEquipment: belongStandardEquipment.value, // 检校标准库
    checkDataPistonGaugeList: list.value,
    itemCategoryId: itemCategoryId.value, // 核查项分类id
    itemCategoryName: itemCategoryName.value, // 核查项分类id
  }
  tableLoading.value = true
  calculateHandle(params).then((res) => {
    list.value = res.data.map((item: any) => {
      return {
        ...item,
        editable: props.pageType !== 'detail',
      }
    })
    tableLoading.value = false
  }).catch(() => {
    tableLoading.value = false
  })
}
// ------------------------------------------------------------------------------------------

// 获取详情
function fetchInfo() {
  if (!infoId.value) { return }
  const loading = ElLoading.service({
    lock: true,
    background: 'rgba(255, 255, 255, 0.8)',
  })
  getInfo({ id: infoId.value }).then((res) => {
    form.value = { ...res.data }
    list.value = res.data.checkDataPistonGaugeList.map((item: any) => {
      return {
        ...item,
        editable: props.pageType !== 'detail',
        measureValueFive: `${item.measureValueFive}` === '' ? undefined : item.measureValueFive, //	测量标准示值5
        measureValueFour: `${item.measureValueFour}` === '' ? undefined : item.measureValueFour, //	测量标准示值4
        measureValueOne: `${item.measureValueOne}` === '' ? undefined : item.measureValueOne, //	测量标准示值1
        measureValueSix: `${item.measureValueSix}` === '' ? undefined : item.measureValueSix, //	测量标准示值6
        measureValueThree: `${item.measureValueThree}` === '' ? undefined : item.measureValueThree, //	测量标准示值3
        measureValueTwo: `${item.measureValueTwo}` === '' ? undefined : item.measureValueTwo, //	测量标准示值2
        secondForwardStroke: `${item.secondForwardStroke}` === '' ? undefined : item.secondForwardStroke, //	第二次正行程
        secondReverseStroke: `${item.secondReverseStroke}` === '' ? undefined : item.secondReverseStroke, //	第二次反行程
        thirdForwardStroke: `${item.thirdForwardStroke}` === '' ? undefined : item.thirdForwardStroke, //	第三次正行程
        thirdReverseStroke: `${item.thirdReverseStroke}` === '' ? undefined : item.thirdReverseStroke, //	第三次反行程
        firstForwardStroke: `${item.firstForwardStroke}` === '' ? undefined : item.firstForwardStroke, //	第一次正行程
        firstReverseStroke: `${item.firstReverseStroke}` === '' ? undefined : item.firstReverseStroke, //	第一次反行程
      }
    })
    loading.close()
  })
}

// -------------------------------------钩子-----------------------------------------------------
watch(() => itemCategoryName.value, (newVal) => {
  if (newVal === '压力值') {
    columns.value = columns_pressure.value
  }
  else {
    columns.value = columns_electrical_signal.value
  }
})

watch(() => props.pageType, (newValue) => {
  if (newValue === 'detail') {
    list.value = list.value.map((item: any) => {
      return {
        ...item,
        editable: props.pageType !== 'detail',
      }
    })
  }
}, { immediate: true })

onMounted(async () => {
  if (props.pageType !== 'add') {
    belongStandardEquipment.value = $route.query.belongStandardEquipment as string // 检校标准库
    itemCategoryId.value = $route.query.itemCategoryId as string // 核查项分类id
    itemCategoryName.value = $route.query.itemCategoryName as string // 核查项分类名称
    fetchInfo()
  }
})

defineExpose({ fetchCheckItemDetail, form, list })
</script>

<template>
  <!-- 核查数据 -->
  <detail-block title="核查数据">
    <template v-if="props.pageType !== 'detail'" #btns>
      <el-button v-if="props.pageType !== 'detail'" type="primary" @click="createResult">
        生成结果处理
      </el-button>
    </template>
    <!-- 表格  -->
    <multi-table
      v-loading="tableLoading"
      :table-data="list"
      :table-header="columns"
      :merge-rows="[]"
      :need-index="true"
    />

    <!-- 结论、备注 -->
    <el-form
      style="margin-top: 20px;"
      :model="form"
      label-width="160"
      label-position="right"
    >
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="结论:" prop="conclusion">
            <el-select v-model="form.conclusion" :placeholder="props.pageType === 'detail' ? ' ' : '结论'" :disabled="props.pageType === 'detail'" class="full-width-input">
              <el-option
                v-for="i in conclusionList"
                :key="i.value"
                :label="i.name"
                :value="i.value"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="备注:" prop="remark">
            <el-input v-model="form.remark" clearable class="full-width-input" :disabled="props.pageType === 'detail'" placeholder="备注" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </detail-block>

  <!-- 保存核查记录  -->
  <save-check-record ref="saveCheckRecordRef" />
</template>

<style lang="scss" scoped>
.link {
  text-decoration: underline;
  color: #3d7eff;
  cursor: pointer;
}

.file-area {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #60627f;
  margin-bottom: 10px;
  margin-left: 40px;
  white-space: nowrap;

  .tech-file {
    display: flex;
    align-items: center;
    margin-left: 20px;

    .file-text {
      margin-right: 10px;
    }
  }
}
</style>