ReplyPopWin.js
5.9 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
import React, {Component} from 'react';
import StorageUtil from '../utils/StorageUtil';
import Utils from '../utils/Utils';
import {xnToast} from "../../utils/utils";
import AppService from "../../service/AppService";
import {Button, Dimensions, Modal, StyleSheet, TextInput, TouchableOpacity, View, NativeModules} from 'react-native';
const {width} = Dimensions.get('window');
export default class ReplyPopWin extends Component {
constructor(props) {
super(props);
this.state = {
show: false,
inputContent: '',
name: ''
};
StorageUtil.get('username', (error, object) => {
if (!error && object != null) {
this.setState({username: object.username});
}
});
}
componentDidMount() {
let input = this.refs.textInput;
if (!Utils.isEmpty(input)) {
input.focus();
}
}
componentWillMount() {
NativeModules.security.getTenantId().then((result) => {
global.tenantId = result;
}
).catch((error) => {
console.log(error)
});
}
W
render() {
//console.log("param" + this.state.param.momentUserName);
//(this.state.param.commentUserName && this.state.param.momentUserName)
let name = this.state.name;
let placeholderText = "回复" + name;
return (
<View style={styles.container}>
<Modal transparent={true}
visible={this.state.show}
onRequestClose={() => this.closeModal()}>
<TouchableOpacity onPress={() => this.closeModal()} style={styles.modalContainer}>
<View style={styles.modalContainer}>
<View style={{
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#EEEEEE',
paddingLeft: 10,
paddingRight: 10
}}>
<TextInput
style={{flex: 1}}
ref="textInput"
placeholder={placeholderText}
autoFocus={true}
onChangeText={(text) => this.setState({inputContent: text})}
/>
{
!Utils.isEmpty(this.state.inputContent) ? (
<Button color={'#49BC1C'} title={"回复"}
onPress={() => this.handleBtnClick()}/>
) : (null)
}
</View>
</View>
</TouchableOpacity>
</Modal>
</View>
);
}
handleBtnClick() {
this.sendPost();
}
sendPost() {
let momentId = this.state.momentId;
let replyContent = this.state.inputContent;
if (Utils.isEmpty(replyContent)) {
xnToast('回复内容不能为空');
return;
}
let params = {
objectId: momentId,
objectType: "MOMENT",
commentContent: replyContent,
tenantId: global.tenantId,
commentUserName: this.state.param.myName,
toCommentId: this.state.param.toCommentId
};
AppService.createComment(params).then((data) => {
if (data.message) {
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
} else {
this.closeModal();
// 刷新回复列表
let data = {
commentContent: replyContent,
objectId: momentId,
commentUserName: this.state.param.myName,
toCommentId: this.state.toCommentId,
toCommentUserName:null
}
if(this.state.toCommentId){
data.toCommentUserName = this.state.commentUserName;
}
let param = {
momentId: momentId,
momentIndex: this.state.momentIndex
}
this.refreshReply(param, data);
}
}).catch((error) => {
this.closeModal();
xnToast(error)
})
}
refreshReply(param, data) {
let callback = this.state.successCallback;
if (!Utils.isEmpty(callback)) {
callback(param, data);
}
}
closeModal() {
this.setState({show: false})
}
//momentId, commentId, momentUsername, momentIndex, commentUserName
showModal( param, successCallback) {
//console.log(momentId + "-" +commentId + "-" + momentUsername + "-" + momentIndex)
let toCommentId = param.commentId;
let name = param.commentUserName ? param.commentUserName: param.momentUserName;
if(param.commentUserId === global.unionId){
toCommentId = null;
name = param.momentUserName;
}
this.setState({
param: param,
momentId: param.momentId,
toCommentId:toCommentId,
momentUserName: param.momentUserName,
momentIndex: param.momentIndex,
commentUserName:param.commentUserName,
show : true,
name : name,
successCallback: successCallback
});
}
}
const styles = StyleSheet.create({
container: {
width: width
},
modalContainer: {
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-end'
}
});