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