feat(oa): 收款账户组件支持图标编辑与删除 (#110)

在 Web 与移动 OA 表单收款账户选择器中,对可见账户增加行尾编辑/删除图标;
复用现有新增表单做编辑,删除二次确认后软删并从已选移除。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-11-19 12:04:08 +08:00
1 parent f0a6abe538
commit aac72e1fd9
3 files changed
+494 -146

No files matched your search

@@ -40,17 +40,39 @@
class="oa-receive-account-select__search"
/>
<div class="oa-receive-account-select__list">
<label
<div
v-for="a in filteredOptions"
:key="a.id"
class="oa-receive-account-select__row"
>
<el-checkbox
:model-value="pendingIds.includes(a.id)"
@change="(v: boolean | string | number) => onNarrowCheck(a.id, !!v)"
/>
<span class="oa-receive-account-select__row-label">{{ a.label }}</span>
</label>
<label class="oa-receive-account-select__row-main">
<el-checkbox
:model-value="pendingIds.includes(a.id)"
@change="(v: boolean | string | number) => onNarrowCheck(a.id, !!v)"
/>
<span class="oa-receive-account-select__row-label">{{ a.label }}</span>
</label>
<div class="oa-receive-account-select__row-actions">
<button
type="button"
class="oa-receive-account-select__icon-btn is-edit"
title="编辑"
aria-label="编辑"
@click="openEditDialog(a.id)"
>
<el-icon><Edit /></el-icon>
</button>
<button
type="button"
class="oa-receive-account-select__icon-btn is-delete"
title="删除"
aria-label="删除"
@click="confirmDelete(a.id)"
>
<el-icon><Delete /></el-icon>
</button>
</div>
</div>
<div v-if="!filteredOptions.length" class="oa-receive-account-select__empty">
暂无本人的收款账户
</div>
@@ -92,7 +114,31 @@
:key="a.id"
:label="a.label"
:value="a.id"
/>
>
<div class="oa-receive-account-select__option">
<span class="oa-receive-account-select__option-label">{{ a.label }}</span>
<span class="oa-receive-account-select__option-actions" @mousedown.prevent @click.stop>
<button
type="button"
class="oa-receive-account-select__icon-btn is-edit"
title="编辑"
aria-label="编辑"
@click="openEditDialog(a.id)"
>
<el-icon><Edit /></el-icon>
</button>
<button
type="button"
class="oa-receive-account-select__icon-btn is-delete"
title="删除"
aria-label="删除"
@click="confirmDelete(a.id)"
>
<el-icon><Delete /></el-icon>
</button>
</span>
</div>
</el-option>
<template #empty>
<div class="oa-receive-account-select__empty">
{{ accountOptions.length === 0 ? '暂无本人的收款账户' : '无匹配数据' }}
@@ -120,8 +166,8 @@
</template>
<el-dialog
v-model="createVisible"
title="新增收款账户"
v-model="formVisible"
:title="formTitle"
width="720px"
class="dialog-form-layout"
align-center
@@ -131,9 +177,9 @@
:close-on-click-modal="false"
>
<el-form
ref="createFormRef"
:model="createForm"
:rules="createRules"
ref="formRef"
:model="formModel"
:rules="formRules"
label-position="top"
scroll-to-error
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
@@ -141,9 +187,9 @@
<div class="form-grid-2">
<el-form-item label="账户类型" prop="accountType" class="form-col-span-2">
<el-select
v-model="createForm.accountType"
v-model="formModel.accountType"
placeholder="请选择"
@change="onCreateTypeChange"
@change="onFormTypeChange"
>
<el-option
v-for="(label, value) in ACCOUNT_TYPE_LABEL"
@@ -154,22 +200,22 @@
</el-select>
</el-form-item>
<el-form-item label="户名" prop="accountName">
<el-input v-model="createForm.accountName" placeholder="请输入户名" maxlength="128" />
<el-input v-model="formModel.accountName" placeholder="请输入户名" maxlength="128" />
</el-form-item>
<el-form-item label="账号" prop="accountNo">
<el-input v-model="createForm.accountNo" placeholder="请输入账号" maxlength="128" />
<el-input v-model="formModel.accountNo" placeholder="请输入账号" maxlength="128" />
</el-form-item>
<template v-if="createForm.accountType !== 'alipay'">
<template v-if="formModel.accountType !== 'alipay'">
<el-form-item label="银行" prop="bankName">
<el-input
v-model="createForm.bankName"
v-model="formModel.bankName"
placeholder="如:中国工商银行"
maxlength="128"
/>
</el-form-item>
<el-form-item label="银行所在省" prop="bankProvince">
<el-input
v-model="createForm.bankProvince"
v-model="formModel.bankProvince"
placeholder="如:安徽省"
maxlength="64"
clearable
@@ -177,7 +223,7 @@
</el-form-item>
<el-form-item label="银行所在市" prop="bankCity">
<el-input
v-model="createForm.bankCity"
v-model="formModel.bankCity"
placeholder="如:合肥市"
maxlength="64"
clearable
@@ -185,7 +231,7 @@
</el-form-item>
<el-form-item label="银行支行" prop="bankBranch" class="form-col-span-2">
<el-input
v-model="createForm.bankBranch"
v-model="formModel.bankBranch"
placeholder="请输入开户支行全称"
maxlength="256"
/>
@@ -193,7 +239,7 @@
</template>
<el-form-item label="备注" class="form-col-span-2">
<el-input
v-model="createForm.remark"
v-model="formModel.remark"
type="textarea"
:rows="2"
placeholder="选填"
@@ -203,15 +249,15 @@
</div>
</el-form>
<template #footer>
<el-button class="btn-ghost" @click="createVisible = false">
<el-button class="btn-ghost" @click="formVisible = false">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button
class="btn-main"
type="primary"
:loading="createLoading"
@click="submitCreate"
:loading="formLoading"
@click="submitForm"
>
<el-icon><Check /></el-icon>
确定
@@ -223,11 +269,13 @@
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
import { Check, Close, Plus } from '@element-plus/icons-vue'
import { Check, Close, Delete, Edit, Plus } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
fetchCreateOaReceiveAccount,
fetchOaReceiveAccountOptions
fetchDeleteOaReceiveAccount,
fetchOaReceiveAccountOptions,
fetchUpdateOaReceiveAccount
} from '@/api/oaApproval'
import {
ACCOUNT_TYPE_LABEL,
@@ -253,6 +301,7 @@
}>()
type AccountOpt = { id: string; label: string }
type FormMode = 'create' | 'edit'
const snapshotMap = ref(new Map<string, ReceiveAccountSnapshot>())
const accountOptions = ref<AccountOpt[]>([])
@@ -263,10 +312,12 @@
const selectRef = ref<{ blur?: () => void } | null>(null)
let mql: MediaQueryList | null = null
const createVisible = ref(false)
const createLoading = ref(false)
const createFormRef = ref()
const createForm = reactive({
const formVisible = ref(false)
const formLoading = ref(false)
const formMode = ref<FormMode>('create')
const editingId = ref('')
const formRef = ref()
const formModel = reactive({
accountType: 'alipay' as ReceiveAccountType,
accountName: '',
accountNo: '',
@@ -277,8 +328,12 @@
remark: ''
})
const formTitle = computed(() =>
formMode.value === 'edit' ? '编辑收款账户' : '新增收款账户'
)
const requireWhenBank = (_rule: any, value: string, callback: (e?: Error) => void) => {
if (createForm.accountType === 'alipay') {
if (formModel.accountType === 'alipay') {
callback()
return
}
@@ -289,7 +344,7 @@
callback()
}
const createRules = computed(() => ({
const formRules = computed(() => ({
accountType: [{ required: true, message: '请选择账户类型', trigger: 'change' }],
accountName: [{ required: true, message: '请输入户名', trigger: 'blur' }],
accountNo: [{ required: true, message: '请输入账号', trigger: 'blur' }],
@@ -358,90 +413,161 @@
drawerVisible.value = false
}
function clearCreateBankFields() {
createForm.bankName = ''
createForm.bankProvince = ''
createForm.bankCity = ''
createForm.bankBranch = ''
function clearBankFields() {
formModel.bankName = ''
formModel.bankProvince = ''
formModel.bankCity = ''
formModel.bankBranch = ''
}
function resetCreateForm() {
createForm.accountType = 'alipay'
createForm.accountName = ''
createForm.accountNo = ''
clearCreateBankFields()
createForm.remark = ''
function resetFormModel() {
formModel.accountType = 'alipay'
formModel.accountName = ''
formModel.accountNo = ''
clearBankFields()
formModel.remark = ''
}
function onCreateTypeChange() {
if (createForm.accountType === 'alipay') clearCreateBankFields()
createFormRef.value?.clearValidate?.()
function fillFormFromSnap(snap: ReceiveAccountSnapshot) {
formModel.accountType = snap.accountType
formModel.accountName = snap.accountName
formModel.accountNo = snap.accountNo
formModel.bankName = snap.bankName
formModel.bankProvince = snap.bankProvince
formModel.bankCity = snap.bankCity
formModel.bankBranch = snap.bankBranch
formModel.remark = snap.remark
if (formModel.accountType === 'alipay') clearBankFields()
}
function onFormTypeChange() {
if (formModel.accountType === 'alipay') clearBankFields()
formRef.value?.clearValidate?.()
}
function buildPayload() {
const payload: Record<string, unknown> = {
accountType: formModel.accountType,
accountName: formModel.accountName.trim(),
accountNo: formModel.accountNo.trim(),
remark: formModel.remark?.trim() || undefined
}
if (formModel.accountType === 'alipay') {
payload.bankName = ''
payload.bankProvince = ''
payload.bankCity = ''
payload.bankBranch = ''
} else {
payload.bankName = formModel.bankName.trim()
payload.bankProvince = formModel.bankProvince.trim()
payload.bankCity = formModel.bankCity.trim()
payload.bankBranch = formModel.bankBranch.trim()
}
return payload
}
function upsertLocalSnap(snap: ReceiveAccountSnapshot) {
if (!snap.id) return
const map = new Map(snapshotMap.value)
map.set(snap.id, snap)
snapshotMap.value = map
const label = optionLabelFromRow(snap)
const idx = accountOptions.value.findIndex((x) => x.id === snap.id)
if (idx >= 0) {
const next = [...accountOptions.value]
next[idx] = { id: snap.id, label }
accountOptions.value = next
} else {
accountOptions.value = [...accountOptions.value, { id: snap.id, label }]
}
}
function openCreateDialog() {
selectRef.value?.blur?.()
resetCreateForm()
createVisible.value = true
nextTick(() => createFormRef.value?.clearValidate?.())
formMode.value = 'create'
editingId.value = ''
resetFormModel()
formVisible.value = true
nextTick(() => formRef.value?.clearValidate?.())
}
async function submitCreate() {
function openEditDialog(id: string) {
const tid = String(id || '').trim()
const snap = snapshotMap.value.get(tid)
if (!snap) {
ElMessage.error('账户不存在或已删除')
return
}
selectRef.value?.blur?.()
formMode.value = 'edit'
editingId.value = tid
fillFormFromSnap(snap)
formVisible.value = true
nextTick(() => formRef.value?.clearValidate?.())
}
async function submitForm() {
try {
await createFormRef.value?.validate?.()
await formRef.value?.validate?.()
} catch {
ElMessageBox.alert('请完善必填项后再提交', '提示', { type: 'warning' })
return
}
createLoading.value = true
formLoading.value = true
try {
const payload: Record<string, unknown> = {
accountType: createForm.accountType,
accountName: createForm.accountName.trim(),
accountNo: createForm.accountNo.trim(),
remark: createForm.remark?.trim() || undefined
}
if (createForm.accountType === 'alipay') {
payload.bankName = ''
payload.bankProvince = ''
payload.bankCity = ''
payload.bankBranch = ''
const payload = buildPayload()
let row: any
if (formMode.value === 'edit' && editingId.value) {
row = await fetchUpdateOaReceiveAccount(editingId.value, payload)
} else {
payload.bankName = createForm.bankName.trim()
payload.bankProvince = createForm.bankProvince.trim()
payload.bankCity = createForm.bankCity.trim()
payload.bankBranch = createForm.bankBranch.trim()
row = await fetchCreateOaReceiveAccount(payload)
}
const created = await fetchCreateOaReceiveAccount(payload)
const snap = snapshotFromRow(created)
const snap = snapshotFromRow(row)
if (!snap.id) {
ElMessage.error('创建成功但未返回账户 ID')
ElMessage.error(formMode.value === 'edit' ? '更新成功但未返回账户 ID' : '创建成功但未返回账户 ID')
return
}
await loadOptions()
// 确保新账户在 map 中(options 可能短暂未刷新)
if (!snapshotMap.value.has(snap.id)) {
const map = new Map(snapshotMap.value)
map.set(snap.id, snap)
snapshotMap.value = map
if (!accountOptions.value.some((x) => x.id === snap.id)) {
accountOptions.value = [
...accountOptions.value,
{ id: snap.id, label: optionLabelFromRow(snap) }
]
upsertLocalSnap(snap)
if (formMode.value === 'edit') {
if (selectModel.value.includes(snap.id)) {
emitFromIds(selectModel.value)
}
} else {
const nextIds = [...selectModel.value]
if (!nextIds.includes(snap.id)) nextIds.push(snap.id)
emitFromIds(nextIds)
if (drawerVisible.value && !pendingIds.value.includes(snap.id)) {
pendingIds.value = [...pendingIds.value, snap.id]
}
}
const nextIds = [...selectModel.value]
if (!nextIds.includes(snap.id)) nextIds.push(snap.id)
emitFromIds(nextIds)
if (drawerVisible.value && !pendingIds.value.includes(snap.id)) {
pendingIds.value = [...pendingIds.value, snap.id]
}
createVisible.value = false
formVisible.value = false
} finally {
createLoading.value = false
formLoading.value = false
}
}
async function confirmDelete(id: string) {
const tid = String(id || '').trim()
const snap = snapshotMap.value.get(tid)
const name = snap?.accountName || tid
try {
await ElMessageBox.confirm(
`确定删除收款账户「${name}」吗?删除后不可再选;已提交单据中的账户快照仍保留。`,
'删除收款账户',
{ type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消' }
)
} catch {
return
}
selectRef.value?.blur?.()
await fetchDeleteOaReceiveAccount(tid)
await loadOptions()
const nextSelected = selectModel.value.filter((x) => x !== tid)
emitFromIds(nextSelected)
pendingIds.value = pendingIds.value.filter((x) => x !== tid)
}
async function loadOptions() {
try {
const res = await fetchOaReceiveAccountOptions()
@@ -512,6 +638,53 @@
min-height: 40px;
}
.oa-receive-account-select__option {
display: flex;
gap: 8px;
align-items: center;
justify-content: space-between;
width: 100%;
min-width: 0;
}
.oa-receive-account-select__option-label {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.oa-receive-account-select__option-actions,
.oa-receive-account-select__row-actions {
display: inline-flex;
flex-shrink: 0;
gap: 4px;
align-items: center;
}
.oa-receive-account-select__icon-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
padding: 0;
border: 0;
border-radius: 6px;
cursor: pointer;
}
.oa-receive-account-select__icon-btn.is-edit {
background: var(--mint-primary-bg, #ecfdf5);
color: var(--mint-primary-dark, #059669);
}
.oa-receive-account-select__icon-btn.is-delete {
background: #fef2f2;
color: #dc2626;
}
.oa-receive-account-select__add-footer {
padding: 4px 8px 8px;
border-top: 1px solid var(--mint-border, #d9e8e2);
@@ -597,6 +770,14 @@
align-items: center;
min-height: 44px;
padding: 6px 4px;
}
.oa-receive-account-select__row-main {
display: flex;
flex: 1;
gap: 8px;
align-items: center;
min-width: 0;
cursor: pointer;
}
@@ -630,5 +811,10 @@
.oa-receive-account-select__trigger {
min-height: 44px;
}
.oa-receive-account-select__icon-btn {
width: 36px;
height: 36px;
}
}
</style>