feat: 新增创建组合币种选择,交易页面去掉币种选择框,明细页货币符号动态显示

This commit is contained in:
claw_bot 2026-03-10 07:16:10 +00:00
parent d9d6ce83f7
commit 6afd34cb0f
2 changed files with 45 additions and 16 deletions

View File

@ -29,6 +29,17 @@
</picker>
<text class="helper-text" v-if="selectedStrategy">{{ selectedStrategy.desc }}</text>
</view>
<view class="form-item">
<text class="label">组合币种</text>
<picker @change="onCurrencyChange" :value="currencyIndex" :range="currencyList" range-key="name">
<view class="picker-box">
<text class="picker-text">{{ currencyList[currencyIndex].name }}</text>
<uni-icons type="bottom" size="14" color="#9CA3AF"></uni-icons>
</view>
</picker>
<text class="helper-text">创建后币种不可修改所有交易只能使用该币种</text>
</view>
</view>
<view class="section-card">
@ -117,6 +128,13 @@ import { api } from '../../utils/api';
const strategies = ref([]);
const strategyIndex = ref(-1);
//
const currencyList = ref([
{ name: '人民币 CNY', code: 'CNY' },
{ name: '美元 USD', code: 'USD' },
{ name: '港币 HKD', code: 'HKD' }
]);
const currencyIndex = ref(0); // CNY
//
let isFetching = false;
@ -253,6 +271,10 @@ const onDateChange = (e, index) => {
form.value.stocks[index].date = e.detail.value;
};
const onCurrencyChange = (e) => {
currencyIndex.value = e.detail.value;
};
const submitForm = async () => {
if (!form.value.name) return uni.showToast({ title: '请输入组合名称', icon: 'none' });
if (strategyIndex.value === -1) return uni.showToast({ title: '请选择策略', icon: 'none' });
@ -294,17 +316,18 @@ const submitForm = async () => {
}
}
const selectedCurrency = currencyList.value[currencyIndex.value].code;
const requestData = {
name: form.value.name,
strategyId: selected.id,
currency: 'USD',
currency: selectedCurrency,
stocks: form.value.stocks.map(stock => ({
name: stock.name,
code: stock.name,
price: parseFloat(stock.price) || 0,
amount: parseFloat(stock.amount) || 0,
date: stock.date,
currency: 'USD'
currency: selectedCurrency
}))
};

View File

@ -16,7 +16,7 @@
</view>
<view class="card-main">
<text class="currency">¥</text>
<text class="currency">{{ getCurrencySymbol(portfolioData.currency) }}</text>
<text class="big-number">{{ (portfolioData.portfolioValue || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</text>
</view>
@ -27,7 +27,7 @@
</view>
<view class="stat-item align-right">
<text class="stat-label">日内波动</text>
<text class="stat-val" :class="(portfolioData.dailyVolatility || 0) >= 0 ? 'text-red' : 'text-green'">{{ (portfolioData.dailyVolatility || 0) >= 0 ? '+' : '' }}¥{{ (portfolioData.dailyVolatility || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</text>
<text class="stat-val" :class="(portfolioData.dailyVolatility || 0) >= 0 ? 'text-red' : 'text-green'">{{ (portfolioData.dailyVolatility || 0) >= 0 ? '+' : '' }}{{ getCurrencySymbol(portfolioData.currency) }}{{ (portfolioData.dailyVolatility || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</text>
</view>
</view>
</view>
@ -83,7 +83,7 @@
</view>
</view>
<view class="flex-col align-right">
<text class="market-val">¥{{ (item.totalValue || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</text>
<text class="market-val">{{ getCurrencySymbol(portfolioData.currency) }}{{ (item.totalValue || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}</text>
<text class="weight-tag">比例 {{ (item.ratio || 0).toFixed(1) }}%</text>
</view>
</view>
@ -94,7 +94,7 @@
<view class="pnl-item">
<text class="pnl-label">变动额</text>
<text class="pnl-val" :class="(item.changeAmount || 0) >= 0 ? 'text-red' : 'text-green'">
{{ (item.changeAmount || 0) >= 0 ? '+' : '' }}¥{{ (item.changeAmount || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}
{{ (item.changeAmount || 0) >= 0 ? '+' : '' }}{{ getCurrencySymbol(portfolioData.currency) }}{{ (item.changeAmount || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }}
</text>
</view>
<view class="pnl-item align-right">
@ -214,15 +214,7 @@
/>
</view>
<view class="form-item">
<text class="form-label">货币</text>
<picker @change="onCurrencyChange" :value="currencyIndex" :range="currencyList" range-key="name">
<view class="form-select">
<text>{{ transactionForm.currency }}</text>
<uni-icons type="bottom" size="14" color="#9CA3AF"></uni-icons>
</view>
</picker>
</view>
<view class="form-item">
<text class="form-label">交易时间</text>
@ -258,6 +250,16 @@
import { ref, onMounted, watch } from 'vue';
import { api } from '../../utils/api';
//
const getCurrencySymbol = (currency) => {
const symbols = {
'CNY': '¥',
'USD': '$',
'HKD': 'HK$'
};
return symbols[currency] || '¥';
};
const portfolioId = ref('');
const portfolioData = ref({
id: '',
@ -297,7 +299,7 @@ const transactionForm = ref({
stockCode: '',
amount: '',
price: '',
currency: 'CNY',
currency: '', // 使
transactionDate: getCurrentDate(),
remark: ''
});
@ -427,12 +429,16 @@ const goStrategyConfig = () => {
const handleBuy = () => {
transactionType.value = 'buy';
resetTransactionForm();
// 使
transactionForm.value.currency = portfolioData.value.currency;
showTransactionForm.value = true;
};
const handleSell = () => {
transactionType.value = 'sell';
resetTransactionForm();
// 使
transactionForm.value.currency = portfolioData.value.currency;
//
searchResults.value = positions.value.map(pos => ({
ticker: pos.stockCode,