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.

348 lines
12 KiB

4 years ago
import 'package:flutter/material.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:huixiang/retrofit/data/rank.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/utils/flutter_utils.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
3 years ago
import 'package:huixiang/view_widget/login_tips_dialog.dart';
3 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class MineVipView extends StatelessWidget {
3 years ago
int vipLevel;
int curLevel;
4 years ago
final int rankMax;
final int rank;
final String createTime;
3 years ago
final String tag;
4 years ago
final double padding;
3 years ago
final UserInfo userInfo;
final List<Rank> ranks;
3 years ago
final bool showRank;
final String price;
4 years ago
3 years ago
MineVipView({
3 years ago
this.vipLevel = 1,
3 years ago
this.ranks,
3 years ago
this.tag,
3 years ago
this.userInfo,
4 years ago
this.padding = 16,
3 years ago
this.curLevel = 1,
4 years ago
this.rankMax = 0,
this.rank = 0,
this.createTime = "",
3 years ago
this.showRank,
this.price
4 years ago
});
4 years ago
String topLeft = "";
String levelText = "普通用户";
4 years ago
4 years ago
@override
Widget build(BuildContext context) {
List<Color> linearColor = [
4 years ago
Color(0xFFD6F6F3),
Color(0xFF86BEBA),
];
4 years ago
Color levelColor = Color(0xFF558B87);
Color textColor = Colors.white;
4 years ago
3 years ago
if (userInfo != null &&
userInfo.memberRankVo != null &&
ranks != null &&
ranks.length > 0) {
3 years ago
curLevel = (ranks.indexWhere((element) => element.id == userInfo.memberRankVo.id) + 1);
3 years ago
vipLevel = curLevel;
}
4 years ago
if (curLevel == vipLevel) {
4 years ago
topLeft = S.of(context).dangqiandengji;
3 years ago
} else if (vipLevel < curLevel) {
4 years ago
topLeft = S.of(context).shangyidengji;
4 years ago
} else {
topLeft = S.of(context).zanweikaitong;
4 years ago
}
4 years ago
switch (vipLevel) {
case 1:
{
linearColor = [
Color(0xFFF2F2F2),
Color(0xFFCCCCCC),
4 years ago
];
levelColor = Color(0xFF575757);
textColor = Color(0xFF575757);
levelText = "VIP ${S.of(context).yinkahuiyuan}";
4 years ago
break;
}
case 2:
4 years ago
{
linearColor = [
Color(0xFFFEF5DC),
Color(0xFFD1B97D),
];
levelColor = Color(0xFFAE9B6D);
textColor = Color(0xFF93723B);
levelText = "VIP ${S.of(context).jinkahuiyuan}";
4 years ago
break;
}
case 3:
4 years ago
{
linearColor = [
Color(0xFFEEEEEF),
Color(0xFF000000),
];
levelColor = Color(0xFF000000);
levelText = "VIP ${S.of(context).gongchuanghuiyuan}";
4 years ago
break;
}
// case 4:
// {
// linearColor = [
// Color(0xFFEEEEEF),
// Color(0xFFA999DB),
// ];
// levelColor = Color(0xFF887CB4);
// levelText = "LV4 ${S.of(context).zuanshihuiyuan}";
// break;
// }
// case 5:
// {
// linearColor = [
// Color(0xFFEEEEEF),
// Color(0xFF000000),
// ];
// levelColor = Color(0xFF000000);
// levelText = "LV5 ${S.of(context).zhizunhuiyuan}";
// break;
// }
4 years ago
}
3 years ago
3 years ago
bool isUserVip = (userInfo == null);
3 years ago
Widget widget = Container(
3 years ago
margin: isUserVip
? EdgeInsets.fromLTRB(padding.w, 16.h, padding.w, 8.h)
: EdgeInsets.fromLTRB(padding.w, 16.h, padding.w, 0),
3 years ago
width: MediaQuery.of(context).size.width - 32.w,
3 years ago
height: ((MediaQuery.of(context).size.width - 32.w) /
(isUserVip ? 1.88 : 1.90) *
3 years ago
AppUtils.textScale(context)),
3 years ago
decoration: BoxDecoration(
gradient: LinearGradient(
colors: linearColor,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
3 years ago
borderRadius: isUserVip
? BorderRadius.circular(8)
: BorderRadius.vertical(top: Radius.circular(8)),
3 years ago
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
3 years ago
),
3 years ago
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
3 years ago
mainAxisAlignment: MainAxisAlignment.spaceBetween,
3 years ago
crossAxisAlignment: CrossAxisAlignment.start,
3 years ago
children: [
3 years ago
Container(
height: 86.w,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.fromLTRB(9.w, 4.h, 8.w, 4.h),
decoration: BoxDecoration(
color: levelColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
bottomRight: Radius.circular(8),
4 years ago
),
3 years ago
),
child: Text(
topLeft,
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: Colors.white,
4 years ago
),
3 years ago
),
3 years ago
),
3 years ago
Container(
margin: EdgeInsets.only(left: 13.w),
child: Text(
levelText,
style: TextStyle(
color: textColor,
3 years ago
fontWeight: MyFontWeight.semi_bold,
3 years ago
fontSize: 23.sp,
),
),
3 years ago
),
3 years ago
],
),
3 years ago
),
3 years ago
Container(
margin: EdgeInsets.only(right: 11.w, bottom: 9.h),
child: Image.asset(
"assets/image/icon_mine_huixiang_logo.png",
width: 86.w,
height: 86.w,
fit: BoxFit.contain,
),
),
],
),
Expanded(
child: Container(
margin: EdgeInsets.only(
left: 13.w,
right: 12.w,
bottom: 12.h,
),
child: Column(
3 years ago
mainAxisAlignment: MainAxisAlignment.spaceAround,
3 years ago
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
3 years ago
children: [
3 years ago
Expanded(
child: Text(
// rank > rankMax
// ? S.of(context).dangqiandengji
// : "${S.of(context).jifen_(rankMax - rank)} ${S.of(context).daoxiayidengji}",
!(showRank??true)?"":((vipLevel < curLevel)?"":(((rank ?? 0) > rankMax || curLevel == 3 || curLevel ==2)
3 years ago
? S.of(context).dangqiandengji
3 years ago
: "消费¥${rankMax - (rank ?? 0)}${S.of(context).daoxiayidengji}")),
3 years ago
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: textColor,
3 years ago
fontWeight: MyFontWeight.regular,
3 years ago
fontSize: 14.sp,
),
),
flex: 1,
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: !(showRank??true)?(vipLevel == 3?"":rankMax.toString()):((vipLevel < curLevel)?rankMax.toString():rank.toString()),
3 years ago
style: TextStyle(
3 years ago
fontSize: 26.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: textColor,
),
3 years ago
),
if(vipLevel == 3 && !(showRank??true))
3 years ago
TextSpan(
text: "${price??""}/永久" ,
3 years ago
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
color: textColor,
3 years ago
),
3 years ago
),
if ((rank ?? 0) <= rankMax && (showRank??true))
TextSpan(
text: rankMax > 0 ? "/$rankMax" : "/0",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
color: textColor,
),
),
3 years ago
],
),
3 years ago
),
3 years ago
],
),
3 years ago
if(vipLevel <= curLevel && (showRank??true))
3 years ago
Container(
height: 8.h,
child: ClipRRect(
borderRadius: BorderRadius.circular(6.5),
child: LinearProgressIndicator(
3 years ago
value: rankMax > (rank ?? 0) ? ((vipLevel < curLevel) ? rankMax/rankMax: (rank ?? 0) / rankMax) : 0,
3 years ago
backgroundColor: Colors.white,
color: levelColor,
),
),
),
3 years ago
// if (isUserVip)
Expanded(child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
S.of(context).kaitongriqi(
(createTime != null && createTime != "")
? createTime.split(" ")[0]
: "$createTime"
),
style: TextStyle(
color: textColor,
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
),
),
Icon(
Icons.qr_code,
size: 24,
color:textColor,
),
],
),),
3 years ago
],
3 years ago
),
3 years ago
),
flex: 1,
3 years ago
),
3 years ago
],
4 years ago
),
);
3 years ago
return GestureDetector(
onTap: () {
if (userInfo != null) {
SharedPreferences.getInstance().then((value) {
if (value.getString("token") == null ||
value.getString("token") == "") {
LoginTipsDialog().show(context);
return;
}
// Navigator.of(context)
// .pushNamed('/router/mine_vip_level_page', arguments: {
// "rankLevel": curLevel,
// "createTime": (userInfo != null) ? "${userInfo.createTime}" : "",
// "points": (userInfo != null) ? int.tryParse(userInfo.points) : 0,
// });
3 years ago
Navigator.of(context)
.pushNamed('/router/mine_vip_core', arguments: {
3 years ago
"rankLevel": curLevel,
"userInfo":userInfo.masterCardRankName,
3 years ago
3 years ago
"createTime": (userInfo != null) ? "${userInfo.createTime}" : "",
"expendAmount": double.tryParse(userInfo?.expendAmount??"0").toInt(),
3 years ago
});
});
}
},
3 years ago
child: widget,
//(tag == null || tag == "")
// ? widget
// : Hero(tag: tag, child: widget)
3 years ago
);
4 years ago
}
}