password.js
8.11 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
/**
* Created by DEV005 on 2017/10/27.
*/
/**
* Created by tdzl2003 on 12/18/16.
*/
import React, {Component, PropTypes} from 'react';
import {
StyleSheet,
Image,
TouchableOpacity,
TouchableHighlight,
ScrollView,
Button,
TextInput,
Text,
View,
Alert,
NativeModules,
ListView,
RefreshControl,
DeviceEventEmitter,
AsyncStorage
} from 'react-native';
import MD5 from "md5"
import {xnToast} from "./../utils/utils";
import {xnAlert} from "./../utils/utils";
import AppService from "./../service/AppService";
import mainCss from "./../css/css";
import Verification from "./publish/verification";
import Password from "./publish/password";
import Loading from '../components/Loading'
export default class password extends Component {
static navigationOptions = ({ navigation, screenProps })=>({
title: '输入交易密码',
headerLeft:(<View style={{flexDirection: 'row',flex: 1}}>
<TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingLeft:10}} onPress={navigation.state.params?navigation.state.params._close:null}>
<Image style={{ width:20,height:20}} source={require('../img/back.png')} resizeMode="contain"/>
</TouchableOpacity>
</View>)
});
constructor(props){
super(props);
this.state = {
title:"",
isVerification:true,
isLoading:false,
};
/* AsyncStorage.setItem("transitNumber","0", function (errs) {
xnToast("验证通过!");
});*/
}
componentWillMount(){
let _this=this;
//设置头部
this.props.navigation.setParams({
_goBack:()=>{
this.props.navigation.goBack();
},
_close:()=>{
NativeModules.system.navTo("BACK")
}
});
//获取列表
_this._init();
}
_init=()=>{
let _this=this;
let vm={
userId:global.userId
};
AppService.transactionPasswordExist(vm).then(data=>{
console.log(data);
this.setState({
isLoading:false
});
if (data.errors == null || data.errors.length > 0) {
xnToast(data.errors[0].message);
return
}
if(!data.verifyResult){
Alert.alert(
'',
"你未设置过交易密码,请您设置6位数交易密码",
[
{text: '取消', onPress: () =>{
NativeModules.system.navTo("BACK")
}},
{text: '确定', onPress: () =>{
_this.props.navigation.navigate("Setting",{callBack:_this.callBackBarcode});
}},
]
);
}
});
AsyncStorage.getItem("transitNumber", function (errs, result) {
console.warn('读取');
console.warn(result);
if (!errs) {
if(result==null){
AsyncStorage.setItem("transitNumber","0", function (errs) {
});
}else{
if(Number(result)>2){
_this.setState({
isVerification:false
})
}
}
}
});
};
callBackBarcode=()=>{
let _this=this;
AsyncStorage.setItem("transitNumber","0", function (errs) {
_this._init();
});
};
//跳转
toForget=()=>{
this.props.navigation.navigate("Forget",{callBack:this.callBackBarcode});
};
_password=(password)=>{
console.log(password);
let _this=this;
let vm={
transactionPassword: MD5(password),
userId: global.userId
};
this.setState({
isLoading:true
});
AppService.transactionPasswordVerify(vm).then(data=>{
console.log(data)
this.setState({
isLoading:false
});
if(data.verifyResult){
AsyncStorage.setItem("transitNumber","0", function (errs) {
NativeModules.system.openRnApp(global.module, global.location)
});
}else {
AsyncStorage.getItem("transitNumber",function (errs, result) {
if (!errs) {
console.warn(result);
var resultNew=Number(result)+1;
AsyncStorage.setItem("transitNumber",resultNew+"", function (errs) {
});
DeviceEventEmitter.emit("initPassword","blur");
switch (Number(resultNew)){
case 1:
Alert.alert(
'',
"交易密码不正确,您还可以输入2次",
[
{text: '忘记密码', onPress: () =>{
_this.toForget();
}},
{text: '重新输入', onPress: () =>{
}},
]
);
break;
case 2:
Alert.alert(
'',
"交易密码不正确,您还可以输入1次",
[
{text: '忘记密码', onPress: () =>{
_this.toForget();
}},
{text: '重新输入', onPress: () =>{
DeviceEventEmitter.emit("initPassword","blur");
}},
]
);
break;
case 3:
default:
Alert.alert(
'',
"交易密码输入3次错误",
[
{text: '取消', onPress: () =>{
_this.setState({
isVerification:false
})
}},
{text: '找回密码', onPress: () =>{
_this.toForget();
}},
]
);
break;
};
}
});
}
});
};
//跳转
verification=(status)=>{
console.log(status);
let _this=this;
if(status){
_this.setState({
isVerification:true,
});
AsyncStorage.setItem("transitNumber","0", function (errs) {
});
// DeviceEventEmitter.emit("initPassword","q");
}
};
render() {
return (
<View style={mainCss.body}>
<View style={mainCss.main}>
{!this.state.isVerification&&<Verification toForget={this.toForget} callBack={this.verification}></Verification>}
{this.state.isVerification&&<Password title={this.state.title} toForget={this.toForget} callBack={this._password} ></Password>}
</View>
<Loading visible={this.state.isLoading} content="验证中" ></Loading>
</View>
);
};
}