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.

595 lines
21 KiB

4 years ago
import 'package:barcode_widget/barcode_widget.dart';
4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
3 years ago
import 'package:flutter_easyloading/flutter_easyloading.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
3 years ago
import 'package:huixiang/retrofit/data/product.dart';
4 years ago
import 'package:huixiang/retrofit/data/vip_card.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/store/scan.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
3 years ago
import 'package:huixiang/utils/location.dart';
4 years ago
import 'package:huixiang/utils/painter_bg.dart';
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:huixiang/view_widget/my_footer.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class VipDetailPage extends StatefulWidget {
4 years ago
final Map<String, dynamic> arguments;
VipDetailPage({this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _VipDetailPage();
}
}
class _VipDetailPage extends State<VipDetailPage> {
4 years ago
ApiService apiService;
3 years ago
@override
void dispose() {
super.dispose();
refreshController.dispose();
3 years ago
Location.getInstance().stopLocation();
3 years ago
}
4 years ago
@override
void initState() {
super.initState();
3 years ago
3 years ago
vipDetail("", "");
3 years ago
startLocation();
}
startLocation() async {
3 years ago
// EasyLoading.show(status: S.current.zhengzaijiazai);
Location.getInstance().startLocation(context, (BaiduLocation result) {
if (result != null &&
result.latitude != null &&
result.longitude != null) {
vipDetail(result.latitude, result.longitude);
3 years ago
} else {
EasyLoading.dismiss();
3 years ago
}
}).then((value) {
3 years ago
if (!value) {
EasyLoading.dismiss();
refreshController.refreshFailed();
}
});
4 years ago
}
VipCard vipCard;
4 years ago
final RefreshController refreshController = RefreshController();
int current = 1;
4 years ago
3 years ago
vipDetail(latitude, longitude) async {
3 years ago
final SharedPreferences value = await SharedPreferences.getInstance();
if(apiService == null)
apiService = ApiService(Dio(), context: context, token: value.getString("token"));
3 years ago
BaseData<VipCard> baseData = await apiService.vipDetail({
3 years ago
"id": widget.arguments["id"],
"latitude": "$latitude",
"longitude": "$longitude",
3 years ago
}).catchError((onError) {});
4 years ago
if (baseData != null && baseData.isSuccess) {
3 years ago
vipCard = baseData.data;
4 years ago
refreshController.loadComplete();
} else {
refreshController.loadFailed();
}
3 years ago
print("object:object");
setState(() {});
4 years ago
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).huiyuankaxiangqing,
titleColor: Colors.white,
background: Color(0xFF3A405A),
3 years ago
brightness: Brightness.dark,
4 years ago
leadingColor: Colors.white,
4 years ago
),
4 years ago
body: Column(
children: [
Stack(
children: [
4 years ago
CustomPaint(
painter: BgPainter(
bgColor: Color(0xFF3A405A),
bezierHeight: 30.h,
),
child: Container(
height: 220.h,
),
4 years ago
),
4 years ago
buildVipCard(),
4 years ago
],
),
Padding(
3 years ago
padding: EdgeInsets.only(left: 16.w, top: 32.h, bottom: 8.h),
4 years ago
child: Row(
children: [
Text(
S.of(context).shiyongmendian,
4 years ago
overflow: TextOverflow.ellipsis,
style: TextStyle(
4 years ago
fontSize: 16.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Colors.black,
),
),
4 years ago
SizedBox(
4 years ago
width: 8.w,
4 years ago
),
4 years ago
Image.asset(
"assets/image/icon_shop.webp",
4 years ago
),
],
4 years ago
),
4 years ago
),
Expanded(
4 years ago
child: SmartRefresher(
controller: refreshController,
enablePullDown: false,
enablePullUp: true,
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
physics: BouncingScrollPhysics(),
child: ListView.builder(
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {},
3 years ago
child: shopItem(vipCard.storeList[position]),
4 years ago
);
},
3 years ago
padding: EdgeInsets.symmetric(vertical: 1),
3 years ago
itemCount: (vipCard != null && vipCard.storeList != null)
3 years ago
? vipCard.storeList.length
: 0,
4 years ago
),
4 years ago
),
4 years ago
),
4 years ago
],
4 years ago
),
);
}
4 years ago
Widget buildVipCard() {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
height: 220.h,
4 years ago
decoration: BoxDecoration(
3 years ago
borderRadius: BorderRadius.circular(8.w),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
4 years ago
child: Stack(
// alignment: Alignment.center,
children: [
Image.asset(
"assets/image/icon_vip_bj.webp",
4 years ago
fit: BoxFit.fill, //填充剩余空间
4 years ago
height: 220.h,
4 years ago
),
Container(
4 years ago
padding: EdgeInsets.all(16.w),
4 years ago
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
4 years ago
MImage(
3 years ago
(vipCard?.storeList?.length ?? 0) > 0
? vipCard.storeList[0].logo
: "",
3 years ago
width: 40,
height: 40,
3 years ago
radius: BorderRadius.circular(4),
4 years ago
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
4 years ago
),
SizedBox(
3 years ago
width: 8.w,
4 years ago
),
Expanded(
child: Container(
4 years ago
height: 54.h,
4 years ago
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
4 years ago
Expanded(
child: Text(
3 years ago
vipCard != null ? vipCard.tenantName : "",
4 years ago
overflow: TextOverflow.ellipsis,
style: TextStyle(
3 years ago
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Colors.black,
),
4 years ago
),
4 years ago
flex: 1,
4 years ago
),
Image.asset(
"assets/image/icon_vip.webp",
4 years ago
),
],
),
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
3 years ago
text: S.of(context).huiyuanka,
4 years ago
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
4 years ago
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
textDirection: TextDirection.ltr,
),
],
),
),
flex: 1,
)
],
),
4 years ago
Expanded(
child: Container(),
flex: 1,
4 years ago
),
4 years ago
Padding(
4 years ago
padding: EdgeInsets.only(left: 32.w, right: 32.w),
4 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
text:
3 years ago
"¥ ${vipCard != null ? vipCard.balance : ""}",
4 years ago
style: TextStyle(
fontSize: 24.sp,
3 years ago
fontWeight: MyFontWeight.medium,
4 years ago
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
),
GestureDetector(
4 years ago
onTap: () {
Navigator.of(context).pushNamed(
'/router/vip_balance',
arguments: {"storeId": vipCard.id});
4 years ago
},
4 years ago
child: Row(
4 years ago
children: [
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
text: S.of(context).yue,
style: TextStyle(
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
),
Icon(
Icons.keyboard_arrow_right,
4 years ago
color: Colors.black,
4 years ago
size: 22.5,
),
],
),
),
],
),
Column(
children: [
Text.rich(
3 years ago
TextSpan(
children: [
TextSpan(
text: "0",
style: TextStyle(
fontSize: 24.sp,
3 years ago
fontWeight: MyFontWeight.medium,
3 years ago
color: Colors.black,
),
4 years ago
),
3 years ago
],
),
4 years ago
),
4 years ago
SizedBox(
4 years ago
height: 5.h,
4 years ago
),
4 years ago
Text.rich(
4 years ago
TextSpan(
children: [
TextSpan(
text: S.of(context).jifen,
style: TextStyle(
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Colors.black,
),
4 years ago
),
4 years ago
],
),
4 years ago
),
],
),
],
4 years ago
),
),
Column(
children: [
Padding(
4 years ago
padding: EdgeInsets.only(top: 5.h, bottom: 5.h),
4 years ago
child: Text(
4 years ago
vipCard != null
? "${vipCard.id.substring(0, 4)} "
3 years ago
"${vipCard.id.substring(4, 8)} "
"${vipCard.id.substring(8, 12)} "
"${vipCard.id.substring(12, 16)} "
"${vipCard.id.substring(16, vipCard.id.length)}"
4 years ago
: "",
4 years ago
maxLines: 1,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
4 years ago
wordSpacing: vipCard == null
? 10
: (MediaQuery.of(context).size.width - 64.w) /
3 years ago
(((vipCard.id.length) * 4)),
4 years ago
letterSpacing: vipCard == null
? 8
: (MediaQuery.of(context).size.width - 64.w) /
3 years ago
(((vipCard.id.length) * 4)),
4 years ago
),
4 years ago
),
),
BarcodeWidget(
barcode: Barcode.code128(),
3 years ago
data: vipCard == null ? "" : vipCard.id,
4 years ago
height: 30.h,
4 years ago
color: Colors.black,
drawText: false,
3 years ago
),
4 years ago
],
4 years ago
)
],
4 years ago
),
),
],
),
);
}
3 years ago
Widget shopItem(StoreListBean store) {
4 years ago
return Container(
3 years ago
margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
children: [
Expanded(
3 years ago
flex: 1,
child: Text(
(store != null) ? store.storeName : "",
style: TextStyle(
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
3 years ago
color: Colors.black,
),
),
),
GestureDetector(
3 years ago
onTap: () {
3 years ago
// Navigator.of(context).pushNamed('/router/union_detail_page',
// arguments: {"id": store.id});
if(store.posType.code == "NORMALSTORE") {
Scan.toScan(
context,
store.id,
store.tenantCode,
store.storeName,
);
} else {
Navigator.of(context).pushNamed(
'/router/store_order',
arguments: {
"id": store.id,
"tenant": store.tenantCode,
"storeName": store.storeName
},
);
}
},
3 years ago
child: Text(
3 years ago
S.of(context).chakan,
4 years ago
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.medium,
color: Color(0xff32A060),
4 years ago
),
),
4 years ago
),
Icon(
Icons.chevron_right,
color: Color(0xff32A060),
size: 16,
),
4 years ago
],
),
SizedBox(
height: 8.h,
),
Row(
children: [
Text(
3 years ago
"${S.of(context).dizhi}: ",
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
color: Color(0xff353535),
4 years ago
),
),
3 years ago
Expanded(
child: Text(
store.address,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xff353535),
),
),
3 years ago
flex: 1,
)
],
4 years ago
),
SizedBox(
height: 4.h,
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
children: [
3 years ago
Expanded(
flex: 1,
child: Text(
S.of(context).yingyeshijian((store.openStartTime == null &&
store.openEndTime == null)
? S.of(context).quantian
: "${store.openStartTime.substring(0, store.openStartTime.lastIndexOf(":"))} - ${store.openEndTime.substring(0, store.openEndTime.lastIndexOf(":"))}"),
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xff353535),
),
),
4 years ago
),
3 years ago
Text(
(store.distance ?? 0) > 1000
3 years ago
? S.of(context).gongli(
((store.distance ?? 0) / 1000 * 100).toInt() / 100.0)
: S
.of(context)
.mi(((store.distance ?? 0) * 100).toInt() / 100.0),
style: TextStyle(
fontSize: 12.sp,
3 years ago
fontWeight: MyFontWeight.regular,
color: Color(0xff868686),
),
),
],
4 years ago
),
],
),
);
}
4 years ago
bool isRemake = true;
String totalPrice(orderInfo) {
if (orderInfo == null) return "";
3 years ago
double totalPrice = (double.tryParse(orderInfo.orderSum) +
double.tryParse(orderInfo.postFee));
if (orderInfo.orderDetail != null &&
orderInfo.orderDetail.couponDTO != null) {
4 years ago
totalPrice -= double.tryParse(orderInfo.orderDetail.couponDTO.money);
}
return "$totalPrice";
}
List<Widget> goodsItem(List<ProductsList> products) {
4 years ago
if (products == null) return [];
if (products.length > 3) {
products = products.sublist(0, 3);
}
3 years ago
return products
.map(
(e) => Container(
3 years ago
margin: EdgeInsets.symmetric(horizontal: 2.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
MImage(
e.skuImg,
width: 75.w,
height: 75.h,
fit: BoxFit.contain,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
4 years ago
),
3 years ago
SizedBox(
height: 4.h,
),
if (isRemake)
Container(
width: 75.w,
child: Text(
e.productName,
maxLines: 1,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.sp,
3 years ago
fontWeight: MyFontWeight.regular,
3 years ago
color: Color(0xFF353535),
),
),
),
],
),
),
3 years ago
)
.toList();
4 years ago
}
4 years ago
}