AddList.js
6.02 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
import React from 'react'
import {
View,
Text,
Image,
StyleSheet,
TouchableOpacity,
TouchableWithoutFeedback,
TextInput,
ScrollView, Alert,
} from 'react-native'
import {observer} from 'mobx-react/native'
import BackButton ,{AndroidView}from '../components/BackButton'
import {line} from "./Write";
// import {WorkerItem} from "./AddWorkers";
import {ownerUserId,ownerUserName} from "../service/rpc";
import addListLogic from '../logic/addListLogic'
import Toast from "react-native-simple-toast";
import {delList} from "../logic/delLogic";
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#f3f3f3",
},
content: {
backgroundColor: 'white'
},
item: {
borderBottomWidth: line,
borderBottomColor: "#eeeeee",
alignItems: 'center',
flexDirection: 'row',
height: 50,
paddingLeft: 15,
backgroundColor: "white",
},
input: {
flex: 1,
fontSize: 16,
},
icon: {
height: 20,
width: 20,
marginRight: 15,
},
addView: {
height: 58,
flexDirection: 'row',
alignItems: 'center',
paddingLeft: 15,
backgroundColor: "white",
},
icon1: {
height: 12,
width: 12,
},
nameBg: {
height: 30,
width: 30,
borderRadius: 4,
backgroundColor: "#2c8fff",
alignItems: 'center',
justifyContent: 'center',
overflow: 'hidden',
marginRight: 13.5
},
nameBgText: {
fontSize: 20,
color: 'white',
},
name: {
fontSize: 16,
flex: 1,
},
buttonText:{
color:'white',
paddingRight:15,
fontSize:15,
fontWeight:"600"
},
delView:{
alignSelf:'stretch',
width:60,
justifyContent:'center',
alignItems:"flex-end",
paddingRight: 15
},
delButton:{
height:44,
alignItems:'center',
justifyContent:'center',
backgroundColor:"white",
marginTop:27
},
delButtonText:{
fontSize:16,
color:"#ed5b51"
}
})
@observer
export class WorkerItem extends React.Component {
render() {
const {data, remove,choose,onChange,close} = this.props
const {name, userId,userName} = data
const icon=choose?require("./imgs/selectActive.png"):require("./imgs/select.png")
return (
<TouchableOpacity style={[styles.item,]} onPress={()=>onChange&&onChange()}>
{onChange&&<Image style={styles.icon} source={icon} resizeMode={"contain"}/>}
<View style={styles.nameBg}>
<Text style={styles.nameBgText}>{name?name[0]:userName[0]}</Text>
</View>
<Text style={styles.name}>{name||userName}</Text>
{close||!onChange&&<TouchableOpacity onPress={() => remove()} style={styles.delView}>
<Image style={styles.icon1} source={require("./imgs/del.png")} resizeMode={"contain"}/>
</TouchableOpacity>}
</TouchableOpacity>
)
}
}
@observer
export default class AddList extends React.Component {
logic = new addListLogic()
static navigationOptions = ({navigation}) => {
return {
headerLeft: <BackButton navigation={navigation}/>,
headerTitle: navigation.state.params.title ,
headerRight:<Text style={styles.buttonText} onPress={()=>navigation.state.params.onPress()}>确定</Text>
}
}
onPress = () => {
const {navigation} = this.props
navigation.navigate("UserList", {callback: this.callback,userList:this.logic.userList})
}
callback = (v) => {
console.log(v)
this.logic.userList.replace(v.map(z=>{return {username:z.name||z.userName,userName:z.name||z.userName,...z}}))
const {navigation} = this.props
// navigation.goBack()
}
async componentWillMount() {
const {state,setParams}=this.props.navigation
console.log(state)
const {params} = state
if (params && params.taskListId) {
await this.logic.getTaskList(params.taskListId)
setParams({onPress:async ()=>{
if(this.logic.text.length===0){
Toast.show("请输入内容")
return
}
if(this.notouch){
return
}
this.notouch=true
await this.logic.edit({id:params.taskListId,objectType:params.objectType});
this.props.navigation.goBack()
}})
return
}
this.logic.userList.push({userId:ownerUserId,userName:ownerUserName})
this.logic.ownerUserId=ownerUserId
setParams({onPress:async ()=>{
if(this.logic.text.length===0){
Toast.show("请输入内容")
return
}
if(this.notouch){
return
}
this.notouch=true
const id=await this.logic.create();
if(id){
const {navigate,state}=this.props.navigation
navigate("TaskList",{listId:id,title:this.logic.text,objectType:"MANUAL",backKey:state.key})
}
}})
}
componentWillUnmount(){
this.notouch=false
}
del(){
const {state,setParams}=this.props.navigation
const {params} = state
Alert.alert("注意","确认要删除吗?",[
{text:"取消",onPress:()=>{}},
{text:"确认",onPress:async()=>{
const data=await delList(params.taskListId)
if(data){
this.props.navigation.goBack(params.backKey)
}
}},
])
}
render() {
const {state,setParams}=this.props.navigation
const {params} = state
return (
<View style={styles.container}>
<ScrollView>
<View style={styles.item}>
<Image source={require("./imgs/menu.png")} style={styles.icon} resizeMode={"contain"}/>
<TextInput
value={this.logic.text}
style={styles.input}
onChangeText={v => this.logic.text = v}
placeholder={"名称"}
underlineColorAndroid={"transparent"}
autoFocus={true}
returnKeyType={"done"}
/>
</View>
<View style={styles.content}>
{this.logic.userList.map((v, i) => <WorkerItem key={i} data={v}
remove={() => this.logic.userList.remove(v)}
close={v.userId===this.logic.ownerUserId}
/>)}
</View>
<TouchableOpacity style={styles.addView} onPress={this.onPress}>
<Image source={require("./imgs/add5.png")} style={styles.icon} resizeMode={"contain"}/>
<Text style={[styles.input, {color: "#999999"}]}>添加成员</Text>
</TouchableOpacity>
{params && params.taskListId&&<TouchableOpacity style={styles.delButton} onPress={()=>this.del()}>
<Text style={styles.delButtonText}>删除清单</Text>
</TouchableOpacity>}
</ScrollView>
</View>
)
}
}