@@ -7,8 +7,8 @@ import { IFundEnt } from '@/model/IFundEnt';
77
88// 缓存基金详情
99let CACHE_FUND_DB_LIST : DBItem < IFundEnt > [ ] ;
10- // 当前基金持有数量
11- let CURRENT_FUND_HOLD_COUNT = 0 ;
10+ // 当前搜索关键字
11+ let CURRENT_SEARCH_WORD = '' ;
1212let QUERY_TIMER : NodeJS . Timeout ;
1313
1414const getMyFundDetails = async ( ) => {
@@ -64,7 +64,7 @@ const getMyFundDetails = async () => {
6464 return FundDBHelper . getAll ( ) ;
6565} ;
6666
67- const fundDetailsToCbList = ( dbList : DBItem < IFundEnt > [ ] ) => {
67+ const fundDetailsToCbList = ( dbList : DBItem < IFundEnt > [ ] , searchWord = '' ) => {
6868 let sumIncome = 0 ;
6969 let cbList = dbList . map ( db => {
7070 const fund = db . data ;
@@ -76,6 +76,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
7676 title : `${ fund . id } ${ fund . name } ${ fund . isValuation ? '' : '✅' } ` ,
7777 description : `${ ( rate * 100 ) . toFixed ( 2 ) } % ¥${ income . toFixed ( 2 ) } ` ,
7878 icon : rate >= 0 ? 'assets/img/up.png' : 'assets/img/down.png' ,
79+ searchWord,
7980 } ;
8081 return cb ;
8182 } ) ;
@@ -85,6 +86,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
8586 title : `` ,
8687 description : `` ,
8788 icon : 'assets/img/add.png' ,
89+ searchWord,
8890 } ,
8991 ] ;
9092 } else {
@@ -93,6 +95,7 @@ const fundDetailsToCbList = (dbList: DBItem<IFundEnt>[]) => {
9395 title : `今日总收益 ${ dbList . every ( x => ! x . data . isValuation ) ? '✅' : '' } ` ,
9496 description : `¥${ sumIncome . toFixed ( 2 ) } ` ,
9597 icon : sumIncome >= 0 ? 'assets/img/up.png' : 'assets/img/down.png' ,
98+ searchWord,
9699 } ,
97100 ...cbList ,
98101 ] ;
@@ -117,7 +120,6 @@ const showFundDetails = async (cb: CallbackSetList, isShowLoading = true) => {
117120 const dbList = await getMyFundDetails ( ) ;
118121 // 缓存
119122 CACHE_FUND_DB_LIST = dbList ;
120- CURRENT_FUND_HOLD_COUNT = 0 ;
121123 const cbList = fundDetailsToCbList ( dbList ) ;
122124 cb ( cbList ) ;
123125 // 定时展示
@@ -139,8 +141,7 @@ const fundMy: TplFeature = {
139141 } ,
140142 search : async ( action , searchWord , callbackSetList ) => {
141143 let dbList = CACHE_FUND_DB_LIST && CACHE_FUND_DB_LIST . length > 0 ? CACHE_FUND_DB_LIST : await getMyFundDetails ( ) ;
142- CURRENT_FUND_HOLD_COUNT = Number ( searchWord ) ;
143- const cbList = fundDetailsToCbList ( dbList ) ;
144+ const cbList = fundDetailsToCbList ( dbList , searchWord ) ;
144145 callbackSetList ( cbList ) ;
145146 } , // 用户选择列表中某个条目时被调用
146147 select : ( action , itemData , callbackSetList ) => {
@@ -150,8 +151,13 @@ const fundMy: TplFeature = {
150151 }
151152 if ( action . type === 'text' && itemData . fundCode ) {
152153 const fundDb = FundDBHelper . get ( itemData . fundCode ) ;
153- fundDb . data . holdCount = CURRENT_FUND_HOLD_COUNT ;
154- FundDBHelper . update ( fundDb ) ;
154+ if ( itemData . searchWord ) {
155+ const holdCount = parseFloat ( itemData . searchWord ) ;
156+ if ( ! Number . isNaN ( holdCount ) ) {
157+ fundDb . data . holdCount = holdCount ;
158+ FundDBHelper . update ( fundDb ) ;
159+ }
160+ }
155161 }
156162 utools . redirect ( '我的自选基金' , '' ) ;
157163 } ,
0 commit comments