feat: 卖出数量限制,不能超过当前持仓数量
This commit is contained in:
parent
97f2442581
commit
a976f2c184
@ -185,12 +185,12 @@
|
||||
</view>
|
||||
|
||||
<view class="form-item">
|
||||
<text class="form-label">数量</text>
|
||||
<text class="form-label">数量{{ transactionType === 'sell' && maxSellAmount > 0 ? `(最多可卖 ${maxSellAmount} 份)` : '' }}</text>
|
||||
<input
|
||||
v-model="transactionForm.amount"
|
||||
class="form-input"
|
||||
type="number"
|
||||
placeholder="请输入数量"
|
||||
:placeholder="transactionType === 'sell' && maxSellAmount > 0 ? `请输入数量,不超过 ${maxSellAmount}` : '请输入数量'"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@ -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' });
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user