219 lines
6.0 KiB
Vue
Raw Normal View History

2025-11-03 18:07:12 +08:00
<template>
<!-- 计算项目表达式生成向导 -->
2025-12-12 15:49:03 +08:00
<el-dialog :model-value="visible" @update:model-value="handleVisibleChange" title="计算项目表达式生成向导" width="600px"
:close-on-click-modal="false" :draggable="true" @close="onClose" @open="onOpen">
2025-11-06 18:22:18 +08:00
<el-row class="input-text">
2025-11-07 17:50:06 +08:00
<el-input type="textarea" v-model="inputText"></el-input>
2025-11-06 18:22:18 +08:00
</el-row>
2025-11-04 15:14:07 +08:00
<el-row>
2025-11-06 18:22:18 +08:00
<el-col :span="12">
2025-12-15 18:06:42 +08:00
<el-input v-model="searchKey" ref="searchInput" size="small" placeholder="快速搜索(支持简拼)" class="mb10" clearable
@clear="filterDataHandle" @input="filterDataHandle" />
<CustomTable ref="tableRefs" :data="filterData" :columns="columns" :config="tableConfig" @row-click="rowHandle"
2025-12-12 15:49:03 +08:00
:enableColumnDrag="true" @column-drag-end="handleColumnDragEnd" />
2025-11-06 18:22:18 +08:00
</el-col>
<el-col :span="12" class="right">
<el-button type="" @click="bClickAdd">+ 加</el-button>
<el-button type="" @click="bClickSub">- 减</el-button>
<el-button type="" @click="bClickMul">* 乘</el-button>
<el-button type="" @click="bClickDiv">/ 除</el-button>
<el-button type="" @click="bClickLeft">(</el-button>
<el-button type="" @click="bClickRight">)</el-button>
<el-button type="" @click="bClickPower">^次方</el-button>
<el-button type="" @click="bClickSex">性别</el-button>
<el-button type="" @click="bClickAge">年龄</el-button>
<h4>说明:</h4>
<h4>1.计算公式中不可包括其他计算项目,若有需要,</h4>
<h4>一律转换为最原始的计算公式</h4>
<h4>2.所有项目代号必须使用“[”和“]”括起来</h4>
<h4>3.表达式可以为一个常数或空字符串</h4>
</el-col>
2025-11-03 18:07:12 +08:00
</el-row>
2025-11-04 15:14:07 +08:00
<!-- 底部按钮(可选) -->
<template #footer>
<el-button type="primary" @click="handleOk">确定</el-button>
2025-11-06 18:22:18 +08:00
<el-button @click="handleCancel">取消</el-button>
2025-11-04 15:14:07 +08:00
</template>
2025-11-03 18:07:12 +08:00
</el-dialog>
</template>
<script setup lang="ts">
import CustomTable from '@/components/elTable/index.vue'
2025-11-06 18:22:18 +08:00
import { queryXmInfoNew } from '@/api/liswork/labItem/labItemApi'
2025-12-15 18:06:42 +08:00
// @ts-ignore
import { getFirstLetter } from '@/utils/pinyin.js';
2025-11-06 18:22:18 +08:00
const props = defineProps({
2025-12-12 15:49:03 +08:00
formData: {
2025-11-06 18:22:18 +08:00
type: Object,
default: {}
}
})
2025-11-03 18:07:12 +08:00
2025-11-04 15:14:07 +08:00
let visible = ref<boolean>()
2025-12-15 18:06:42 +08:00
const currentIndex = ref(0)
const searchKey = ref('');
const filterData = ref<{ [key: string]: any; pinyinMap: Record<string, string> }[]>([]);
2025-11-04 15:14:07 +08:00
const tableData = ref()
2025-11-03 18:07:12 +08:00
const inputText = ref('')
2025-12-15 18:06:42 +08:00
const tableRefs = ref()
2025-11-04 15:14:07 +08:00
const emit = defineEmits(['update:model-value', 'confirm'])
2025-11-03 18:07:12 +08:00
2025-11-04 15:14:07 +08:00
const columns = ref([
2025-12-12 15:49:03 +08:00
{ prop: 'xmdh', label: '项目代号', align: 'center', visible: true, width: 100 },
{ prop: 'xmmc', label: '项目名称', align: 'center', visible: true, width: 180 }
2025-11-04 15:14:07 +08:00
])
// 表格配置
const tableConfig = ref(
{
// stripe: true, // 斑马纹
border: true, // 边框
2025-11-06 18:22:18 +08:00
height: '350', // 高度
2025-11-04 15:14:07 +08:00
highlightCurrentRow: true, // 高亮当前行
fit: true
}
)
2025-11-03 18:07:12 +08:00
2025-11-07 17:50:06 +08:00
//向外暴露数据
2025-12-12 15:49:03 +08:00
defineExpose({ inputText })
2025-11-07 17:50:06 +08:00
watch(
() => props.formData.jsgs, // 监听的目标:formData.jsgs
2025-12-12 15:49:03 +08:00
(newVal: any) => {
2025-11-07 17:50:06 +08:00
inputText.value = newVal // 当新值变化时,更新 inputText
},
{ immediate: true } // 立即执行一次(确保初始化时也能同步)
)
2025-11-04 15:14:07 +08:00
const handleColumnDragEnd = (newColumns: any) => {
columns.value = newColumns.columns
2025-11-03 18:07:12 +08:00
}
2025-12-15 18:06:42 +08:00
2025-11-06 18:22:18 +08:00
const rowHandle = (row: any) => {
2025-12-12 15:49:03 +08:00
inputText.value += '[' + row.xmdh + ']'
2025-11-03 18:07:12 +08:00
}
2025-11-04 15:14:07 +08:00
const onClose = () => {
emit('update:model-value', false)
}
const handleOk = () => {
2025-12-12 15:49:03 +08:00
emit('confirm', inputText.value) // 通知外部执行确认操作
2025-11-04 15:14:07 +08:00
emit('update:model-value', false) // 确认后关闭
}
2025-11-03 18:07:12 +08:00
const handleCancel = () => {
2025-11-04 15:14:07 +08:00
emit('update:model-value', false)
}
const handleVisibleChange = (newVisible: boolean) => {
// 通知父组件:状态变为 newVisible(可能是 true 或 false)
emit('update:model-value', newVisible)
}
const bClickAdd = () => {
2025-11-06 18:22:18 +08:00
inputText.value += '+'
2025-11-03 18:07:12 +08:00
}
2025-11-04 15:14:07 +08:00
const bClickSub = () => {
2025-11-06 18:22:18 +08:00
inputText.value += '-'
2025-11-04 15:14:07 +08:00
}
const bClickMul = () => {
2025-11-06 18:22:18 +08:00
inputText.value += '*'
2025-11-04 15:14:07 +08:00
}
const bClickDiv = () => {
2025-11-06 18:22:18 +08:00
inputText.value += '/'
2025-11-04 15:14:07 +08:00
}
const bClickLeft = () => {
2025-11-06 18:22:18 +08:00
inputText.value += '('
2025-11-04 15:14:07 +08:00
}
const bClickRight = () => {
2025-11-06 18:22:18 +08:00
inputText.value += ')'
2025-11-04 15:14:07 +08:00
}
const bClickPower = () => {
2025-11-06 18:22:18 +08:00
inputText.value += '^'
}
const bClickSex = () => {
inputText.value += '[SEX]'
}
const bClickAge = () => {
inputText.value += '[AGE]'
2025-11-04 15:14:07 +08:00
}
2025-12-12 15:49:03 +08:00
const onOpen = async () => {
2025-11-07 17:50:06 +08:00
const res = await queryXmInfoNew(props.formData.xmgl);
2025-12-15 18:06:42 +08:00
tableData.value = processTableData(res.data)
filterData.value = [...tableData.value]
}
// 预处理数据:生成拼音信息
const processTableData = (data: object[]) => {
return data.map((item: any) => {
const pinyinMap: Record<string, string> = {};
// 处理label字段拼音
if (item.xmmc) {
pinyinMap.xmmc = getFirstLetter(item.xmmc).toLowerCase();
}
if (item.xmdh) {
pinyinMap.xmdh = getFirstLetter(item.xmdh).toLowerCase();
}
return { ...item, pinyinMap };
});
};
// 搜索过滤逻辑
const filterDataHandle = () => {
const key = searchKey.value.trim().toLowerCase();
if (!key) {
// 空搜索时显示全部预处理数据
filterData.value = [...tableData.value];
return;
} else {
currentIndex.value = 0
}
filterData.value = tableData.value.filter((item: any) => {
// 1. 原文本匹配
const matchLabel = item.xmmc?.toString().toLowerCase().includes(key);
const matchValue = item.xmdh?.toString().toLowerCase().includes(key);
// 2. 拼音匹配
const matchLabelPinyin = item.pinyinMap.xmmc?.includes(key);
const matchValuePinyin = item.pinyinMap.xmdh?.includes(key);
return matchLabel || matchValue || matchLabelPinyin || matchValuePinyin;
});
if (filterData.value.length > 0) {
tableRefs.value.setScrollTop(0)
tableRefs.value.setCurrentRow(filterData.value[0]);
}
};
2025-11-06 18:22:18 +08:00
2025-11-03 18:07:12 +08:00
</script>
<style scoped lang="scss">
2025-11-06 18:22:18 +08:00
.input-text {
margin-bottom: 10px;
}
2025-12-12 15:49:03 +08:00
2025-11-06 18:22:18 +08:00
// .right {
// margin-left: 2px;
// }
.el-button {
margin-bottom: 5px;
}
2025-11-03 18:07:12 +08:00
</style>