coupon_page.dart
17.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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/pages/coupon/coupon_sun_page.dart';
import 'package:one_key/provider/coupon_provider.dart';
import 'package:one_key/provider/personnel_provider.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/route/navigator_util.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';
import 'package:barcode_scan2/barcode_scan2.dart';
import '../../provider/marketing_center_provider.dart';
import '../../utils/dialog_util.dart';
import '../../utils/misc.dart';
import '../../utils/screen_util.dart';
import '../../utils/utils.dart';
import 'coupon_has_verification_page.dart';
/**
* 优惠券列表
*/
class CouponPage extends StatefulWidget {
final bool needRefrsh;
CouponPage({Key key, this.needRefrsh = false}) : super(key: key);
@override
_CouponPageState createState() => _CouponPageState();
}
class _CouponPageState extends State<CouponPage> with TickerProviderStateMixin {
EasyRefreshController _controller = EasyRefreshController();
CouponProvider couponProvider;
TabController tabController;
// ///获取优惠券列表数据
// _couponNetworkData(int index, {bool isShowLoading = true}) async {
// Map<String, String> params = {
// "uid": Provider.of<UserModel>(context, listen: false).user.openid,
// // 'is_time': '0'
// "is_type": index.toString()
// };
// await couponProvider.getCustomerActivity(context, params,
// isShowLoading: isShowLoading);
// }
///修改活动信息
// _setCustomerActivity(int index) async {
// Map<String, String> params = {
// "id": couponProvider.couponList[index].id,
// "status": couponProvider.couponList[index].isOpenBool ? '1' : '0'
// };
// bool isSuccess = await couponProvider.setCustomerActivity(context, params,
// isShowLoading: false);
// print(isSuccess);
// _couponNetworkData(tabController.index, isShowLoading: false);
// // if (isSuccess) {
// // couponProvider.notifyListeners();
// // } else {
// // couponProvider.couponList[index].isOpenBool =
// // !couponProvider.couponList[index].isOpenBool;
// // couponProvider.notifyListeners();
// // }
// }'
ScanResult scanResult;
var _aspectTolerance = 0.5;
// var _numberOfCameras = 0;
var _selectedCamera = -1;
var _autoEnableFlash = false;
static final _possibleFormats = BarcodeFormat.values.toList()
..removeWhere((e) => e == BarcodeFormat.unknown);
List<BarcodeFormat> selectedFormats = [..._possibleFormats];
@override
void initState() {
// TODO: implement initState
super.initState();
// Future.delayed(Duration.zero, () async {
// // _numberOfCameras = await BarcodeScanner.numberOfCameras;
// setState(() {});
// });
tabController = TabController(length: 4, vsync: this);
tabController.addListener(() {
// couponProvider.couponList = [];
// couponProvider.pageState = PageState.Loading;
// setState(() {});
//点击tab时或滑动tab回调一次
if (tabController.index.toDouble() == tabController.animation.value) {
// couponProvider.notifyListeners();
// _couponNetworkData(tabController.index);
// selectIndex = tabController.index;
// setState(() {});
}
});
WidgetsBinding.instance.addPostFrameCallback((_) {
// _couponNetworkData(0);
});
// bus.on("refresh_coupon_list_f", (arg) {
// _couponNetworkData(tabController.index);
// });
}
@override
void dispose() {
if (widget.needRefrsh) {
EventBus().emit('refresh_coupon_invitation');
} else {
EventBus().emit('changeStatusColor');
}
bus.off("refresh_coupon_list_f");
super.dispose();
}
Future<void> _scan() async {
try {
final result = await BarcodeScanner.scan(
options: ScanOptions(
strings: {'cancel': '退出', 'flash_on': '开闪光灯', 'flash_off': '关闪光灯'},
restrictFormat: selectedFormats,
useCamera: _selectedCamera,
autoEnableFlash: _autoEnableFlash, //true打开闪光灯, false关闭闪光灯
android: AndroidOptions(
aspectTolerance: 0.5, useAutoFocus: true), //(默认已配)添加Android自动对焦
),
);
// result.rawContent
setState(() => scanResult = result);
print(result);
if (result.rawContent is String) {
if (Utils.cnIsNumber(result.rawContent)) {
NavigatorUtil.goVerificationCouponPage(context, result.rawContent);
}
}
} on PlatformException catch (e) {
setState(() {
scanResult = ScanResult(
type: ResultType.Error,
rawContent: e.code == BarcodeScanner.cameraAccessDenied
? 'The user did not grant the camera permission!'
: 'Unknown error: $e',
);
if (e.code == BarcodeScanner.cameraAccessDenied) {
DialogUtil.openAlertDialog(
context, '未获得相机权限', "请在手机的权限管理里,将相机权限开启", '去设置', 340.0,
onTap: () {
openSetting();
Navigator.pop(context, '');
});
}
});
}
}
@override
Widget build(BuildContext context) {
couponProvider = Provider.of<CouponProvider>(context, listen: true);
return Scaffold(
backgroundColor: MyColours.color_f3f3f3,
appBar: Utils.getAuthority(context, '线上券-设置')
? SystemAppBar(
'线上券',
rightImgName: 'set_g.png',
onTapRight: () {
NavigatorUtil.goCouponSettingPage(context);
},
)
: SystemAppBar(
'线上券',
),
body: Column(
children: <Widget>[
Container(
width: double.infinity,
height: ScreenUtil().setWidth(80),
color: MyColours.color_ffffff,
padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(6)),
child: TabBar(
controller: tabController,
tabs: [
Tab(
text: "全部",
),
Tab(
text: "店铺优惠券",
),
Tab(
text: "我的优惠券",
),
Tab(
text: "核销记录",
)
],
indicatorColor: MyColours.color_438E93,
indicatorSize: TabBarIndicatorSize.label,
indicatorWeight: ScreenUtil().setWidth(4),
labelColor: MyColours.color_438E93,
unselectedLabelColor: MyColours.color_999999,
labelStyle: TextStyle(
color: MyColours.color_438E93,
fontSize: ScreenUtil().setSp(25),
fontWeight: FontWeight.bold),
unselectedLabelStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(24),
),
)),
VEmptyView(32),
Expanded(
child: TabBarView(
controller: tabController,
children: [
ChangeNotifierProvider<PersonnelProvider>(
create: (_) => PersonnelProvider(),
child: ChangeNotifierProvider<MarketingCenterProvider>(
create: (_) => MarketingCenterProvider(),
child: CouponSunPage(index: 0))),
ChangeNotifierProvider<PersonnelProvider>(
create: (_) => PersonnelProvider(),
child: ChangeNotifierProvider<MarketingCenterProvider>(
create: (_) => MarketingCenterProvider(),
child: CouponSunPage(index: 1))),
ChangeNotifierProvider<PersonnelProvider>(
create: (_) => PersonnelProvider(),
child: ChangeNotifierProvider<MarketingCenterProvider>(
create: (_) => MarketingCenterProvider(),
child: CouponSunPage(index: 2))),
ChangeNotifierProvider<PersonnelProvider>(
create: (_) => PersonnelProvider(),
child: CouponHasVerificationPage()),
],
),
),
Container(
height: ScreenUtil().setWidth(91 * 2),
padding: EdgeInsets.only(
top: ScreenUtil().setWidth(16 * 2),
bottom: ScreenUtil().setWidth(35 * 2),
left: ScreenUtil().setWidth(45 * 2),
right: ScreenUtil().setWidth(45 * 2),
),
decoration: BoxDecoration(
color: MyColours.color_ffffff,
boxShadow: [
BoxShadow(
spreadRadius: ScreenUtil().setWidth(2),
color: Color.fromRGBO(0, 0, 0, 0.1),
offset: Offset(0, ScreenUtil().setWidth(-2)),
blurRadius: ScreenUtil().setWidth(8))
],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(ScreenUtil().setWidth(16)),
topRight: Radius.circular(ScreenUtil().setWidth(16))),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
tabController.index == 3
? Expanded(
child: RoundButton(
text: '扫码核销',
width: tabController.index == 3
? double.infinity
: w(100),
gradientStart: MyColours.color_ffffff,
gradientEnd: MyColours.color_ffffff,
borderColor: MyColours.color_438E93,
textColor: MyColours.color_438E93,
height: ScreenUtil().setWidth(80),
radius: ScreenUtil().setWidth(14),
isBold: true,
fontSize: 28,
onPressed: () async {
_scan();
},
),
)
: RoundButton(
text: '扫码核销',
width: w(100),
gradientStart: MyColours.color_ffffff,
gradientEnd: MyColours.color_ffffff,
borderColor: MyColours.color_438E93,
textColor: MyColours.color_438E93,
height: ScreenUtil().setWidth(80),
radius: ScreenUtil().setWidth(14),
isBold: true,
fontSize: 28,
onPressed: () async {
_scan();
},
),
if (tabController.index != 3) HEmptyView(30),
if (tabController.index != 3)
Expanded(
child: RoundButton(
text: '创建新的优惠券',
height: ScreenUtil().setWidth(80),
radius: ScreenUtil().setWidth(14),
isBold: false,
fontSize: 28,
onPressed: () async {
// UserModel userModel =
// Provider.of<UserModel>(context, listen: false);
if (Utils.getAuthority(context, '创建新的优惠券')) {
NavigatorUtil.goCouponCreateSelectTypePage(context);
}
// if (userModel.user.role_name == '管理员' ||
// userModel.user.role_name == '店长') {
// NavigatorUtil.goCouponCreateSelectTypePage(context);
// }
else {
bool needRefresh =
await NavigatorUtil.goCouponEditPage(context);
print(needRefresh);
if (needRefresh != null && needRefresh) {
bus.emit('refresh_coupon_list_f');
//刷新页面数据
// _controller.callRefresh();
// _couponNetworkData(tabController.index);
}
}
},
),
)
],
))
],
),
// child: Column(
// children: [
// Expanded(child: Consumer<CouponProvider>(
// builder: (context, model, _) {
// if (model.pageState != PageState.Success) {
// return ExceptionPage(
// pageState: model.pageState,
// callback: () {
// // offset = 0;
// // getMessage(showLoading: true);
// _couponNetworkData();
// },
// emptyMsg: "暂时没有列表信息哦",
// emptyImg: "empty_search",
// showMsg: "加载中,请稍后...",
// );
// } else {
// return EasyRefresh.custom(
// controller: _controller,
// shrinkWrap: true,
// slivers: [
// SliverList(
// delegate: SliverChildBuilderDelegate(
// (BuildContext context, int index) {
// return Container(
// margin:
// EdgeInsets.all(ScreenUtil().setWidth(40)),
// padding:
// EdgeInsets.all(ScreenUtil().setWidth(30)),
// color: MyColours.color_F0F0F0,
// child: Text(
// '使用说明:需在结账前出示优惠券二维码,店内工作人员微信扫码核销。超过有效期的券,会自动作废并移出列表。优惠券不可找零、兑现。',
// style: TextStyle(
// color: MyColours.color_666666,
// fontSize: ScreenUtil().setSp(24),
// ),
// strutStyle: StrutStyle(
// forceStrutHeight: true,
// height: 1,
// leading: 0.3),
// ));
// }, childCount: 1),
// ),
// SliverList(
// delegate: SliverChildBuilderDelegate(
// (BuildContext context, int index) {
// return CouponItem(
// from: 'quan',
// couponSonModel:
// couponProvider.couponList[index],
// showBtn: true,
// onPressedSwich: () {
// couponProvider.couponList[index].isOpenBool =
// !couponProvider
// .couponList[index].isOpenBool;
// _setCustomerActivity(index);
// },
// onPressed: () {
// NavigatorUtil.goCouponDetailPage(context,
// couponProvider.couponList[index]);
// },
// );
// }, childCount: couponProvider.couponList.length),
// )
// ],
// // onRefresh: () async {
// // // offset = 0;
// // // getMessage(showLoading: false);
// // },
// // onLoad: () async {
// // // offset++;
// // // getMessage(showLoading: false);
// // },
// );
// }
// },
// )),
// VEmptyView(20),
// Padding(
// padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(40), 0,
// ScreenUtil().setWidth(40), ScreenUtil().setWidth(40)),
// child: RoundButton(
// onPressed: () async {
// bool needRefresh =
// await NavigatorUtil.goCouponEditPage(context);
// print(needRefresh);
// if (needRefresh != null && needRefresh) {
// //刷新页面数据
// // _controller.callRefresh();
// _couponNetworkData();
// }
// },
// text: '创建新券',
// fontSize: 34,
// isBold: false,
// height: ScreenUtil().setWidth(80),
// width: double.infinity,
// radius: ScreenUtil().setWidth(10),
// ))
// ],
// )
);
}
}