w-R 3 years ago
parent
commit
91be0a76fb
  1. 4
      lib/retrofit/retrofit_api.dart
  2. 191
      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,
);

191
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();
@ -55,8 +53,8 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
///
clearShopCar() async {
shopCarGoods[0].shoppingCartSkuItemList.forEach((element) {
if(element.selected == 1){
shopCartAdd(element,-element.buyNum,element.selected);
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,
@ -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,39 +213,44 @@ 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(
Expanded(
child: Text(
"全选",
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Color(0xFFA29E9E),
),
),),
!topIndex ?
Row(
),
),
!topIndex
? Row(
children: [
Text.rich(
TextSpan(
@ -262,26 +264,27 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
),
),
TextSpan(
text:((shopCarGoods?.length??0) > 0) ? (shopCarGoods[0]?.cartSum ?? "") : "",
text: ((shopCarGoods?.length ?? 0) > 0)
? (shopCarGoods[0]?.cartSum ?? "")
: "",
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
],
),
),
GestureDetector(
onTap:(){
onTap: () {
toDownOrder();
},
child:Container(
child: Container(
alignment: Alignment.center,
width: 70.w,
height: 32.h,
margin: EdgeInsets.only(left:6.w),
margin: EdgeInsets.only(left: 6.w),
decoration: BoxDecoration(
color: Color(0xFF32A060),
borderRadius: BorderRadius.circular(16),
@ -302,18 +305,19 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
color: Colors.white,
),
),
),),
),
),
],
):
GestureDetector(
onTap: (){
)
: GestureDetector(
onTap: () {
clearShopCar();
},
child: Container(
alignment: Alignment.center,
width: 70.w,
height: 32.h,
margin: EdgeInsets.only(left:6.w),
margin: EdgeInsets.only(left: 6.w),
decoration: BoxDecoration(
color: Color(0xFFFB312B),
borderRadius: BorderRadius.circular(16),
@ -336,7 +340,6 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
),
),
),
],
),
),
@ -345,19 +348,21 @@ 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:"目前暂无商品,要快去买点好吃的哦~",
text: "目前暂无商品,要快去买点好吃的哦~",
fontSize: 16.sp,
margin: EdgeInsets.only(top: 150.h),
):
Container(
)
: Container(
margin: EdgeInsets.only(bottom: 50.h),
child: ListView.builder(
itemCount:((shopCarGoods?.length ?? 0) > 0) ? (shopCarGoods[0]?.shoppingCartSkuItemList?.length ?? 0) : 0,
itemCount: ((shopCarGoods?.length ?? 0) > 0)
? (shopCarGoods[0]?.shoppingCartSkuItemList?.length ?? 0)
: 0,
shrinkWrap: true,
padding: EdgeInsets.only(
top: 8.h,
@ -366,8 +371,7 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return InkWell(
onTap: () {
},
onTap: () {},
child: cartGoodsItem(position),
);
}),
@ -395,38 +399,48 @@ 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,
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(
Expanded(
child: Container(
height: 81.h,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
shopCarGoods[0].shoppingCartSkuItemList[index]?.productName ?? "",
shopCarGoods[0]
.shoppingCartSkuItemList[index]
?.productName ??
"",
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@ -437,7 +451,8 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
),
// SizedBox(height: 5.h),
Text(
shopCarGoods[0].shoppingCartSkuItemList[index]?.skuName ?? "",
shopCarGoods[0].shoppingCartSkuItemList[index]?.skuName ??
"",
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.medium,
@ -449,7 +464,8 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(child:Text.rich(
Expanded(
child: Text.rich(
TextSpan(
children: [
TextSpan(
@ -461,7 +477,10 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
),
),
TextSpan(
text:shopCarGoods[0].shoppingCartSkuItemList[index]?.skuPrice ?? "",
text: shopCarGoods[0]
.shoppingCartSkuItemList[index]
?.skuPrice ??
"",
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
@ -473,12 +492,22 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,children: [
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);
if (shopCarGoods[0]
.shoppingCartSkuItemList[index]
.buyNum >
1)
shopCartAdd(
shopCarGoods[0]
.shoppingCartSkuItemList[index],
-1,
shopCarGoods[0]
.shoppingCartSkuItemList[index]
.selected);
});
},
child: Image.asset(
@ -491,7 +520,11 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
width: 30,
alignment: Alignment.center,
child: Text(
shopCarGoods[0].shoppingCartSkuItemList[index]?.buyNum.toString() ?? 0,
shopCarGoods[0]
.shoppingCartSkuItemList[index]
?.buyNum
.toString() ??
0,
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
@ -502,7 +535,13 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
InkWell(
onTap: () {
setState(() {
shopCartAdd(shopCarGoods[0].shoppingCartSkuItemList[index],1,shopCarGoods[0].shoppingCartSkuItemList[index].selected);
shopCartAdd(
shopCarGoods[0]
.shoppingCartSkuItemList[index],
1,
shopCarGoods[0]
.shoppingCartSkuItemList[index]
.selected);
});
},
child: Image.asset(
@ -511,11 +550,13 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
height: 22,
),
),
],)
],
)
],
),
],
)),),
)),
),
],
),
);

Loading…
Cancel
Save