SearchPersonal.js
14.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
import React, {Component} from "react";
import {DeviceEventEmitter, FlatList, Image, StyleSheet, Text, TouchableOpacity, View} from "react-native";
import {width, zoomH, zoomW} from "../../utils/getSize";
import CustomInput from "../../widget/CustomInput";
import {xnToast,NoDoublePress,getHomeColor} from "../../utils/utils";
import AppService from "../../service/AppService";
const defaultIcon = require("../../img/defaultIcon.png");
export default class SearchPersonal extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
queryCount: 0,
isInvite: false
};
}
attention = (id)=> {
const _this = this;
let params = {
forumId: global.forumId,
targetUserId: id,
attentionUserId: global.userId,
targetType: 1,
isActive: true
};
if (global.isConnected) {
AppService.attention(params).then((data)=> {
this.setState({
loading: false
});
if (data.message) {
xnToast(data.message);
return;
}
if (!!data.errors === true && !!data.errors.length > 0) {
xnToast(data.errors[0].message);
} else {
xnToast('已关注');
this.setState({
data: []
});
this.getList();
DeviceEventEmitter.emit('refreshHomeHistory');
DeviceEventEmitter.emit('refreshCollectList');
DeviceEventEmitter.emit('refreshAttention');
DeviceEventEmitter.emit('refreshHomeList');
DeviceEventEmitter.emit("refreshAllList");
DeviceEventEmitter.emit('reGetThreadDetailInfo');
}
})
} else {
this.setState({
loading: false
});
xnToast('请检查网络');
}
};
cancelAttention = (id)=> {
// console.logic(id);
console.log(id)
const _this = this;
let params = {
id: id
};
if (global.isConnected) {
AppService.cancleAttention(params).then((data) => {
_this.setState({
loading: false
});
if (data.message) {
xnToast(data.message);
return;
}
if (!!data.errors === true && !!data.errors.length > 0) {
xnToast(data.errors[0].message);
} else {
xnToast('取消关注');
_this.setState({
data: []
});
this.getList();
DeviceEventEmitter.emit('refreshHomeHistory');
DeviceEventEmitter.emit('refreshCollectList');
DeviceEventEmitter.emit('refreshAttention');
DeviceEventEmitter.emit('refreshHomeList');
DeviceEventEmitter.emit("refreshAllList");
DeviceEventEmitter.emit('reGetThreadDetailInfo');
}
})
} else {
xnToast('请检查网络');
}
};
// 调用接口数据
componentWillMount() {
this.getList();
}
componentDidMount() {
}
// 获取关注的人的列表
getList() {
if (!global.isConnected) {
xnToast("暂无网络连接,请稍后重试");
return;
}
let params = {
name:this.props.triData,
includeOwner:false,
pageSize:0
};
AppService.queryUser(params)
.then(data => {
this.dataHandle(data);
})
.catch(error => {
xnToast(error);
});
}
// 查询关注的用户 根据用户名
queryUserByName(name) {
if (!!!name) {
xnToast("输入为空");
return;
}
let params = {
name: name,
isActive: true
};
AppService.queryUser(params)
.then(data => {
this.queryUserDataHandle(data);
this.setState({
queryCount: 0
});
})
.catch(error => {
xnToast(error);
});
}
// 邀请用户回答
inviteUer(userId) {
if (!!!userId) {
xnToast("邀请失败,ID不存在");
return;
}
let params = {
userId: userId
};
AppService.inviteComment(params)
.then(data => {
if (data.firstErrorMessage == "") {
this.setState({
isInvite: true
});
return;
}
xnToast(data.firstErrorMessage);
})
.catch(error => {
xnToast(error);
});
}
/**
* 接口数据处理
* @param {*} data
*/
dataHandle(data) {
if (!!!data) {
// xnToast("暂无数据!!!");
return;
}
let resultStr = data.result;
let resultArr = [];
for (let i = 0; i < resultStr.length; i++) {
let item = {
headUrl: null,
userName: "",
userDesc: "",
tenantId: "",
userId: "",
isAttend: false,
attentionid:0
};
item.headUrl = resultStr[i].headFileUrl;
item.userName = resultStr[i].name;
item.userDesc = resultStr[i].description;
item.tenantId = resultStr[i].tenantId;
item.userId = resultStr[i].id;
item.isAttend = resultStr[i].hasBeenAttended;
if (resultStr[i].attention) {
item.attentionid = resultStr[i].attention.id;
}
resultArr.push(item);
}
this.setState({
data: resultArr
});
}
queryUserDataHandle(data) {
if (!!!data) {
// xnToast("暂无数据!!!");
return;
}
let resultStr = data.result;
let resultArr = [];
for (let i = 0; i < resultStr.length; i++) {
let item = {
headUrl: "",
userName: "",
userDesc: "",
tenantId: "",
userId: ""
};
item.url = resultStr[i].headFileUrl;
item.userName = resultStr[i].name;
item.userDesc = resultStr[i].description;
item.tenantId = resultStr[i].tenantId;
item.userId = resultStr[i].id;
resultArr.push(item);
}
this.setState({
data: resultArr
});
}
//渲染item
keyExtractor = (item, index) => index;
renderItem({ item, index }) {
return (
<View>
<TouchableOpacity
onPress={() => {
NoDoublePress.onPress(()=>{
this.props.navigation.navigate('PersonalHomePage',{ 'userId': item.userId});
})
}}
style={styles.itemBackground}
>
{/*头像部分*/}
<View style={styles.headerPhotoViewStyle}>
{!item.headUrl ? (
<Image
style={styles.headerPhotoStyle}
source={defaultIcon}
resizeMode="cover"
/>
) : (
<Image
style={styles.headerPhotoStyle}
source={{
uri: item.headUrl,
cache: "force-cache"
}}
resizeMode="cover"
/>
)}
</View>
{/*文字部分*/}
<View style={styles.itemTextViewStyle}>
<Text numberOfLines={1} style={styles.itemTextNameStyle}>
{item.userName}
</Text>
<Text numberOfLines={5} style={styles.itemTextContentStyle}>
{item.userDesc}
</Text>
</View>
{/*申请按钮部分*/}
<View style={styles.inviteBtnViewStyle}>
<TouchableOpacity
style={[styles.invitedBtnStyle, { backgroundColor: item.isAttend ? '#E9E9E9' : global.homeColor }]}
onPress={() => {
if (item.isAttend) {
this.cancelAttention(item.attentionid);
}else {
this.attention(item.userId);
}
}}
>
<Text style={{ fontSize: 14, color: item.isAttend ? 'rgba(0,0,0,0.45)' : '#fff' }}>
{item.isAttend ? "已关注" : "关注"}
</Text>
</TouchableOpacity>
</View>
</TouchableOpacity>
</View>
);
}
renderHeaderView() {
return (
<View style={styles.headerViewStyle}>
<CustomInput
style={styles.inputStyle}
ref={c => (this.input = c)}
placeholder={"输入搜索关键字"}
placeholderTextColor={"#999999"}
onFocus={() => {
this.setState({
data: []
});
}}
onSubmitEditing={event => {
if (this.state.queryCount == 0) {
this.queryUserByName(event.nativeEvent.text);
this.setState({
queryCount: 1
});
}
}}
onTextEmpty={() => {
this.getList();
}}
onButtonClick={() => {
//根据需要自己控制
this.input.clearInputValue();
this.getList();
}}
/>
</View>
);
}
render() {
return (
<View style={styles.background}>
{this.state.data && (
<FlatList
style={{ flex: 1, display: "flex" }}
refreshing={false}
keyExtractor={this.keyExtractor}
data={this.state.data}
renderItem={this.renderItem.bind(this)}
showsVerticalScrollIndicator={false}
/>
)}
</View>
);
}
}
const styles = StyleSheet.create({
background: {
flex: 1,
flexDirection: "column",
backgroundColor: "#fff"
},
headerViewStyle: {
flexDirection: "row",
height: width * 0.14,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#f3f5f6"
},
inputStyle: {
fontSize: 14,
color: "#878787",
width: width - 54, //给TextInput设置宽度,根据需要来
height: width * 0.1,
backgroundColor: "#fff",
paddingLeft: 30,
paddingTop: 11,
borderTopLeftRadius: 8,
borderBottomLeftRadius: 8,
marginTop: 6,
marginBottom: 6,
marginLeft: 15
},
itemBackground: {
backgroundColor: "#fff",
padding: 15 / zoomH,
flexDirection: "row",
alignItems: "center"
},
headerPhotoViewStyle: {
width: 35 / zoomH,
height: 31 / zoomH
},
headerPhotoStyle: {
width: 44 / zoomH,
height: 44 / zoomH,
borderRadius : 22 / zoomH
},
topSearchView: {
flex: 1,
width: "100%",
height: 40 / zoomH,
backgroundColor: "#FFFFFF",
borderRadius: 2,
marginLeft: 15 / zoomW,
marginRight: 15 / zoomW
},
tabStyle: {
height: 34 / zoomH,
backgroundColor: "#fff",
elevation: 0,
borderWidth: StyleSheet.hairlineWidth
},
starItem: {
flex: 1,
justifyContent: "flex-start",
flexDirection: "row"
},
forwardingBg: {
borderWidth: 1,
borderColor: "#eeeeee"
},
itemTextViewStyle: {
flexDirection: "column",
marginTop:18,
marginLeft: 15,
justifyContent: "center"
},
itemTextNameStyle: {
fontSize: 16,
color: "#000",
opacity: 0.85,
fontWeight: "bold"
},
itemTextContentStyle: {
marginTop:5,
fontSize: 12,
width: width * 0.52,
color: "#000",
opacity: 0.65
},
inviteBtnViewStyle: {
flex: 1,
flexDirection: "row",
justifyContent: "flex-end"
},
inviteBtnStyle: {
paddingLeft: 15,
paddingRight: 15,
paddingTop: 5,
paddingBottom: 5,
borderRadius: 2,
backgroundColor: "white"
},
invitedBtnStyle: {
width: 70 / zoomW,
height: 30,
borderRadius: 4,
justifyContent: 'center',
alignItems: 'center'
},
inviteBtnTextStyle: {
color: "#333333",
fontSize: 14
},
invitedBtnTextStyle: {
color: "#000",
fontSize: 14,
opacity: 0.25
}
});