diff --git a/pages/config/config.vue b/pages/config/config.vue index 013d7cd..5a20a94 100644 --- a/pages/config/config.vue +++ b/pages/config/config.vue @@ -29,6 +29,17 @@ {{ selectedStrategy.desc }} + + + 组合币种 + + + {{ currencyList[currencyIndex].name }} + + + + 创建后币种不可修改,所有交易只能使用该币种 + @@ -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 })) }; diff --git a/pages/detail/detail.vue b/pages/detail/detail.vue index 07dda63..c91ccdf 100644 --- a/pages/detail/detail.vue +++ b/pages/detail/detail.vue @@ -16,7 +16,7 @@ - ¥ + {{ getCurrencySymbol(portfolioData.currency) }} {{ (portfolioData.portfolioValue || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }} @@ -27,7 +27,7 @@ 日内波动 - {{ (portfolioData.dailyVolatility || 0) >= 0 ? '+' : '' }}¥{{ (portfolioData.dailyVolatility || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }} + {{ (portfolioData.dailyVolatility || 0) >= 0 ? '+' : '' }}{{ getCurrencySymbol(portfolioData.currency) }}{{ (portfolioData.dailyVolatility || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }} @@ -83,7 +83,7 @@ - ¥{{ (item.totalValue || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }} + {{ getCurrencySymbol(portfolioData.currency) }}{{ (item.totalValue || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }} 比例 {{ (item.ratio || 0).toFixed(1) }}% @@ -94,7 +94,7 @@ 变动额 - {{ (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 }) }} @@ -214,15 +214,7 @@ /> - - 货币 - - - {{ transactionForm.currency }} - - - - + 交易时间 @@ -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,