142 lines
3.9 KiB
Vue
Raw Normal View History

2025-10-16 11:20:50 +08:00
<template>
2025-10-22 17:36:25 +08:00
<div class="reex_box">
2025-10-24 17:36:06 +08:00
<div class="mb10">
2025-10-29 18:02:33 +08:00
<el-button type="primary" plain @click="openItemDictDialog">新增</el-button>
2025-10-24 17:36:06 +08:00
</div>
2025-10-22 17:36:25 +08:00
<!-- 结果复查 -->
2025-10-24 17:36:06 +08:00
<el-table ref="tableRef" :data="tableData" style="width: 100%" border height="77vh" show-overflow-tooltip>
2025-10-24 15:23:13 +08:00
<el-table-column prop="xmdh" label="检验项目" align="center" width="120" />
2025-10-24 17:36:06 +08:00
<el-table-column prop="csjg" label="复查前结果" align="center" width="150">
<template #default="{ row }">
<el-input v-model="row.csjg" class="full-width-input" @change="handleCsjgEnter(row)" />
</template>
</el-table-column>
2025-10-24 15:23:13 +08:00
<el-table-column label="操作" width="150">
2025-10-29 18:02:33 +08:00
<template #default="{ row }">
<el-button type="primary" link size="small" @click="deleteRedo(row)"> 删除 </el-button>
<el-button type="primary" link size="small" @click="jhRedo(row)">交换</el-button>
2025-10-24 15:23:13 +08:00
</template>
</el-table-column>
</el-table>
2025-10-29 18:02:33 +08:00
2025-11-03 12:12:47 +08:00
<!-- 新增明细-->
<ProjectDetails ref="itemDictRef" :dialog-title="'选择检验项目'" :tableKey="tablekey" @select="handleItemSelect" />
2025-10-16 11:20:50 +08:00
</div>
</template>
<script setup lang="ts">
2025-10-29 18:02:33 +08:00
import { ref, watch, toRefs, onMounted, nextTick } from 'vue'
import { redoResult, queryXmInfo, saveRedo, swapRedo, delRedo } from "@/api/liswork/work/LisWork";
import { ElMessage } from 'element-plus'
// @ts-ignore
2025-11-03 12:12:47 +08:00
import ProjectDetails from '@/components/projectDetails/index.vue'
2025-10-22 17:36:25 +08:00
const props = defineProps({
// 主键
queryParams: {
type: Object,
default: {}
},
2025-11-03 12:12:47 +08:00
tablekey: {
type: Object,
default: () => { }
}
2025-10-22 17:36:25 +08:00
})
// 解构 props
const { queryParams } = toRefs(props);
2025-10-29 18:02:33 +08:00
const tableData: any = ref([]);
2025-10-22 17:36:25 +08:00
const getReexamination = () => {
redoResult(queryParams.value).then((res: any) => {
if (res.code == 0) {
2025-10-24 15:23:13 +08:00
tableData.value = res.data || [];
2025-10-22 17:36:25 +08:00
}
})
};
watch(() => queryParams.value, () => {
getReexamination();
2025-11-27 17:50:31 +08:00
}, {
immediate: true,
deep: true
})
2025-10-24 17:36:06 +08:00
2025-10-29 18:02:33 +08:00
const tableRef = ref();
const itemDictRef = ref(); // DictInput组件引用
2025-11-03 12:12:47 +08:00
2025-10-29 18:02:33 +08:00
// 事件定义
const emits = defineEmits(['fetchResults',]);
const openItemDictDialog = () => {
2025-11-03 12:12:47 +08:00
itemDictRef.value.openDictSelector(); // 确保方法存在再调用
2025-10-29 18:02:33 +08:00
};
const handleItemSelect = async (selectedItem: any) => {
// 1. 构造新增行数据
const newRow = {
id: `temp_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`,
xmdh: selectedItem.value,
xmmc: selectedItem.label,
dw: selectedItem.dw || "",
refs: selectedItem.refs || "",
jyrq: queryParams.value.jyrq,
yq: queryParams.value.yq,
ybh: queryParams.value.ybh,
};
addRowFromDict(newRow);
// ElMessage.success(`已新增项目:${newRow.xmmc}`);
};
const addRowFromDict = async (rowData: any) => {
2025-11-03 12:12:47 +08:00
if (!rowData.xmdh) return ElMessage.error("新增失败:项目编码不能为空");
2025-10-29 18:02:33 +08:00
const isDuplicate = tableData.value.some((item: any) => item.xmdh === rowData.xmdh);
2025-11-03 12:12:47 +08:00
if (isDuplicate) return ElMessage.warning(`项目【${rowData.xmmc}】已存在`);
2025-10-29 18:02:33 +08:00
const newRow = { ...rowData, csjg: "" };
tableData.value.push(newRow);
// 5. 自动聚焦
nextTick(() => {
tableRef.value.setCurrentRow(newRow);
2025-11-03 18:07:51 +08:00
tableRef.value.setScrollTo(tableData.value.length - 1)
2025-11-03 12:12:47 +08:00
// 聚焦到新行的输入框
const inputs = document.querySelectorAll('.full-width-input .el-input__inner') as NodeListOf<HTMLInputElement>;
if (inputs.length > 0) {
inputs[inputs.length - 1]?.focus();
}
2025-10-29 18:02:33 +08:00
});
};
2025-10-24 17:36:06 +08:00
const handleCsjgEnter = (row: any) => {
2025-10-29 18:02:33 +08:00
saveRedo(row)
}
const deleteRedo = (row: any) => {
delRedo(row).then((res: any) => {
if (res.code == 0) {
getReexamination();
}
})
}
const jhRedo = (row: any) => {
swapRedo(row).then((res: any) => {
if (res.code == 0) {
getReexamination();
emits('fetchResults')
}
})
2025-10-24 17:36:06 +08:00
}
2025-10-16 11:20:50 +08:00
</script>
2025-10-22 17:36:25 +08:00
<style scoped lang="scss">
.reex_box {
height: 82vh;
overflow-y: auto;
}
</style>