47 lines
1.3 KiB
Vue
47 lines
1.3 KiB
Vue
<template>
|
||
<view class="page">
|
||
<scroll-view scroll-y class="list">
|
||
<view class="item" v-for="a in accounts" :key="a.id" @click="select(a)">
|
||
<view class="name">{{ a.name }}</view>
|
||
<view class="meta">{{ typeLabel(a.type) }} · 余额:{{ a.balance?.toFixed ? a.balance.toFixed(2) : a.balance }}</view>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import { get } from '../../common/http.js'
|
||
const TYPE_MAP = { cash: '现金', bank: '银行', alipay: '支付宝', wechat: '微信', other: '其他' }
|
||
export default {
|
||
data() { return { accounts: [] } },
|
||
async onLoad() {
|
||
try {
|
||
const res = await get('/api/accounts')
|
||
this.accounts = Array.isArray(res) ? res : (res?.list || [])
|
||
} catch(e) { uni.showToast({ title: '加载失败', icon: 'none' }) }
|
||
},
|
||
methods: {
|
||
select(a) {
|
||
const opener = getCurrentPages()[getCurrentPages().length-2]
|
||
if (opener && opener.$vm) {
|
||
opener.$vm.selectedAccountId = a.id
|
||
opener.$vm.selectedAccountName = a.name
|
||
}
|
||
uni.navigateBack()
|
||
},
|
||
typeLabel(t) { return TYPE_MAP[t] || t }
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
.page { display:flex; flex-direction: column; height: 100vh; }
|
||
.list { flex:1; }
|
||
.item { padding: 20rpx 24rpx; background:#fff; border-bottom: 1rpx solid #f1f1f1; }
|
||
.name { color:#333; margin-bottom: 6rpx; }
|
||
.meta { color:#888; font-size: 24rpx; }
|
||
</style>
|
||
|
||
|
||
|