<!-- 第6套:安全阀标准装置 -->
<!-- 检定数据管理详情模板 -->
<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 './sixth-interface'
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 multiTable from '@/components/MultiHeaderTable/index.vue'
import { calc } from '@/utils/useCalc'
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', // 外观检查
tightness: '1', // 密封试验
remark: '无', // 情况说明
conclusion: '1', // 检验结论
sealingTest: 1,
appearanceFunctionCheck: 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 conclusionList = ref<dictType[]>([])// 结论
async function getDict() {
// 结论
getDictByCode('bizUltimateness').then((response) => {
conclusionList.value = response.data
})
}
getDict()
// ------------------------------------------标签----------------------------------------------------------
const radioMenus = ref([ // 标签内容
{ name: '检定数据', value: 'measure-data' },
{ name: '历史修改记录', value: 'change-record' },
])
const current = ref('measure-data') // 选择的tab 默认基本信息
// ---------------------------------------检定项数据表格----------------------------------------------------
const list = ref<IDetailMeasureList[]>([]) // 表格数据
const columns = ref([ // 一般压力表、精密压力表、电接点一般压力表
{ text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
{ text: '单位', value: 'unit', align: 'center', required: true, type: 'text' },
{ text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'text' },
{ text: '允许值', value: 'allowValue', align: 'center', required: true, type: 'text' },
{
text: '第一次',
value: '',
align: 'center',
required: false,
children: [
{ text: '调整前', value: 'beforeAdjustFirst', align: 'center', required: true, width: '180', type: 'inputNumber' },
{ text: '调整后', value: 'afterAdjustFirst', align: 'center', required: true, width: '180', type: 'inputNumber' },
],
},
{
text: '第二次',
value: '',
align: 'center',
required: false,
children: [
{ text: '调整前', value: 'beforeAdjustSecond', align: 'center', required: true, width: '180', type: 'inputNumber' },
{ text: '调整后', value: 'afterAdjustSecond', align: 'center', required: true, width: '180', type: 'inputNumber' },
],
},
{
text: '第三次',
value: '',
align: 'center',
required: false,
children: [
{ text: '调整前', value: 'beforeAdjustThird', align: 'center', required: true, width: '180', type: 'inputNumber' },
{ text: '调整后', value: 'afterAdjustThird', align: 'center', required: true, width: '180', type: 'inputNumber' },
],
},
{
text: '平均值',
value: '',
align: 'center',
required: false,
children: [
{ text: '调整前', value: 'beforeAdjustAverage', align: 'center', required: false, type: 'text' },
{ text: '调整后', value: 'afterAdjustAverage', align: 'center', required: false, type: 'text' },
],
},
])
// -------------------------------------------获取详情信息--------------------------------------------------
// 获取页面详情信息
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)
res.data.measureDataSafetyValueList.forEach((item: any) => {
list.value.push({
beforeAdjustAverage: item.beforeAdjustAverage,
afterAdjustAverage: item.afterAdjustAverage,
beforeAdjustThird: item.beforeAdjustThird,
afterAdjustThird: item.afterAdjustThird,
beforeAdjustSecond: item.beforeAdjustSecond,
afterAdjustSecond: item.afterAdjustSecond,
beforeAdjustFirst: item.beforeAdjustFirst,
afterAdjustFirst: item.afterAdjustFirst,
allowValue: `${item.lowerAllowValue}~${item.upperAllowValue}`,
nominalValue: item.nominalValue,
lowerAllowValue: item.lowerAllowValue,
upperAllowValue: item.upperAllowValue,
unit: item.unit,
params: '整定压力',
editable: pageType.value !== 'detail',
id: item.id,
} as any)
})
// =======================================表单公共组件数据处理=======================================================
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) => {
data.forEach((item: any) => {
list.value.push({
beforeAdjustAverage: '',
afterAdjustAverage: '',
beforeAdjustThird: null,
afterAdjustThird: null,
beforeAdjustSecond: null,
afterAdjustSecond: null,
beforeAdjustFirst: null,
afterAdjustFirst: null,
allowValue: `${item.lowerAllowValue}~${item.upperAllowValue}`,
nominalValue: item.nominalValue,
lowerAllowValue: item.lowerAllowValue,
upperAllowValue: item.upperAllowValue,
unit: item.unit,
params: '整定压力',
editable: true,
} as any)
})
// if (pageType.value === 'add') {
// list.value = list.value.map((item: any) => ({ ...item, beforeAdjustSecond: item.beforeAdjustFirst || '', beforeAdjustThird: item.beforeAdjustFirst || '' }))
// }
}
/**
* 新增的时候获取检定项输入数据(获取检定项分类详情)
* @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, 'data')
// itemFormData.value.appearance = res.data.measureItemConfigPistonGauge.appearance ? '1' : '' // 外观及功能检查 1有外观,2没有外观
itemFormData.value.appearanceFunctionCheck = res.data.appearanceFunctionCheck // 外观及功能检查
itemFormData.value.sealingTest = res.data.sealingTest // 密封
// console.log(itemFormData.value, 'itemFormData.value')
initInputData(res.data.measureItemDataSafetyValveList)
})
}
// ----------------------------------------点击保存时校验---------------------------------------
// 校验
const checkout = () => {
return useCheckList(list.value, columns.value, '整定压力')
}
// -----------------------------------------生成结果处理----------------------------------------
// 点击生成结果处理
const createResult = () => {
// 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
// }
// })
}
// 计算结果
const countResult = () => {
if (checkout()) {
list.value.forEach((item: any) => {
item.beforeAdjustAverage = ((Number(item.beforeAdjustThird) + Number(item.beforeAdjustSecond) + Number(item.beforeAdjustFirst)) / 3).toFixed(4)
item.afterAdjustAverage = ((Number(item.afterAdjustThird) + Number(item.afterAdjustSecond) + Number(item.afterAdjustFirst)) / 3).toFixed(4)
})
}
}
// -------------------------------------------处理表格函数---------------------------------------
// el-input-number组件值变化
const handleInputNumberChange = (data: any) => {
console.log(data, 'data')
if (data.cellIndex === 5 && data.column.label === '调整前') {
console.log(data, 'data')
list.value[data.$index].beforeAdjustSecond = data.row.beforeAdjustFirst
list.value[data.$index].beforeAdjustThird = data.row.beforeAdjustFirst
}
}
// ------------------------------------------钩子----------------------------------------------
// 监听外观、密封、结论变化一次改变情况说明数据
watch(() => [itemFormData.value.appearance, itemFormData.value.tightness, itemFormData.value.conclusion], (newValue) => {
let state = ''
if (newValue[0] === '1' && newValue[1] === '1' && newValue[2] === '1') {
state = '无'
}
else {
const appearance = newValue[0] === '2' ? '外观不合格 ' : ''
const tightness = newValue[1] === '2' ? ' 密封试验不合格 ' : ''
const conclusion = newValue[2] === '2' ? ' 整定压力超差' : ''
state = appearance + tightness + conclusion
}
itemFormData.value.remark = state
})
watch(() => list.value, (newVal) => {
if (newVal) {
if (newVal.length && pageType.value !== 'detail') {
const flag = newVal.every((item: any) => Number(item.beforeAdjustAverage) <= Number(item.upperAllowValue) && Number(item.beforeAdjustAverage) >= Number(item.lowerAllowValue) && Number(item.afterAdjustAverage) <= Number(item.upperAllowValue) && Number(item.afterAdjustAverage) >= Number(item.lowerAllowValue))
if (flag && (itemFormData.value.appearance == '1' && itemFormData.value.appearanceFunctionCheck) && (itemFormData.value.tightness === '1' && itemFormData.value.sealingTest)) {
itemFormData.value.conclusion = '1'
itemFormData.value.remark = '无'
}
else if (flag && (itemFormData.value.appearance == '1' && itemFormData.value.appearanceFunctionCheck) && !itemFormData.value.sealingTest) {
itemFormData.value.conclusion = '1'
itemFormData.value.remark = '无'
}
else if (flag && (itemFormData.value.tightness === '1' && itemFormData.value.sealingTest) && !itemFormData.value.appearanceFunctionCheck) {
itemFormData.value.conclusion = '1'
itemFormData.value.remark = '无'
}
else if (flag && !itemFormData.value.appearanceFunctionCheck && !itemFormData.value.sealingTest) {
itemFormData.value.conclusion = '1'
itemFormData.value.remark = '无'
}
if (!flag) {
itemFormData.value.conclusion = '2'
itemFormData.value.remark = '整定压力超差'
}
}
}
}, {
deep: true,
})
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, list, templateFormAndTableRef, pageType })
</script>
<template>
<div>
<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>
<!-- 外观 -->
<el-col v-if="itemFormData.appearanceFunctionCheck" :span="6">
<el-form-item label="外观检查:" prop="appearance">
<el-select v-model="itemFormData.appearance" :disabled="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 v-if="itemFormData.sealingTest" :span="6">
<el-form-item label="密封试验:" prop="tightness">
<el-select v-model="itemFormData.tightness" :disabled="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-row>
</el-form>
<detail-block v-if="current === 'measure-data'" title="整定压力" style="margin-top: 0;padding: 0;">
<template v-if="pageType !== 'detail'" #btns>
<el-button type="primary" @click="countResult">
计算结果
</el-button>
</template>
<multi-table
:table-data="list"
:table-header="columns"
:merge-rows="[]"
:need-index="true"
@handle-input-number-change="handleInputNumberChange"
/>
</detail-block>
<el-form
v-if="current === 'measure-data'"
ref="formRef"
:model="itemFormData"
label-width="140"
label-position="right"
style="margin-top: 20px;"
>
<el-row>
<!-- 检验结论 -->
<el-col :span="6">
<el-form-item label="检验结论:" prop="conclusion">
<el-select v-model="itemFormData.conclusion" :disabled="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="itemFormData.remark"
autosize
type="textarea"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<!-- 历史修改记录 -->
<change-record v-show="pageType === 'detail' && current === 'change-record'" :info-id="infoId" />
</detail-block>
</div>
</template>
<style lang="scss" scoped>
.setBottom {
padding-bottom: 20px;
}
</style>