WfQuickCommentView.js
18.7 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
import React, {Component} from 'react';
import {
View,
Text,
TextInput,
TouchableOpacity, FlatList
} from 'react-native';
import AppService from "../service/AppService";
import {xnToast} from "../utils/utils";
import {NoDoublePress} from "../utils/Common";
import OrderFlatList from 'react-native-order-flat-list'
import {width} from "../utils/getSize";
import {SwipeRow} from "react-native-swipe-list-view";
const defaultHeight = (62);
const titleViewHeight = (24);
const HPading = (16);
const VPading = (6);
export default class WfQuickCommentView extends Component {
//自定义属性类型申明(暂时注掉,RN版本会出现propTypes报错的问题)
// static propTypes = {
// category:React.PropTypes.string,// approve:同意 reject:拒绝
// chooseCallback:React.PropTypes.func,// 选择审批意见后的回调
// userId:React.PropTypes.string, // 用户id
// }
constructor(props) {
super(props);
this.maxCount = 10;// 最多允许10条审批意见
this.userId = !!this.props.userId?this.props.userId:'';
this.category = !!this.props.category?this.props.category:'approve';
this.chooseCallback = !!this.props.chooseCallback?this.props.chooseCallback:null;
this.state = {
category:!!this.props.category?this.props.category:'approve',
mode:'choose',// 模式 choose:选择模式 edit:编辑模式 add:新增模式 sort:排序模式
originData:{}, // 查询到的常用审批意见
currentItem:[],// 当前处理的数据
tempSortData:{},// 排序数组,目前的逻辑是先排序,最后一把保存
}
this.swipeRowIndex = '';// 侧滑下标,用于卡控同一时间只允许一个侧滑打开以及关闭侧滑
}
componentDidMount() {
this._query(this.userId);
}
_query(userId){
let _this = this;
let vm = {
userId: userId,
pageSize:this.maxCount,
pageNum:0,
};
AppService.findWfComment(vm).then(data => {
_this.setState({
mode:'choose'
},()=>{
if (data.message) {
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
return;
}
console.log(data);
_this.setState({
originData: data.result,
})
})
});
}
_update(id,text,rowVersion,userId){
let _this = this;
let vm = {
id: id,
text: text,
rowVersion:rowVersion
};
AppService.updateWfComment(vm).then(data => {
if (data.message) {
_this.setState({
mode:'choose'
})
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
_this.setState({
mode:'choose'
})
xnToast(data.errors[0].message);
return;
}
console.log(data);
_this._query(userId);
});
}
_delete(id,userId){
let _this = this;
let vm = {
id: id
};
AppService.deleteWfComment(vm).then(data => {
if (data.message) {
_this.setState({
mode:'choose'
})
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
_this.setState({
mode:'choose'
})
xnToast(data.errors[0].message);
return;
}
console.log(data);
_this._query(userId);
});
}
_add(text,userId){
let _this = this;
let vm = {
text:text
};
AppService.createWfComment(vm).then(data => {
if (data.message) {
_this.setState({
mode:'choose'
})
xnToast(data.message);
return;
}
if (data.errors.length > 0) {
_this.setState({
mode:'choose'
})
xnToast(data.errors[0].message);
return;
}
console.log(data);
_this._query(userId);
});
}
_sort(ids,userId){
let _this = this;
let vm = {
ids:ids
};
AppService.sortWfComment(vm).then(data => {
if (data.message) {
xnToast(data.message);
this.setState({
mode:'choose',
})
return;
}
if (data.errors.length > 0) {
xnToast(data.errors[0].message);
this.setState({
mode:'choose',
})
return;
}
console.log(data);
_this._query(userId);
});
}
keyExtractor = (item, index) => index;
renderItem({item,index}){
let _this = this;
const ref = 'SwipeRow' + index;
if(this.state.mode == 'edit' && this.state.currentItem.id == item.id){
return (
<View style={{width:'100%',height:120,marginVertical:10,
paddingHorizontal:16,flexDirection:'row',justifyContent:'flex-start',alignItems:'center',backgroundColor:'#fff'
}}>
<TextInput
style={{fontSize: 16,
color: 'black',
flex:1,
backgroundColor: '#f5f5f5',
textAlign: 'left',
marginTop:4,
marginBottom:4,
padding:4,
height:120,
borderRadius:4,
}}
minLength={0}
maxLength={100}
numberOfLines={6}
multiline={true}
onChangeText={(text) => {
let temp = this.state.currentItem;
temp.text = text;
this.setState({
currentItem:temp,
})
}}
value={this.state.currentItem.text||''}
placeholderTextColor={'#999'}
placeholder={'0-100字'}
underlineColorAndroid="transparent"
/>
<TouchableOpacity activeOpacity={1} style={{width:40,marginLeft:10}} onPress={()=>NoDoublePress.onPress(()=>{
if(!!!this.state.currentItem.text || this.state.currentItem.text.length == 0){
xnToast('请填写内容');
this.setState({
mode:'choose',
})
return;
}
this._update(this.state.currentItem.id,this.state.currentItem.text,this.state.currentItem.rowVersion,this.userId);
})}>
<Text numberOfLines={1} style={{fontSize:16,color:"#3399ff",marginRight:0}}>{'保存'}</Text>
</TouchableOpacity>
</View>
)
}else{
return (
<SwipeRow
// closeOnRowPress={true}
key={ref}
ref={(swipeRow) => {
this[ref] = swipeRow;
}}
leftOpenValue={138}
rightOpenValue={-138}
stopRightSwipe={-138}
disableRightSwipe={true} //禁止向右滑动
onRowOpen={(rowData, rowMap) =>{
// 打开侧滑
if (this.swipeRowIndex !== 'SwipeRow'+index && this.swipeRowIndex !== '') {
this[this.swipeRowIndex].closeRow();
this.swipeRowIndex = '';
}
this.swipeRowIndex = 'SwipeRow'+index;
}}
>
<View style={{width: 138, height: 48, alignItems: 'center', flexDirection: 'row', position: 'absolute', right: 0}}>
<TouchableOpacity
style={{width: 69, height: 48, backgroundColor: 'rgba(255, 141, 26, 1)', justifyContent: 'center', alignItems: 'center'}}
activeOpacity={0.8}
onPress={() =>NoDoublePress.onPress(()=>{
if (this.swipeRowIndex !== '') {
this[this.swipeRowIndex].closeRow();
this.swipeRowIndex = '';
}
this.setState({
mode: 'edit',
currentItem:item,
});
})}
>
<Text style={{fontSize: 14, color: 'rgba(255, 255, 255, 1)'}} allowFontScaling={false}>编辑</Text>
</TouchableOpacity>
<TouchableOpacity
style={{width: 69, height: 48, backgroundColor: 'rgba(212, 48, 48, 1)', justifyContent: 'center', alignItems: 'center'}}
activeOpacity={0.8}
onPress={() => NoDoublePress.onPress(()=>{
if (this.swipeRowIndex !== '') {
this[this.swipeRowIndex].closeRow();
this.swipeRowIndex = '';
}
this._delete(item.id)
})}
>
<Text style={{fontSize: 14, color: 'rgba(255, 255, 255, 1)'}} allowFontScaling={false}>删除</Text>
</TouchableOpacity>
</View>
<TouchableOpacity
style={{flex:1,backgroundColor:'#fff'}}
activeOpacity={1}
onPress={()=>{
if(this.state.mode != 'choose'){
if (this.swipeRowIndex !== '') {
this[this.swipeRowIndex].closeRow();
this.swipeRowIndex = '';
}
this.setState({
mode:'choose'
})
}else{
if(!!this.chooseCallback){
this.chooseCallback(item.text||'');
}
}
}}
>
<View style={{minHeight: 48,maxHeight:120, flexDirection: 'row', alignItems: 'center', paddingHorizontal: 20, backgroundColor: 'white'}}>
<Text style={{flex: 1, fontSize: 14, color: 'rgba(0, 0, 0 , 1)', marginLeft: 10}}>{item.text||''}</Text>
</View>
</TouchableOpacity>
</SwipeRow>
)
}
}
render() {
let count = this.state.originData.length||0;
let str = '已添加常用审批意见(' + count + '/' + this.maxCount + ')'
return (
<View style={{flex:1, backgroundColor: '#fff', paddingTop: VPading,paddingHorizontal:0,height:defaultHeight}}>
{this.state.mode != 'add' &&<TouchableOpacity activeOpacity={1} style={{width:'100%',height:54,paddingVertical:10,
paddingHorizontal:16,flexDirection:'row',justifyContent:'flex-start',alignItems:'center',backgroundColor:'#fff'
}} onPress={()=>NoDoublePress.onPress(()=>{
if(count == this.maxCount){
xnToast('最多添加'+ count + '条审批意见');
}else{
this.setState({
mode:'add',
currentItem:[]
})
}
})}>
<Text style={{fontSize:16,color:'#999',flex:1}}>{'+ 常用审批意见'}</Text>
</TouchableOpacity>}
{this.state.mode == 'add' &&<View style={{width:'100%',height:120,paddingVertical:10,
paddingHorizontal:16,flexDirection:'row',justifyContent:'flex-start',alignItems:'center',backgroundColor:'#fff'
}}>
<TextInput
style={{fontSize: 16,
color: 'black',
flex:1,
backgroundColor: '#fff',
textAlign: 'left',
marginTop:4,
marginBottom:4,
padding:0,
height:120
}}
minLength={0}
maxLength={100}
numberOfLines={6}
multiline={true}
onChangeText={(text) => {
let temp = this.state.currentItem;
temp.text = text
this.setState({
currentItem:temp,
})
}}
placeholderTextColor={'#999'}
placeholder={'0-100字'}
underlineColorAndroid="transparent"
/>
<TouchableOpacity activeOpacity={1} style={{width:40,marginLeft:10}} onPress={()=>NoDoublePress.onPress(()=>{
if(this.state.mode == 'add'){
if(!!!this.state.currentItem.text || this.state.currentItem.text.length == 0){
xnToast('请填写内容');
this.setState({
mode:'choose',
})
return;
}
this._add(this.state.currentItem.text,this.userId);
}else{
if (this.swipeRowIndex !== '') {
this[this.swipeRowIndex].closeRow();
this.swipeRowIndex = '';
}
this.setState({
mode:'choose',
})
}
})}>
<Text numberOfLines={1} style={{fontSize:16,color:"#3399ff",marginRight:0}}>{'添加'}</Text>
</TouchableOpacity>
</View>}
<View style={{width:'100%',backgroundColor:'#f5f5f5',height:44,flexDirection:'row',justifyContent:'flex-start',alignItems:'center'}}>
<Text style={{color:'#666',fontSize:12,flex:1,marginLeft:HPading}}>{str}</Text>
<TouchableOpacity style={{width:44,height:'100%',justifyContent:'center',alignItems:'center',marginRight:HPading}}
activeOpacity={1} onPress={()=>NoDoublePress.onPress(()=>{
let mode = this.state.mode
if(mode != 'sort'){
let data = this.state.originData;
// 切换到排序模式
this.setState({
mode:'sort',
tempSortData:data,
})
}else{
let ids = [];
this.state.tempSortData.map((k,v)=>{
ids.push(k.id);
});
this.setState({
mode:'choose',
originData :this.state.tempSortData,
})
// this._sort(ids,this.userId);
}
})}>
<Text style={{fontSize:16,color:"#3399ff"}}>{this.state.mode == 'sort'?'完成':'排序'}</Text>
</TouchableOpacity>
</View>
{
this.state.mode == 'sort' &&
<OrderFlatList
itemHeight={44}
ref={(flatList) => this._flatList = flatList}
style={{flex:1,backgroundColor:'#fff'}}
scrollEnabled={false}
onOrder={(orderKeys)=>{
console.log(orderKeys);
this.setState({
tempSortData:orderKeys.list,
})
}}
isOrder={true}
data={this.state.tempSortData}
renderItem={this.renderItem.bind(this)}
keyExtractor={this.keyExtractor}
extraData={this.state}
showsVerticalScrollIndicator={false}
ItemSeparatorComponent={()=><View style={{width:'100%',height:1,backgroundColor:'#fff'}} >
<View style={{marginLeft:30,width:width-30,height:1,backgroundColor:'#eee'}}/>
</View>}
/>
}
{this.state.mode != 'sort' &&<FlatList
ref={(flatList) => this._flatList = flatList}
style={{flex:1,backgroundColor:'#fff'}}
data={this.state.originData}
renderItem={this.renderItem.bind(this)}
keyExtractor={this.keyExtractor}
extraData={this.state}
showsVerticalScrollIndicator={false}
ItemSeparatorComponent={()=><View style={{width:width,height:1,backgroundColor:'#fff'}} >
<View style={{marginLeft:30,width:width-30,height:1,backgroundColor:'#eee'}}/>
</View>}
/>}
</View>
);
}
}