開發準備
上一節我們實現了回收金提現的功能,并且成功展示了當前賬戶的支出列表,但是我們的提現相關的記錄并沒有很好的給用戶做出展示,用戶只知道當前賬戶提現扣款,并不知道回收金的去向,這一節我們就要實現回收金記錄的查詢添加、查詢、展示
功能分析
要實現這些功能我們需要新建一張表,根據當前用戶綁定的信息去填充對應的信息,把提現的銀行卡,提現狀態,提現時間,提現金額都先添加到表里,在用戶進入提現記錄頁面之后,通過userid去查詢當前用戶的記錄然后在列表里進行展示
代碼實現
首先我們創建對應的提現記錄表
{"objectTypeName": "withdrawal_record","fields": [{"fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},{"fieldName": "user_id", "fieldType": "Integer", "notNull": true, "defaultValue": 0},{"fieldName": "bank_name", "fieldType": "String"},{"fieldName": "bank_num", "fieldType": "String"},{"fieldName": "creat_time", "fieldType": "String"},{"fieldName": "type_str", "fieldType": "String"},{"fieldName": "money", "fieldType": "Double"}],"indexes": [{"indexName": "field1Index", "indexList": [{"fieldName":"id","sortType":"ASC"}]}],"permissions": [{"role": "World", "rights": ["Read", "Upsert", "Delete"]},{"role": "Authenticated", "rights": ["Read", "Upsert", "Delete"]},{"role": "Creator", "rights": ["Read", "Upsert", "Delete"]},{"role": "Administrator", "rights": ["Read", "Upsert", "Delete"]}]
}
我們生成對應的實體和db類之后,在提現成功的提交記錄里,把我們表需要的信息添加進去
let record=new withdrawal_record()record.id=Math.floor(Math.random() * 1000000)record.user_id=this.user!.user_idrecord.bank_name=this.bankList[0].bank_namerecord.bank_num=this.bankList[0].bank_cardrecord.creat_time=this.year+"-"+this.month+"-"+this.day+" "+this.timerecord.type_str='0'record.money=this.moneyNumlet status = await databaseZone.upsert(record);
添加完成之后我們新建一個提現記錄展示頁面
@Entry
@Component
struct WithdrawalRecordPage {@State user: User|null=nullbuild() {Column() {CommonTopBar({ title: "提現記錄", alpha: 0, titleAlignment: TextAlign.Center ,backButton:true})}.backgroundColor("#F1F3F5").height('100%').width('100%')}
}
首先進行數據的查詢
@State user: User|null=null@State withdrawalRecordList:WithdrawalRecord[]=[]async aboutToAppear(): Promise<void> {const value = await StorageUtils.getAll('user');if (value != "") {this.user = JSON.parse(value)}let databaseZone = cloudDatabase.zone('default');let condition = new cloudDatabase.DatabaseQuery(withdrawal_record);condition.equalTo("user_id", this.user?.user_id)let listData = await databaseZone.query(condition);let json = JSON.stringify(listData)let data: WithdrawalRecord[] = JSON.parse(json)if (data.length>0) {this.withdrawalRecordList=data}}
然后把我們查詢到的數據展示到列表組件中
List({space:10}){ForEach(this.withdrawalRecordList,(item:WithdrawalRecord,index:number)=>{ListItem(){Column({space:10}){Row(){Text(item.type_str=='0'?"提現成功":"提現中").fontColor(item.type_str=='0'?Color.Green:Color.Black).fontSize(16).fontWeight(FontWeight.Bold)Text("¥"+item.money+"").fontSize(16).fontWeight(FontWeight.Bold).fontColor(Color.Black)}.width('100%').justifyContent(FlexAlign.SpaceBetween)Row(){Text(item.bank_name+" ("+item.bank_num+")").fontColor(Color.Black).fontSize(14).fontWeight(FontWeight.Bold)Text(item.creat_time+"").fontSize(14).fontWeight(FontWeight.Bold).fontColor(Color.Grey)}.width('100%').justifyContent(FlexAlign.SpaceBetween)}.padding(10).width('100%').borderRadius(10).backgroundColor(Color.White)}})}.padding(10)
現在讓我們運行代碼查看效果