Showing
3 changed files
with
139 additions
and
63 deletions
| @@ -5,6 +5,8 @@ import { PageRepository } from '../../repository/PageRepository'; | @@ -5,6 +5,8 @@ import { PageRepository } from '../../repository/PageRepository'; | ||
| 5 | import { ProcessUtils } from 'wdRouter'; | 5 | import { ProcessUtils } from 'wdRouter'; |
| 6 | import { HttpUtils } from 'wdNetwork/Index'; | 6 | import { HttpUtils } from 'wdNetwork/Index'; |
| 7 | import { DateTimeUtils } from 'wdKit'; | 7 | import { DateTimeUtils } from 'wdKit'; |
| 8 | +import { LiveModel } from '../../viewmodel/LiveModel' | ||
| 9 | +import { Logger, ToastUtils } from 'wdKit'; | ||
| 8 | 10 | ||
| 9 | /** | 11 | /** |
| 10 | * 直播预约卡 | 12 | * 直播预约卡 |
| @@ -12,13 +14,62 @@ import { DateTimeUtils } from 'wdKit'; | @@ -12,13 +14,62 @@ import { DateTimeUtils } from 'wdKit'; | ||
| 12 | */ | 14 | */ |
| 13 | const TAG = 'Zh_Single_Row-03' | 15 | const TAG = 'Zh_Single_Row-03' |
| 14 | 16 | ||
| 17 | +interface reserveItem { | ||
| 18 | + liveId: number, | ||
| 19 | + relationId: string, | ||
| 20 | + subscribe: boolean | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +interface reserveReqItem { | ||
| 24 | + liveId: string, | ||
| 25 | + relationId: string, | ||
| 26 | +} | ||
| 27 | + | ||
| 15 | @Entry | 28 | @Entry |
| 16 | @Component | 29 | @Component |
| 17 | export struct ZhSingleRow03 { | 30 | export struct ZhSingleRow03 { |
| 18 | @State compDTO: CompDTO = {} as CompDTO | 31 | @State compDTO: CompDTO = {} as CompDTO |
| 19 | @State isEndEdge: boolean = false; | 32 | @State isEndEdge: boolean = false; |
| 33 | + // @State reserveStatus: reserveItem[] = [] | ||
| 34 | + @State reservedIds: number[] = []; | ||
| 20 | scroller: Scroller = new Scroller() | 35 | scroller: Scroller = new Scroller() |
| 21 | 36 | ||
| 37 | + aboutToAppear(): void { | ||
| 38 | + this.getReserveState(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + // 请求所有预约状态 | ||
| 42 | + async getReserveState() { | ||
| 43 | + const reserveBean: reserveReqItem[] = this.compDTO.operDataList.map((item: ContentDTO) => { | ||
| 44 | + const reqItem: reserveReqItem = { | ||
| 45 | + liveId: item.objectId, | ||
| 46 | + relationId: item.relId | ||
| 47 | + } | ||
| 48 | + return reqItem; | ||
| 49 | + }) | ||
| 50 | + const res = await LiveModel.getAppointmentStatus(reserveBean); | ||
| 51 | + // this.reserveStatus = res; | ||
| 52 | + res.map((item: reserveItem) => { | ||
| 53 | + if (item.subscribe) { | ||
| 54 | + this.reservedIds.push(item.liveId) | ||
| 55 | + } | ||
| 56 | + }) | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + // 判断是否预约 | ||
| 60 | + isReserved(liveId: number) { | ||
| 61 | + return this.reservedIds.includes(liveId) | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + // 预约/取消预约 | ||
| 65 | + async bookAndCancel(relationId: string, liveId: string, isSubscribe: boolean) { | ||
| 66 | + const res = await LiveModel.liveAppointment(relationId, liveId, isSubscribe); | ||
| 67 | + if (res.code == 0) { | ||
| 68 | + ToastUtils.shortToast(isSubscribe ? '预约成功' : '取消预约成功') | ||
| 69 | + this.getReserveState(); | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + | ||
| 22 | format(timeNum: number) { | 73 | format(timeNum: number) { |
| 23 | const todayDate = new Date().setHours(0,0,0,0) | 74 | const todayDate = new Date().setHours(0,0,0,0) |
| 24 | const parseDate = new Date(timeNum).setHours(0,0,0,0); | 75 | const parseDate = new Date(timeNum).setHours(0,0,0,0); |
| @@ -44,64 +95,7 @@ export struct ZhSingleRow03 { | @@ -44,64 +95,7 @@ export struct ZhSingleRow03 { | ||
| 44 | Scroll(this.scroller){ | 95 | Scroll(this.scroller){ |
| 45 | Row() { | 96 | Row() { |
| 46 | ForEach(this.compDTO.operDataList, (item: ContentDTO) => { | 97 | ForEach(this.compDTO.operDataList, (item: ContentDTO) => { |
| 47 | - Column() { | ||
| 48 | - Row() { | ||
| 49 | - Image(item.coverUrl) | ||
| 50 | - .width(106) | ||
| 51 | - .height(60) | ||
| 52 | - .margin({right: 12}) | ||
| 53 | - Text(item.newsTitle) | ||
| 54 | - .width(154) | ||
| 55 | - .height(60) | ||
| 56 | - .maxLines(3) | ||
| 57 | - .textOverflow({overflow: TextOverflow.Ellipsis}) | ||
| 58 | - } | ||
| 59 | - .margin({bottom: 16}) | ||
| 60 | - | ||
| 61 | - Row() { | ||
| 62 | - Flex({justifyContent: FlexAlign.SpaceBetween}){ | ||
| 63 | - Row() { | ||
| 64 | - Text(this.format(new Date(item.liveInfo.liveStartTime).getTime())) | ||
| 65 | - .margin({right: 6}) | ||
| 66 | - .fontColor(0x000000) | ||
| 67 | - .fontSize(13) | ||
| 68 | - .textAlign(TextAlign.Start) | ||
| 69 | - Image($r('app.media.timeline_rect')) | ||
| 70 | - .width(4) | ||
| 71 | - .height(3) | ||
| 72 | - .margin({right: 6}) | ||
| 73 | - Text(item.liveInfo.liveStartTime.split(' ')[1].slice(0, 5)) | ||
| 74 | - .margin({right: 6}) | ||
| 75 | - .fontColor(0x000000) | ||
| 76 | - .fontSize(13) | ||
| 77 | - Text('开始直播') | ||
| 78 | - .fontColor(0xC8C8C8) | ||
| 79 | - .fontSize(13) | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - Row() { | ||
| 83 | - Text('预约') | ||
| 84 | - .width(48) | ||
| 85 | - .height(24) | ||
| 86 | - .backgroundColor(0xED2800) | ||
| 87 | - .fontColor(0xffffff) | ||
| 88 | - .fontSize(12) | ||
| 89 | - .textAlign(TextAlign.Center) | ||
| 90 | - .borderRadius(3) | ||
| 91 | - } | ||
| 92 | - .margin({top: -5}) | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - } | ||
| 96 | - } | ||
| 97 | - .width(298) | ||
| 98 | - .height(116) | ||
| 99 | - .padding({top: 12, bottom: 12, left: 12, right: 12}) | ||
| 100 | - .backgroundColor(0xf9f9f9) | ||
| 101 | - .margin({right: 8}) | ||
| 102 | - .onClick(() => { | ||
| 103 | - ProcessUtils.processPage(item) | ||
| 104 | - }) | 98 | + this.ItemCard(item) |
| 105 | }) | 99 | }) |
| 106 | } | 100 | } |
| 107 | } | 101 | } |
| @@ -131,6 +125,73 @@ export struct ZhSingleRow03 { | @@ -131,6 +125,73 @@ export struct ZhSingleRow03 { | ||
| 131 | } | 125 | } |
| 132 | 126 | ||
| 133 | @Builder | 127 | @Builder |
| 128 | + ItemCard(item: ContentDTO) { | ||
| 129 | + Column() { | ||
| 130 | + Row() { | ||
| 131 | + Image(item.coverUrl) | ||
| 132 | + .width(106) | ||
| 133 | + .height(60) | ||
| 134 | + .margin({right: 12}) | ||
| 135 | + Text(item.newsTitle) | ||
| 136 | + .width(154) | ||
| 137 | + .height(60) | ||
| 138 | + .maxLines(3) | ||
| 139 | + .textOverflow({overflow: TextOverflow.Ellipsis}) | ||
| 140 | + } | ||
| 141 | + .margin({bottom: 16}) | ||
| 142 | + | ||
| 143 | + Row() { | ||
| 144 | + Flex({justifyContent: FlexAlign.SpaceBetween}){ | ||
| 145 | + Row() { | ||
| 146 | + Text(this.format(new Date(item.liveInfo.liveStartTime).getTime())) | ||
| 147 | + .margin({right: 6}) | ||
| 148 | + .fontColor(0x000000) | ||
| 149 | + .fontSize(13) | ||
| 150 | + .textAlign(TextAlign.Start) | ||
| 151 | + Image($r('app.media.timeline_rect')) | ||
| 152 | + .width(4) | ||
| 153 | + .height(3) | ||
| 154 | + .margin({right: 6}) | ||
| 155 | + Text(item.liveInfo.liveStartTime.split(' ')[1].slice(0, 5)) | ||
| 156 | + .margin({right: 6}) | ||
| 157 | + .fontColor(0x000000) | ||
| 158 | + .fontSize(13) | ||
| 159 | + Text('开始直播') | ||
| 160 | + .fontColor(0xC8C8C8) | ||
| 161 | + .fontSize(13) | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + Row() { | ||
| 165 | + Text(this.isReserved(Number(item.objectId)) ? '已预约' : '预约') | ||
| 166 | + .width(48) | ||
| 167 | + .height(24) | ||
| 168 | + .backgroundColor(this.isReserved(Number(item.objectId)) ? 0xffffff : 0xED2800) | ||
| 169 | + .fontColor(this.isReserved(Number(item.objectId)) ? 0xC8C8C8 : 0xffffff) | ||
| 170 | + .fontSize(12) | ||
| 171 | + .textAlign(TextAlign.Center) | ||
| 172 | + .borderRadius(3) | ||
| 173 | + .onClick(() => { | ||
| 174 | + this.bookAndCancel(item.relId, item.objectId, !this.isReserved(Number(item.objectId))) | ||
| 175 | + }) | ||
| 176 | + | ||
| 177 | + } | ||
| 178 | + .margin({top: -5}) | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + .width(298) | ||
| 184 | + .height(116) | ||
| 185 | + .padding({top: 12, bottom: 12, left: 12, right: 12}) | ||
| 186 | + .backgroundColor(0xf9f9f9) | ||
| 187 | + .margin({right: 8}) | ||
| 188 | + .onClick(() => { | ||
| 189 | + ProcessUtils.processPage(item) | ||
| 190 | + }) | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + | ||
| 194 | + @Builder | ||
| 134 | CompHeader(item: CompDTO) { | 195 | CompHeader(item: CompDTO) { |
| 135 | Row() { | 196 | Row() { |
| 136 | Row() { | 197 | Row() { |
| @@ -83,7 +83,7 @@ struct ReserveMorePage { | @@ -83,7 +83,7 @@ struct ReserveMorePage { | ||
| 83 | this.reserveBean = this.transformToLiveDetailsBeans(liveReviewDTO.list) | 83 | this.reserveBean = this.transformToLiveDetailsBeans(liveReviewDTO.list) |
| 84 | 84 | ||
| 85 | const apointMentStatus = await LiveModel.getAppointmentStatus(this.reserveBean) | 85 | const apointMentStatus = await LiveModel.getAppointmentStatus(this.reserveBean) |
| 86 | - console.info(`cj2024 ${apointMentStatus.code}`) | 86 | + // console.info(`cj2024 ${apointMentStatus.code}`) |
| 87 | }) | 87 | }) |
| 88 | 88 | ||
| 89 | 89 |
| @@ -5,6 +5,17 @@ import { LiveDetailsBean, ReserveBean } from 'wdBean/Index'; | @@ -5,6 +5,17 @@ import { LiveDetailsBean, ReserveBean } from 'wdBean/Index'; | ||
| 5 | 5 | ||
| 6 | const TAG = 'LiveModel' | 6 | const TAG = 'LiveModel' |
| 7 | 7 | ||
| 8 | +interface ReserveRes { | ||
| 9 | + code: string | number, | ||
| 10 | + data: ReserveItem[] | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +interface ReserveItem { | ||
| 14 | + liveId: number, | ||
| 15 | + relationId: string, | ||
| 16 | + subscribe: boolean | ||
| 17 | +} | ||
| 18 | + | ||
| 8 | export class LiveModel { | 19 | export class LiveModel { |
| 9 | /** | 20 | /** |
| 10 | * 直播内容详情 | 21 | * 直播内容详情 |
| @@ -74,17 +85,21 @@ export class LiveModel { | @@ -74,17 +85,21 @@ export class LiveModel { | ||
| 74 | static getAppointmentStatus(reserveBean: ReserveBean[]) { | 85 | static getAppointmentStatus(reserveBean: ReserveBean[]) { |
| 75 | // let params: Record<string, ArrayList<ReserveBean>> = {}; | 86 | // let params: Record<string, ArrayList<ReserveBean>> = {}; |
| 76 | // params = reserveBean | 87 | // params = reserveBean |
| 77 | - return new Promise<ResponseDTO<string>>((success, fail) => { | ||
| 78 | - HttpRequest.post<ResponseDTO<string>>( | 88 | + return new Promise<Array<ReserveItem>>((success, fail) => { |
| 89 | + HttpRequest.post<ResponseDTO<Array<ReserveItem>>>( | ||
| 79 | HttpUrlUtils.getAppointmentStatusUrl(), | 90 | HttpUrlUtils.getAppointmentStatusUrl(), |
| 80 | reserveBean, | 91 | reserveBean, |
| 81 | - ).then((data: ResponseDTO<string>) => { | 92 | + ).then((data: ResponseDTO<Array<ReserveItem>>) => { |
| 93 | + if (!data || !data.data) { | ||
| 94 | + fail("数据为空") | ||
| 95 | + return | ||
| 96 | + } | ||
| 82 | if (data.code != 0) { | 97 | if (data.code != 0) { |
| 83 | fail(data.message) | 98 | fail(data.message) |
| 84 | ToastUtils.shortToast(data.message) | 99 | ToastUtils.shortToast(data.message) |
| 85 | return | 100 | return |
| 86 | } | 101 | } |
| 87 | - success(data) | 102 | + success(data.data) |
| 88 | }, (error: Error) => { | 103 | }, (error: Error) => { |
| 89 | fail(error.message) | 104 | fail(error.message) |
| 90 | Logger.debug(TAG + ":error ", error.toString()) | 105 | Logger.debug(TAG + ":error ", error.toString()) |
-
Please register or login to post a comment