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.

412 lines
15 KiB

import 'dart:convert';
import 'package:dio/dio.dart';
3 years ago
import 'package:flutter/cupertino.dart';
3 years ago
import 'package:flutter/material.dart';
3 years ago
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
3 years ago
import 'package:flutter_svg/svg.dart';
3 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
3 years ago
import 'package:huixiang/retrofit/data/msg_stats.dart';
3 years ago
import 'package:huixiang/retrofit/data/social_info.dart';
3 years ago
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/activity_coupons.dart';
3 years ago
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:huixiang/view_widget/login_tips_dialog.dart';
3 years ago
import 'package:huixiang/view_widget/request_permission.dart';
3 years ago
import 'package:huixiang/view_widget/round_button.dart';
3 years ago
import 'package:permission_handler/permission_handler.dart';
import 'package:shared_preferences/shared_preferences.dart';
3 years ago
// import 'package:qrscan/qrscan.dart' as scanner;
3 years ago
class MineView extends StatefulWidget {
final UserInfo userInfo;
3 years ago
final GestureTapCallback toUserInfo;
final GestureTapCallback toIntegralPage;
3 years ago
final Function messageZero;
final int totalMsg;
3 years ago
final SocialInfo infoNumber;
3 years ago
3 years ago
MineView(this.userInfo, this.toUserInfo, this.toIntegralPage,this.messageZero,this.totalMsg,this.infoNumber);
3 years ago
@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);
}
}
3 years ago
3 years ago
@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
3 years ago
margin: EdgeInsets.only(top: 29.h),
3 years ago
alignment: Alignment.centerRight,
3 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
3 years ago
Container(
3 years ago
height: 24.h,
3 years ago
alignment: Alignment.center,
child: GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/router/system_msg_page').then((value) {
widget.messageZero();
});
},
child: Container(
3 years ago
height: 24.h,
3 years ago
alignment:Alignment.center,
child:Stack(
children: [
Image.asset(
"assets/image/icon_notices.webp",
3 years ago
width:32,
height: 32,
3 years ago
color: Colors.white,
3 years ago
),
if(widget.totalMsg != 0)
Container(
3 years ago
width:36.w,
3 years ago
alignment: Alignment.topRight,
child:Container(
3 years ago
width:22.w,
height:14.h,
3 years ago
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(
width: 1,
color: Colors.white,
style: BorderStyle.solid,
),
color:Color(0xFFFF441A),
),
child:RoundButton(
text:widget.totalMsg.toString(),
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize:8.sp,
radius: 100,
)
),
)
],
),
)
)
),
3 years ago
InkWell(
onTap: () {
3 years ago
toScan();
3 years ago
},
child: Container(
padding: EdgeInsets.all(8.h),
child: Image.asset(
"assets/image/icon_scan_qr_code.webp",
3 years ago
width:32,
height: 32,
3 years ago
color: Colors.white,
3 years ago
),
),
),
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",
3 years ago
width: 32,
height: 32,
3 years ago
color: Colors.white,
3 years ago
),
),
),
],
),
3 years ago
),
3 years ago
mineView(),
3 years ago
SizedBox(
3 years ago
height: 12.h,
3 years ago
),
],
);
}
3 years ago
toScan() async {
if (await Permission.camera.isPermanentlyDenied) {
showCupertinoDialog(
context: context,
builder: (context) {
return RequestPermission(
"assets/image/icon_camera_permission_tips.webp",
3 years ago
S.of(context).ninxiangjiquanxianweikaiqi,
S.of(context).weilekaipaizhaoxuanzhetouxiang,
3 years ago
S.of(context).kaiqiquanxian,
3 years ago
(result) async {
3 years ago
if (result) {
await openAppSettings();
}
},
heightRatioWithWidth: 0.82,
);
});
} else if (await Permission.camera.isGranted) {
3 years ago
// http://pos.app.gznl.top/placeorder/?tableId=1315903669597634560&tenantCode=1166&shopId=1300372027722432512
3 years ago
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;
}
3 years ago
// String result = await scanner.scan();
3 years ago
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 != "") {
3 years ago
Navigator.of(context).pushNamed(
'/router/store_order',
arguments: {
"id": shopId,
"tenant": tenantCode,
"storeName": "",
"tableId": int.tryParse(tableId),
},
);
}
3 years ago
} else {
await Permission.camera.request();
}
}
activityShowAlertDialog(String result) {
//显示对话框
showDialog(
context: context,
builder: (BuildContext context) {
return ActivityCoupons(result);
},
);
}
3 years ago
///我的信息部分
Widget mineView() {
3 years ago
print("---" + widget.userInfo.toString());
3 years ago
return Container(
alignment: Alignment.center,
3 years ago
margin: EdgeInsets.only(left: 16.w),
3 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
3 years ago
InkWell(
3 years ago
onTap: () {
widget.toUserInfo();
},
child: Stack(
children: [
MImage(
widget.userInfo == null ? "" : widget.userInfo.headimg,
isCircle: true,
3 years ago
width: 58,
height: 58,
3 years ago
fit: BoxFit.cover,
errorSrc: "assets/image/default_user.webp",
fadeSrc: "assets/image/default_user.webp",
3 years ago
),
Positioned(
bottom: 0,
right: 2.w,
child: Image.asset(
"assets/image/icon_mine_edit.webp",
3 years ago
width: 17,
height: 17,
3 years ago
),
3 years ago
),
],
),
3 years ago
),
SizedBox(
width: 10.w,
),
Expanded(
flex: 1,
child: Container(
height: 53.h,
3 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
widget.userInfo == null
3 years ago
? InkWell(
child: Text(
S.of(context).denglu,
style: TextStyle(
fontSize: 16.sp,
fontWeight: MyFontWeight.medium,
3 years ago
color: Color(0xFFFFFFFF),
3 years ago
),
3 years ago
),
3 years ago
onTap: widget.toUserInfo,
3 years ago
)
: Row(
children: [
InkWell(
onTap: () {
if (widget.userInfo == null) {
3 years ago
LoginTipsDialog().show(context);
3 years ago
}
},
child: Text(
widget.userInfo == null
? S.of(context).denglu
: "${widget.userInfo.nickname??""}",
3 years ago
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.bold,
3 years ago
color: Color(0xFFFFFFFF),
3 years ago
),
),
),
if(widget.userInfo.level != 1)
3 years ago
Image.asset(
"assets/image/icon_user.webp",
3 years ago
width: 18.w,
height: 18.h,
),
],
),
widget.userInfo == null
? Text(
S.of(context).weidengluxinxi,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xFFFFFFFF),
3 years ago
),
)
3 years ago
: Row(
children: [
Text(
"${S.of(context).guanzhu} ${widget?.infoNumber?.follow ?? "0"}",
3 years ago
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xFFFFFFFF),
3 years ago
),
),
Container(
width: 1.w,
height: 12.h,
margin: EdgeInsets.symmetric(horizontal: 3.w),
3 years ago
color: Color(0xFFFFFFFF),
3 years ago
),
Text(
"${S.of(context).fensi} ${widget?.infoNumber?.fans ?? "0"}",
3 years ago
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xFFFFFFFF),
3 years ago
),
3 years ago
),
],
),
3 years ago
],
),
),
),
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(
3 years ago
padding: EdgeInsets.only(top: 4.h, bottom: 4.h, right: 16.w,left: 7.w),
3 years ago
margin: EdgeInsets.only(right: 14.w),
decoration: BoxDecoration(
3 years ago
borderRadius: BorderRadius.circular(12),
color: Colors.white
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Image.asset(
3 years ago
"assets/image/icon_gold_coin.webp",
3 years ago
width: 16,
height: 16,
),
Text(
3 years ago
"天天领积分",
style: TextStyle(
3 years ago
color: Color(0xFF32A060),
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
),
),
// Icon(
// Icons.keyboard_arrow_right,
// size: 16,
// color: Colors.black,
// )
],
3 years ago
),
)),
3 years ago
),
],
),
);
}
}