|
|
|
@ -2,6 +2,9 @@ import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:flutter_swiper/flutter_swiper.dart'; |
|
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/shoppingCart.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/min_api.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
|
|
|
import 'package:huixiang/store/shopping/shopping_home/recommend_goods_list_view.dart'; |
|
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
@ -23,12 +26,101 @@ class ShoppingCartPage extends StatefulWidget {
|
|
|
|
|
class _ShoppingCartPage extends State<ShoppingCartPage> |
|
|
|
|
with AutomaticKeepAliveClientMixin { |
|
|
|
|
ApiService apiService; |
|
|
|
|
MinApiService minService; |
|
|
|
|
ShoppingCart shopCarGoods; |
|
|
|
|
String pName; |
|
|
|
|
String pid; |
|
|
|
|
String cName; |
|
|
|
|
String cid; |
|
|
|
|
int tableId = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
|
super.initState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///清空购物车 |
|
|
|
|
clearShopCar() async { |
|
|
|
|
BaseData<bool> baseData = await minService.clearShoppingCart(); |
|
|
|
|
if (baseData.isSuccess) { |
|
|
|
|
shopCarGoods = null; |
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///查询购物车 |
|
|
|
|
Future<ShoppingCart> queryShopCar() async { |
|
|
|
|
pName="";//活动 |
|
|
|
|
pid="";//活动 |
|
|
|
|
cName="";//优惠券 |
|
|
|
|
cid="";//优惠券 |
|
|
|
|
BaseData<List<ShoppingCart>> baseDate = |
|
|
|
|
await minService.getShoppingCart(tableId); |
|
|
|
|
if (baseDate != null && |
|
|
|
|
baseDate.isSuccess && |
|
|
|
|
baseDate.data != null && |
|
|
|
|
baseDate.data.length > 0) { |
|
|
|
|
if( baseDate.data[0].selectDiscount ==1){ |
|
|
|
|
baseDate.data[0].couponList.forEach((element) { |
|
|
|
|
if(element.isMaxCoupon){ |
|
|
|
|
cName = element.promotionName; |
|
|
|
|
cid = element.id; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}else if(baseDate.data[0].selectDiscount==2){ |
|
|
|
|
baseDate.data[0].promotionInfoList.forEach((element) { |
|
|
|
|
if(element.isMaxPromotion){ |
|
|
|
|
pName=element.name; |
|
|
|
|
pid=element.id; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
return baseDate.data[0]; |
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// 购物车的key,用于刷新UI |
|
|
|
|
GlobalKey shopCartKey = GlobalKey(); |
|
|
|
|
|
|
|
|
|
///购物车➕1 |
|
|
|
|
Future<ShoppingCart> shopCartAdd( |
|
|
|
|
ShoppingCartSkuItemListBean cartSkuItem) async { |
|
|
|
|
Map<String, dynamic> shopCarTemp = shopCarGoods.toJson(); |
|
|
|
|
cartSkuItem.buyNum += 1; |
|
|
|
|
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; |
|
|
|
|
BaseData<List<ShoppingCart>> baseDate = |
|
|
|
|
await minService.shoppingCartSingle(shopCarTemp); |
|
|
|
|
if (baseDate.isSuccess) { |
|
|
|
|
this.shopCarGoods = await queryShopCar(); |
|
|
|
|
if (shopCartKey != null) { |
|
|
|
|
shopCartKey.currentState.setState(() {}); |
|
|
|
|
} |
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
return this.shopCarGoods; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///购物车➖1 |
|
|
|
|
Future<ShoppingCart> shopCartReduce( |
|
|
|
|
ShoppingCartSkuItemListBean cartSkuItem) async { |
|
|
|
|
Map<String, dynamic> shopCarTemp = shopCarGoods.toJson(); |
|
|
|
|
cartSkuItem.buyNum -= 1; |
|
|
|
|
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; |
|
|
|
|
BaseData<List<ShoppingCart>> baseDate = |
|
|
|
|
await minService.shoppingCartSingle(shopCarTemp); |
|
|
|
|
if (baseDate.isSuccess) { |
|
|
|
|
this.shopCarGoods = await queryShopCar(); |
|
|
|
|
if (shopCartKey != null) { |
|
|
|
|
shopCartKey.currentState.setState(() {}); |
|
|
|
|
} |
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
return this.shopCarGoods; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final SwiperController controller = SwiperController(); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|