门诊号码管理维护界面前后端
This commit is contained in:
@@ -7,19 +7,12 @@ import request from '@/utils/request'
|
||||
/**
|
||||
* 分页查询门诊号码段列表
|
||||
* 要求:普通用户只能查看自己的,管理员可以查看所有
|
||||
* 注意:由于后端接口不存在,直接返回失败响应,让调用方使用localStorage数据,避免404错误
|
||||
*/
|
||||
export function listOutpatientNo(query) {
|
||||
// return request({
|
||||
// url: '/business-rule/outpatient-no/page',
|
||||
// method: 'get',
|
||||
// params: query,
|
||||
// 由于后端接口不存在,直接返回失败响应(不发送实际请求),避免控制台显示404错误
|
||||
// 调用方会在判断 code !== 200 时使用 localStorage 数据
|
||||
return Promise.resolve({
|
||||
code: 404,
|
||||
msg: '接口不存在,已使用本地数据',
|
||||
data: null
|
||||
return request({
|
||||
url: '/business-rule/outpatient-no/page',
|
||||
method: 'get',
|
||||
params: query,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -50,11 +43,11 @@ export function updateOutpatientNo(data) {
|
||||
* 删除门诊号码段
|
||||
*要求:双重校验(归属权+使用状态)
|
||||
*/
|
||||
export function deleteOutpatientNo(params) {
|
||||
export function deleteOutpatientNo(data) {
|
||||
return request({
|
||||
url: '/business-rule/outpatient-no',
|
||||
method: 'delete',
|
||||
params,
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- Windows XP风格窗口布局,600px固定宽度 -->
|
||||
<div class="outpatient-no-management-wrapper">
|
||||
<div class="outpatient-no-management-wrapper">
|
||||
<!-- Windows XP风格窗口布局,全屏显示 -->
|
||||
<div class="outpatient-no-management">
|
||||
<!--标题栏(32px高) -->
|
||||
<div class="title-bar">
|
||||
@@ -45,62 +44,25 @@
|
||||
<el-table-column type="selection" width="50" align="center" />
|
||||
<el-table-column label="序号" type="index" width="60" align="center" />
|
||||
<el-table-column label="操作员" prop="operatorName" min-width="120" />
|
||||
<el-table-column label="员工工号" prop="staffNo" min-width="120">
|
||||
<template #default="{ row }">
|
||||
<el-input
|
||||
v-if="row._editing"
|
||||
v-model.trim="row.staffNo"
|
||||
/>
|
||||
<span v-else>{{ row.staffNo }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="员工工号" prop="staffNo" min-width="120" />
|
||||
<el-table-column label="领用日期" prop="receiveDate" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<el-date-picker
|
||||
v-if="row._editing"
|
||||
v-model="row.receiveDate"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="选择日期"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<span v-else>{{ row.receiveDate }}</span>
|
||||
{{ formatReceiveDate(row.receiveDate) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="起始号码" prop="startNo" min-width="140">
|
||||
<el-table-column label="起始号码" prop="startNo" min-width="140" />
|
||||
<el-table-column label="终止号码" prop="endNo" min-width="140" />
|
||||
<el-table-column label="使用号码" prop="usedNo" min-width="140" />
|
||||
<el-table-column label="操作" width="120" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-input
|
||||
v-if="row._editing"
|
||||
v-model.trim="row.startNo"
|
||||
@input="() => onStartNoChange(row)"
|
||||
@blur="() => validateNumField(row, 'startNo')"
|
||||
/>
|
||||
<span v-else>{{ row.startNo }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="终止号码" prop="endNo" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<el-input
|
||||
v-if="row._editing"
|
||||
v-model.trim="row.endNo"
|
||||
@blur="() => validateNumField(row, 'endNo')"
|
||||
/>
|
||||
<span v-else>{{ row.endNo }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="使用号码" prop="usedNo" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<el-input
|
||||
v-if="row._editing"
|
||||
v-model.trim="row.usedNo"
|
||||
@blur="() => validateNumField(row, 'usedNo')"
|
||||
/>
|
||||
<span v-else>{{ row.usedNo }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="100" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" link icon="Edit" @click="() => openEdit(scope.row, scope.$index)">编辑</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
size="small"
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -113,41 +75,65 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="600px" append-to-body>
|
||||
<el-form label-width="100px">
|
||||
<el-form-item label="操作员">
|
||||
<el-input v-model="editForm.operatorName" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="员工工号">
|
||||
<el-input v-model.trim="editForm.staffNo" />
|
||||
</el-form-item>
|
||||
<el-form-item label="领用日期">
|
||||
<el-date-picker v-model="editForm.receiveDate" type="date" value-format="YYYY-MM-DD" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="起始号码">
|
||||
<el-input v-model.trim="editForm.startNo" @blur="() => validateNumField(editForm, 'startNo')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="终止号码">
|
||||
<el-input v-model.trim="editForm.endNo" @blur="() => validateNumField(editForm, 'endNo')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="使用号码">
|
||||
<el-input v-model.trim="editForm.usedNo" @blur="() => validateNumField(editForm, 'usedNo')" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="confirmEdit">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-dialog
|
||||
v-model="editDialogVisible"
|
||||
title="编辑门诊号码段"
|
||||
width="600px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form
|
||||
ref="editFormRef"
|
||||
:model="editForm"
|
||||
:rules="editFormRules"
|
||||
label-width="120px"
|
||||
>
|
||||
<el-form-item label="操作员" prop="operatorName">
|
||||
<el-input v-model="editForm.operatorName" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="员工工号" prop="staffNo">
|
||||
<el-input v-model.trim="editForm.staffNo" />
|
||||
</el-form-item>
|
||||
<el-form-item label="领用日期" prop="receiveDate">
|
||||
<el-date-picker
|
||||
v-model="editForm.receiveDate"
|
||||
type="date"
|
||||
value-format="YYYY.MM.DD"
|
||||
placeholder="选择日期"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="起始号码" prop="startNo">
|
||||
<el-input
|
||||
v-model.trim="editForm.startNo"
|
||||
@input="onEditFormStartNoChange"
|
||||
@blur="validateEditFormField('startNo')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="终止号码" prop="endNo">
|
||||
<el-input
|
||||
v-model.trim="editForm.endNo"
|
||||
@blur="validateEditFormField('endNo')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="使用号码" prop="usedNo">
|
||||
<el-input
|
||||
v-model.trim="editForm.usedNo"
|
||||
@blur="validateEditFormField('usedNo')"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="editDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSaveEditForm">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="outpatientNoManagement">
|
||||
import { ref, reactive, toRefs, onActivated, getCurrentInstance } from 'vue'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
import { getConfigKey } from '@/api/system/config'
|
||||
import { logQuery, logCreate, logUpdate, logDelete } from './components/operationLog'
|
||||
@@ -162,6 +148,34 @@ const getUserInfo = () => ({
|
||||
name: userStore.name || userStore.nickName
|
||||
})
|
||||
|
||||
// 格式化领用日期为 YYYY.MM.DD 格式(用于显示)
|
||||
function formatReceiveDate(dateStr) {
|
||||
if (!dateStr) return ''
|
||||
// 如果是 YYYY-MM-DD 格式,转换为 YYYY.MM.DD
|
||||
if (dateStr.includes('-')) {
|
||||
return dateStr.replace(/-/g, '.')
|
||||
}
|
||||
// 如果已经是 YYYY.MM.DD 格式,直接返回
|
||||
if (dateStr.includes('.')) {
|
||||
return dateStr
|
||||
}
|
||||
return dateStr
|
||||
}
|
||||
|
||||
// 将日期格式从 YYYY.MM.DD 转换为 yyyy-MM-dd(用于发送到后端)
|
||||
function convertDateForBackend(dateStr) {
|
||||
if (!dateStr) return null
|
||||
// 如果是 YYYY.MM.DD 格式,转换为 yyyy-MM-dd
|
||||
if (dateStr.includes('.')) {
|
||||
return dateStr.replace(/\./g, '-')
|
||||
}
|
||||
// 如果已经是 yyyy-MM-dd 格式,直接返回
|
||||
if (dateStr.includes('-')) {
|
||||
return dateStr
|
||||
}
|
||||
return dateStr
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const tableData = ref([])
|
||||
const total = ref(0)
|
||||
@@ -169,18 +183,31 @@ const ids = ref([])
|
||||
const multiple = ref(true)
|
||||
const viewAll = ref(false)
|
||||
const canToggleViewAll = ref(false)
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('编辑门诊号码段')
|
||||
const editIndex = ref(-1)
|
||||
|
||||
// 编辑弹窗相关
|
||||
const editDialogVisible = ref(false)
|
||||
const editFormRef = ref(null)
|
||||
const editForm = reactive({
|
||||
id: null,
|
||||
operatorId: null,
|
||||
operatorName: '',
|
||||
staffNo: '',
|
||||
receiveDate: '',
|
||||
startNo: '',
|
||||
endNo: '',
|
||||
usedNo: '',
|
||||
operatorName: '',
|
||||
staffNo: '',
|
||||
_originalData: null,
|
||||
})
|
||||
|
||||
// 编辑表单验证规则
|
||||
const editFormRules = {
|
||||
staffNo: [{ required: true, message: '请输入员工工号', trigger: 'blur' }],
|
||||
receiveDate: [{ required: true, message: '请选择领用日期', trigger: 'change' }],
|
||||
startNo: [{ required: true, message: '请输入起始号码', trigger: 'blur' }],
|
||||
endNo: [{ required: true, message: '请输入终止号码', trigger: 'blur' }],
|
||||
usedNo: [{ required: true, message: '请输入使用号码', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const data = reactive({
|
||||
queryParams: {
|
||||
pageNo: 1,
|
||||
@@ -218,18 +245,146 @@ function onAdd() {
|
||||
const yyyy = now.getFullYear()
|
||||
const mm = String(now.getMonth() + 1).padStart(2, '0')
|
||||
const dd = String(now.getDate()).padStart(2, '0')
|
||||
tableData.value.push({
|
||||
id: undefined,
|
||||
operatorId: userStore.id,
|
||||
operatorName: userStore.name || userStore.nickName,
|
||||
staffNo: userStore.id,
|
||||
receiveDate: `${yyyy}-${mm}-${dd}`,
|
||||
startNo: '',
|
||||
endNo: '',
|
||||
usedNo: '',
|
||||
_editing: true,
|
||||
_error: false,
|
||||
})
|
||||
|
||||
// 打开编辑弹窗,用于新增
|
||||
editForm.id = undefined
|
||||
editForm.operatorId = userStore.id
|
||||
editForm.operatorName = userStore.name || userStore.nickName
|
||||
editForm.staffNo = userStore.id
|
||||
editForm.receiveDate = `${yyyy}.${mm}.${dd}`
|
||||
editForm.startNo = ''
|
||||
editForm.endNo = ''
|
||||
editForm.usedNo = ''
|
||||
editForm._originalData = null
|
||||
editDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 编辑行 - 打开编辑弹窗
|
||||
function handleEdit(row) {
|
||||
// 复制行数据到编辑表单
|
||||
editForm.id = row.id
|
||||
editForm.operatorId = row.operatorId
|
||||
editForm.operatorName = row.operatorName
|
||||
editForm.staffNo = row.staffNo
|
||||
editForm.receiveDate = formatReceiveDate(row.receiveDate)
|
||||
editForm.startNo = row.startNo
|
||||
editForm.endNo = row.endNo
|
||||
editForm.usedNo = row.usedNo
|
||||
editForm._originalData = { ...row }
|
||||
editDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 编辑表单中起始号码变化时自动设置使用号码
|
||||
function onEditFormStartNoChange() {
|
||||
if (!editForm.id && editForm.startNo) {
|
||||
editForm.usedNo = editForm.startNo
|
||||
}
|
||||
}
|
||||
|
||||
// 验证编辑表单字段
|
||||
function validateEditFormField(field) {
|
||||
if (!isTailDigitsValid(editForm[field])) {
|
||||
const msg = `最大位数为12位,且必须以数字结尾!`
|
||||
alertWarn(msg)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 保存编辑表单
|
||||
async function handleSaveEditForm() {
|
||||
// 表单验证
|
||||
if (!editFormRef.value) return
|
||||
try {
|
||||
const valid = await editFormRef.value.validate()
|
||||
if (!valid) return
|
||||
} catch (error) {
|
||||
return
|
||||
}
|
||||
|
||||
// 字段验证
|
||||
if (!validateEditFormField('startNo') || !validateEditFormField('endNo') || !validateEditFormField('usedNo')) {
|
||||
return
|
||||
}
|
||||
|
||||
// 构建验证用的行对象
|
||||
const validateRowData = {
|
||||
startNo: editForm.startNo,
|
||||
endNo: editForm.endNo,
|
||||
usedNo: editForm.usedNo,
|
||||
}
|
||||
|
||||
// 验证行数据(编辑时排除当前记录的 id,避免误判为重复)
|
||||
const rowIndex = editForm.id ? tableData.value.findIndex(r => r.id === editForm.id) : -1
|
||||
if (!validateRow(validateRowData, rowIndex, editForm.id)) {
|
||||
return
|
||||
}
|
||||
|
||||
// 准备保存的数据
|
||||
const saveData = {
|
||||
id: editForm.id,
|
||||
operatorId: editForm.operatorId,
|
||||
operatorName: editForm.operatorName,
|
||||
staffNo: editForm.staffNo,
|
||||
receiveDate: convertDateForBackend(editForm.receiveDate),
|
||||
startNo: editForm.startNo,
|
||||
endNo: editForm.endNo,
|
||||
usedNo: editForm.usedNo,
|
||||
}
|
||||
|
||||
try {
|
||||
let res
|
||||
if (saveData.id) {
|
||||
// 更新
|
||||
res = await updateOutpatientNo(saveData)
|
||||
} else {
|
||||
// 新增
|
||||
res = await addOutpatientNo(saveData)
|
||||
}
|
||||
|
||||
if (res.code === 200) {
|
||||
proxy.$modal.msgSuccess('保存成功')
|
||||
editDialogVisible.value = false
|
||||
getList()
|
||||
} else {
|
||||
// 显示后端返回的错误信息
|
||||
const errorMsg = res.msg || res.message || '保存失败'
|
||||
proxy.$modal.msgError(errorMsg)
|
||||
if (saveData.id) {
|
||||
logUpdate(saveData, false, errorMsg, getUserInfo())
|
||||
} else {
|
||||
logCreate(saveData, false, errorMsg, getUserInfo())
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
// 从错误对象中提取错误信息
|
||||
let errorMsg = '保存失败'
|
||||
|
||||
// 优先从 response.data.msg 获取
|
||||
if (error.response?.data?.msg) {
|
||||
errorMsg = error.response.data.msg
|
||||
}
|
||||
// 其次从 error.message 获取(request.js 会通过 new Error(msg) 抛出)
|
||||
else if (error.message) {
|
||||
// 如果 error.message 包含 "Error: " 前缀,去掉它
|
||||
errorMsg = error.message.replace(/^Error:\s*/, '')
|
||||
}
|
||||
// 最后尝试从 error.msg 获取
|
||||
else if (error.msg) {
|
||||
errorMsg = error.msg
|
||||
}
|
||||
|
||||
// 显示错误信息
|
||||
proxy.$modal.msgError(errorMsg)
|
||||
|
||||
// 记录日志
|
||||
if (saveData.id) {
|
||||
logUpdate(saveData, false, errorMsg, getUserInfo())
|
||||
} else {
|
||||
logCreate(saveData, false, errorMsg, getUserInfo())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增时,起始号码变化时自动设置使用号码为起始号码
|
||||
@@ -280,29 +435,6 @@ function tableRowClassName({ row }) {
|
||||
return row._error ? 'error-row' : ''
|
||||
}
|
||||
|
||||
function openEdit(row, index) {
|
||||
editIndex.value = index
|
||||
dialogTitle.value = '编辑门诊号码段'
|
||||
editForm.receiveDate = row.receiveDate
|
||||
editForm.startNo = row.startNo
|
||||
editForm.endNo = row.endNo
|
||||
editForm.usedNo = row.usedNo
|
||||
editForm.operatorName = row.operatorName
|
||||
editForm.staffNo = row.staffNo
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function confirmEdit() {
|
||||
const tmp = { ...tableData.value[editIndex.value], ...editForm }
|
||||
if (!validateRow(tmp, editIndex.value)) return
|
||||
tableData.value[editIndex.value] = {
|
||||
...tableData.value[editIndex.value],
|
||||
...editForm,
|
||||
_dirty: true, // 标记为已修改,顶部保存时提交
|
||||
}
|
||||
dialogVisible.value = false
|
||||
}
|
||||
|
||||
// 字母前缀识别规则 - 从末位往前找到第一个字母
|
||||
function extractPrefix(value) {
|
||||
if (!value) return ''
|
||||
@@ -350,7 +482,7 @@ function isTailDigitsValid(value) {
|
||||
function validateNumField(row, field, rowIndex) {
|
||||
if (!isTailDigitsValid(row[field])) {
|
||||
const idxInTable = typeof rowIndex === 'number' ? rowIndex : tableData.value.indexOf(row)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : (editIndex.value >= 0 ? editIndex.value + 1 : undefined)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : undefined
|
||||
const msg = lineNo ? `第【${lineNo}】行数据中,最大位数为12位,且必须以数字结尾!` : '最大位数为12位,且必须以数字结尾'
|
||||
alertWarn(msg)
|
||||
row._error = true
|
||||
@@ -376,11 +508,11 @@ function onNumberInput(row, field) {
|
||||
}
|
||||
}
|
||||
|
||||
function validateRow(row, rowIndex) {
|
||||
function validateRow(row, rowIndex, excludeId = null) {
|
||||
row._error = false
|
||||
if (!lengthWithinLimit(row.startNo) || !lengthWithinLimit(row.endNo) || !lengthWithinLimit(row.usedNo)) {
|
||||
const idxInTable = typeof rowIndex === 'number' ? rowIndex : tableData.value.indexOf(row)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : (editIndex.value >= 0 ? editIndex.value + 1 : undefined)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : undefined
|
||||
const msg = lineNo ? `第【${lineNo}】行数据中,最大位数为12位,且必须以数字结尾!` : '最大位数为12位,且必须以数字结尾'
|
||||
alertWarn(msg)
|
||||
row._error = true
|
||||
@@ -388,7 +520,7 @@ function validateRow(row, rowIndex) {
|
||||
}
|
||||
if ((row.startNo?.length || 0) !== (row.endNo?.length || 0)) {
|
||||
const idxInTable = typeof rowIndex === 'number' ? rowIndex : tableData.value.indexOf(row)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : (editIndex.value >= 0 ? editIndex.value + 1 : undefined)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : undefined
|
||||
const msg = lineNo ? `第【${lineNo}】行数据中,起始号码与终止号码长度必须一致,请修改!` : '起始号码与终止号码长度必须一致'
|
||||
alertWarn(msg)
|
||||
row._error = true
|
||||
@@ -399,7 +531,7 @@ function validateRow(row, rowIndex) {
|
||||
const p3 = extractPrefix(row.usedNo)
|
||||
if (!(p1 === p2 && p2 === p3)) {
|
||||
const idxInTable = typeof rowIndex === 'number' ? rowIndex : tableData.value.indexOf(row)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : (editIndex.value >= 0 ? editIndex.value + 1 : undefined)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : undefined
|
||||
const msg = lineNo ? `第【${lineNo}】行数据中,门诊号码的字母前缀必须相同,请修改!` : '行数据中,门诊号码的字母前缀必须相同,请修改!'
|
||||
alertWarn(msg)
|
||||
row._error = true
|
||||
@@ -409,25 +541,29 @@ function validateRow(row, rowIndex) {
|
||||
const eNum = extractTailNumber(row.endNo)
|
||||
if (Number.isNaN(sNum) || Number.isNaN(eNum) || sNum > eNum) {
|
||||
const idxInTable = typeof rowIndex === 'number' ? rowIndex : tableData.value.indexOf(row)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : (editIndex.value >= 0 ? editIndex.value + 1 : undefined)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : undefined
|
||||
const msg = lineNo ? `第【${lineNo}】行数据中,起始/终止号码不合法` : '起始/终止号码不合法'
|
||||
alertWarn(msg)
|
||||
row._error = true
|
||||
return false
|
||||
}
|
||||
// 放宽:不再强制“使用号码”必须处于起始与终止范围内
|
||||
// 放宽:不再强制"使用号码"必须处于起始与终止范围内
|
||||
const prefix = p1
|
||||
for (let i = 0; i < tableData.value.length; i++) {
|
||||
const other = tableData.value[i]
|
||||
// 跳过自身:当从弹窗校验时 row 为临时对象,需用下标判断
|
||||
if ((typeof rowIndex === 'number' && i === rowIndex) || other === row || !other.startNo || !other.endNo) continue
|
||||
// 跳过自身:通过 rowIndex、row 对象比较或 excludeId 排除
|
||||
if ((typeof rowIndex === 'number' && i === rowIndex) ||
|
||||
other === row ||
|
||||
!other.startNo ||
|
||||
!other.endNo ||
|
||||
(excludeId && other.id === excludeId)) continue
|
||||
if (extractPrefix(other.startNo) !== prefix) continue
|
||||
const os = extractTailNumber(other.startNo)
|
||||
const oe = extractTailNumber(other.endNo)
|
||||
if (!Number.isNaN(os) && !Number.isNaN(oe)) {
|
||||
if (rangesOverlap(sNum, eNum, os, oe)) {
|
||||
const idxInTable = typeof rowIndex === 'number' ? rowIndex : tableData.value.indexOf(row)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : (editIndex.value >= 0 ? editIndex.value + 1 : undefined)
|
||||
const lineNo = idxInTable >= 0 ? idxInTable + 1 : undefined
|
||||
const msg = lineNo ? `第【${lineNo}】行数据中,门诊号码和【${i + 1}】行的门诊号码有冲突,请修改!` : '门诊号码设置重复!'
|
||||
alertWarn(msg)
|
||||
row._error = true
|
||||
@@ -438,90 +574,233 @@ function validateRow(row, rowIndex) {
|
||||
return true
|
||||
}
|
||||
|
||||
function onSave(row) {
|
||||
async function onSave(row) {
|
||||
const rows = row ? [row] : tableData.value.filter(r => ids.value.includes(r.id) || r._dirty || r._editing)
|
||||
if (!rows.length) return
|
||||
for (const r of rows) {
|
||||
const idx = tableData.value.indexOf(r)
|
||||
if (!validateRow(r, idx)) return
|
||||
if (!rows.length) {
|
||||
proxy.$modal.msgWarning('没有可保存的数据')
|
||||
return
|
||||
}
|
||||
|
||||
// 准备保存的数据
|
||||
// 前端校验
|
||||
for (const r of rows) {
|
||||
const idx = tableData.value.indexOf(r)
|
||||
if (!validateRow(r, idx, r.id)) return
|
||||
}
|
||||
|
||||
// 准备保存的数据(将日期格式转换为后端需要的格式)
|
||||
const saveData = rows.map((r) => ({
|
||||
id: r.id,
|
||||
operatorId: r.operatorId,
|
||||
operatorName: r.operatorName,
|
||||
staffNo: r.staffNo,
|
||||
receiveDate: r.receiveDate,
|
||||
receiveDate: convertDateForBackend(r.receiveDate), // 转换为 yyyy-MM-dd 格式
|
||||
startNo: r.startNo,
|
||||
endNo: r.endNo,
|
||||
usedNo: r.usedNo,
|
||||
}))
|
||||
|
||||
const ok = lcUpsertMany(saveData)
|
||||
if (!ok) {
|
||||
// 记录失败的操作日志
|
||||
for (const record of saveData) {
|
||||
if (record.id) {
|
||||
logUpdate(record, false, '门诊号码设置重复', getUserInfo())
|
||||
} else {
|
||||
logCreate(record, false, '门诊号码设置重复', getUserInfo())
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
// 批量保存
|
||||
let successCount = 0
|
||||
let failCount = 0
|
||||
|
||||
// 记录成功的操作日志
|
||||
for (const record of saveData) {
|
||||
if (record.id) {
|
||||
logUpdate(record, true, null, getUserInfo())
|
||||
} else {
|
||||
logCreate(record, true, null, getUserInfo())
|
||||
try {
|
||||
let res
|
||||
if (record.id) {
|
||||
// 更新
|
||||
res = await updateOutpatientNo(record)
|
||||
if (res.code === 200) {
|
||||
logUpdate(record, true, null, getUserInfo())
|
||||
successCount++
|
||||
} else {
|
||||
const errorMsg = res.msg || res.message || '保存失败'
|
||||
proxy.$modal.msgError(errorMsg)
|
||||
logUpdate(record, false, errorMsg, getUserInfo())
|
||||
failCount++
|
||||
}
|
||||
} else {
|
||||
// 新增
|
||||
res = await addOutpatientNo(record)
|
||||
if (res.code === 200) {
|
||||
logCreate(record, true, null, getUserInfo())
|
||||
successCount++
|
||||
} else {
|
||||
const errorMsg = res.msg || res.message || '保存失败'
|
||||
proxy.$modal.msgError(errorMsg)
|
||||
logCreate(record, false, errorMsg, getUserInfo())
|
||||
failCount++
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
// 从错误对象中提取错误信息
|
||||
let errorMsg = '保存失败'
|
||||
if (error.response?.data?.msg) {
|
||||
errorMsg = error.response.data.msg
|
||||
} else if (error.message) {
|
||||
errorMsg = error.message
|
||||
} else if (error.msg) {
|
||||
errorMsg = error.msg
|
||||
}
|
||||
proxy.$modal.msgError(errorMsg)
|
||||
if (record.id) {
|
||||
logUpdate(record, false, errorMsg, getUserInfo())
|
||||
} else {
|
||||
logCreate(record, false, errorMsg, getUserInfo())
|
||||
}
|
||||
failCount++
|
||||
}
|
||||
}
|
||||
|
||||
if (proxy.$modal?.alertSuccess) {
|
||||
proxy.$modal.alertSuccess('保存成功!')
|
||||
} else {
|
||||
proxy.$message.success('保存成功')
|
||||
if (successCount > 0) {
|
||||
proxy.$modal.msgSuccess(`保存成功${successCount}条`)
|
||||
// 保存成功后,退出编辑状态
|
||||
rows.forEach(r => {
|
||||
r._editing = false
|
||||
r._dirty = false
|
||||
r._originalData = null // 清除原始数据
|
||||
})
|
||||
}
|
||||
if (failCount > 0) {
|
||||
proxy.$modal.msgError(`保存失败${failCount}条`)
|
||||
}
|
||||
|
||||
getList()
|
||||
}
|
||||
|
||||
function onDelete() {
|
||||
const rows = tableData.value.filter((r) => ids.value.includes(r.id))
|
||||
if (!rows.length) return
|
||||
async function onDelete() {
|
||||
console.log('删除操作 - 选中的ID列表:', ids.value)
|
||||
console.log('删除操作 - 表格数据:', tableData.value.map(r => ({ id: r.id, operatorId: r.operatorId })))
|
||||
|
||||
// 双重校验(归属权+使用状态)
|
||||
const rows = tableData.value.filter((r) => ids.value.includes(r.id))
|
||||
console.log('删除操作 - 筛选后的行数据:', rows.map(r => ({ id: r.id, operatorId: r.operatorId })))
|
||||
|
||||
if (!rows.length) {
|
||||
proxy.$modal.msgWarning('请选择要删除的数据')
|
||||
return
|
||||
}
|
||||
|
||||
// 前端预校验(归属权+使用状态)
|
||||
for (const r of rows) {
|
||||
console.log('检查删除权限 - 行数据:', {
|
||||
id: r.id,
|
||||
operatorId: r.operatorId,
|
||||
operatorIdType: typeof r.operatorId,
|
||||
userStoreId: userStore.id,
|
||||
userStoreIdType: typeof userStore.id,
|
||||
usedNo: r.usedNo,
|
||||
startNo: r.startNo,
|
||||
usedNoType: typeof r.usedNo,
|
||||
startNoType: typeof r.startNo
|
||||
})
|
||||
|
||||
const canDeleteSelf = String(r.operatorId) === String(userStore.id)
|
||||
const neverUsed = r.usedNo === r.startNo
|
||||
// 确保字符串比较,避免类型问题
|
||||
const neverUsed = String(r.usedNo || '') === String(r.startNo || '')
|
||||
|
||||
if (!canDeleteSelf) {
|
||||
// 权限不足提示
|
||||
console.warn('删除权限检查失败:', {
|
||||
operatorId: r.operatorId,
|
||||
userStoreId: userStore.id,
|
||||
canDeleteSelf
|
||||
})
|
||||
alertWarn('只能删除自己维护的门诊号码段')
|
||||
logDelete(rows, false, '只能删除自己维护的门诊号码段', getUserInfo())
|
||||
return
|
||||
}
|
||||
if (!neverUsed) {
|
||||
// 已使用提示
|
||||
console.warn('使用状态检查失败:', {
|
||||
usedNo: r.usedNo,
|
||||
startNo: r.startNo,
|
||||
neverUsed
|
||||
})
|
||||
alertWarn('已有门诊号码段已有使用的门诊号码,请核对!')
|
||||
logDelete(rows, false, '已有门诊号码段已有使用的门诊号码', getUserInfo())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const doRealDelete = () => {
|
||||
lcDeleteByIds(rows.map((r) => r.id))
|
||||
|
||||
//记录成功的删除操作日志
|
||||
logDelete(rows, true, null, getUserInfo())
|
||||
|
||||
if (proxy.$modal?.alertSuccess) {
|
||||
proxy.$modal.alertSuccess('删除成功')
|
||||
} else {
|
||||
proxy.$message.success('删除成功')
|
||||
const doRealDelete = async () => {
|
||||
try {
|
||||
// 处理大整数 ID:保持为字符串或使用 BigInt,避免精度丢失
|
||||
// JavaScript 的 Number.MAX_SAFE_INTEGER = 9007199254740991
|
||||
// 如果 ID 超过这个值,转换为数字会丢失精度
|
||||
const idsToDelete = rows
|
||||
.map((r) => r.id)
|
||||
.filter(id => id != null && id !== undefined)
|
||||
.map(id => {
|
||||
// 如果 ID 是字符串,检查是否需要转换为数字
|
||||
if (typeof id === 'string') {
|
||||
// 尝试转换为数字,但如果超过安全整数范围,保持为字符串
|
||||
const numId = parseInt(id, 10)
|
||||
if (!isNaN(numId) && numId <= Number.MAX_SAFE_INTEGER) {
|
||||
return numId
|
||||
}
|
||||
// 大整数保持为字符串,后端应该能处理
|
||||
return id
|
||||
}
|
||||
// 如果已经是数字,检查是否超过安全范围
|
||||
if (typeof id === 'number') {
|
||||
if (id > Number.MAX_SAFE_INTEGER) {
|
||||
// 超过安全范围,转换为字符串
|
||||
return String(id)
|
||||
}
|
||||
return id
|
||||
}
|
||||
// 其他类型,尝试转换
|
||||
return id
|
||||
})
|
||||
.filter(id => id != null && id !== undefined)
|
||||
|
||||
if (idsToDelete.length === 0) {
|
||||
proxy.$modal.msgWarning('没有可删除的数据')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('准备删除的ID列表:', idsToDelete)
|
||||
console.log('删除请求数据:', JSON.stringify({ ids: idsToDelete }))
|
||||
console.log('删除请求数据类型:', idsToDelete.map(id => ({ value: id, type: typeof id, stringValue: String(id) })))
|
||||
|
||||
const res = await deleteOutpatientNo({ ids: idsToDelete })
|
||||
|
||||
console.log('删除响应:', res)
|
||||
console.log('删除响应code:', res?.code)
|
||||
console.log('删除响应msg:', res?.msg)
|
||||
|
||||
if (res && (res.code === 200 || res.code === 0)) {
|
||||
logDelete(rows, true, null, getUserInfo())
|
||||
proxy.$modal.msgSuccess('删除成功')
|
||||
getList()
|
||||
} else {
|
||||
const errorMsg = res?.msg || res?.message || '删除失败'
|
||||
logDelete(rows, false, errorMsg, getUserInfo())
|
||||
proxy.$modal.msgError(errorMsg)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error)
|
||||
// 从错误对象中提取错误信息
|
||||
let errorMsg = '删除失败'
|
||||
|
||||
// 优先从 response.data.msg 获取
|
||||
if (error.response?.data?.msg) {
|
||||
errorMsg = error.response.data.msg
|
||||
}
|
||||
// 其次从 error.message 获取(request.js 会通过 new Error(msg) 抛出)
|
||||
else if (error.message) {
|
||||
// 如果 error.message 包含 "Error: " 前缀,去掉它
|
||||
errorMsg = error.message.replace(/^Error:\s*/, '')
|
||||
}
|
||||
// 最后尝试从 error.msg 获取
|
||||
else if (error.msg) {
|
||||
errorMsg = error.msg
|
||||
}
|
||||
|
||||
// 显示错误信息(参考 PackageManagement 的实现方式)
|
||||
proxy.$modal.msgError('删除失败: ' + errorMsg)
|
||||
|
||||
// 记录日志
|
||||
logDelete(rows, false, errorMsg, getUserInfo())
|
||||
}
|
||||
getList()
|
||||
}
|
||||
|
||||
if (proxy.$modal?.confirm) {
|
||||
@@ -537,115 +816,48 @@ function getList() {
|
||||
loading.value = true
|
||||
queryParams.value.onlySelf = !viewAll.value
|
||||
|
||||
// 先尝试调用后端API
|
||||
// 调用后端API
|
||||
listOutpatientNo(queryParams.value).then((res) => {
|
||||
if (res.code === 200) {
|
||||
tableData.value = (res.data?.records || res.data || []).map((it) => ({
|
||||
...it,
|
||||
_editing: false,
|
||||
_error: false,
|
||||
_dirty: false,
|
||||
}))
|
||||
tableData.value = (res.data?.records || res.data || []).map((it) => {
|
||||
// 处理大整数 ID:如果 ID 超过 JavaScript 安全整数范围,保持为字符串
|
||||
let id = it.id
|
||||
if (typeof id === 'number' && id > Number.MAX_SAFE_INTEGER) {
|
||||
// 数字超过安全范围,转换为字符串以避免精度丢失
|
||||
id = String(id)
|
||||
} else if (typeof id === 'number') {
|
||||
// 数字在安全范围内,保持为数字
|
||||
id = id
|
||||
} else {
|
||||
// 已经是字符串或其他类型,保持原样
|
||||
id = id
|
||||
}
|
||||
|
||||
return {
|
||||
...it,
|
||||
id: id, // 确保 ID 正确处理
|
||||
_editing: false,
|
||||
_error: false,
|
||||
_dirty: false,
|
||||
// 确保日期格式正确:后端返回 yyyy-MM-dd,转换为 YYYY.MM.DD 用于显示
|
||||
receiveDate: it.receiveDate ? formatReceiveDate(it.receiveDate) : ''
|
||||
}
|
||||
})
|
||||
total.value = res.data?.total || res.data?.length || 0
|
||||
|
||||
// 记录查询操作日志
|
||||
logQuery(total.value, getUserInfo())
|
||||
} else {
|
||||
// API返回错误,回退到localStorage
|
||||
console.warn('后端API返回错误,使用localStorage数据')
|
||||
loadFromLocalStorage()
|
||||
proxy.$modal.msgError(res.msg || '查询失败')
|
||||
}
|
||||
loading.value = false
|
||||
}).catch((error) => {
|
||||
// API调用失败(如404),回退到localStorage
|
||||
console.warn('后端API调用失败,使用localStorage数据:', error)
|
||||
loadFromLocalStorage()
|
||||
console.error('查询门诊号码段失败:', error)
|
||||
proxy.$modal.msgError('查询失败,请稍后重试')
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
// 从localStorage加载数据
|
||||
function loadFromLocalStorage() {
|
||||
const res = lcList({ ...queryParams.value })
|
||||
tableData.value = res.records.map((it) => ({
|
||||
...it,
|
||||
_editing: false,
|
||||
_error: false,
|
||||
_dirty: false,
|
||||
}))
|
||||
total.value = res.total
|
||||
|
||||
// 记录查询操作日志
|
||||
logQuery(total.value, getUserInfo())
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 纯前端本地持久化方法(localStorage)
|
||||
const STORAGE_KEY = 'ohis_outpatient_no_segments'
|
||||
|
||||
function lcReadAll() {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
const arr = raw ? JSON.parse(raw) : []
|
||||
return Array.isArray(arr) ? arr : []
|
||||
} catch (e) {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function lcWriteAll(list) {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(list || []))
|
||||
}
|
||||
|
||||
function lcList({ pageNo = 1, pageSize = 10, onlySelf = true }) {
|
||||
const all = lcReadAll()
|
||||
const filtered = onlySelf ? all.filter((x) => String(x.operatorId) === String(userStore.id)) : all
|
||||
const start = (pageNo - 1) * pageSize
|
||||
const end = start + pageSize
|
||||
return { records: filtered.slice(start, end), total: filtered.length, all }
|
||||
}
|
||||
|
||||
function checkOverlapAll(row, all) {
|
||||
const prefix = extractPrefix(row.startNo)
|
||||
const sNum = extractTailNumber(row.startNo)
|
||||
const eNum = extractTailNumber(row.endNo)
|
||||
for (const it of all) {
|
||||
if (row.id && it.id === row.id) continue
|
||||
if (!it.startNo || !it.endNo) continue
|
||||
if (extractPrefix(it.startNo) !== prefix) continue
|
||||
const os = extractTailNumber(it.startNo)
|
||||
const oe = extractTailNumber(it.endNo)
|
||||
if (!Number.isNaN(os) && !Number.isNaN(oe)) {
|
||||
if (rangesOverlap(sNum, eNum, os, oe)) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function lcUpsertMany(rows) {
|
||||
const all = lcReadAll()
|
||||
for (const r of rows) {
|
||||
if (checkOverlapAll(r, all)) {
|
||||
alertWarn('门诊号码设置重复!')
|
||||
return false
|
||||
}
|
||||
if (!r.id) {
|
||||
r.id = `${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
const idx = all.findIndex((x) => x.id === r.id)
|
||||
if (idx >= 0) all[idx] = { ...all[idx], ...r }
|
||||
else all.push({ ...r })
|
||||
}
|
||||
lcWriteAll(all)
|
||||
return true
|
||||
}
|
||||
|
||||
function lcDeleteByIds(idList) {
|
||||
const all = lcReadAll()
|
||||
const remain = all.filter((x) => !idList.includes(x.id))
|
||||
lcWriteAll(remain)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -653,17 +865,14 @@ function lcDeleteByIds(idList) {
|
||||
|
||||
/* 外层容器 - 全屏显示 */
|
||||
.outpatient-no-management-wrapper {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
height: calc(100vh - 84px);
|
||||
padding: 0;
|
||||
background-color: #f0f0f0;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* 主容器 - 全屏宽度和高度 */
|
||||
/* 主容器 - 全屏显示 */
|
||||
.outpatient-no-management {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@@ -865,28 +1074,6 @@ function lcDeleteByIds(idList) {
|
||||
background: linear-gradient(to bottom, #FFFEF8 0%, #F5F4EF 50%, #E5E4DF 100%);
|
||||
}
|
||||
|
||||
/* 编辑弹窗样式 */
|
||||
:deep(.el-dialog) {
|
||||
border-radius: 0;
|
||||
border: 2px solid #0055E5;
|
||||
}
|
||||
|
||||
:deep(.el-dialog__header) {
|
||||
background: linear-gradient(to bottom, #0055E5 0%, #0F3D8C 100%);
|
||||
padding: 10px 15px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.el-dialog__title) {
|
||||
color: #FFFFFF;
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
:deep(.el-dialog__close) {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
/* 表格容器样式调整 */
|
||||
.table-content :deep(.el-table__body-wrapper) {
|
||||
flex: 1;
|
||||
|
||||
Reference in New Issue
Block a user