feat: 卖出数量限制,不能超过当前持仓数量

This commit is contained in:
claw_bot 2026-03-10 02:45:32 +00:00
parent 97f2442581
commit a976f2c184

View File

@ -185,12 +185,12 @@
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="form-label">数量</text> <text class="form-label">数量{{ transactionType === 'sell' && maxSellAmount > 0 ? `(最多可卖 ${maxSellAmount} 份)` : '' }}</text>
<input <input
v-model="transactionForm.amount" v-model="transactionForm.amount"
class="form-input" class="form-input"
type="number" type="number"
placeholder="请输入数量" :placeholder="transactionType === 'sell' && maxSellAmount > 0 ? `请输入数量,不超过 ${maxSellAmount}` : '请输入数量'"
/> />
</view> </view>
@ -292,6 +292,8 @@ const transactionForm = ref({
transactionDate: getCurrentDate(), transactionDate: getCurrentDate(),
remark: '' remark: ''
}); });
//
const maxSellAmount = ref(0);
// //
const currencyList = ref([ const currencyList = ref([
@ -349,6 +351,13 @@ const selectStock = (result) => {
transactionForm.value.currency = currency; 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 = []; searchResults.value = [];
}; };
@ -418,9 +427,10 @@ const handleSell = () => {
// //
searchResults.value = positions.value.map(pos => ({ searchResults.value = positions.value.map(pos => ({
ticker: pos.stockCode, ticker: pos.stockCode,
name: pos.stockName, stockName: pos.stockName,
assetType: pos.assetType || 'Stock', assetType: pos.assetType || 'Stock',
priceCurrency: pos.currency, currency: pos.currency,
amount: pos.amount,
exchange: '' exchange: ''
})); }));
showTransactionForm.value = true; showTransactionForm.value = true;
@ -437,16 +447,23 @@ const resetTransactionForm = () => {
}; };
// //
searchResults.value = []; searchResults.value = [];
//
maxSellAmount.value = 0;
}; };
const submitTransaction = async () => { const submitTransaction = async () => {
// //
if (!transactionForm.value.stockCode) { 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' }); 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) { if (!transactionForm.value.price || parseFloat(transactionForm.value.price) <= 0) {
return uni.showToast({ title: '请输入有效的价格', icon: 'none' }); return uni.showToast({ title: '请输入有效的价格', icon: 'none' });
} }