binding_phone.dart
16.5 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
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/models/store_info.dart';
import 'package:one_key/provider/create_store_model.dart';
import 'package:one_key/provider/other_login_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
class BindingPhone extends StatefulWidget {
final bool wechat;
BindingPhone({Key? key, this.wechat = true}) : super(key: key);
@override
_BindingPhoneState createState() => _BindingPhoneState();
}
class _BindingPhoneState extends State<BindingPhone> {
ScrollController? _controller;
FocusNode? _phoneNode;
FocusNode? _codeNode;
//定义变量
late Timer _timer;
//倒计时数值
var countdownTime = 0;
String? phone;
String? code;
bool enabled = true; //手机号码框是否可以编辑
bool codeEnabled = false; //验证码是否可用
@override
void initState() {
super.initState();
_controller = ScrollController();
_phoneNode = FocusNode();
_codeNode = FocusNode();
}
@override
void dispose() {
super.dispose();
_timer.cancel();
}
///倒计时方法
startCountdown(OtherLoginProvider model) {
countdownTime = 300;
final call = (timer) {
setState(() {
if (countdownTime < 1) {
// model.code = null;
enabled = true;
codeEnabled = false;
_timer.cancel();
} else {
enabled = false;
codeEnabled = true;
countdownTime -= 1;
}
});
};
_timer = Timer.periodic(Duration(seconds: 1), call);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: SystemAppBar(
'',
// leftTitle: '上一步',
onTap: () {
if (Navigator.canPop(context)) {
Navigator.pop(context);
}
},
),
body: InkWell(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
},
child: Container(
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(35 * 2),
vertical: ScreenUtil().setWidth(30 * 2)),
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
controller: _controller,
child: Consumer<OtherLoginProvider>(
builder: (context, model, _) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('绑定您的手机号',
style: TextStyle(
fontWeight: FontWeight.bold,
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(40))),
VEmptyView(100),
Container(
height: ScreenUtil().setHeight(52 * 2),
// width: ScreenUtil().setWidth(611),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(20)),
margin: EdgeInsets.only(
top: ScreenUtil().setHeight(8)),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(
color: MyColours.color_bff6f7,
width: ScreenUtil().setWidth(2)),
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(10))),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
HEmptyView(30),
Text(
"手机号",
style: TextStyle(
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(26)),
),
HEmptyView(30),
Expanded(
child: TextField(
enabled: enabled,
focusNode: _phoneNode,
style: TextStyle(
color: MyColours.color_353535,
fontSize: ScreenUtil().setSp(28)),
decoration: InputDecoration(
hintText: "请输入手机号",
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(26)),
contentPadding: EdgeInsets.zero,
border: OutlineInputBorder(
borderSide: BorderSide.none),
// contentPadding: EdgeInsets.fromLTRB(
// 0,
// ScreenUtil().setWidth(28),
// ScreenUtil().setWidth(30),
// ScreenUtil().setWidth(28)),
),
onChanged: (value) {
phone = value;
},
onEditingComplete: () {
FocusScope.of(context).requestFocus(
FocusNode()); //点击空白处隐藏键盘
},
keyboardType:
TextInputType.numberWithOptions(
decimal: true),
),
)
],
)),
VEmptyView(10),
Container(
height: ScreenUtil().setHeight(52 * 2),
// width: ScreenUtil().setWidth(611),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(20)),
margin: EdgeInsets.only(
top: ScreenUtil().setHeight(8)),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(
color: MyColours.color_bff6f7,
width: ScreenUtil().setWidth(2)),
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(10))),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
HEmptyView(30),
Text(
"验证码",
style: TextStyle(
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(26)),
),
HEmptyView(30),
Expanded(
child: TextField(
focusNode: _codeNode,
style: TextStyle(
color: MyColours.color_353535,
fontSize: ScreenUtil().setSp(28)),
decoration: InputDecoration(
hintText: "请输入验证码",
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(26)),
contentPadding: EdgeInsets.zero,
border: OutlineInputBorder(
borderSide: BorderSide.none),
// contentPadding: EdgeInsets.fromLTRB(
// 0,
// ScreenUtil().setWidth(28),
// ScreenUtil().setWidth(30),
// ScreenUtil().setWidth(28)),
),
onChanged: (value) {
code = value;
},
onEditingComplete: () {
FocusScope.of(context).requestFocus(
FocusNode()); //点击空白处隐藏键盘
},
keyboardType:
TextInputType.numberWithOptions(
decimal: true),
),
),
HEmptyView(10),
RoundButton(
height: ScreenUtil().setWidth(84),
text: countdownTime > 0
? "${Utils.durationTransform(countdownTime)}后重新获取"
: "获取验证码",
radius: ScreenUtil().setWidth(10),
textColor: MyColours.color_199095,
gradientStart: MyColours.color_ffffff,
gradientEnd: MyColours.color_ffffff,
borderColor: Colors.transparent,
fontSize: 26,
isBold: false,
onPressed: () async {
if (countdownTime == 0) {
if (phone == null ||
phone!.trim().length == 0) {
Utils.showToast('请输入手机号码');
return;
}
if (!Utils.isInteger(
phone!.replaceAll(' ', ''))) {
Utils.showToast(
'您输入的手机号码格式不正确,请重新输入');
return;
}
model.code = Utils.randomBit(4);
Map<String, String?> params = {
"phone": phone!.replaceAll(' ', ''),
"code": model.code,
};
startCountdown(model);
bool success = await model
.getPhoneCode(context, params);
if (!success) {
_timer.cancel();
} else {
Utils.showToast('短信验证码已发送,请注意查收');
}
}
},
),
HEmptyView(20),
],
)),
VEmptyView(120),
RoundButton(
text: '确定',
gradientStart: MyColours.color_199095,
gradientEnd: MyColours.color_199095,
// borderColor: MyColours.color_999999,
radius: ScreenUtil().setWidth(20),
fontSize: 34,
isBold: false,
onPressed: () async {
if (phone == null || phone!.trim().length == 0) {
Utils.showToast('请输入手机号码');
return;
}
if (code == null || code!.trim().length == 0) {
Utils.showToast('请输入验证码');
return;
}
if (model.code != null && !codeEnabled) {
Utils.showToast('验证码已失效,请重新获取');
return;
}
if (model.code == null) {
Utils.showToast('请获取验证码');
return;
}
if (model.code != code) {
Utils.showToast('您输入的验证码不正确,请重新输入');
return;
}
if (widget.wechat) {
CreateStoreModel createStoreModel =
Provider.of<CreateStoreModel>(context,
listen: false);
createStoreModel.storeInfo = StoreInfo();
//新建店铺默认接单电话号码
createStoreModel.storeInfo!.phone = phone;
NavigatorUtil.goIfNeedCreateStorePage(
context);
} else {
Map<String, String> params = {
"seller_code": '001297',
"alias": "ssahdahgdafgahjkhakjgh",
"account": "0001",
"password": "123456"
};
UserModel userModel = UserModel();
userModel
.login(context, params)
.then((value) {});
}
},
)
// Spacer(),
],
);
}),
),
),
],
))),
);
}
}