w-R 3 years ago
parent
commit
91be0a76fb
  1. 4
      lib/retrofit/retrofit_api.dart
  2. 539
      lib/store/shopping/shopping_cart/shopping_cart_page.dart

4
lib/retrofit/retrofit_api.dart

@ -91,8 +91,8 @@ abstract class ApiService {
headers["Environment"] = "app"; headers["Environment"] = "app";
} }
dio.options = BaseOptions( dio.options = BaseOptions(
connectTimeout: 60000, connectTimeout: 15000,
receiveTimeout: 60000, receiveTimeout: 15000,
headers: headers, headers: headers,
responseType: ResponseType.json, responseType: ResponseType.json,
); );

539
lib/store/shopping/shopping_cart/shopping_cart_page.dart

@ -16,8 +16,6 @@ import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:huixiang/view_widget/no_data_view.dart'; import 'package:huixiang/view_widget/no_data_view.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ShoppingCartPage extends StatefulWidget { class ShoppingCartPage extends StatefulWidget {
final String minToken; final String minToken;
@ -25,7 +23,8 @@ class ShoppingCartPage extends StatefulWidget {
final String tenant; final String tenant;
final StoreInfo storeInfo; final StoreInfo storeInfo;
ShoppingCartPage(this.minToken,this.storeId, this.tenant,this.storeInfo); ShoppingCartPage(this.minToken, this.storeId, this.tenant, this.storeInfo);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
return _ShoppingCartPage(); return _ShoppingCartPage();
@ -45,7 +44,6 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
bool topIndex = false; bool topIndex = false;
bool isAllSelect = false; bool isAllSelect = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -54,12 +52,12 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
/// ///
clearShopCar() async { clearShopCar() async {
shopCarGoods[0].shoppingCartSkuItemList.forEach((element) { shopCarGoods[0].shoppingCartSkuItemList.forEach((element) {
if(element.selected == 1){ if (element.selected == 1) {
shopCartAdd(element,-element.buyNum,element.selected); shopCartAdd(element, -element.buyNum, element.selected);
} }
}); });
queryShopCar(); queryShopCar();
} }
/// ///
@ -69,10 +67,10 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
arguments: { arguments: {
"storeInfo": widget.storeInfo, "storeInfo": widget.storeInfo,
"tableId": tableId, "tableId": tableId,
"pName":pName, "pName": pName,
"pid":pid, "pid": pid,
"cName":cName, "cName": cName,
"cid":cid, "cid": cid,
}, },
); );
queryShopCar(); queryShopCar();
@ -80,9 +78,8 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
/// ///
queryShopCar() async { queryShopCar() async {
if(widget.minToken == null) if (widget.minToken == null) return;
return; if (minService == null)
if(minService == null)
minService = MinApiService( minService = MinApiService(
Dio(), Dio(),
context: context, context: context,
@ -92,7 +89,7 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
showLoading: false, showLoading: false,
); );
BaseData<List<ShoppingCart>> baseData = BaseData<List<ShoppingCart>> baseData =
await minService.getShoppingCart(tableId).catchError((error) { await minService.getShoppingCart(tableId).catchError((error) {
refreshController.refreshFailed(); refreshController.refreshFailed();
}); });
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
@ -108,14 +105,13 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
/// ///
shopCartAdd( shopCartAdd(
ShoppingCartSkuItemListBean cartSkuItem,int count,int selected) async { ShoppingCartSkuItemListBean cartSkuItem, int count, int selected) async {
Map<String, dynamic> shopCarTemp = shopCarGoods[0].toJson(); Map<String, dynamic> shopCarTemp = shopCarGoods[0].toJson();
cartSkuItem.buyNum += count; cartSkuItem.buyNum += count;
cartSkuItem.selected = selected; cartSkuItem.selected = selected;
shopCarTemp["selected"] = selected; shopCarTemp["selected"] = selected;
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
BaseData baseDate = BaseData baseDate = await minService.shoppingCartSingle(shopCarTemp);
await minService.shoppingCartSingle(shopCarTemp);
if (baseDate.isSuccess) { if (baseDate.isSuccess) {
setState(() { setState(() {
queryShopCar(); queryShopCar();
@ -148,7 +144,7 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
background: Colors.transparent, background: Colors.transparent,
actions: [ actions: [
GestureDetector( GestureDetector(
onTap: (){ onTap: () {
setState(() { setState(() {
topIndex = !topIndex; topIndex = !topIndex;
}); });
@ -156,11 +152,12 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
child: Container( child: Container(
alignment: Alignment.center, alignment: Alignment.center,
margin: EdgeInsets.only(right: 12.w), margin: EdgeInsets.only(right: 12.w),
child: Text(!topIndex ? "管理" :S.of(context).quxiao, child: Text(
!topIndex ? "管理" : S.of(context).quxiao,
style: TextStyle( style: TextStyle(
fontSize: 18.sp, fontSize: 18.sp,
fontWeight: MyFontWeight.semi_bold, fontWeight: MyFontWeight.semi_bold,
color:Colors.black, color: Colors.black,
), ),
), ),
), ),
@ -200,9 +197,9 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
], ],
), ),
Align( Align(
alignment: Alignment(0.8,0.8), alignment: Alignment(0.8, 0.8),
child: Container( child: Container(
height:70.h, height: 70.h,
width: double.infinity, width: double.infinity,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
@ -216,127 +213,133 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
], ],
color: Color(0xFFFAFAFA), color: Color(0xFFFAFAFA),
), ),
padding: EdgeInsets.only(left: 16.w,right: 16.w), padding: EdgeInsets.only(left: 16.w, right: 16.w),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
GestureDetector( GestureDetector(
onTap: (){ onTap: () {
setState(() { setState(() {
isAllSelect = !isAllSelect; isAllSelect = !isAllSelect;
shopCarGoods[0].shoppingCartSkuItemList.forEach((element) { shopCarGoods[0]
element.selected = isAllSelect?1:0; .shoppingCartSkuItemList
shopCartAdd(element,0,element.selected); .forEach((element) {
element.selected = isAllSelect ? 1 : 0;
shopCartAdd(element, 0, element.selected);
}); });
}); });
}, },
child:Image.asset( child: Image.asset(
isAllSelect ? "assets/image/icon_radio_selected.webp" : isAllSelect
"assets/image/icon_radio_unselected.webp", ? "assets/image/icon_radio_selected.webp"
: "assets/image/icon_radio_unselected.webp",
width: 16, width: 16,
height: 16, height: 16,
), ),
), ),
SizedBox(width: 5.w), SizedBox(width: 5.w),
Expanded(child: Text( Expanded(
"全选", child: Text(
style: TextStyle( "全选",
fontSize: 12.sp, style: TextStyle(
fontWeight: MyFontWeight.regular, fontSize: 12.sp,
color: Color(0xFFA29E9E), fontWeight: MyFontWeight.regular,
color: Color(0xFFA29E9E),
),
), ),
),), ),
!topIndex ? !topIndex
Row( ? Row(
children: [
Text.rich(
TextSpan(
children: [ children: [
TextSpan( Text.rich(
text: "合计:", TextSpan(
style: TextStyle( children: [
fontSize: 12.sp, TextSpan(
fontWeight: MyFontWeight.regular, text: "合计:",
color: Colors.black, style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Colors.black,
),
),
TextSpan(
text: ((shopCarGoods?.length ?? 0) > 0)
? (shopCarGoods[0]?.cartSum ?? "")
: "",
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
],
), ),
), ),
TextSpan( GestureDetector(
text:((shopCarGoods?.length??0) > 0) ? (shopCarGoods[0]?.cartSum ?? "") : "", onTap: () {
style: TextStyle( toDownOrder();
fontSize: 20.sp, },
fontWeight: MyFontWeight.semi_bold, child: Container(
color: Color(0xFF32A060), alignment: Alignment.center,
width: 70.w,
height: 32.h,
margin: EdgeInsets.only(left: 6.w),
decoration: BoxDecoration(
color: Color(0xFF32A060),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
),
],
),
child: Text(
"结算",
style: TextStyle(
fontSize: 16.sp,
fontWeight: MyFontWeight.regular,
color: Colors.white,
),
),
), ),
), ),
], ],
), )
), : GestureDetector(
GestureDetector( onTap: () {
onTap:(){ clearShopCar();
toDownOrder(); },
}, child: Container(
child:Container( alignment: Alignment.center,
alignment: Alignment.center, width: 70.w,
width: 70.w, height: 32.h,
height: 32.h, margin: EdgeInsets.only(left: 6.w),
margin: EdgeInsets.only(left:6.w), decoration: BoxDecoration(
decoration: BoxDecoration( color: Color(0xFFFB312B),
color: Color(0xFF32A060), borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(16), boxShadow: [
boxShadow: [ BoxShadow(
BoxShadow( color: Colors.black.withAlpha(12),
color: Colors.black.withAlpha(12), offset: Offset(0, 3),
offset: Offset(0, 3), blurRadius: 14,
blurRadius: 14, spreadRadius: 0,
spreadRadius: 0, ),
],
), ),
], child: Text(
), "删除",
child: Text( style: TextStyle(
"结算", fontSize: 16.sp,
style: TextStyle( fontWeight: MyFontWeight.regular,
fontSize: 16.sp, color: Colors.white,
fontWeight: MyFontWeight.regular,
color: Colors.white,
),
),
),),
],
):
GestureDetector(
onTap: (){
clearShopCar();
},
child: Container(
alignment: Alignment.center,
width: 70.w,
height: 32.h,
margin: EdgeInsets.only(left:6.w),
decoration: BoxDecoration(
color: Color(0xFFFB312B),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
), ),
],
),
child: Text(
"删除",
style: TextStyle(
fontSize: 16.sp,
fontWeight: MyFontWeight.regular,
color: Colors.white,
), ),
), ),
), ),
),
], ],
), ),
), ),
@ -345,33 +348,34 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
); );
} }
Widget cartGoodsList(){ Widget cartGoodsList() {
return (shopCarGoods == null || shopCarGoods.length == 0) return (shopCarGoods == null || shopCarGoods.length == 0)
? NoDataView( ? NoDataView(
src: "assets/image/shopping_k.webp", src: "assets/image/shopping_k.webp",
isShowBtn: false, isShowBtn: false,
text:"目前暂无商品,要快去买点好吃的哦~", text: "目前暂无商品,要快去买点好吃的哦~",
fontSize: 16.sp, fontSize: 16.sp,
margin: EdgeInsets.only(top: 150.h), margin: EdgeInsets.only(top: 150.h),
): )
Container( : Container(
margin: EdgeInsets.only(bottom: 50.h), margin: EdgeInsets.only(bottom: 50.h),
child: ListView.builder( child: ListView.builder(
itemCount:((shopCarGoods?.length ?? 0) > 0) ? (shopCarGoods[0]?.shoppingCartSkuItemList?.length ?? 0) : 0, itemCount: ((shopCarGoods?.length ?? 0) > 0)
shrinkWrap: true, ? (shopCarGoods[0]?.shoppingCartSkuItemList?.length ?? 0)
padding: EdgeInsets.only( : 0,
top: 8.h, shrinkWrap: true,
bottom: 84.h, /* + (375.h - 88.h) + 4.h*/ padding: EdgeInsets.only(
), top: 8.h,
physics: BouncingScrollPhysics(), bottom: 84.h, /* + (375.h - 88.h) + 4.h*/
itemBuilder: (context, position) { ),
return InkWell( physics: BouncingScrollPhysics(),
onTap: () { itemBuilder: (context, position) {
}, return InkWell(
child: cartGoodsItem(position), onTap: () {},
); child: cartGoodsItem(position),
}), );
); }),
);
} }
Widget cartGoodsItem(index) { Widget cartGoodsItem(index) {
@ -395,127 +399,164 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
GestureDetector( GestureDetector(
onTap: (){ onTap: () {
setState(() { setState(() {
shopCarGoods[0].shoppingCartSkuItemList[index].selected = (shopCarGoods[0].shoppingCartSkuItemList[index].selected == 0) ? 1 : 0; shopCarGoods[0].shoppingCartSkuItemList[index].selected =
shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index],0,shopCarGoods[0].shoppingCartSkuItemList[index].selected); (shopCarGoods[0].shoppingCartSkuItemList[index].selected ==
0)
? 1
: 0;
shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index], 0,
shopCarGoods[0].shoppingCartSkuItemList[index].selected);
}); });
}, },
child:Image.asset( child: Image.asset(
(shopCarGoods[0].shoppingCartSkuItemList[index].selected==1) ? "assets/image/icon_radio_selected.webp" : (shopCarGoods[0].shoppingCartSkuItemList[index].selected == 1)
"assets/image/icon_radio_unselected.webp", ? "assets/image/icon_radio_selected.webp"
width:16, : "assets/image/icon_radio_unselected.webp",
height:16, width: 16,
height: 16,
), ),
), ),
SizedBox(width: 16.w), SizedBox(width: 16.w),
MImage( MImage(
shopCarGoods[0].shoppingCartSkuItemList[index]?.skuImg ?? "", shopCarGoods[0].shoppingCartSkuItemList[index]?.skuImg ?? "",
isCircle: true, isCircle: true,
width:81, width: 81,
height:81, height: 81,
fit: BoxFit.cover, fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp", errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp",
), ),
SizedBox(width: 10.w), SizedBox(width: 10.w),
Expanded(child: Expanded(
Container( child: Container(
height:81.h,child:Column( height: 81.h,
mainAxisAlignment: MainAxisAlignment.spaceBetween, child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Text( children: [
shopCarGoods[0].shoppingCartSkuItemList[index]?.productName ?? "", Text(
maxLines: 2, shopCarGoods[0]
overflow: TextOverflow.ellipsis, .shoppingCartSkuItemList[index]
style: TextStyle( ?.productName ??
fontSize: 14.sp, "",
fontWeight: MyFontWeight.medium, maxLines: 2,
color: Color(0xFF353535), overflow: TextOverflow.ellipsis,
), style: TextStyle(
), fontSize: 14.sp,
// SizedBox(height: 5.h), fontWeight: MyFontWeight.medium,
Text( color: Color(0xFF353535),
shopCarGoods[0].shoppingCartSkuItemList[index]?.skuName ?? "",
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF727272),
),
),
// SizedBox(height: 5.h),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(child:Text.rich(
TextSpan(
children: [
TextSpan(
text: "",
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
TextSpan(
text:shopCarGoods[0].shoppingCartSkuItemList[index]?.skuPrice ?? "",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
],
),
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,children: [
InkWell(
onTap: () {
setState(() {
if(shopCarGoods[0].shoppingCartSkuItemList[index].buyNum > 1)
shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index],-1,shopCarGoods[0].shoppingCartSkuItemList[index].selected);
});
},
child: Image.asset(
"assets/image/reduce.webp",
width: 22,
height: 22,
), ),
), ),
Container( // SizedBox(height: 5.h),
width: 30, Text(
alignment: Alignment.center, shopCarGoods[0].shoppingCartSkuItemList[index]?.skuName ??
child: Text( "",
shopCarGoods[0].shoppingCartSkuItemList[index]?.buyNum.toString() ?? 0, style: TextStyle(
style: TextStyle( fontSize: 10.sp,
color: Colors.black, fontWeight: MyFontWeight.medium,
fontSize: 14.sp, color: Color(0xFF727272),
fontWeight: MyFontWeight.medium,
),
), ),
), ),
InkWell( // SizedBox(height: 5.h),
onTap: () { Row(
setState(() { mainAxisAlignment: MainAxisAlignment.center,
shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index],1,shopCarGoods[0].shoppingCartSkuItemList[index].selected); crossAxisAlignment: CrossAxisAlignment.end,
}); children: [
}, Expanded(
child: Image.asset( child: Text.rich(
"assets/image/add.webp", TextSpan(
width: 22, children: [
height: 22, TextSpan(
), text: "",
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
TextSpan(
text: shopCarGoods[0]
.shoppingCartSkuItemList[index]
?.skuPrice ??
"",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
],
),
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
InkWell(
onTap: () {
setState(() {
if (shopCarGoods[0]
.shoppingCartSkuItemList[index]
.buyNum >
1)
shopCartAdd(
shopCarGoods[0]
.shoppingCartSkuItemList[index],
-1,
shopCarGoods[0]
.shoppingCartSkuItemList[index]
.selected);
});
},
child: Image.asset(
"assets/image/reduce.webp",
width: 22,
height: 22,
),
),
Container(
width: 30,
alignment: Alignment.center,
child: Text(
shopCarGoods[0]
.shoppingCartSkuItemList[index]
?.buyNum
.toString() ??
0,
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
),
),
),
InkWell(
onTap: () {
setState(() {
shopCartAdd(
shopCarGoods[0]
.shoppingCartSkuItemList[index],
1,
shopCarGoods[0]
.shoppingCartSkuItemList[index]
.selected);
});
},
child: Image.asset(
"assets/image/add.webp",
width: 22,
height: 22,
),
),
],
)
],
), ),
],) ],
], )),
), ),
],
)),),
], ],
), ),
); );

Loading…
Cancel
Save