fix: 修复股票搜索功能

- 将u-input替换为原生input,解决事件参数问题
- 添加onStockInput方法正确处理input事件
- 添加调试日志便于排查问题
This commit is contained in:
claw_bot 2026-03-13 06:18:56 +00:00
parent 65fd6ce23d
commit 258d92ac1c

View File

@ -197,13 +197,12 @@
<view class="form-item"> <view class="form-item">
<text class="form-label">{{ transactionType === 'sell' ? '选择持仓' : '股票代码' }}</text> <text class="form-label">{{ transactionType === 'sell' ? '选择持仓' : '股票代码' }}</text>
<view class="relative"> <view class="relative">
<u-input <input
v-model="transactionForm.stockCode" v-model="transactionForm.stockCode"
class="stock-input"
:placeholder="transactionType === 'sell' ? '点击选择要卖出的持仓' : '请输入股票代码搜索'" :placeholder="transactionType === 'sell' ? '点击选择要卖出的持仓' : '请输入股票代码搜索'"
:disabled="transactionType === 'sell'" :disabled="transactionType === 'sell'"
:border="false" @input="onStockInput"
:customStyle="{ backgroundColor: '#F9FAFB', borderRadius: '16rpx', height: '80rpx', padding: '0 20rpx', border: '2rpx solid #E5E7EB' }"
@input="transactionType === 'buy' ? searchStock($event) : () => {}"
@click="handleStockInputClick" @click="handleStockInputClick"
/> />
<!-- 搜索下拉列表 --> <!-- 搜索下拉列表 -->
@ -351,7 +350,6 @@ const searchTimer = ref(null);
const handleStockInputClick = () => { const handleStockInputClick = () => {
if (transactionType.value === 'sell') { if (transactionType.value === 'sell') {
//
searchResults.value = positions.value.map(pos => ({ searchResults.value = positions.value.map(pos => ({
ticker: pos.stockCode, ticker: pos.stockCode,
stockCode: pos.stockCode, stockCode: pos.stockCode,
@ -365,8 +363,14 @@ const handleStockInputClick = () => {
} }
}; };
const onStockInput = (e) => {
const keyword = e.detail.value;
console.log('🔍 股票输入:', keyword);
searchStock(keyword);
};
const searchStock = async (keyword) => { const searchStock = async (keyword) => {
// console.log('🔍 searchStock 调用:', keyword);
if (searchTimer.value) clearTimeout(searchTimer.value); if (searchTimer.value) clearTimeout(searchTimer.value);
if (!keyword || keyword.length < 1) { if (!keyword || keyword.length < 1) {
searchResults.value = []; searchResults.value = [];
@ -375,7 +379,9 @@ const searchStock = async (keyword) => {
searchTimer.value = setTimeout(async () => { searchTimer.value = setTimeout(async () => {
try { try {
console.log('📤 调用 api.ticker.search:', keyword);
const res = await api.ticker.search(keyword); const res = await api.ticker.search(keyword);
console.log('📥 搜索结果:', res);
if (res.code === 200) { if (res.code === 200) {
searchResults.value = res.data; searchResults.value = res.data;
} }
@ -822,6 +828,18 @@ const deletePortfolio = async () => {
margin-bottom: 12rpx; margin-bottom: 12rpx;
} }
.stock-input {
width: 100%;
height: 80rpx;
background-color: #F9FAFB;
border: 2rpx solid #E5E7EB;
border-radius: 16rpx;
padding: 0 20rpx;
font-size: 26rpx;
color: #1F2937;
box-sizing: border-box;
}
.form-select { .form-select {
width: 100%; width: 100%;
height: 80rpx; height: 80rpx;