feat: 卖出功能优化,点击减少自动展示已有持仓列表供选择
This commit is contained in:
parent
fa45406d8d
commit
97f2442581
@ -159,14 +159,14 @@
|
|||||||
|
|
||||||
<view class="form-content">
|
<view class="form-content">
|
||||||
<view class="form-item relative">
|
<view class="form-item relative">
|
||||||
<text class="form-label">股票代码</text>
|
<text class="form-label">{{ transactionType === 'sell' ? '选择持仓' : '股票代码' }}</text>
|
||||||
<input
|
<input
|
||||||
v-model="transactionForm.stockCode"
|
v-model="transactionForm.stockCode"
|
||||||
class="form-input"
|
class="form-input"
|
||||||
placeholder="请输入股票代码"
|
:placeholder="transactionType === 'sell' ? '请选择要卖出的持仓' : '请输入股票代码'"
|
||||||
@input="(e) => searchStock(e.detail.value)"
|
@input="(e) => searchStock(e.detail.value)"
|
||||||
/>
|
/>
|
||||||
<!-- 搜索下拉列表 -->
|
<!-- 搜索下拉列表/持仓列表 -->
|
||||||
<view class="search-dropdown" v-if="searchResults.length > 0">
|
<view class="search-dropdown" v-if="searchResults.length > 0">
|
||||||
<view
|
<view
|
||||||
class="dropdown-item"
|
class="dropdown-item"
|
||||||
@ -175,10 +175,11 @@
|
|||||||
@click="selectStock(result)"
|
@click="selectStock(result)"
|
||||||
>
|
>
|
||||||
<view class="item-left">
|
<view class="item-left">
|
||||||
<text class="item-ticker">{{ result.ticker }}</text>
|
<text class="item-ticker">{{ result.ticker || result.stockCode }}</text>
|
||||||
|
<text class="item-name">{{ result.name || result.stockName }}</text>
|
||||||
<text class="item-type" v-if="result.assetType">{{ result.assetType }}</text>
|
<text class="item-type" v-if="result.assetType">{{ result.assetType }}</text>
|
||||||
</view>
|
</view>
|
||||||
<text class="item-exchange">{{ result.exchange }}</text>
|
<text class="item-exchange">{{ result.exchange || '' }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -334,17 +335,18 @@ const searchStock = async (keyword) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const selectStock = (result) => {
|
const selectStock = (result) => {
|
||||||
transactionForm.value.stockCode = result.ticker || result.Ticker;
|
transactionForm.value.stockCode = result.ticker || result.Ticker || result.stockCode;
|
||||||
// 自动填充对应货币
|
// 自动填充对应货币
|
||||||
if (result.priceCurrency) {
|
const currency = result.priceCurrency || result.currency;
|
||||||
|
if (currency) {
|
||||||
const currencyMap = {
|
const currencyMap = {
|
||||||
'CNY': 0,
|
'CNY': 0,
|
||||||
'USD': 1,
|
'USD': 1,
|
||||||
'HKD': 2
|
'HKD': 2
|
||||||
};
|
};
|
||||||
if (currencyMap[result.priceCurrency] !== undefined) {
|
if (currencyMap[currency] !== undefined) {
|
||||||
currencyIndex.value = currencyMap[result.priceCurrency];
|
currencyIndex.value = currencyMap[currency];
|
||||||
transactionForm.value.currency = result.priceCurrency;
|
transactionForm.value.currency = currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
searchResults.value = [];
|
searchResults.value = [];
|
||||||
@ -413,6 +415,14 @@ const handleBuy = () => {
|
|||||||
const handleSell = () => {
|
const handleSell = () => {
|
||||||
transactionType.value = 'sell';
|
transactionType.value = 'sell';
|
||||||
resetTransactionForm();
|
resetTransactionForm();
|
||||||
|
// 卖出时自动填充持仓列表作为可选
|
||||||
|
searchResults.value = positions.value.map(pos => ({
|
||||||
|
ticker: pos.stockCode,
|
||||||
|
name: pos.stockName,
|
||||||
|
assetType: pos.assetType || 'Stock',
|
||||||
|
priceCurrency: pos.currency,
|
||||||
|
exchange: ''
|
||||||
|
}));
|
||||||
showTransactionForm.value = true;
|
showTransactionForm.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -425,6 +435,8 @@ const resetTransactionForm = () => {
|
|||||||
transactionDate: getCurrentDate(),
|
transactionDate: getCurrentDate(),
|
||||||
remark: ''
|
remark: ''
|
||||||
};
|
};
|
||||||
|
// 重置搜索结果
|
||||||
|
searchResults.value = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitTransaction = async () => {
|
const submitTransaction = async () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user