fix: 修复货币下拉列表无法展开问题,支持CNY/USD/HKD三种货币选择,选择股票时自动填充对应货币
This commit is contained in:
parent
c10b951f4a
commit
0b76ea601d
@ -200,10 +200,12 @@
|
||||
|
||||
<view class="form-item">
|
||||
<text class="form-label">货币</text>
|
||||
<view class="form-select">
|
||||
<text>{{ transactionForm.currency }}</text>
|
||||
<uni-icons type="bottom" size="14" color="#9CA3AF"></uni-icons>
|
||||
</view>
|
||||
<picker @change="onCurrencyChange" :value="currencyIndex" :range="currencyList" range-key="name">
|
||||
<view class="form-select">
|
||||
<text>{{ transactionForm.currency }}</text>
|
||||
<uni-icons type="bottom" size="14" color="#9CA3AF"></uni-icons>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view class="form-item">
|
||||
@ -264,13 +266,26 @@ const transactionForm = ref({
|
||||
remark: ''
|
||||
});
|
||||
|
||||
// 货币选择相关
|
||||
const currencyList = ref([
|
||||
{ name: '人民币 CNY', code: 'CNY' },
|
||||
{ name: '美元 USD', code: 'USD' },
|
||||
{ name: '港币 HKD', code: 'HKD' }
|
||||
]);
|
||||
const currencyIndex = ref(0);
|
||||
|
||||
const onCurrencyChange = (e) => {
|
||||
currencyIndex.value = e.detail.value;
|
||||
transactionForm.value.currency = currencyList.value[currencyIndex.value].code;
|
||||
};
|
||||
|
||||
// 股票搜索相关
|
||||
const searchResults = ref([]);
|
||||
const searchTimer = ref(null);
|
||||
const searchStock = async (keyword) => {
|
||||
// 防抖
|
||||
if (searchTimer.value) clearTimeout(searchTimer.value);
|
||||
if (!keyword || keyword.length < 2) {
|
||||
if (!keyword || keyword.length < 1) {
|
||||
searchResults.value = [];
|
||||
return;
|
||||
}
|
||||
@ -289,7 +304,19 @@ const searchStock = async (keyword) => {
|
||||
};
|
||||
|
||||
const selectStock = (result) => {
|
||||
transactionForm.value.stockCode = result.Ticker;
|
||||
transactionForm.value.stockCode = result.ticker || result.Ticker;
|
||||
// 自动填充对应货币
|
||||
if (result.priceCurrency) {
|
||||
const currencyMap = {
|
||||
'CNY': 0,
|
||||
'USD': 1,
|
||||
'HKD': 2
|
||||
};
|
||||
if (currencyMap[result.priceCurrency] !== undefined) {
|
||||
currencyIndex.value = currencyMap[result.priceCurrency];
|
||||
transactionForm.value.currency = result.priceCurrency;
|
||||
}
|
||||
}
|
||||
searchResults.value = [];
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user