feat(web-admin): allow creating receive accounts from the form select.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1b6ef504ac
commit
6c4c0184d0
1 file changed
+278
-6
@@ -54,6 +54,14 @@
|
||||
<div v-if="!filteredOptions.length" class="oa-receive-account-select__empty">
|
||||
暂无收款账户
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="oa-receive-account-select__add-row"
|
||||
@click="openCreateDialog"
|
||||
>
|
||||
<el-icon><Plus /></el-icon>
|
||||
新增收款账户
|
||||
</button>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="drawerVisible = false">
|
||||
@@ -70,6 +78,7 @@
|
||||
|
||||
<el-select
|
||||
v-else
|
||||
ref="selectRef"
|
||||
:model-value="selectModel"
|
||||
class="oa-receive-account-select__select"
|
||||
filterable
|
||||
@@ -84,6 +93,14 @@
|
||||
:label="a.label"
|
||||
:value="a.id"
|
||||
/>
|
||||
<template #footer>
|
||||
<div class="oa-receive-account-select__add-footer" @mousedown.prevent>
|
||||
<el-button class="oa-receive-account-select__add-btn" @click="openCreateDialog">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新增收款账户
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-select>
|
||||
|
||||
<div v-if="normalized.length" class="oa-receive-account-select__detail">
|
||||
@@ -96,20 +113,125 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-dialog
|
||||
v-model="createVisible"
|
||||
title="新增收款账户"
|
||||
width="720px"
|
||||
class="dialog-form-layout"
|
||||
align-center
|
||||
append-to-body
|
||||
modal-class="protocol-dialog-mask"
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form
|
||||
ref="createFormRef"
|
||||
:model="createForm"
|
||||
:rules="createRules"
|
||||
label-position="top"
|
||||
scroll-to-error
|
||||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||||
>
|
||||
<div class="form-grid-2">
|
||||
<el-form-item label="账户类型" prop="accountType" class="form-col-span-2">
|
||||
<el-select
|
||||
v-model="createForm.accountType"
|
||||
placeholder="请选择"
|
||||
@change="onCreateTypeChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="(label, value) in ACCOUNT_TYPE_LABEL"
|
||||
:key="value"
|
||||
:label="label"
|
||||
:value="value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="户名" prop="accountName">
|
||||
<el-input v-model="createForm.accountName" placeholder="请输入户名" maxlength="128" />
|
||||
</el-form-item>
|
||||
<el-form-item label="账号" prop="accountNo">
|
||||
<el-input v-model="createForm.accountNo" placeholder="请输入账号" maxlength="128" />
|
||||
</el-form-item>
|
||||
<template v-if="createForm.accountType !== 'alipay'">
|
||||
<el-form-item label="银行" prop="bankName">
|
||||
<el-input
|
||||
v-model="createForm.bankName"
|
||||
placeholder="如:中国工商银行"
|
||||
maxlength="128"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="银行所在省" prop="bankProvince">
|
||||
<el-input
|
||||
v-model="createForm.bankProvince"
|
||||
placeholder="如:安徽省"
|
||||
maxlength="64"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="银行所在市" prop="bankCity">
|
||||
<el-input
|
||||
v-model="createForm.bankCity"
|
||||
placeholder="如:合肥市"
|
||||
maxlength="64"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="银行支行" prop="bankBranch" class="form-col-span-2">
|
||||
<el-input
|
||||
v-model="createForm.bankBranch"
|
||||
placeholder="请输入开户支行全称"
|
||||
maxlength="256"
|
||||
/>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<el-form-item label="备注" class="form-col-span-2">
|
||||
<el-input
|
||||
v-model="createForm.remark"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
placeholder="选填"
|
||||
maxlength="512"
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="createVisible = false">
|
||||
<el-icon><Close /></el-icon>
|
||||
取消
|
||||
</el-button>
|
||||
<el-button
|
||||
class="btn-main"
|
||||
type="primary"
|
||||
:loading="createLoading"
|
||||
@click="submitCreate"
|
||||
>
|
||||
<el-icon><Check /></el-icon>
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { Check, Close } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { fetchOaReceiveAccountOptions } from '@/api/oaApproval'
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||
import { Check, Close, Plus } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
fetchCreateOaReceiveAccount,
|
||||
fetchOaReceiveAccountOptions
|
||||
} from '@/api/oaApproval'
|
||||
import {
|
||||
ACCOUNT_TYPE_LABEL,
|
||||
formatReceiveAccountLine,
|
||||
normalizeReceiveAccountModelValue,
|
||||
optionLabelFromRow,
|
||||
snapshotFromRow,
|
||||
type ReceiveAccountSnapshot
|
||||
type ReceiveAccountSnapshot,
|
||||
type ReceiveAccountType
|
||||
} from '@/utils/oa-receive-account-value'
|
||||
|
||||
defineOptions({ name: 'receiveAccount' })
|
||||
@@ -133,8 +255,45 @@
|
||||
const drawerVisible = ref(false)
|
||||
const keyword = ref('')
|
||||
const pendingIds = ref<string[]>([])
|
||||
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({
|
||||
accountType: 'alipay' as ReceiveAccountType,
|
||||
accountName: '',
|
||||
accountNo: '',
|
||||
bankName: '',
|
||||
bankProvince: '',
|
||||
bankCity: '',
|
||||
bankBranch: '',
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const requireWhenBank = (_rule: any, value: string, callback: (e?: Error) => void) => {
|
||||
if (createForm.accountType === 'alipay') {
|
||||
callback()
|
||||
return
|
||||
}
|
||||
if (!String(value || '').trim()) {
|
||||
callback(new Error('请填写'))
|
||||
return
|
||||
}
|
||||
callback()
|
||||
}
|
||||
|
||||
const createRules = computed(() => ({
|
||||
accountType: [{ required: true, message: '请选择账户类型', trigger: 'change' }],
|
||||
accountName: [{ required: true, message: '请输入户名', trigger: 'blur' }],
|
||||
accountNo: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
||||
bankName: [{ validator: requireWhenBank, trigger: 'blur' }],
|
||||
bankProvince: [{ validator: requireWhenBank, trigger: 'blur' }],
|
||||
bankCity: [{ validator: requireWhenBank, trigger: 'blur' }],
|
||||
bankBranch: [{ validator: requireWhenBank, trigger: 'blur' }]
|
||||
}))
|
||||
|
||||
const normalized = computed(() => normalizeReceiveAccountModelValue(props.modelValue))
|
||||
|
||||
const selectModel = computed(() => normalized.value.map((x) => x.id))
|
||||
@@ -194,6 +353,90 @@
|
||||
drawerVisible.value = false
|
||||
}
|
||||
|
||||
function clearCreateBankFields() {
|
||||
createForm.bankName = ''
|
||||
createForm.bankProvince = ''
|
||||
createForm.bankCity = ''
|
||||
createForm.bankBranch = ''
|
||||
}
|
||||
|
||||
function resetCreateForm() {
|
||||
createForm.accountType = 'alipay'
|
||||
createForm.accountName = ''
|
||||
createForm.accountNo = ''
|
||||
clearCreateBankFields()
|
||||
createForm.remark = ''
|
||||
}
|
||||
|
||||
function onCreateTypeChange() {
|
||||
if (createForm.accountType === 'alipay') clearCreateBankFields()
|
||||
createFormRef.value?.clearValidate?.()
|
||||
}
|
||||
|
||||
function openCreateDialog() {
|
||||
selectRef.value?.blur?.()
|
||||
resetCreateForm()
|
||||
createVisible.value = true
|
||||
nextTick(() => createFormRef.value?.clearValidate?.())
|
||||
}
|
||||
|
||||
async function submitCreate() {
|
||||
try {
|
||||
await createFormRef.value?.validate?.()
|
||||
} catch {
|
||||
ElMessageBox.alert('请完善必填项后再提交', '提示', { type: 'warning' })
|
||||
return
|
||||
}
|
||||
createLoading.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 = ''
|
||||
} else {
|
||||
payload.bankName = createForm.bankName.trim()
|
||||
payload.bankProvince = createForm.bankProvince.trim()
|
||||
payload.bankCity = createForm.bankCity.trim()
|
||||
payload.bankBranch = createForm.bankBranch.trim()
|
||||
}
|
||||
const created = await fetchCreateOaReceiveAccount(payload)
|
||||
const snap = snapshotFromRow(created)
|
||||
if (!snap.id) {
|
||||
ElMessage.error('创建成功但未返回账户 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) }
|
||||
]
|
||||
}
|
||||
}
|
||||
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
|
||||
} finally {
|
||||
createLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOptions() {
|
||||
try {
|
||||
const res = await fetchOaReceiveAccountOptions()
|
||||
@@ -206,7 +449,6 @@
|
||||
map.set(snap.id, snap)
|
||||
opts.push({ id: snap.id, label: optionLabelFromRow(snap) })
|
||||
}
|
||||
// 保留已选快照(主数据可能已删除该账户)
|
||||
for (const x of normalized.value) {
|
||||
if (!map.has(x.id)) map.set(x.id, x)
|
||||
}
|
||||
@@ -265,6 +507,36 @@
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.oa-receive-account-select__add-footer {
|
||||
padding: 4px 8px 8px;
|
||||
border-top: 1px solid var(--mint-border, #d9e8e2);
|
||||
}
|
||||
|
||||
.oa-receive-account-select__add-btn {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
color: var(--mint-primary-dark, #059669);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.oa-receive-account-select__add-row {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
min-height: 44px;
|
||||
margin-top: 8px;
|
||||
padding: 8px;
|
||||
border: 1px dashed var(--mint-border, #a7f3d0);
|
||||
border-radius: 8px;
|
||||
background: var(--mint-primary-bg, #ecfdf5);
|
||||
color: var(--mint-primary-dark, #059669);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.oa-receive-account-select__trigger {
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
|
||||
Reference in new issue
Block a user