|
|
|
@ -11,9 +11,11 @@ import 'package:huixiang/retrofit/data/activity.dart';
|
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/miNiDetail.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/shoppingCart.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/store_info.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/min_api.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
|
|
|
import 'package:huixiang/store/sku.dart'; |
|
|
|
|
import 'package:huixiang/store/store_view/product_sku.dart'; |
|
|
|
|
import 'package:huixiang/store/store_view/shop_car.dart'; |
|
|
|
|
import 'package:huixiang/store/store_view/store_activity.dart'; |
|
|
|
@ -48,17 +50,12 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
StoreInfo storeInfo; |
|
|
|
|
List<Activity> activitys; |
|
|
|
|
RefreshController refreshController; |
|
|
|
|
|
|
|
|
|
int allCount = 0; |
|
|
|
|
double allPrice = 0; |
|
|
|
|
StoreOrderListPage storeOrderListPage; |
|
|
|
|
|
|
|
|
|
List<Map<String, dynamic>> shopCarGoods = []; |
|
|
|
|
List<FindMiNiGroupList> appletProducts = []; |
|
|
|
|
List<ProductListBean> shopCar = []; |
|
|
|
|
|
|
|
|
|
ScrollController controller = ScrollController(); |
|
|
|
|
|
|
|
|
|
List<ShoppingCart> shopCarGoods; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
|
super.initState(); |
|
|
|
@ -74,16 +71,14 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_fc(int count, String productId, int allCount, double allPrice) { |
|
|
|
|
if (count == 0) { |
|
|
|
|
int index = |
|
|
|
|
shopCarGoods.indexWhere((element) => element["id"] == productId); |
|
|
|
|
shopCarGoods.removeAt(index); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setState(() { |
|
|
|
|
this.allCount = allCount; |
|
|
|
|
this.allPrice = allPrice; |
|
|
|
|
}); |
|
|
|
|
// if (count == 0) { |
|
|
|
|
// int index = shopCarGoods.indexWhere((element) => element.id == productId); |
|
|
|
|
// shopCarGoods.removeAt(index); |
|
|
|
|
// } |
|
|
|
|
// setState(() { |
|
|
|
|
// this.allCount = allCount; |
|
|
|
|
// this.allPrice = allPrice; |
|
|
|
|
// }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// 小程序登录 |
|
|
|
@ -102,10 +97,12 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
Map<String, dynamic> minStoreInfo = baseData.data; |
|
|
|
|
String minToken = minStoreInfo["token"]; |
|
|
|
|
String tenant = widget.arguments["tenant"]; |
|
|
|
|
String storeId = widget.arguments["id"]; |
|
|
|
|
SharedPreferences.getInstance().then( |
|
|
|
|
(value) => { |
|
|
|
|
value.setString('minToken', minToken), |
|
|
|
|
value.setString('tenant', tenant), |
|
|
|
|
value.setString('storeId', storeId), |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
minService = MinApiService( |
|
|
|
@ -113,6 +110,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
context: context, |
|
|
|
|
token: minToken, |
|
|
|
|
tenant: tenant, |
|
|
|
|
storeId: storeId, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -400,7 +398,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
child: RoundButton( |
|
|
|
|
width: 17, |
|
|
|
|
height: 17, |
|
|
|
|
text: "$allCount", |
|
|
|
|
text: "${allCount}", |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
@ -422,14 +420,12 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
SmartDialog.showToast("请选择要购买的商品~"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
getShopCarGoods(); |
|
|
|
|
|
|
|
|
|
Navigator.of(context).pushNamed( |
|
|
|
|
'/router/settlement', |
|
|
|
|
arguments: { |
|
|
|
|
"storeInfo": storeInfo, |
|
|
|
|
"shopGoods": shopCarGoods, |
|
|
|
|
"shopProduct": shopCar, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
@ -471,58 +467,36 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_productListResult(List<FindMiNiGroupList> appletProducts) { |
|
|
|
|
this.appletProducts = appletProducts; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///获取购物车内的商品 |
|
|
|
|
getShopCarGoods() { |
|
|
|
|
if (appletProducts == null || appletProducts.length == 0) return; |
|
|
|
|
shopCar = []; |
|
|
|
|
if (shopCarGoods != null && shopCarGoods.length > 0) { |
|
|
|
|
shopCarGoods.forEach((element) { |
|
|
|
|
appletProducts.forEach((element1) { |
|
|
|
|
element1.productList.forEach((element2) { |
|
|
|
|
if (element["id"] == element2.id) { |
|
|
|
|
shopCar.add(element2); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///购物车弹窗 |
|
|
|
|
showShoppingCart() { |
|
|
|
|
getShopCarGoods(); |
|
|
|
|
queryShopCar().then((value) { |
|
|
|
|
|
|
|
|
|
showModalBottomSheet( |
|
|
|
|
context: context, |
|
|
|
|
backgroundColor: Colors.transparent, |
|
|
|
|
builder: (context) { |
|
|
|
|
return ShopCar( |
|
|
|
|
shopCar, |
|
|
|
|
shopCarGoods, |
|
|
|
|
value, |
|
|
|
|
clearShopCar, |
|
|
|
|
toDownOrder, |
|
|
|
|
(int count, String productId, allCount, allPrice) { |
|
|
|
|
print("shopCarCount: $allCount allPrice: $allPrice "); |
|
|
|
|
setState(() { |
|
|
|
|
this.allCount = allCount; |
|
|
|
|
this.allPrice = allPrice; |
|
|
|
|
}); |
|
|
|
|
// print("shopCarCount: $allCount allPrice: $allPrice "); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///清空购物车 |
|
|
|
|
clearShopCar() { |
|
|
|
|
if (shopCarGoods != null) shopCarGoods.clear(); |
|
|
|
|
calculatePrice(); |
|
|
|
|
clearShopCar() async { |
|
|
|
|
BaseData<bool> baseData = await minService.clearShoppingCart(); |
|
|
|
|
if (baseData.isSuccess) { |
|
|
|
|
|
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///选规格 |
|
|
|
|
_queryMiNiDetail(String id) async { |
|
|
|
@ -533,83 +507,53 @@ class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///添加购物车 |
|
|
|
|
addsShoppingCart() async { |
|
|
|
|
BaseData baseDate = await apiService.creditOrder({ |
|
|
|
|
"parentId": widget.arguments["parentId"], |
|
|
|
|
"skuImg": null, |
|
|
|
|
"skuNameStr": widget.arguments["skuNameStr"], |
|
|
|
|
"skuPrice": widget.arguments["skuPrice"], |
|
|
|
|
"skuStock": widget.arguments["skuStock"], |
|
|
|
|
_addShopCar(Sku sku) async { |
|
|
|
|
if (sku != null) { |
|
|
|
|
BaseData<List<ShoppingCart>> baseDate = await minService.addShoppingCart({ |
|
|
|
|
"storeId": storeInfo.id, |
|
|
|
|
"storeName": storeInfo.storeName ?? "", |
|
|
|
|
"tableId": 0, |
|
|
|
|
"shoppingCartSkuItemList": [ |
|
|
|
|
{ |
|
|
|
|
"buyNum": sku.count, |
|
|
|
|
"id": sku.skuId, |
|
|
|
|
"platterList": [ |
|
|
|
|
{ |
|
|
|
|
"skuId": sku.skuId |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
"productId": sku.id, |
|
|
|
|
"productName": sku.name, |
|
|
|
|
"skuName": "", |
|
|
|
|
"storeId": storeInfo.id, |
|
|
|
|
} |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
if (baseDate != null && baseDate.isSuccess) {} |
|
|
|
|
if (baseDate != null && baseDate.isSuccess) { |
|
|
|
|
queryShopCar(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///查询购物车 |
|
|
|
|
Future<List<ShoppingCart>> queryShopCar() async { |
|
|
|
|
BaseData<List<ShoppingCart>> baseDate = await minService.getShoppingCart(0); |
|
|
|
|
if (baseDate != null && baseDate.isSuccess) { |
|
|
|
|
return baseDate.data; |
|
|
|
|
} else { |
|
|
|
|
return []; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///选规格弹窗 |
|
|
|
|
showStoreSelector(MiNiDetail miNiDetail, String id) async { |
|
|
|
|
var result = await showModalBottomSheet( |
|
|
|
|
showModalBottomSheet( |
|
|
|
|
context: context, |
|
|
|
|
backgroundColor: Colors.transparent, |
|
|
|
|
builder: (context) { |
|
|
|
|
return ProductSku(miNiDetail, id); |
|
|
|
|
return ProductSku(miNiDetail, id, _addShopCar); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
if (result != null) { |
|
|
|
|
result["name"] = miNiDetail.productName; |
|
|
|
|
miNiDetail.productSkuVOList.forEach((e0) { |
|
|
|
|
String attr1 = ""; |
|
|
|
|
String attr2 = ""; |
|
|
|
|
e0.skuAttrList.forEach((e2) { |
|
|
|
|
attr1 += e2.attrValueId; |
|
|
|
|
}); |
|
|
|
|
(result["attr"] as List).forEach((e1) { |
|
|
|
|
attr2 += e1["attrValue"]; |
|
|
|
|
}); |
|
|
|
|
if(attr1 == attr2){ |
|
|
|
|
result["skuId"] = e0.id; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
if (shopCarGoods == null || shopCarGoods.length == 0) { |
|
|
|
|
shopCarGoods = []; |
|
|
|
|
shopCarGoods.add(result); |
|
|
|
|
} else { |
|
|
|
|
Map<String, dynamic> map; |
|
|
|
|
shopCarGoods.forEach((element) { |
|
|
|
|
if (element["id"] == result["id"]) { |
|
|
|
|
map = element; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
if (map != null) { |
|
|
|
|
int index = shopCarGoods |
|
|
|
|
.indexWhere((element) => element["id"] == result["id"]); |
|
|
|
|
shopCarGoods.removeAt(index); |
|
|
|
|
shopCarGoods.insert(index, result); |
|
|
|
|
} else { |
|
|
|
|
shopCarGoods.add(result); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
calculatePrice(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
calculatePrice() { |
|
|
|
|
AiDecimalAccuracy allPriceDecimal = AiDecimalAccuracy.zero; |
|
|
|
|
int allCount = 0; |
|
|
|
|
shopCarGoods.forEach((element2) { |
|
|
|
|
if (element2["price"] != null && element2["price"] != "") { |
|
|
|
|
double singlePrice = double.tryParse(element2["price"]); |
|
|
|
|
allCount += element2["count"]; |
|
|
|
|
|
|
|
|
|
AiDecimalAccuracy aiDecimalAccuracy = |
|
|
|
|
AiDecimalAccuracy.fromInt(element2["count"]); |
|
|
|
|
AiDecimalAccuracy aiPrice = AiDecimalAccuracy.tryParse("$singlePrice"); |
|
|
|
|
|
|
|
|
|
allPriceDecimal += (aiPrice * aiDecimalAccuracy); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.allCount = allCount; |
|
|
|
|
this.allPrice = allPriceDecimal.toDouble(); |
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @override |
|
|
|
|