Files
zkxw/mobile-oa-h5/src/oa/components/OaReceiveAccountSelect.vue
T
2026-08-13 14:31:57 +08:00

190 lines
5.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="oa-recv">
<van-field
:model-value="summary"
readonly
:is-link="!disabled"
input-align="left"
:disabled="disabled"
placeholder="请选择收款账户"
@click="openPicker"
/>
<!-- 单账户已在 summary 展示完整行,避免详情/发起页重复两遍 -->
<div v-if="normalized.length > 1" class="oa-recv__detail">
<div v-for="item in normalized" :key="item.id" class="oa-recv__line">
{{ formatReceiveAccountLine(item) }}
</div>
</div>
<van-popup v-model:show="visible" position="bottom" round :style="{ height: '70%' }">
<div class="oa-recv__sheet">
<div class="oa-recv__hd">
<span @click="visible = false">取消</span>
<strong>选择收款账户</strong>
<span class="oa-recv__ok" @click="confirm">确定</span>
</div>
<van-search
v-model="keyword"
shape="round"
label-align="left"
input-align="left"
placeholder="搜索账户名称或账号"
/>
<div class="oa-recv__list">
<van-checkbox-group v-model="pendingIds">
<div
v-for="a in filtered"
:key="a.id"
class="oa-sheet-row"
:class="{ 'is-selected': pendingIds.includes(a.id) }"
@click="toggle(a.id)"
>
<van-checkbox
class="oa-sheet-row__check"
:name="a.id"
@click.stop
/>
<div class="oa-sheet-row__main">
<div class="oa-sheet-row__title">{{ a.label }}</div>
<div v-if="a.sub" class="oa-sheet-row__meta">{{ a.sub }}</div>
</div>
</div>
</van-checkbox-group>
<van-empty v-if="!loading && !filtered.length" description="暂无收款账户" />
</div>
</div>
</van-popup>
</div>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue'
import { showToast } from 'vant'
import { fetchReceiveAccountOptions } from '../../api/oa.js'
import {
ACCOUNT_TYPE_LABEL,
formatReceiveAccountLine,
normalizeReceiveAccountModelValue,
optionLabelFromRow,
snapshotFromRow
} from '../../utils/receive-account-value.js'
defineOptions({ name: 'receiveAccount' })
const props = defineProps({
modelValue: { type: [Array, Object], default: () => [] },
disabled: { type: Boolean, default: false },
formCreateInject: { type: Object, default: null }
})
const emit = defineEmits(['update:modelValue', 'change'])
const visible = ref(false)
const loading = ref(false)
const keyword = ref('')
const pendingIds = ref([])
const snapshotMap = ref(new Map())
const accountOptions = ref([])
const normalized = computed(() => normalizeReceiveAccountModelValue(props.modelValue))
const summary = computed(() => {
const n = normalized.value.length
if (!n) return ''
if (n === 1) return formatReceiveAccountLine(normalized.value[0])
return `已选 ${n} 个账户`
})
const filtered = computed(() => {
const kw = keyword.value.trim().toLowerCase()
if (!kw) return accountOptions.value
return accountOptions.value.filter(
(a) =>
a.label.toLowerCase().includes(kw) ||
String(a.sub || '')
.toLowerCase()
.includes(kw)
)
})
function emitItems(items) {
emit('update:modelValue', items)
emit('change', items)
}
function openPicker() {
if (props.disabled) return
pendingIds.value = normalized.value.map((x) => x.id)
visible.value = true
if (!accountOptions.value.length) loadOptions()
}
function toggle(id) {
const set = new Set(pendingIds.value)
if (set.has(id)) set.delete(id)
else set.add(id)
pendingIds.value = [...set]
}
function confirm() {
const items = pendingIds.value
.map((id) => snapshotMap.value.get(id))
.filter(Boolean)
emitItems(items)
visible.value = false
}
async function loadOptions() {
loading.value = true
try {
const res = await fetchReceiveAccountOptions()
const list = res?.list || []
const map = new Map()
const opts = []
for (const row of list) {
const snap = snapshotFromRow(row)
if (!snap.id) continue
map.set(snap.id, snap)
const typeLabel = ACCOUNT_TYPE_LABEL[snap.accountType] || snap.accountType
const label = [typeLabel, snap.accountName].filter(Boolean).join(' · ')
const subParts = [snap.accountNo]
if (
(snap.accountType === 'personal' || snap.accountType === 'corporate') &&
snap.bankName
) {
subParts.push(snap.bankName)
}
const sub = subParts.filter(Boolean).join(' · ')
opts.push({
id: snap.id,
label: label || optionLabelFromRow(snap),
sub
})
}
for (const x of normalized.value) {
if (!map.has(x.id)) map.set(x.id, x)
}
snapshotMap.value = map
accountOptions.value = opts
} catch (e) {
showToast(e?.message || '加载收款账户失败')
} finally {
loading.value = false
}
}
onMounted(() => {
loadOptions()
})
</script>
<style scoped>
.oa-recv__detail {
padding: 0 12px 8px;
color: var(--text-muted, #5f7a6d);
font-size: 12px;
line-height: 1.5;
text-align: left;
}
.oa-recv__line + .oa-recv__line {
margin-top: 4px;
}
</style>