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
import React, {useState, useEffect} from 'react';
import {
View,
Text,
StyleSheet,
Dimensions,
TouchableOpacity,
Platform,
Alert,
TouchableWithoutFeedback,
Keyboard,
KeyboardAvoidingView,
} from 'react-native';
import R from '../../../assets/R';
import HeaderBack from '../../../components/Header/HeaderBack';
import TextField from '../../../components/Input/TextField';
import TextMulti from '../../../components/Input/TextMulti';
import TextDisable from '../../../components/Input/TextDisable';
import {connect} from 'react-redux';
import {
getFontXD,
HEIGHTXD,
toPriceVnd,
checkFormatArray,
} from '../../../Config/Functions';
import PickerItem from '../../../components/Picker/PickerItem';
import RadioForm from 'react-native-simple-radio-button';
import {widthDraw, getListWidthDraw} from '../../../apis/Functions/Widthdraw';
import {useNavigation} from '@react-navigation/native';
import {showLoading, hideLoading} from '../../../actions/loadingAction';
import {confirmAlert} from '../../../components/Aleart';
import {ADDMETHODPAY} from '../../../routers/ScreenNames';
var radio_props = [
{label: 'Từ ví', value: 'WALLET'},
{label: 'Từ tài khoản CQG', value: 'INVESTMENT'},
];
const {width} = Dimensions.get('window');
const WalletWithdraw = (props) => {
const [data, setData] = useState([]);
const [src, setSrc] = useState('WALLET');
const [type, setType] = useState();
const [amount, setAmount] = useState();
const [notes, setNotes] = useState('');
const navigate = useNavigation();
useEffect(() => {
const unsubscribe = navigate.addListener('focus', () => {
getData();
});
return unsubscribe;
}, [navigate]);
const getData = async () => {
const res = await getListWidthDraw({
platform: Platform.OS,
});
if (res.data.code == 200 && res.data.data) {
if (res.data.data.length == 0) {
confirmAlert(
'Bạn chưa có phương thức thanh toán.Đi đến cài đặt phương thức thanh toán?',
() => navigate.navigate(ADDMETHODPAY),
);
} else {
const newList = res.data.data.map((e) => {
return {...e, value: e.id, name: e.method};
});
setData(newList);
}
} else {
alert('Không lấy được danh sách phương thức!');
}
};
const onPressWithdraw = async () => {
const titles = ['tài khoản hưởng thụ', 'số tiền'];
const index = checkFormatArray([type, amount]);
if (index === true) {
props.showLoading();
const res = await widthDraw({
src,
receiving_account: type.id,
amount,
platform: Platform.OS,
notes,
fee: 0,
});
props.hideLoading();
if (res.data.code == 200) {
setTimeout(() => {
Alert.alert('Thông báo!', res.data.message);
navigate.goBack();
}, 500);
} else {
setTimeout(() => {
Alert.alert('Thông báo!', res.data.message);
}, 500);
}
} else {
Alert.alert('Vui lòng điền ' + titles[index]);
}
};
return (
<KeyboardAvoidingView
behavior={Platform.Os === 'ios' ? 'padding' : 'height'}
style={{flex: 1}}
keyboardVerticalOffset={-50}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={{flex: 1}}>
<HeaderBack title={'Rút tiền'} />
<View style={styles.container}>
{/* <View style={styles.wrapTop}>
<View style={styles.itemTop}>
<Text style={styles.txtTitle}>Ví</Text>
<Text style={styles.txtMoney}>{toPriceVnd(1000000)}</Text>
</View>
<View style={{width: 1, backgroundColor: '#DBDBDB'}} />
<View style={styles.itemTop}>
<Text style={styles.txtTitle}>CQG</Text>
<Text style={styles.txtMoney}>{toPriceVnd(1000000)}</Text>
</View>
</View> */}
<View style={styles.wrapBody}>
<Text
style={{
fontSize: getFontXD(42),
color: R.colors.color777,
}}>
Tài khoản nguồn
</Text>
{/* <View style={styles.row}> */}
<RadioForm
radio_props={radio_props}
labelStyle={{fontSize: getFontXD(42)}}
formHorizontal={true}
style={styles.row}
initial={0}
onPress={(value) => {
setSrc(value);
}}
/>
{/* </View> */}
<Text
style={{
fontSize: getFontXD(42),
color: R.colors.color777,
}}>
Chọn tài khoản hưởng thụ
</Text>
<PickerItem
width={width - 20}
data={data}
onValueChange={(value, items) => {
setType(items);
}}
/>
<TextField
onChangeText={(val) => setAmount(val)}
title={'Số tiền'}
isNumber={true}
/>
<TextMulti
onChangeText={(val) => setNotes(val)}
title={'Ghi chú'}
/>
</View>
</View>
<TouchableOpacity onPress={onPressWithdraw} style={styles.btnSend}>
<Text style={styles.txtSend}>Rút tiền</Text>
</TouchableOpacity>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: R.colors.white,
marginVertical: 10,
shadowColor: '#AFA9A9',
shadowOffset: {
width: 0,
height: 1,
},
shadowOpacity: 0.25,
shadowRadius: 1.84,
elevation: 1,
},
wrapTop: {
flexDirection: 'row',
borderBottomWidth: 1,
borderBottomColor: '#DBDBDB',
},
itemTop: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingVertical: 20,
},
wrapBody: {
paddingHorizontal: 10,
paddingVertical: 20,
},
txtMoney: {
color: '#1C6AF6',
fontSize: getFontXD(52),
},
txtTitle: {
color: R.colors.black,
fontSize: getFontXD(42),
},
txtSend: {
fontSize: getFontXD(42),
color: R.colors.white,
fontWeight: 'bold',
},
btnSend: {
position: 'absolute',
bottom: 30,
right: width / 2 - 70,
width: 140,
height: 40,
backgroundColor: R.colors.main,
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
row: {
height: HEIGHTXD(109),
width: '100%',
justifyContent: 'space-between',
marginVertical: 5,
},
});
const mapStateToProps = (state) => {
return {
user: state.userReducer,
};
};
export default connect(mapStateToProps, {
showLoading,
hideLoading,
})(WalletWithdraw);