From a976f2c184688b5ac1aa0c4289f81b6021c427df Mon Sep 17 00:00:00 2001 From: claw_bot Date: Tue, 10 Mar 2026 02:45:32 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=96=E5=87=BA=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E9=99=90=E5=88=B6=EF=BC=8C=E4=B8=8D=E8=83=BD=E8=B6=85=E8=BF=87?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=8C=81=E4=BB=93=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/detail/detail.vue | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pages/detail/detail.vue b/pages/detail/detail.vue index 67f03fc..8a6ac10 100644 --- a/pages/detail/detail.vue +++ b/pages/detail/detail.vue @@ -185,12 +185,12 @@ - 数量 + 数量{{ transactionType === 'sell' && maxSellAmount > 0 ? `(最多可卖 ${maxSellAmount} 份)` : '' }} @@ -292,6 +292,8 @@ const transactionForm = ref({ transactionDate: getCurrentDate(), remark: '' }); +// 当前选中持仓的最大可卖数量 +const maxSellAmount = ref(0); // 货币选择相关 const currencyList = ref([ @@ -349,6 +351,13 @@ const selectStock = (result) => { transactionForm.value.currency = currency; } } + // 如果是卖出,获取该持仓的最大可卖数量 + if (transactionType.value === 'sell') { + const position = positions.value.find(pos => pos.stockCode === transactionForm.value.stockCode); + maxSellAmount.value = position ? position.amount : 0; + } else { + maxSellAmount.value = 0; + } searchResults.value = []; }; @@ -418,9 +427,10 @@ const handleSell = () => { // 卖出时自动填充持仓列表作为可选 searchResults.value = positions.value.map(pos => ({ ticker: pos.stockCode, - name: pos.stockName, + stockName: pos.stockName, assetType: pos.assetType || 'Stock', - priceCurrency: pos.currency, + currency: pos.currency, + amount: pos.amount, exchange: '' })); showTransactionForm.value = true; @@ -437,16 +447,23 @@ const resetTransactionForm = () => { }; // 重置搜索结果 searchResults.value = []; + // 重置最大可卖数量 + maxSellAmount.value = 0; }; const submitTransaction = async () => { // 表单验证 if (!transactionForm.value.stockCode) { - return uni.showToast({ title: '请输入股票代码', icon: 'none' }); + return uni.showToast({ title: transactionType.value === 'sell' ? '请选择要卖出的持仓' : '请输入股票代码', icon: 'none' }); } - if (!transactionForm.value.amount || parseFloat(transactionForm.value.amount) <= 0) { + const amount = parseFloat(transactionForm.value.amount); + if (!amount || amount <= 0) { return uni.showToast({ title: '请输入有效的数量', icon: 'none' }); } + // 卖出时校验数量不超过持仓 + if (transactionType.value === 'sell' && amount > maxSellAmount.value) { + return uni.showToast({ title: `卖出数量不能超过持仓数量 ${maxSellAmount.value}`, icon: 'none' }); + } if (!transactionForm.value.price || parseFloat(transactionForm.value.price) <= 0) { return uni.showToast({ title: '请输入有效的价格', icon: 'none' }); }