You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
331 lines
11 KiB
331 lines
11 KiB
import 'dart:convert'; |
|
|
|
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/user_info.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/view_widget/activity_coupons.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:huixiang/view_widget/login_tips_dialog.dart'; |
|
import 'package:huixiang/view_widget/request_permission.dart'; |
|
import 'package:permission_handler/permission_handler.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
// import 'package:qrscan/qrscan.dart' as scanner; |
|
|
|
class MineView extends StatefulWidget { |
|
final UserInfo userInfo; |
|
final GestureTapCallback toUserInfo; |
|
final GestureTapCallback toIntegralPage; |
|
|
|
MineView(this.userInfo, this.toUserInfo, this.toIntegralPage); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _MineView(); |
|
} |
|
} |
|
|
|
class _MineView extends State<MineView> { |
|
ApiService apiService; |
|
|
|
///核销用户优惠券 |
|
queryWiped(memberCouponId) async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
BaseData baseData = await apiService.wiped(memberCouponId); |
|
if (baseData != null && baseData.isSuccess) { |
|
SmartDialog.showToast("核销成功", alignment: Alignment.center); |
|
} else { |
|
SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Column( |
|
children: [ |
|
Container( |
|
margin: EdgeInsets.only(top: 28.w), |
|
alignment: Alignment.centerRight, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.end, |
|
children: [ |
|
InkWell( |
|
onTap: () { |
|
toScan(); |
|
}, |
|
child: Container( |
|
padding: EdgeInsets.all(8.h), |
|
child: Image.asset( |
|
"assets/image/icon_scan_qr_code.webp", |
|
width:32.w, |
|
height: 32.h, |
|
), |
|
), |
|
), |
|
InkWell( |
|
onTap: () { |
|
Navigator.of(context).pushNamed('/router/setting_page'); |
|
}, |
|
child: Container( |
|
padding: EdgeInsets.all(8.h), |
|
margin: EdgeInsets.only(right: 12.w), |
|
child: Image.asset( |
|
"assets/image/icon_mine_setting.webp", |
|
width: 32.w, |
|
height: 32.h, |
|
), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
mineView(), |
|
SizedBox( |
|
height: 12.h, |
|
), |
|
], |
|
); |
|
} |
|
|
|
toScan() async { |
|
if (await Permission.camera.isPermanentlyDenied) { |
|
showCupertinoDialog( |
|
context: context, |
|
builder: (context) { |
|
return RequestPermission( |
|
"assets/image/icon_camera_permission_tips.webp", |
|
S.of(context).ninxiangjiquanxianweikaiqi, |
|
S.of(context).weilekaipaizhaoxuanzhetouxiang, |
|
S.of(context).kaiqiquanxian, |
|
(result) async { |
|
if (result) { |
|
await openAppSettings(); |
|
} |
|
}, |
|
heightRatioWithWidth: 0.82, |
|
); |
|
}); |
|
} else if (await Permission.camera.isGranted) { |
|
// http://pos.app.gznl.top/placeorder/?tableId=1315903669597634560&tenantCode=1166&shopId=1300372027722432512 |
|
var result = await Navigator.of(context).pushNamed('/router/qr_scan'); |
|
if(result.toString().contains("type\":\"coupon")){ |
|
///活动优惠券赠送弹窗 |
|
activityShowAlertDialog(result.toString()); |
|
return; |
|
}if(result.toString().contains("type\":\"wiped")){ |
|
///核销券 |
|
queryWiped(jsonDecode(result.toString())["memberCouponId"]); |
|
return; |
|
} |
|
// String result = await scanner.scan(); |
|
Uri uri = Uri.parse(result); |
|
String tableId = uri.queryParameters["tableId"]; |
|
String tenantCode = uri.queryParameters["tenantCode"]; |
|
String shopId = uri.queryParameters["shopId"]; |
|
if (tableId != null && |
|
tableId != "" && |
|
tenantCode != null && |
|
tenantCode != "" && |
|
shopId != null && |
|
shopId != "") { |
|
Navigator.of(context).pushNamed( |
|
'/router/store_order', |
|
arguments: { |
|
"id": shopId, |
|
"tenant": tenantCode, |
|
"storeName": "", |
|
"tableId": int.tryParse(tableId), |
|
}, |
|
); |
|
} |
|
} else { |
|
await Permission.camera.request(); |
|
} |
|
} |
|
|
|
activityShowAlertDialog(String result) { |
|
//显示对话框 |
|
showDialog( |
|
context: context, |
|
builder: (BuildContext context) { |
|
return ActivityCoupons(result); |
|
}, |
|
); |
|
} |
|
|
|
///我的信息部分 |
|
Widget mineView() { |
|
print("---" + widget.userInfo.toString()); |
|
return Container( |
|
alignment: Alignment.center, |
|
margin: EdgeInsets.symmetric(horizontal: 16.w), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
InkWell( |
|
onTap: () { |
|
widget.toUserInfo(); |
|
}, |
|
child: Stack( |
|
children: [ |
|
MImage( |
|
widget.userInfo == null ? "" : widget.userInfo.headimg, |
|
isCircle: true, |
|
width: 50, |
|
height: 50, |
|
fit: BoxFit.cover, |
|
errorSrc: "assets/image/default_user.webp", |
|
fadeSrc: "assets/image/default_user.webp", |
|
), |
|
Positioned( |
|
bottom: 0, |
|
right: 2.w, |
|
child: Image.asset( |
|
"assets/image/icon_mine_edit.webp", |
|
width: 17.w, |
|
height: 17.w, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
SizedBox( |
|
width: 10.w, |
|
), |
|
Expanded( |
|
flex: 1, |
|
child: Container( |
|
height: 53.h, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.stretch, |
|
children: [ |
|
widget.userInfo == null |
|
? InkWell( |
|
child: Text( |
|
S.of(context).denglu, |
|
style: TextStyle( |
|
fontSize: 16.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
onTap: widget.toUserInfo, |
|
) |
|
: Row( |
|
children: [ |
|
InkWell( |
|
onTap: () { |
|
if (widget.userInfo == null) { |
|
LoginTipsDialog().show(context); |
|
} |
|
}, |
|
child: Text( |
|
widget.userInfo == null |
|
? S.of(context).denglu |
|
: "${widget.userInfo.nickname}", |
|
style: TextStyle( |
|
fontSize: 16.sp, |
|
fontWeight: FontWeight.bold, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
), |
|
if(widget.userInfo.level != 1) |
|
Image.asset( |
|
"assets/image/icon_user.webp", |
|
width: 18.w, |
|
height: 18.h, |
|
), |
|
], |
|
), |
|
widget.userInfo == null |
|
? Text( |
|
S.of(context).weidengluxinxi, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF2F2F2F), |
|
), |
|
) |
|
: Text( |
|
widget.userInfo == null |
|
? "" |
|
: "我的积分:${widget.userInfo.points}", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF2F2F2F), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
), |
|
widget.userInfo == null |
|
? Container( |
|
alignment: Alignment.center, |
|
height: 50.h, |
|
child: Icon( |
|
Icons.keyboard_arrow_right, |
|
size: 20, |
|
color: Colors.black, |
|
), |
|
) |
|
: Container( |
|
alignment: Alignment.bottomRight, |
|
height: 50.h, |
|
child: GestureDetector( |
|
onTap: () { |
|
widget.toIntegralPage(); |
|
}, |
|
child: Container( |
|
padding: EdgeInsets.only(top: 4, bottom: 4, right: 16,left: 7), |
|
decoration: BoxDecoration( |
|
color: Color(0xFF87E8B0), |
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(100),bottomLeft:Radius.circular(100)), |
|
), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.end, |
|
children: [ |
|
Image.asset( |
|
"assets/image/ji_fen.webp", |
|
width: 16.w, |
|
height: 16.h, |
|
), |
|
Text( |
|
"签到得积分", |
|
style: TextStyle( |
|
color: Colors.black, |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
// Icon( |
|
// Icons.keyboard_arrow_right, |
|
// size: 16, |
|
// color: Colors.black, |
|
// ) |
|
], |
|
), |
|
)), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|