235 lines
6.3 KiB
Plaintext
235 lines
6.3 KiB
Plaintext
import { ItemCompPublic } from './ItemCompPublic'
|
|
import { ConsulList,ConsulModel,ConsulModelHis } from '../model/ConsulModel'
|
|
import { HdList, HdListController,BasicConstant,hdHttp, HdResponse ,logger} from '@itcast/basic/Index'
|
|
import { promptAction, router } from '@kit.ArkUI'
|
|
import { BusinessError } from '@kit.BasicServicesKit';
|
|
import { EmptyViewComp,HdLoadingDialog } from '@itcast/basic'
|
|
import HashMap from '@ohos.util.HashMap';
|
|
import { HMLifecycleState, HMRouterMgr } from '@hadss/hmrouter';
|
|
|
|
|
|
@Component
|
|
export struct ListCompPublic {
|
|
// pathStack: NavPathStack = new NavPathStack()
|
|
@State isEmptyViewVisible: boolean = false; // 控制显隐的状态变量
|
|
@Prop
|
|
@Watch('onUpdate')
|
|
isHistory:boolean = false;//是否是我已回答
|
|
|
|
@State
|
|
list: ConsulList[] = []
|
|
controller = new HdListController()
|
|
@State
|
|
page: number = 1
|
|
@State
|
|
yetDayTotalNum: number = 0
|
|
@State
|
|
yetDayTotalnumEPNum: number = 0
|
|
|
|
@State url:string=BasicConstant.newConsultList
|
|
|
|
hashMap: HashMap<string, string> = new HashMap();
|
|
|
|
|
|
dialog: CustomDialogController = new CustomDialogController({
|
|
builder: HdLoadingDialog({ message: '加载中...' }),
|
|
customStyle: true,
|
|
alignment: DialogAlignment.Center
|
|
})
|
|
|
|
onUpdate() {
|
|
this.onRefresh()
|
|
|
|
}
|
|
|
|
onRefresh() {
|
|
this.page = 1
|
|
this.initData(0)
|
|
|
|
}
|
|
// private lifecycleOwner = HMRouterMgr.getCurrentLifecycleOwner()
|
|
// private handleCallback = () => {
|
|
// this.initData(0)
|
|
//
|
|
// }
|
|
// aboutToAppear() {
|
|
//
|
|
// this.lifecycleOwner?.addObserver(HMLifecycleState.onShown,this.handleCallback)
|
|
// }
|
|
// aboutToDisappear(): void {
|
|
// this.lifecycleOwner?.removeObserver(HMLifecycleState.onShown,this.handleCallback)
|
|
// }
|
|
|
|
initData(type:number)
|
|
{
|
|
this.dialog.open()
|
|
this.hashMap.clear();
|
|
this.hashMap.set('page', this.page+"")
|
|
if(this.isHistory)
|
|
{
|
|
this.url=BasicConstant.consultListHis
|
|
}
|
|
else
|
|
{
|
|
this.url=BasicConstant.newConsultList
|
|
}
|
|
hdHttp.httpReq<string>(this.url,this.hashMap).then(async (res: HdResponse<string>) => {
|
|
this.dialog.close()
|
|
|
|
if(type==0)
|
|
{
|
|
this.controller.refreshed()
|
|
}
|
|
else
|
|
{
|
|
this.controller.loaded()
|
|
}
|
|
if(this.isHistory)
|
|
{
|
|
let json:ConsulModelHis = JSON.parse(res+'') as ConsulModelHis;
|
|
if(this.page==1)
|
|
{
|
|
this.list=[]
|
|
if(json.data!=null&&json.data.list!=null&&json.data.list!=null&&json.data.list.length>0)
|
|
{
|
|
this.list = json.data.list
|
|
}
|
|
|
|
}
|
|
else if(this.page>1&&json.data!=null&&json.data.list!=null&&json.data.list.length>0)
|
|
{
|
|
this.list.push(...json.data.list)
|
|
}
|
|
|
|
if (this.page >= json.data.totalPage) {
|
|
this.controller.finished()
|
|
} else {
|
|
this.page++
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
let json:ConsulModel = JSON.parse(res+'') as ConsulModel;
|
|
this.yetDayTotalNum=json.data.yetDayTotalNum
|
|
this.yetDayTotalnumEPNum=json.data.yetDayTotalnumEPNum
|
|
if(this.page==1)
|
|
{
|
|
this.list=[]
|
|
if(json.data!=null&&json.data.consult_list!=null&&json.data.consult_list.list!=null&&json.data.consult_list.list.length>0)
|
|
{
|
|
this.list = json.data.consult_list.list
|
|
}
|
|
|
|
}
|
|
else if(this.page>1&&json.data!=null&&json.data.consult_list!=null&&json.data.consult_list.list!=null&&json.data.consult_list.list.length>0)
|
|
{
|
|
this.list.push(...json.data.consult_list.list)
|
|
}
|
|
|
|
if (this.page >= json.data.consult_list.totalPage) {
|
|
this.controller.finished()
|
|
} else {
|
|
this.page++
|
|
}
|
|
}
|
|
|
|
if (this.list.length > 0) {
|
|
this.isEmptyViewVisible = false;
|
|
} else {
|
|
this.isEmptyViewVisible = true;
|
|
}
|
|
|
|
}).catch((err: BusinessError) => {
|
|
this.dialog.close()
|
|
if (this.list.length > 0) {
|
|
this.isEmptyViewVisible = false;
|
|
} else {
|
|
this.isEmptyViewVisible = true;
|
|
}
|
|
})
|
|
}
|
|
|
|
build() {
|
|
Column()
|
|
{
|
|
if(!this.isHistory)
|
|
{
|
|
Column()
|
|
{
|
|
Text() {
|
|
Span('昨天共有').fontSize(14).fontColor(Color.White)
|
|
Span(this.yetDayTotalNum+'').fontColor('#FFEB63') .fontSize(20)
|
|
Span('条公益咨询').fontSize(14).fontColor(Color.White)
|
|
|
|
}
|
|
.margin({top:20})
|
|
.width('100%')
|
|
.textAlign(TextAlign.Start)
|
|
.padding({left:120})
|
|
Text() {
|
|
if(this.yetDayTotalnumEPNum>0)
|
|
{
|
|
Span('您回答了').fontSize(14).fontColor(Color.White)
|
|
Span(this.yetDayTotalnumEPNum+'').fontColor('#FFEB63') .fontSize(20)
|
|
Span('条,谢谢您的支持!').fontSize(14).fontColor(Color.White)
|
|
}
|
|
else
|
|
{
|
|
Span('邀请您一起参与').fontSize(14).fontColor(Color.White)
|
|
ImageSpan($r('app.media.consult_zero')).width(35).height(20).padding({top:4,bottom:2}).objectFit(ImageFit.Contain)
|
|
|
|
}
|
|
|
|
}
|
|
.width('100%')
|
|
.textAlign(TextAlign.Start)
|
|
.padding({left:120})
|
|
.margin({top:10})
|
|
}
|
|
.backgroundImage($r('app.media.consult_background'))
|
|
.height(90)
|
|
.backgroundImageSize(ImageSize.Cover)
|
|
.backgroundImagePosition(Alignment.Center)
|
|
.width('100%')
|
|
.visibility(this.yetDayTotalNum>0?Visibility.Visible:Visibility.None)
|
|
Text('').width('100%').height(5).backgroundColor($r('app.color.efefef'))
|
|
.visibility(this.yetDayTotalNum>0?Visibility.Visible:Visibility.None)
|
|
|
|
}
|
|
if (this.isEmptyViewVisible){
|
|
EmptyViewComp({promptText:'暂无公益咨询',isVisibility:this.isEmptyViewVisible})
|
|
.width('100%')
|
|
.height('100%')
|
|
} else
|
|
{
|
|
HdList({
|
|
lw: 1,
|
|
controller: this.controller,
|
|
strokeWidth:5,
|
|
onRefresh: () => {
|
|
this.onRefresh()
|
|
},
|
|
onLoad: () => {
|
|
this.initData(1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
{
|
|
ForEach(this.list, (item: ConsulList) => {
|
|
ListItem() {
|
|
ItemCompPublic({ item,isHistory:this.isHistory })
|
|
|
|
}
|
|
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
} |