coupon_edit_page.dart
21.9 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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:one_key/provider/coupon_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/MyDivider.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 CouponEidtPage extends StatefulWidget {
final bool isMine;
CouponEidtPage({Key key, this.isMine = true}) : super(key: key);
@override
_CouponEidtPageState createState() => _CouponEidtPageState();
}
class _CouponEidtPageState extends State<CouponEidtPage> {
ScrollController controller = ScrollController();
TextEditingController _couponNameEditControl = TextEditingController();
TextEditingController _couponRequireEditControl = TextEditingController();
TextEditingController _couponExplainEditControl = TextEditingController();
final heightCell = ScreenUtil().setWidth(48 * 2);
bool swichState = true; //默认启用 开关状态
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
String fromDate = '点击选择'; //有效期开始时间
String endDate = '点击选择'; //有效期结束时间
FocusNode _nameFocusNode = FocusNode();
FocusNode _requireFocusNode = FocusNode();
bool showDateSelWidget = false;
CouponProvider couponProvider;
bool swichHexiao = true; //默认启用 核销状态
String uids = '';
@override
void initState() {
super.initState();
_nameFocusNode.addListener(() {
if (_nameFocusNode.hasFocus) {
//有焦点
if (showDateSelWidget) {
Navigator.pop(context);
showDateSelWidget = false;
}
} else {
//失去焦点
// _editingController.text = '';
}
});
_requireFocusNode.addListener(() {
if (_requireFocusNode.hasFocus) {
//有焦点
if (showDateSelWidget) {
Navigator.pop(context);
showDateSelWidget = false;
}
} else {
//失去焦点
// _editingController.text = '';
}
});
}
//创建新券 客户经理创建活动
_createNewCoupon() async {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
Map<String, String> params = {
"uid": Provider.of<UserModel>(context, listen: false).user.openid,
"aname": _couponNameEditControl.text.trim(),
"desc": _couponRequireEditControl.text.trim(),
"stime": fromDate == '点击选择'
? ""
: '${DateUtil.getDateMsByTimeStr(fromDate) / 1000}',
"etime": endDate == '点击选择'
? ''
: '${DateUtil.getDateMsByTimeStr(endDate) / 1000}',
"explain": _couponExplainEditControl.text,
"is_open": swichState ? "1" : "0",
"status": swichState ? "1" : "0",
'is_type': widget.isMine ? "2" : "1"
};
if (!widget.isMine) {
params['is_examine'] = swichHexiao ? "1" : "0";
params['uid_list'] = uids;
}
bool isSuccess =
await couponProvider.createCustomerActivity(context, params);
if (isSuccess) {
//成功之后跳回前一个页面
// bus.emit('refresh_coupon_list');
EventBus().emit('refresh_coupon_invitation');
bus.emit('refresh_coupon_list_f');
bus.emit('refresh_table_m_coupon');
Navigator.pop(context, true);
}
}
///输入框
Widget _textfield(String title, String hintText) {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Text(
title,
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.9),
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(32)),
),
),
HEmptyView(80),
Container(
width: ScreenUtil().setWidth(231 * 2),
child: TextField(
controller: title == '券名称'
? _couponNameEditControl
: _couponRequireEditControl,
textAlign: TextAlign.right,
textAlignVertical: TextAlignVertical.bottom,
maxLines: 1,
// //光标颜色
// cursorColor:
// widget.isSelect ? Colors.white : MyColours.color_199095,
//输入文本的样式
style: TextStyle(
color: MyColours.color_515151,
fontSize: ScreenUtil().setSp(32),
),
focusNode: title == '券名称' ? _nameFocusNode : _requireFocusNode,
decoration: InputDecoration(
border: OutlineInputBorder(borderSide: BorderSide.none),
hintText: hintText,
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(32),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
focusedBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
),
onChanged: (value) {},
onEditingComplete: () {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
},
keyboardType: TextInputType.text,
),
),
HEmptyView(32)
],
),
);
}
///时间选择
Widget _select(String title, String hintText, GestureTapCallback onTap) {
return InkWell(
onTap: onTap,
child: Container(
padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(28)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
// height: ScreenUtil().setWidth(40),
// color: Colors.red,
child: Text(
title,
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.9),
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(32)),
),
),
HEmptyView(20),
Spacer(),
Text(hintText,
style: TextStyle(
color: hintText == '点击选择'
? MyColours.color_999999
: MyColours.color_515151,
fontSize: ScreenUtil().setSp(32),
)),
HEmptyView(20),
Image.asset(
Utils.getImgPath('arrow_right_new'),
width: ScreenUtil().setWidth(20),
),
HEmptyView(32),
],
),
),
);
}
///券说明
Widget _explain(String title, String hintText) {
return Container(
// height: ScreenUtil().setWidth(380),
padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(28)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
title,
textAlign: TextAlign.left,
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.9),
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(32)),
)),
VEmptyView(26),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
TextField(
controller: _couponExplainEditControl,
// keyboardType: TextInputType.number, //键盘类型,数字键盘
maxLines: 3,
maxLength: 50,
// maxLengthEnforced: true,
style: TextStyle(
fontSize: ScreenUtil().setSp(32),
color: MyColours.color_333333), //输入文本的样式
decoration: InputDecoration(
contentPadding: EdgeInsets.all(ScreenUtil().setWidth(30)),
hintText: hintText,
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(32),
),
border: OutlineInputBorder(borderSide: BorderSide.none),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
focusedBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
// fillColor: MyColours.color_F9F9F9,
// // fillColor: Colors.red,
// filled: true,
// enabledBorder: OutlineInputBorder(
// //未选中时候的颜色
// borderRadius: BorderRadius.circular(ScreenUtil().setWidth(20)),
// borderSide: BorderSide(
// color: MyColours.color_cccccc,
// width: ScreenUtil().setWidth(2)),
// ),
// focusedBorder: OutlineInputBorder(
// //选中时外边框颜色
// borderRadius: BorderRadius.circular(ScreenUtil().setWidth(20)),
// borderSide: BorderSide(
// color: MyColours.app_main,
// ),
// ),
// border: OutlineInputBorder(
// borderRadius:
// BorderRadius.circular(ScreenUtil().setWidth(20)),
// borderSide: BorderSide(
// color: Colors.red, width: ScreenUtil().setWidth(2))),
),
onChanged: (value) {},
),
],
),
);
}
///是否立即启用
Widget _canUse(String title, bool swich, GestureTapCallback onTap) {
return InkWell(
onTap: onTap,
child: Container(
padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(24)),
margin: EdgeInsets.only(right: ScreenUtil().setWidth(32)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
// height: ScreenUtil().setWidth(40),
// color: Colors.red,
child: Text(
title,
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.9),
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(32)),
),
),
Spacer(),
Image.asset(
swich
? Utils.getImgPath('swich_on')
: Utils.getImgPath('swich_off'),
width: ScreenUtil().setWidth(44 * 2),
)
],
),
),
);
}
///
Widget _item(String title, String subTitle) {
return Container(
padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(28)),
margin: EdgeInsets.only(right: ScreenUtil().setWidth(32)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
child: Text(
title,
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.9),
fontWeight: FontWeight.bold,
fontSize: ScreenUtil().setSp(32)),
),
),
HEmptyView(60),
Expanded(
child: Text(
subTitle,
maxLines: 20,
textAlign: TextAlign.right,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.4),
fontSize: ScreenUtil().setSp(32),
),
))
],
),
);
}
@override
Widget build(BuildContext context) {
couponProvider = Provider.of<CouponProvider>(context, listen: true);
return Scaffold(
backgroundColor: MyColours.color_ffffff,
key: scaffoldKey,
appBar: SystemAppBar(
'优惠券详情',
onTap: () {
Navigator.pop(context, false);
},
),
body: InkWell(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
},
child: Container(
color: MyColours.color_ffffff,
child: Column(children: [
Expanded(
child: SingleChildScrollView(
controller: controller,
physics: BouncingScrollPhysics(),
child: Padding(
padding:
EdgeInsets.only(left: ScreenUtil().setWidth(32)),
child: Column(
children: [
VEmptyView(56),
_item('券类型', widget.isMine ? '我的优惠券' : '店铺优惠券'),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
VEmptyView(24),
widget.isMine
? SizedBox()
: _canUse('是否核销', swichHexiao, () {
setState(() {
swichHexiao = !swichHexiao;
});
}),
widget.isMine
? SizedBox()
: Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
widget.isMine ? SizedBox() : VEmptyView(24),
_textfield('券名称', '例:9折券/200元代金券/菜品券'),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
VEmptyView(24),
_textfield('券要求', '例:无门槛/满2000元'),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
VEmptyView(24),
_select('有效期从', fromDate, () {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
//弹出时间选择器
// showPickerDateTime(context);
showDateSelWidget = true;
DialogUtil.showPickerDateTime24(
context,
scaffoldKey,
(value) {
// {'text': picker.adapter.text, 'select': selecteds}
if (value != null) {
setState(() {
print(value);
fromDate = DateUtil.formatDateStr(
value,
format: DateFormats.full);
});
}
showDateSelWidget = false;
},
dateTime: DateUtil.getDateTime(fromDate),
onCancel: () {
showDateSelWidget = false;
});
}),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
VEmptyView(24),
_select('有效期至', endDate, () {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
//弹出时间选择器
// showPickerDateTime(context);
showDateSelWidget = true;
DialogUtil.showPickerDateTime24(
context,
scaffoldKey,
(value) {
// {'text': picker.adapter.text, 'select': selecteds}
if (value != null) {
setState(() {
print(value);
endDate = DateUtil.formatDateStr(
value,
format: DateFormats.full);
});
}
showDateSelWidget = false;
},
dateTime: DateUtil.getDateTime(endDate),
onCancel: () {
showDateSelWidget = false;
});
}),
Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
VEmptyView(24),
widget.isMine
? SizedBox()
: _select('谁可以发放', '编辑', () async {
Map temp = await NavigatorUtil
.goCouponToPersonnalPage(
context, uids);
if (temp != null &&
temp['object'] != null) {
uids = temp['object'];
}
}),
widget.isMine
? SizedBox()
: Container(
height: ScreenUtil().setWidth(2),
color: MyColours.color_E7E7E7,
),
widget.isMine ? SizedBox() : VEmptyView(24),
_explain('券说明', '例:可用包间,停车免费,不与店内其他活动共享等'),
VEmptyView(20),
_canUse('立即启用', swichState, () {
setState(() {
swichState = !swichState;
});
}),
VEmptyView(30),
],
))),
),
VEmptyView(20),
RoundButton(
onPressed: () {
if (_couponNameEditControl.text.trim().length == 0) {
Utils.showToast('请填写券名称');
return;
}
if (_couponRequireEditControl.text.trim().length == 0) {
Utils.showToast('请填写券要求');
return;
}
if (fromDate == '点击选择') {
Utils.showToast('请选择有效期起始时间');
return;
}
if (endDate == '点击选择') {
Utils.showToast('请选择有效期结束时间');
return;
}
if (DateUtil.getDateTime(endDate)
.compareTo(DateUtil.getDateTime(fromDate)) <
0) {
Utils.showToast('有效期结束时间不能早于起始时间');
return;
}
// ***参数***
// _couponNameEditControl.text
// _couponRequireEditControl.text
// fromDate
// endDate
// _couponExplainEditControl.text
// swichState
_createNewCoupon();
},
text: '立即创建',
fontSize: 24,
isBold: false,
height: ScreenUtil().setWidth(37 * 2),
width: ScreenUtil().setWidth(130 * 2),
radius: ScreenUtil().setWidth(22),
),
VEmptyView(32)
]))),
);
}
}