wwf
2 天以前 791a96ae03cf92478244127b294c1fe520d31e89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { promptAction, router } from "@kit.ArkUI"
import { http } from "@kit.NetworkKit"
import { LvMarkdownIn } from "@luvi/lv-markdown-in"
import { HttpResponseResult } from "../../data/HttpResponse"
import { DOMAIN } from "../../utils/config"
 
class Activity {
  id: string = ''
  name: string = ''
  pic: string = ''
  startDate: string = ''
  endTime: string = ''
  signupCount: number = 0
  status: string = ''
  content: string = ''
}
 
@Entry
@Component
export struct ActiveDetail {
  @State hotTrainingId: string = ''
  @State activeInfo: Activity = {
    id: '',
    name: '',
    pic: '',
    startDate: '',
    endTime: '',
    signupCount: 0,
    status: '',
    content: '',
  }
  aboutToAppear(): void {
    interface Params {
      id: string
    }
    const params: Params = router.getParams() as Params
    this.hotTrainingId = params.id
    this.getDetail()
  }
 
  getDetail() {
    let httpRequest = http.createHttp();
    httpRequest.request(
      `${DOMAIN}/quiz-community/public/v1.0/home/hotTraining/details?hotTrainingId=${this.hotTrainingId}`,
      {
        method: http.RequestMethod.GET,
        header: { 'Content-Type': 'application/json', 'x-jwt-token': `Bearer ${AppStorage.get('x-jwt-token')}` },
      },
      (err, data) => {
        console.log('response', '/home/hotTraining/details')
        console.log(JSON.stringify(data.result))
        if (data.responseCode == 200) {
          const resData = (typeof data.result == 'string' ? JSON.parse(data.result) : data.result) as HttpResponseResult<Activity>
          if (resData.code == 200) {
            this.activeInfo = resData.data as Activity
          } else {
            promptAction.showToast({ message: resData.msg })
          }
        }
      }
    )
  }
 
  getTagFontColor(statusText: string) {
    switch (statusText) {
      case 'signup':
        return '#10920e'
      case 'training':
        return '#ffa100'
      default :
        return '#666666'
    }
  }
 
  getTagBgColor(status: string) {
    switch (status) {
      case 'signup':
        return '#d5f2db'
      case 'training':
        return '#fff0cc'
      default :
        return '#ebebeb'
    }
  }
 
  getStatusText(status: string) {
    if (status == 'signup') {
      return '报名中'
    } else if (status == 'training') {
      return '进行中'
    } else if (status == 'finished') {
      return '已结束'
    }
    return ''
  }
 
  build() {
    Column() {
      Row() {
        Image($r('app.media.left_icon'))
          .width(20)
          .height(20)
          .onClick(() => {
            router.back()
          })
        Text('详情页')
          .fontSize(18)
          .fontWeight(700)
        Row()
      }
      .width('100%')
      .padding(10)
      .justifyContent(FlexAlign.SpaceBetween)
 
      Image($r('app.media.image1'))
        .width('100%')
        .height(150)
 
      Column({ space: 14 }) {
        Text(this.activeInfo.name)
          .fontWeight(800)
          .width('100%')
 
        Row({ space: 10 }) {
          Text(this.getStatusText(this.activeInfo.status))
            .fontSize(10)
            .fontWeight(500)
            .padding({ left: 4, right: 4, top: 2, bottom: 2 })
            .borderRadius(10)
            .fontColor(this.getTagFontColor(this.activeInfo.status))
            .backgroundColor(this.getTagBgColor(this.activeInfo.status))
          Row() {
            Image($r('app.media.date_icon'))
              .width(12)
              .height(12)
            Text(`${this.activeInfo.startDate}-${this.activeInfo.endTime}`)
              .fontSize(10)
              .fontColor('#676767')
              .margin({ left: 4 })
          }
          Text(`${this.activeInfo.signupCount}人已报名`)
            .fontSize(10)
            .fontColor('#676767')
        }
        .width('100%')
        .justifyContent(FlexAlign.Start)
 
        LvMarkdownIn({ text: this.activeInfo.content })
          .width('100%')
          .height(560)
          .padding({ left: 10, right: 10 })
      }
      .padding(14)
    }
    .width('100%')
    .height('100%')
  }
}