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.
645 lines
21 KiB
645 lines
21 KiB
import 'package:barcode_widget/barcode_widget.dart'; |
|
import 'package:dio/dio.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/page.dart'; |
|
import 'package:huixiang/retrofit/data/product.dart'; |
|
import 'package:huixiang/retrofit/data/user_bill.dart'; |
|
import 'package:huixiang/retrofit/data/vip_card.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/store/scan.dart'; |
|
import 'package:huixiang/utils/font_weight.dart'; |
|
import 'package:huixiang/utils/location.dart'; |
|
import 'package:huixiang/utils/painter_bg.dart'; |
|
import 'package:huixiang/view_widget/classic_header.dart'; |
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
import 'package:huixiang/view_widget/my_appbar.dart'; |
|
import 'package:huixiang/view_widget/my_footer.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
class MineShopDetails extends StatefulWidget { |
|
final Map<String, dynamic> arguments; |
|
|
|
MineShopDetails({this.arguments}); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _MineShopDetails(); |
|
} |
|
} |
|
|
|
class _MineShopDetails extends State<MineShopDetails> { |
|
ApiService apiService; |
|
int selectType = 0; |
|
List<UserBill> userBill = []; |
|
|
|
@override |
|
void dispose() { |
|
super.dispose(); |
|
refreshController.dispose(); |
|
consumeRefreshController.dispose(); |
|
Location.getInstance().stopLocation(); |
|
} |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
SharedPreferences.getInstance().then((value) { |
|
apiService = |
|
ApiService(Dio(), token: value.getString("token"), context: context); |
|
vipDetail("", ""); |
|
}); |
|
startLocation(); |
|
} |
|
|
|
VipCard vipCard; |
|
final RefreshController refreshController = RefreshController(); |
|
final RefreshController consumeRefreshController = RefreshController(); |
|
int current = 1; |
|
|
|
vipDetail(latitude, longitude) async { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
if (apiService == null) |
|
apiService = |
|
ApiService(Dio(), context: context, token: value.getString("token")); |
|
BaseData<VipCard> baseData = await apiService.vipDetail({ |
|
"id": widget.arguments["id"], |
|
"latitude": "$latitude", |
|
"longitude": "$longitude", |
|
}).catchError((onError) {}); |
|
if (baseData != null && baseData.isSuccess) { |
|
vipCard = baseData.data; |
|
refreshController.loadComplete(); |
|
} else { |
|
refreshController.loadFailed(); |
|
} |
|
print("object:object"); |
|
setState(() {}); |
|
} |
|
|
|
startLocation() async { |
|
// EasyLoading.show(status: S.current.zhengzaijiazai); |
|
Location.getInstance() |
|
.aMapFlutterLocation |
|
.onResultCallback() |
|
.listen((event) { |
|
if (event != null && |
|
event["latitude"] != null && |
|
event["longitude"] != null) { |
|
vipDetail(event["latitude"], event["longitude"]); |
|
} else { |
|
EasyLoading.dismiss(); |
|
} |
|
}); |
|
Location.getInstance().prepareLoc(); |
|
Location.getInstance().startLocation(context).then((value) { |
|
if (!value) { |
|
EasyLoading.dismiss(); |
|
refreshController.refreshFailed(); |
|
} |
|
}); |
|
} |
|
|
|
billInfo() async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService(Dio(), |
|
context: context, token: value.getString("token"), showLoading: true); |
|
} |
|
BaseData<PageInfo<UserBill>> baseData = await apiService.queryBillInfo({ |
|
"current": current, |
|
"model": {"category": "", "title": "bill_title_balance", "type": ""}, |
|
"order": "descending", |
|
"size": 10, |
|
"sort": "id" |
|
}).catchError((onError) { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
consumeRefreshController.refreshFailed(); |
|
consumeRefreshController.loadFailed(); |
|
}); |
|
if (baseData != null && baseData.isSuccess) { |
|
if (current == 1) { |
|
userBill.clear(); |
|
} |
|
userBill.addAll(baseData.data.records); |
|
refreshController.refreshCompleted(); |
|
refreshController.loadComplete(); |
|
consumeRefreshController.refreshCompleted(); |
|
consumeRefreshController.loadComplete(); |
|
if (current * 10 > int.tryParse(baseData.data.total)) { |
|
refreshController.loadNoData(); |
|
consumeRefreshController.loadNoData(); |
|
} else { |
|
current += 1; |
|
} |
|
} else { |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
consumeRefreshController.refreshFailed(); |
|
consumeRefreshController.loadFailed(); |
|
} |
|
if (mounted) setState(() {}); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: MyAppBar( |
|
title: S.of(context).huiyuankaxiangqing, |
|
titleColor: Colors.black, |
|
background: Colors.white, |
|
brightness: Brightness.dark, |
|
leadingColor: Colors.black, |
|
), |
|
body: Column( |
|
children: [ |
|
buildVipCard(), |
|
Container( |
|
margin: EdgeInsets.only(left: 14.w), |
|
child: Row( |
|
children: [ |
|
GestureDetector( |
|
onTap: () { |
|
setState(() { |
|
selectType = 0; |
|
}); |
|
}, |
|
child: Column( |
|
children: [ |
|
Text( |
|
"适用门店", |
|
style: TextStyle( |
|
color: |
|
Color(selectType == 0 ? 0xFF000000 : 0xFF868686), |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
SizedBox( |
|
height: 8.h, |
|
), |
|
if (selectType == 0) |
|
Container( |
|
width: 52.w, |
|
height: 2.h, |
|
color: Color(0xFF32A060), |
|
) |
|
], |
|
), |
|
), |
|
SizedBox( |
|
width: 20.w, |
|
), |
|
// GestureDetector( |
|
// onTap: () { |
|
// setState(() { |
|
// selectType = 1; |
|
// billInfo(); |
|
// }); |
|
// }, |
|
// child: Column( |
|
// children: [ |
|
// Text( |
|
// "余额明细", |
|
// style: TextStyle( |
|
// color: |
|
// Color(selectType == 1 ? 0xFF000000 : 0xFF868686), |
|
// fontSize: 15.sp, |
|
// fontWeight: MyFontWeight.medium, |
|
// ), |
|
// ), |
|
// SizedBox( |
|
// height: 8.h, |
|
// ), |
|
// if (selectType == 1) |
|
// Container( |
|
// width: 52.w, |
|
// height: 2.h, |
|
// color: Color(0xFF32A060), |
|
// ) |
|
// ], |
|
// ), |
|
// ), |
|
], |
|
), |
|
), |
|
selectType == 0 |
|
? Expanded( |
|
child: SmartRefresher( |
|
controller: refreshController, |
|
enablePullDown: false, |
|
enablePullUp: false, |
|
footer: CustomFooter( |
|
builder: (context, mode) { |
|
return MyFooter(mode); |
|
}, |
|
), |
|
physics: BouncingScrollPhysics(), |
|
child: ListView.builder( |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () {}, |
|
child: shopItem(vipCard.storeList[position]), |
|
); |
|
}, |
|
padding: EdgeInsets.symmetric(vertical: 1), |
|
itemCount: (vipCard != null && vipCard.storeList != null) |
|
? vipCard.storeList.length |
|
: 0, |
|
), |
|
), |
|
) |
|
: Expanded( |
|
child: SmartRefresher( |
|
controller: consumeRefreshController, |
|
enablePullDown: true, |
|
enablePullUp: true, |
|
physics: BouncingScrollPhysics(), |
|
header: MyHeader(), |
|
footer: CustomFooter( |
|
builder: (context, mode) { |
|
return MyFooter(mode); |
|
}, |
|
), |
|
onRefresh: (){ |
|
current = 1; |
|
billInfo(); |
|
}, |
|
onLoading: () { |
|
billInfo(); |
|
}, |
|
child: ListView.builder( |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
onTap: () {}, |
|
child: consumeItem(userBill[position]), |
|
); |
|
}, |
|
shrinkWrap: true, |
|
padding: EdgeInsets.symmetric(vertical: 1), |
|
itemCount: userBill != null ? userBill.length : 0, |
|
)), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
int colorByName(String storeName) { |
|
if (storeName == null) return 0xFF32A060; |
|
if (storeName.contains("百年川椒") || storeName.contains("百年川椒")) { |
|
return 0xFFC30D23; |
|
} else if (storeName.contains("海峡姐妹") || storeName.contains("海峽姐妹")) { |
|
return 0xFFE4C796; |
|
} else if (storeName.contains("前进麦味") || storeName.contains("前進麥味")) { |
|
return 0xFF265782; |
|
} |
|
return 0xFF32A060; |
|
} |
|
|
|
Widget buildVipCard() { |
|
return Container( |
|
width: double.infinity, |
|
// height:140.h, |
|
margin: EdgeInsets.only(bottom: 24.h, top: 14.h, left: 14.w, right: 14.w), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Container( |
|
decoration: BoxDecoration( |
|
borderRadius: new BorderRadius.only( |
|
topLeft: Radius.circular(6), |
|
topRight: Radius.circular(6), |
|
), |
|
color: Color(colorByName(vipCard?.tenantName ?? "")), |
|
), |
|
padding: EdgeInsets.only(left: 12.w), |
|
height: 62.h, |
|
child: Row( |
|
children: [ |
|
MImage( |
|
(vipCard?.storeList?.length ?? 0) > 0 |
|
? vipCard.storeList[0].logo |
|
: "", |
|
width: 38, |
|
height: 38, |
|
radius: BorderRadius.circular(100), |
|
fit: BoxFit.cover, |
|
errorSrc: "assets/image/default_1.webp", |
|
fadeSrc: "assets/image/default_1.webp", |
|
), |
|
SizedBox( |
|
width: 6, |
|
), |
|
Text( |
|
vipCard != null ? vipCard.tenantName : "", |
|
style: TextStyle( |
|
color: Color(0xFFFFFFFF), |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
Container( |
|
decoration: BoxDecoration( |
|
borderRadius: new BorderRadius.only( |
|
bottomRight: Radius.circular(6), |
|
topRight: Radius.circular(6), |
|
), |
|
color: Colors.white, |
|
), |
|
padding: EdgeInsets.all(12.h), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
"店铺余额(元)", |
|
style: TextStyle( |
|
color: Color(0xFF262626), |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
Text( |
|
"No.${vipCard?.id ?? ""}", |
|
style: TextStyle( |
|
color: Color(0xFF262626), |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
], |
|
), |
|
SizedBox( |
|
height: 4.h, |
|
), |
|
Text( |
|
"¥${vipCard != null ? vipCard.balance : ""}", |
|
style: TextStyle( |
|
color: Color(0xFF262626), |
|
fontSize: 24.sp, |
|
fontWeight: MyFontWeight.bold, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget shopItem(StoreListBean store) { |
|
return Container( |
|
decoration: BoxDecoration( |
|
borderRadius: new BorderRadius.circular(6), |
|
color: Colors.white, |
|
), |
|
padding: EdgeInsets.all(12), |
|
margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
children: [ |
|
Expanded( |
|
flex: 1, |
|
child: Text( |
|
(store != null) ? store.storeName : "", |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: Colors.black, |
|
), |
|
), |
|
), |
|
GestureDetector( |
|
onTap: () { |
|
// 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 |
|
}, |
|
); |
|
} |
|
}, |
|
child: Text( |
|
S.of(context).chakan, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.medium, |
|
color: Color(0xff32A060), |
|
), |
|
), |
|
), |
|
Icon( |
|
Icons.chevron_right, |
|
color: Color(0xff32A060), |
|
size: 16, |
|
), |
|
], |
|
), |
|
SizedBox( |
|
height: 8.h, |
|
), |
|
Row( |
|
children: [ |
|
Text( |
|
"${S.of(context).dizhi}: ", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xff353535), |
|
), |
|
), |
|
Expanded( |
|
child: Text( |
|
store.address, |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xff353535), |
|
), |
|
), |
|
flex: 1, |
|
) |
|
], |
|
), |
|
SizedBox( |
|
height: 4.h, |
|
), |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
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, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xff353535), |
|
), |
|
), |
|
), |
|
Text( |
|
(store.distance ?? 0) > 1000 |
|
? 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, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xff868686), |
|
), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget consumeItem(UserBill userBill) { |
|
return Container( |
|
decoration: BoxDecoration( |
|
borderRadius: new BorderRadius.circular(6), |
|
color: Colors.white, |
|
), |
|
padding: EdgeInsets.all(12), |
|
margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
userBill.name ?? "", |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.semi_bold, |
|
color: Colors.black, |
|
), |
|
), |
|
SizedBox( |
|
height: 4, |
|
), |
|
Text( |
|
userBill.updateTime ?? "", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF4D4D4D), |
|
), |
|
), |
|
], |
|
), |
|
Text( |
|
"-${double.tryParse(userBill.number ?? "0").toInt().toString()}元", |
|
style: TextStyle( |
|
fontSize: 18.sp, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF4D4D4D), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
bool isRemake = true; |
|
|
|
String totalPrice(orderInfo) { |
|
if (orderInfo == null) return ""; |
|
double totalPrice = (double.tryParse(orderInfo.orderSum) + |
|
double.tryParse(orderInfo.postFee)); |
|
if (orderInfo.orderDetail != null && |
|
orderInfo.orderDetail.couponDTO != null) { |
|
totalPrice -= double.tryParse(orderInfo.orderDetail.couponDTO.money); |
|
} |
|
return "$totalPrice"; |
|
} |
|
|
|
List<Widget> goodsItem(List<ProductsList> products) { |
|
if (products == null) return []; |
|
if (products.length > 3) { |
|
products = products.sublist(0, 3); |
|
} |
|
return products |
|
.map( |
|
(e) => Container( |
|
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", |
|
), |
|
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, |
|
fontWeight: MyFontWeight.regular, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
), |
|
], |
|
), |
|
), |
|
) |
|
.toList(); |
|
} |
|
}
|
|
|