feat(oa): 收款账户组件支持图标编辑与删除 (#110) #126
No files matched your search
@@ -25,6 +25,17 @@ export function fetchCreateReceiveAccount(data) {
|
||||
return post('/web/admin/oa-approval/receive-accounts', data)
|
||||
}
|
||||
|
||||
export function fetchUpdateReceiveAccount(id, data) {
|
||||
return put(`/web/admin/oa-approval/receive-accounts/${id}`, data)
|
||||
}
|
||||
|
||||
export function fetchDeleteReceiveAccount(id) {
|
||||
return request({
|
||||
url: `/web/admin/oa-approval/receive-accounts/${id}`,
|
||||
method: 'DELETE'
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchRelatedCandidates(params) {
|
||||
return get('/web/admin/oa-approval/related-candidates', params)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,24 @@
|
||||
<div class="oa-sheet-row__title">{{ a.label }}</div>
|
||||
<div v-if="a.sub" class="oa-sheet-row__meta">{{ a.sub }}</div>
|
||||
</div>
|
||||
<div class="oa-sheet-row__actions" @click.stop>
|
||||
<button
|
||||
type="button"
|
||||
class="oa-sheet-row__icon is-edit"
|
||||
aria-label="编辑"
|
||||
@click="openEdit(a.id)"
|
||||
>
|
||||
<van-icon name="edit" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="oa-sheet-row__icon is-delete"
|
||||
aria-label="删除"
|
||||
@click="confirmDelete(a.id)"
|
||||
>
|
||||
<van-icon name="delete-o" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</van-checkbox-group>
|
||||
<van-empty v-if="!loading && !filtered.length" description="暂无本人的收款账户" />
|
||||
@@ -63,17 +81,17 @@
|
||||
</div>
|
||||
</van-popup>
|
||||
|
||||
<van-popup v-model:show="createVisible" position="bottom" round>
|
||||
<van-popup v-model:show="formVisible" position="bottom" round>
|
||||
<div class="oa-recv__sheet oa-recv__sheet--create">
|
||||
<div class="oa-recv__hd">
|
||||
<span @click="createVisible = false">取消</span>
|
||||
<strong>新增收款账户</strong>
|
||||
<span @click="formVisible = false">取消</span>
|
||||
<strong>{{ formTitle }}</strong>
|
||||
<span
|
||||
class="oa-recv__ok"
|
||||
:class="{ 'is-busy': createLoading }"
|
||||
@click="submitCreate"
|
||||
:class="{ 'is-busy': formLoading }"
|
||||
@click="submitForm"
|
||||
>
|
||||
{{ createLoading ? '提交中' : '确定' }}
|
||||
{{ formLoading ? '提交中' : '确定' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="oa-recv__form">
|
||||
@@ -87,45 +105,45 @@
|
||||
<label class="oa-recv-field">
|
||||
<span class="oa-recv-field__label">户名<b>*</b></span>
|
||||
<span class="oa-recv-field__box">
|
||||
<input v-model="createForm.accountName" maxlength="128" placeholder="请输入户名" />
|
||||
<input v-model="formModel.accountName" maxlength="128" placeholder="请输入户名" />
|
||||
</span>
|
||||
</label>
|
||||
<label class="oa-recv-field">
|
||||
<span class="oa-recv-field__label">账号<b>*</b></span>
|
||||
<span class="oa-recv-field__box">
|
||||
<input v-model="createForm.accountNo" maxlength="128" placeholder="请输入账号" />
|
||||
<input v-model="formModel.accountNo" maxlength="128" placeholder="请输入账号" />
|
||||
</span>
|
||||
</label>
|
||||
<template v-if="createForm.accountType !== 'alipay'">
|
||||
<template v-if="formModel.accountType !== 'alipay'">
|
||||
<label class="oa-recv-field">
|
||||
<span class="oa-recv-field__label">银行<b>*</b></span>
|
||||
<span class="oa-recv-field__box">
|
||||
<input v-model="createForm.bankName" maxlength="128" placeholder="如:中国工商银行" />
|
||||
<input v-model="formModel.bankName" maxlength="128" placeholder="如:中国工商银行" />
|
||||
</span>
|
||||
</label>
|
||||
<label class="oa-recv-field">
|
||||
<span class="oa-recv-field__label">银行所在省<b>*</b></span>
|
||||
<span class="oa-recv-field__box">
|
||||
<input v-model="createForm.bankProvince" maxlength="64" placeholder="如:安徽省" />
|
||||
<input v-model="formModel.bankProvince" maxlength="64" placeholder="如:安徽省" />
|
||||
</span>
|
||||
</label>
|
||||
<label class="oa-recv-field">
|
||||
<span class="oa-recv-field__label">银行所在市<b>*</b></span>
|
||||
<span class="oa-recv-field__box">
|
||||
<input v-model="createForm.bankCity" maxlength="64" placeholder="如:合肥市" />
|
||||
<input v-model="formModel.bankCity" maxlength="64" placeholder="如:合肥市" />
|
||||
</span>
|
||||
</label>
|
||||
<label class="oa-recv-field">
|
||||
<span class="oa-recv-field__label">银行支行<b>*</b></span>
|
||||
<span class="oa-recv-field__box">
|
||||
<input v-model="createForm.bankBranch" maxlength="256" placeholder="请输入开户支行全称" />
|
||||
<input v-model="formModel.bankBranch" maxlength="256" placeholder="请输入开户支行全称" />
|
||||
</span>
|
||||
</label>
|
||||
</template>
|
||||
<label class="oa-recv-field">
|
||||
<span class="oa-recv-field__label">备注</span>
|
||||
<span class="oa-recv-field__box oa-recv-field__box--area">
|
||||
<textarea v-model="createForm.remark" maxlength="512" rows="2" placeholder="选填" />
|
||||
<textarea v-model="formModel.remark" maxlength="512" rows="2" placeholder="选填" />
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
@@ -135,7 +153,7 @@
|
||||
<van-popup v-model:show="typePickerVisible" position="bottom" round>
|
||||
<van-picker
|
||||
:columns="accountTypeColumns"
|
||||
:model-value="[createForm.accountType]"
|
||||
:model-value="[formModel.accountType]"
|
||||
@confirm="onTypeConfirm"
|
||||
@cancel="typePickerVisible = false"
|
||||
/>
|
||||
@@ -145,8 +163,13 @@
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { showToast } from 'vant'
|
||||
import { fetchCreateReceiveAccount, fetchReceiveAccountOptions } from '../../api/oa.js'
|
||||
import { showConfirmDialog, showToast } from 'vant'
|
||||
import {
|
||||
fetchCreateReceiveAccount,
|
||||
fetchDeleteReceiveAccount,
|
||||
fetchReceiveAccountOptions,
|
||||
fetchUpdateReceiveAccount
|
||||
} from '../../api/oa.js'
|
||||
import {
|
||||
ACCOUNT_TYPE_LABEL,
|
||||
formatReceiveAccountLine,
|
||||
@@ -170,17 +193,19 @@ const keyword = ref('')
|
||||
const pendingIds = ref([])
|
||||
const snapshotMap = ref(new Map())
|
||||
const accountOptions = ref([])
|
||||
const createVisible = ref(false)
|
||||
const createLoading = ref(false)
|
||||
const formVisible = ref(false)
|
||||
const formLoading = ref(false)
|
||||
const formMode = ref('create')
|
||||
const editingId = ref('')
|
||||
const typePickerVisible = ref(false)
|
||||
const accountTypeColumns = [
|
||||
{ text: '支付宝', value: 'alipay' },
|
||||
{ text: '个人银行卡', value: 'personal' },
|
||||
{ text: '对公银行账户', value: 'corporate' }
|
||||
]
|
||||
const createForm = ref(emptyCreateForm())
|
||||
const formModel = ref(emptyForm())
|
||||
|
||||
function emptyCreateForm() {
|
||||
function emptyForm() {
|
||||
return {
|
||||
accountType: 'alipay',
|
||||
accountName: '',
|
||||
@@ -193,8 +218,12 @@ function emptyCreateForm() {
|
||||
}
|
||||
}
|
||||
|
||||
const formTitle = computed(() =>
|
||||
formMode.value === 'edit' ? '编辑收款账户' : '新增收款账户'
|
||||
)
|
||||
|
||||
const accountTypeLabel = computed(
|
||||
() => ACCOUNT_TYPE_LABEL[createForm.value.accountType] || ''
|
||||
() => ACCOUNT_TYPE_LABEL[formModel.value.accountType] || ''
|
||||
)
|
||||
|
||||
const normalized = computed(() => normalizeReceiveAccountModelValue(props.modelValue))
|
||||
@@ -260,26 +289,78 @@ function optionFromSnap(snap) {
|
||||
}
|
||||
}
|
||||
|
||||
function upsertLocalSnap(snap) {
|
||||
if (!snap.id) return
|
||||
const map = new Map(snapshotMap.value)
|
||||
map.set(snap.id, snap)
|
||||
snapshotMap.value = map
|
||||
const opt = optionFromSnap(snap)
|
||||
const idx = accountOptions.value.findIndex((x) => x.id === snap.id)
|
||||
if (idx >= 0) {
|
||||
const next = [...accountOptions.value]
|
||||
next[idx] = opt
|
||||
accountOptions.value = next
|
||||
} else {
|
||||
accountOptions.value = [...accountOptions.value, opt]
|
||||
}
|
||||
}
|
||||
|
||||
function fillFormFromSnap(snap) {
|
||||
const form = {
|
||||
accountType: snap.accountType || 'alipay',
|
||||
accountName: snap.accountName || '',
|
||||
accountNo: snap.accountNo || '',
|
||||
bankName: snap.bankName || '',
|
||||
bankProvince: snap.bankProvince || '',
|
||||
bankCity: snap.bankCity || '',
|
||||
bankBranch: snap.bankBranch || '',
|
||||
remark: snap.remark || ''
|
||||
}
|
||||
if (form.accountType === 'alipay') {
|
||||
form.bankName = ''
|
||||
form.bankProvince = ''
|
||||
form.bankCity = ''
|
||||
form.bankBranch = ''
|
||||
}
|
||||
formModel.value = form
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
createForm.value = emptyCreateForm()
|
||||
formMode.value = 'create'
|
||||
editingId.value = ''
|
||||
formModel.value = emptyForm()
|
||||
typePickerVisible.value = false
|
||||
createVisible.value = true
|
||||
formVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(id) {
|
||||
const tid = String(id || '').trim()
|
||||
const snap = snapshotMap.value.get(tid)
|
||||
if (!snap) {
|
||||
showToast('账户不存在或已删除')
|
||||
return
|
||||
}
|
||||
formMode.value = 'edit'
|
||||
editingId.value = tid
|
||||
fillFormFromSnap(snap)
|
||||
typePickerVisible.value = false
|
||||
formVisible.value = true
|
||||
}
|
||||
|
||||
function onTypeConfirm({ selectedOptions }) {
|
||||
const next = selectedOptions?.[0]?.value || 'alipay'
|
||||
const form = { ...createForm.value, accountType: next }
|
||||
const form = { ...formModel.value, accountType: next }
|
||||
if (next === 'alipay') {
|
||||
form.bankName = ''
|
||||
form.bankProvince = ''
|
||||
form.bankCity = ''
|
||||
form.bankBranch = ''
|
||||
}
|
||||
createForm.value = form
|
||||
formModel.value = form
|
||||
typePickerVisible.value = false
|
||||
}
|
||||
|
||||
function validateCreate(form) {
|
||||
function validateForm(form) {
|
||||
if (!form.accountName.trim()) return '请输入户名'
|
||||
if (!form.accountNo.trim()) return '请输入账号'
|
||||
if (form.accountType !== 'alipay') {
|
||||
@@ -291,14 +372,7 @@ function validateCreate(form) {
|
||||
return ''
|
||||
}
|
||||
|
||||
async function submitCreate() {
|
||||
if (createLoading.value) return
|
||||
const form = createForm.value
|
||||
const invalid = validateCreate(form)
|
||||
if (invalid) {
|
||||
showToast(invalid)
|
||||
return
|
||||
}
|
||||
function buildPayload(form) {
|
||||
const payload = {
|
||||
accountType: form.accountType,
|
||||
accountName: form.accountName.trim(),
|
||||
@@ -316,36 +390,80 @@ async function submitCreate() {
|
||||
payload.bankCity = form.bankCity.trim()
|
||||
payload.bankBranch = form.bankBranch.trim()
|
||||
}
|
||||
createLoading.value = true
|
||||
return payload
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (formLoading.value) return
|
||||
const form = formModel.value
|
||||
const invalid = validateForm(form)
|
||||
if (invalid) {
|
||||
showToast(invalid)
|
||||
return
|
||||
}
|
||||
const payload = buildPayload(form)
|
||||
formLoading.value = true
|
||||
try {
|
||||
const created = await fetchCreateReceiveAccount(payload)
|
||||
const snap = snapshotFromRow(created)
|
||||
const row =
|
||||
formMode.value === 'edit' && editingId.value
|
||||
? await fetchUpdateReceiveAccount(editingId.value, payload)
|
||||
: await fetchCreateReceiveAccount(payload)
|
||||
const snap = snapshotFromRow(row)
|
||||
if (!snap.id) {
|
||||
showToast('创建成功但未返回账户 ID')
|
||||
showToast(formMode.value === 'edit' ? '更新成功但未返回账户 ID' : '创建成功但未返回账户 ID')
|
||||
return
|
||||
}
|
||||
await loadOptions()
|
||||
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, optionFromSnap(snap)]
|
||||
upsertLocalSnap(snap)
|
||||
if (formMode.value === 'edit') {
|
||||
const selected = normalized.value.map((x) => x.id)
|
||||
if (selected.includes(snap.id)) {
|
||||
emitItems(selected.map((id) => snapshotMap.value.get(id)).filter(Boolean))
|
||||
}
|
||||
showToast('更新成功')
|
||||
} else {
|
||||
const selected = new Set(normalized.value.map((x) => x.id))
|
||||
selected.add(snap.id)
|
||||
emitItems([...selected].map((id) => snapshotMap.value.get(id)).filter(Boolean))
|
||||
if (!pendingIds.value.includes(snap.id)) {
|
||||
pendingIds.value = [...pendingIds.value, snap.id]
|
||||
}
|
||||
keyword.value = ''
|
||||
showToast('创建成功')
|
||||
}
|
||||
const selected = new Set(normalized.value.map((x) => x.id))
|
||||
selected.add(snap.id)
|
||||
emitItems([...selected].map((id) => snapshotMap.value.get(id)).filter(Boolean))
|
||||
if (!pendingIds.value.includes(snap.id)) {
|
||||
pendingIds.value = [...pendingIds.value, snap.id]
|
||||
}
|
||||
keyword.value = ''
|
||||
createVisible.value = false
|
||||
showToast('创建成功')
|
||||
formVisible.value = false
|
||||
} catch (e) {
|
||||
showToast(e?.message || '新增收款账户失败')
|
||||
showToast(e?.message || (formMode.value === 'edit' ? '编辑收款账户失败' : '新增收款账户失败'))
|
||||
} finally {
|
||||
createLoading.value = false
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmDelete(id) {
|
||||
const tid = String(id || '').trim()
|
||||
const snap = snapshotMap.value.get(tid)
|
||||
const name = snap?.accountName || tid
|
||||
try {
|
||||
await showConfirmDialog({
|
||||
title: '删除收款账户',
|
||||
message: `确定删除收款账户「${name}」吗?删除后不可再选;已提交单据中的账户快照仍保留。`
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await fetchDeleteReceiveAccount(tid)
|
||||
await loadOptions()
|
||||
const nextSelected = normalized.value
|
||||
.map((x) => x.id)
|
||||
.filter((x) => x !== tid)
|
||||
.map((x) => snapshotMap.value.get(x))
|
||||
.filter(Boolean)
|
||||
emitItems(nextSelected)
|
||||
pendingIds.value = pendingIds.value.filter((x) => x !== tid)
|
||||
showToast('删除成功')
|
||||
} catch (e) {
|
||||
showToast(e?.message || '删除收款账户失败')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +529,39 @@ onMounted(() => {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.oa-sheet-row__actions {
|
||||
display: inline-flex;
|
||||
flex: none;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.oa-sheet-row__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
background: transparent;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.oa-sheet-row__icon.is-edit {
|
||||
background: #ecfdf5;
|
||||
color: var(--brand-green-dark, #16a34a);
|
||||
}
|
||||
|
||||
.oa-sheet-row__icon.is-delete {
|
||||
background: #fef2f2;
|
||||
color: #dc2626;
|
||||
}
|
||||
|
||||
.oa-recv__add {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user