This commit is contained in:
zlwu committed 2026-05-17 23:08:38 +08:00
1 parent 135dd550b6
commit 2a4767a014
76 files changed
+25160 -2306

No files matched your search

@@ -0,0 +1,222 @@
<!-- 采集协议单 — 状态变更弹窗(协议生效 / 协议过期 / 协议作废 / 协议转科研) -->
<template>
<el-dialog
:model-value="modelValue"
:title="dialogTitle"
width="560px"
class="dialog-form-layout"
align-center
destroy-on-close
:close-on-click-modal="false"
@update:model-value="emit('update:modelValue', $event)"
@closed="resetForm"
>
<p v-if="targets.length > 1" class="status-change-hint">
将对已选
<strong>{{ targets.length }}</strong> 条协议单执行<strong>{{ actionLabel }}</strong
>操作,每条各记一次变更。
</p>
<p v-else-if="targets.length === 1" class="status-change-hint">
协议号:<strong>{{ targets[0].protocolNo || '—' }}</strong>
</p>
<el-form
ref="formRef"
:model="form"
:rules="rules"
label-position="top"
class="biz-dialog-form"
@submit.prevent
>
<el-form-item :label="timeLabel" prop="changeTime">
<el-date-picker
v-model="form.changeTime"
type="datetime"
placeholder="请选择时间"
style="width: 100%"
value-format="YYYY-MM-DD HH:mm:ss"
/>
</el-form-item>
<el-form-item :label="descLabel">
<el-input
v-model="form.changeDesc"
type="textarea"
:rows="3"
placeholder="可选"
maxlength="500"
show-word-limit
/>
</el-form-item>
</el-form>
<template #footer>
<el-button class="btn-ghost" @click="emit('update:modelValue', false)">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button class="btn-main" type="primary" :loading="submitting" @click="handleSubmit">
<el-icon><Check /></el-icon>
确定
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import type { FormInstance, FormRules } from 'element-plus'
import { ElMessage } from 'element-plus'
import { Check, Close } from '@element-plus/icons-vue'
import { fetchUpdateCollectionProtocol } from '@/api/collection-protocol'
import { withFullscreenLoading, fullscreenLoadingText } from '@/utils/fullscreen-loading'
export type StatusChangeAction = 'activate' | 'expire' | 'void' | 'toResearch'
export type StatusChangeTarget = {
id: string
protocolNo?: string
}
defineOptions({ name: 'ProtocolStatusChangeDialog' })
const props = defineProps<{
modelValue: boolean
actionType: StatusChangeAction
targets: StatusChangeTarget[]
}>()
const emit = defineEmits<{
(e: 'update:modelValue', val: boolean): void
(e: 'submitted'): void
}>()
const ACTION_CONFIG: Record<
StatusChangeAction,
{
label: string
timeLabel: string
descLabel: string
status: string
timeKey: string
descKey: string
}
> = {
activate: {
label: '协议生效',
timeLabel: '协议生效时间',
descLabel: '协议生效描述',
status: 'sxz',
timeKey: 'effectiveTime',
descKey: 'effectiveDesc'
},
expire: {
label: '协议过期',
timeLabel: '协议过期时间',
descLabel: '协议过期描述',
status: 'ygq',
timeKey: 'expireTime',
descKey: 'expireDesc'
},
void: {
label: '协议作废',
timeLabel: '协议作废时间',
descLabel: '协议作废描述',
status: 'yzf',
timeKey: 'voidTime',
descKey: 'voidDesc'
},
toResearch: {
label: '协议转科研',
timeLabel: '协议转科研时间',
descLabel: '协议转科研描述',
status: 'zky',
timeKey: 'toResearchTime',
descKey: 'toResearchDesc'
}
}
const config = computed(() => ACTION_CONFIG[props.actionType])
const actionLabel = computed(() => config.value.label)
const timeLabel = computed(() => config.value.timeLabel)
const descLabel = computed(() => config.value.descLabel)
const dialogTitle = computed(() => {
const label = config.value.label
return props.targets.length > 1 ? `批量${label}(${props.targets.length} 条)` : label
})
const formRef = ref<FormInstance>()
const submitting = ref(false)
const form = reactive({
changeTime: '',
changeDesc: ''
})
const rules: FormRules = {
changeTime: [{ required: true, message: '请选择时间', trigger: 'change' }]
}
function resetForm() {
form.changeTime = ''
form.changeDesc = ''
formRef.value?.clearValidate()
}
async function handleSubmit() {
const valid = await formRef.value?.validate().catch(() => false)
if (!valid || !props.targets.length) return
const cfg = config.value
const payload: Record<string, unknown> = {
protocolStatus: cfg.status,
[cfg.timeKey]: form.changeTime,
[cfg.descKey]: form.changeDesc.trim() || undefined
}
const rows = [...props.targets]
const isBatch = rows.length > 1
submitting.value = true
try {
await withFullscreenLoading(
async () => {
let ok = 0
const failed: string[] = []
for (const row of rows) {
try {
await fetchUpdateCollectionProtocol(String(row.id), payload)
ok += 1
} catch {
failed.push(row.protocolNo || String(row.id))
}
}
if (isBatch) {
if (failed.length) {
ElMessage.warning(`${cfg.label}成功 ${ok} 条,失败 ${failed.length} 条`)
} else {
ElMessage.success(`批量${cfg.label}成功,共 ${ok} 条`)
}
}
if (ok > 0) {
emit('update:modelValue', false)
emit('submitted')
}
},
isBatch ? fullscreenLoadingText.batchAudit : fullscreenLoadingText.save
)
} finally {
submitting.value = false
}
}
</script>
<style scoped lang="scss">
.status-change-hint {
margin: 0 0 16px;
font-size: 13px;
line-height: 1.5;
color: var(--mint-text-muted, #64748b);
strong {
color: #1e293b;
font-weight: 600;
}
}
</style>