CertificateInfo.ets
7.2 KB
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
import preferencesUtil from '../utils/preferences'
import { personCertificateTest, personCertificateRow, CertificateTest, CertificateRow } from '../api/userType'
import baseUrl from '../utils/baseUrl'
import { getPersonalCertificate, getCertificateList, updatePersonalCertificate, addPersonalCertificate } from '../api/user'
import { AxiosResponse } from '@ohos/axios'
import CertificateDialog from '../dialog/CertificateDialog'
import PhotoBrowser from '../dialog/PhotoBrowserDialog'
import { uploadFile, uploadResult } from '../utils/uploadFile'
import { request } from '@kit.BasicServicesKit'
import { promptAction } from '@kit.ArkUI';
import NavHeader from '../components/NavHeader'
let personId = preferencesUtil.get('XF_PERSON_ID', 0) as number
@Entry
@Component
struct EditUser {
private selectedDate: Date = new Date()
@State personCertificateInfo: personCertificateRow = {
certificateName: '',
certificateLevel: '',
certificateNo: '',
certificateId: 1,
certificateImg: '',
issueDate: '选择日期',
memo: '无',
personId
}
@State selectValue: string = '请选择证书类型'
@State certificateData: CertificateRow[] = []
@State certificateList: string[] = []
@State isEdit: boolean = false
async aboutToAppear() {
console.log(JSON.stringify(personId))
const result: AxiosResponse<personCertificateTest> = await getPersonalCertificate({pageNum: 1, pageSize: 10, personId: Number(personId)})
const res: AxiosResponse<CertificateTest> = await getCertificateList({pageNum: 1, pageSize: 10})
this.isEdit = result.data.rows.length > 0
if(result.data.rows.length > 0 ) {
this.personCertificateInfo = result.data.rows[0]
this.selectValue = this.personCertificateInfo?.certificateLevel + this.personCertificateInfo?.certificateName
}
this.certificateData = res.data.rows
this.certificateList = res.data.rows.map((item: CertificateRow) => item.certificateLevel + item.certificateName)
this.personCertificateInfo.certificateId = this.certificateData[0].certificateId
}
dialogController: CustomDialogController = new CustomDialogController({
builder: CertificateDialog({
certificateList: this.certificateList,
selectValue: this.selectValue,
certificateData: this.certificateData,
personCertificateInfo: this.personCertificateInfo
})
})
photoBrowserController: CustomDialogController = new CustomDialogController({
builder: PhotoBrowser({ imagesList: [baseUrl + this.personCertificateInfo.certificateImg]}),
customStyle: true,
offset: { dx: 0, dy: 0 },
alignment: DialogAlignment.Top,
})
build() {
Column(){
NavHeader({ title: '证书信息'})
Column(){
Column(){
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('证书类型')
}.width(90)
Text(this.selectValue == '' ? '选择证书类型' : this.selectValue).layoutWeight(1).padding({left: 8,right: 8, top: 16, bottom: 16})
.onClick(() => {
this.dialogController.open()
})
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('证书编号')
}.width(90)
TextInput({placeholder: '请输入证书编号', text: $$this.personCertificateInfo.certificateNo})
.backgroundColor('#fff').layoutWeight(1).type(InputType.Email)
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('颁发日期')
}.width(90)
Text(this.personCertificateInfo.issueDate).padding({top: 8, bottom: 8, left: 16, right: 16})
.backgroundColor('#fff').layoutWeight(1).fontColor('#000').onClick(() => {
CalendarPickerDialog.show({
selected: this.selectedDate,
onAccept: (value) => {
this.personCertificateInfo.issueDate = JSON.stringify(value).slice(1, 11)
}
})
})
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('证书扫描件')
}.width(90)
Row({space: 20}){
Image(this.personCertificateInfo.certificateImg !== '' ? baseUrl + this.personCertificateInfo.certificateImg : $r('app.media.certificateCard')).width(120).height(120)
.onClick(async () => {
let that = this
let uploader = await uploadFile() as request.UploadTask
// 3. 监控上传错误
uploader.on('fail', (err) => {
console.log('上传错误--->', JSON.stringify(err))
})
// 4. 获取服务器返回来的数据
uploader.on('headerReceive',(res)=>{
let uploadInfo = JSON.parse(res['body']) as uploadResult
that.personCertificateInfo.certificateImg = uploadInfo.fileName
})
})
}.layoutWeight(1).margin({left: 20})
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('备注')
}.width(100)
TextArea({
text: $$this.personCertificateInfo.memo,
placeholder: '请输入内容'
}).layoutWeight(1).height(80).borderRadius(5).backgroundColor('#fff')
.border({width: 1, color: "#eee"})
}.padding({top: 10, bottom: 10})
}.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10)
}.padding(10).margin({bottom: 20, top: 10}).layoutWeight(1)
Row({ space: 10 }){
Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(async () => {
let valueArr = Object.values(this.personCertificateInfo) as (string | number)[]
if(!valueArr.every(item => item !== '')) return promptAction.showToast({message: '请填写完整信息'})
if(this.isEdit) {
await updatePersonalCertificate(this.personCertificateInfo)
promptAction.showToast({
message: '更新成功,点击刷新查看数据'
})
} else {
await addPersonalCertificate(this.personCertificateInfo)
promptAction.showToast({
message: '添加成功,点击刷新查看新数据'
})
}
})
Text('图片预览').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
.backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
.onClick(() => {
this.photoBrowserController.open()
})
}.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
}.width('100%').height('100%').backgroundColor('#f2f3f7')
}
}