Browse Source

safety

master
fmk 3 years ago
parent
commit
6388601314
  1. 2
      lib/main.dart
  2. 1
      lib/retrofit/data/settlement_bean.dart
  3. 4
      lib/retrofit/data/shoppingCart.dart
  4. 8
      lib/retrofit/min_api.dart
  5. 22
      lib/retrofit/min_api.g.dart
  6. 635
      lib/settlement/settlement.dart
  7. 41
      lib/settlement/settlement_view/settlement_order_commodity.dart
  8. 71
      lib/store/sku.dart
  9. 248
      lib/store/store_order.dart
  10. 116
      lib/store/store_view/product_sku.dart
  11. 89
      lib/store/store_view/shop_car.dart
  12. 55
      lib/store/store_view/shop_goods.dart
  13. 65
      lib/store/store_view/store_order_list.dart

2
lib/main.dart

@ -54,7 +54,7 @@ import 'package:huixiang/setting/permission_setting_page.dart';
import 'package:huixiang/setting/setting_page.dart'; import 'package:huixiang/setting/setting_page.dart';
import 'package:huixiang/setting/treaty_page.dart'; import 'package:huixiang/setting/treaty_page.dart';
import 'package:huixiang/store/store_order.dart'; import 'package:huixiang/store/store_order.dart';
import 'package:huixiang/store/store_view/settlement.dart'; import 'package:huixiang/settlement/settlement.dart';
import 'package:huixiang/test_page.dart'; import 'package:huixiang/test_page.dart';
import 'package:huixiang/union/location_map_page.dart'; import 'package:huixiang/union/location_map_page.dart';

1
lib/retrofit/data/settlement_bean.dart

@ -7,6 +7,7 @@
/// promotionInfoDTO : {"couponId":0,"promotionId":0} /// promotionInfoDTO : {"couponId":0,"promotionId":0}
class SettlementBean { class SettlementBean {
SettlementBean({ SettlementBean({
int addressId, int addressId,
int buyNum, int buyNum,

4
lib/retrofit/data/shoppingCart.dart

@ -30,7 +30,7 @@ class ShoppingCart {
return shoppingCartBean; return shoppingCartBean;
} }
Map toJson() => { Map<String, dynamic> toJson() => {
"cartSum": cartSum, "cartSum": cartSum,
"numberOfPeople": numberOfPeople, "numberOfPeople": numberOfPeople,
"selected": selected, "selected": selected,
@ -71,7 +71,7 @@ class ShoppingCartSkuItemListBean {
String skuPrice; String skuPrice;
int skuStock; int skuStock;
String storeId; String storeId;
int tableId; String tableId;
static ShoppingCartSkuItemListBean fromJson(Map<String, dynamic> map) { static ShoppingCartSkuItemListBean fromJson(Map<String, dynamic> map) {
if (map == null) return null; if (map == null) return null;

8
lib/retrofit/min_api.dart

@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/address.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/placeOrderFirst.dart'; import 'package:huixiang/retrofit/data/placeOrderFirst.dart';
import 'package:huixiang/retrofit/data/settlement_bean.dart'; import 'package:huixiang/retrofit/data/settlement_bean.dart';
@ -164,9 +165,11 @@ abstract class MinApiService {
/// ///
@POST("order/getOrderInfo") @POST("order/getOrderInfo")
Future<BaseData<SettleOrderInfo>> getOrderInfo( Future<BaseData<SettleOrderInfo>> getOrderInfo(@Body() Map<String, dynamic> param);
@Body() Map<String, dynamic> param);
///
@GET("address/queryMemberAddress")
Future<BaseData<List<Address>>> queryAddress();
/// ///
@POST("order/placeOrderFirst") @POST("order/placeOrderFirst")
@ -175,4 +178,5 @@ abstract class MinApiService {
/// ///
@POST("order/settlement") @POST("order/settlement")
Future<BaseData> settlementApi(@Body() Map<String, dynamic> param); Future<BaseData> settlementApi(@Body() Map<String, dynamic> param);
} }

22
lib/retrofit/min_api.g.dart

@ -203,6 +203,28 @@ class _MinApiService implements MinApiService {
return value; return value;
} }
@override
Future<BaseData<List<Address>>> queryAddress() async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
final _result = await _dio.request<Map<String, dynamic>>(
'address/queryMemberAddress',
queryParameters: queryParameters,
options: RequestOptions(
method: 'GET',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<List<Address>>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<Address>((i) => Address.fromJson(i as Map<String, dynamic>))
.toList());
return value;
}
@override @override
Future<BaseData<dynamic>> placeOrderFirst(param) async { Future<BaseData<dynamic>> placeOrderFirst(param) async {
ArgumentError.checkNotNull(param, 'param'); ArgumentError.checkNotNull(param, 'param');

635
lib/store/store_view/settlement.dart → lib/settlement/settlement.dart

@ -2,11 +2,12 @@ import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_utils/flutter_baidu_mapapi_utils.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/order/order_view/order_commodity.dart'; import 'package:huixiang/retrofit/data/address.dart';
import 'package:huixiang/order/order_view/order_info.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/retrofit/data/placeOrderFirst.dart'; import 'package:huixiang/retrofit/data/placeOrderFirst.dart';
@ -15,14 +16,13 @@ import 'package:huixiang/retrofit/data/settlement_bean.dart';
import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/store/sku.dart'; import 'package:huixiang/settlement/settlement_view/settlement_order_commodity.dart';
import 'package:huixiang/store/store_view/settlement_order_commodity.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/utils/location.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:huixiang/view_widget/rename_dialog.dart';
import 'package:huixiang/view_widget/rename_dialog_content.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
import 'package:huixiang/view_widget/separator.dart'; import 'package:huixiang/view_widget/separator.dart';
import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -45,9 +45,6 @@ class _Settlement extends State<Settlement> {
SettleOrderInfo settleOrderInfo; SettleOrderInfo settleOrderInfo;
int selectedCouponIndex = -1; int selectedCouponIndex = -1;
List<ProductListBean> shopCar = [];
List<Sku> shopCarGoods = [];
TextEditingController _vc; TextEditingController _vc;
List<String> addressBgs = [ List<String> addressBgs = [
"assets/svg/dingdan_ziqu.svg", "assets/svg/dingdan_ziqu.svg",
@ -59,8 +56,6 @@ class _Settlement extends State<Settlement> {
void initState() { void initState() {
super.initState(); super.initState();
storeInfo = widget.arguments["storeInfo"]; storeInfo = widget.arguments["storeInfo"];
shopCar = widget.arguments["shopProduct"];
shopCarGoods = widget.arguments["shopGoods"];
_vc = TextEditingController( _vc = TextEditingController(
text: storeInfo != null ? storeInfo.headMobile : ""); text: storeInfo != null ? storeInfo.headMobile : "");
@ -68,24 +63,69 @@ class _Settlement extends State<Settlement> {
SharedPreferences.getInstance().then((value) { SharedPreferences.getInstance().then((value) {
String minToken = value.getString("minToken"); String minToken = value.getString("minToken");
String tenant = value.getString("tenant"); String tenant = value.getString("tenant");
String storeId = value.getString("storeId");
minService = MinApiService( minService = MinApiService(
Dio(), Dio(),
context: context, context: context,
token: minToken, token: minToken,
tenant: tenant, tenant: tenant,
storeId: storeId,
); );
queryOrderInfo(); queryOrderInfo(null, selectedBtn, null, 0, null);
});
startLocation();
}
BMFCoordinate myLatLng;
String distance = "0";
///
void startLocation() async {
Location.getInstance()
.aMapFlutterLocation
.onResultCallback()
.listen((event) {
if (event != null &&
event["latitude"] != null &&
event["longitude"] != null) {
print("location: $event");
if (event["latitude"] is String && event["longitude"] is String) {
myLatLng = BMFCoordinate(double.tryParse(event["latitude"]),
double.tryParse(event["longitude"]));
} else {
myLatLng = BMFCoordinate(event["latitude"], event["longitude"]);
}
calculateDistance();
}
}); });
Location.getInstance().prepareLoc();
Location.getInstance().startLocation(context);
}
///线
calculateDistance() async {
BMFCoordinate bmfCoordinate = BMFCoordinate(
double.tryParse(storeInfo.latitude),
double.tryParse(storeInfo.longitude));
double mi =
await BMFCalculateUtils.getLocationDistance(bmfCoordinate, myLatLng);
NumberFormat numberFormat = NumberFormat("#.#");
distance = "${numberFormat.format(mi / 1000)}";
print("distance: $distance");
setState(() {});
Location.getInstance().stopLocation();
} }
/// ///
queryOrderInfo() async { queryOrderInfo(
addressId, isTake, memberCouponId, orderId, promotionId) async {
BaseData<SettleOrderInfo> baseData = await minService.getOrderInfo({ BaseData<SettleOrderInfo> baseData = await minService.getOrderInfo({
"addressId": null, "addressId": addressId,
"isTake": 0, "isTake": isTake,
"memberCouponId": null, "memberCouponId": memberCouponId,
"orderId": 0, "orderId": orderId,
"promotionId": null "promotionId": promotionId
}); });
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
setState(() { setState(() {
@ -94,6 +134,55 @@ class _Settlement extends State<Settlement> {
} }
} }
Address address;
queryAddress() async {
if (address != null) {
queryOrderInfo(address.id, selectedBtn, null, 0, null);
return;
}
BaseData<List<Address>> baseDate =
await minService.queryAddress().catchError((error) {});
BMFCoordinate bmfCoordinate = BMFCoordinate(
double.tryParse(storeInfo.latitude),
double.tryParse(storeInfo.longitude),
);
if (baseDate != null && baseDate.isSuccess) {
address = baseDate.data[0];
for (int i = 1; i < baseDate.data.length; i++) {
Address address1 = baseDate.data[i];
BMFCoordinate coordinate = await BMFCalculateUtils.coordConvert(
coordinate: BMFCoordinate(
double.tryParse(address.longitude),
double.tryParse(address.latitude),
),
fromType: BMF_COORD_TYPE.COMMON,
toType: BMF_COORD_TYPE.BD09LL);
BMFCoordinate coordinate1 = await BMFCalculateUtils.coordConvert(
coordinate: BMFCoordinate(
double.tryParse(address1.longitude),
double.tryParse(address1.latitude),
),
fromType: BMF_COORD_TYPE.COMMON,
toType: BMF_COORD_TYPE.BD09LL);
double mi = await BMFCalculateUtils.getLocationDistance(
bmfCoordinate, coordinate);
double mi1 = await BMFCalculateUtils.getLocationDistance(
bmfCoordinate, coordinate1);
print("address 1111: $mi");
print("address 11: $mi1");
if (mi1 < mi) {
address = address1;
}
}
queryOrderInfo(address.id, selectedBtn, null, 0, null);
}
}
/// ///
queryPlaceOrderFirst() async { queryPlaceOrderFirst() async {
PlaceOrderFirst placeOrderFirst = PlaceOrderFirst(); PlaceOrderFirst placeOrderFirst = PlaceOrderFirst();
@ -109,34 +198,21 @@ class _Settlement extends State<Settlement> {
placeOrderFirst.parentId = 0; placeOrderFirst.parentId = 0;
placeOrderFirst.payChannel = 1; placeOrderFirst.payChannel = 1;
placeOrderFirst.promotionInfoDTO = PlaceOrderFirstPromotionInfoDTO(); placeOrderFirst.promotionInfoDTO = PlaceOrderFirstPromotionInfoDTO();
placeOrderFirst.promotionInfoDTO.couponId = selectedCouponIndex == -1?null : settleOrderInfo.couponList[selectedCouponIndex].couponId; placeOrderFirst.promotionInfoDTO.couponId = selectedCouponIndex == -1
? null
: settleOrderInfo.couponList[selectedCouponIndex].couponId;
placeOrderFirst.promotionInfoDTO.promotionId = "0"; placeOrderFirst.promotionInfoDTO.promotionId = "0";
placeOrderFirst.recMobile = storeInfo.headMobile; placeOrderFirst.recMobile = storeInfo.headMobile;
placeOrderFirst.shoppingCartSkuItemList = []; placeOrderFirst.shoppingCartSkuItemList = [];
placeOrderFirst.skuItemDTOList = []; placeOrderFirst.skuItemDTOList = [];
shopCarGoods.forEach((e0) {
SkuItemDTOList skuItemDTOListBean = SkuItemDTOList();
skuItemDTOListBean.skuId = e0.skuId;
skuItemDTOListBean.buyNum = e0.count;
PlatterList platterListBean = PlatterList();
platterListBean.skuId = e0.skuId;
platterListBean.productId = e0.id;
skuItemDTOListBean.platterList = [];
skuItemDTOListBean.platterList.add(platterListBean);
placeOrderFirst.skuItemDTOList.add(skuItemDTOListBean);
ShoppingCartSkuItemListBean shoppingCartSkuItemListBean = ShoppingCartSkuItemListBean();
shoppingCartSkuItemListBean.buyNum = e0.count;
shoppingCartSkuItemListBean.productId = e0.id;
shoppingCartSkuItemListBean.productName = e0.name;
shoppingCartSkuItemListBean.skuId = e0.skuId;
placeOrderFirst.shoppingCartSkuItemList.add(shoppingCartSkuItemListBean);
});
placeOrderFirst.source = 1; placeOrderFirst.source = 1;
placeOrderFirst.storeId = storeInfo.id; placeOrderFirst.storeId = storeInfo.id;
placeOrderFirst.subcribeTime = null; placeOrderFirst.subcribeTime = null;
placeOrderFirst.tableId = 0; placeOrderFirst.tableId = 0;
BaseData baseData = await minService.placeOrderFirst( BaseData baseData = await minService
placeOrderFirst.toJson()).catchError((error) {}); .placeOrderFirst(placeOrderFirst.toJson())
.catchError((error) {});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
querySettlement(); querySettlement();
} }
@ -150,97 +226,18 @@ class _Settlement extends State<Settlement> {
settlementBean.id = 0; settlementBean.id = 0;
settlementBean.isLogistics = true; settlementBean.isLogistics = true;
settlementBean.orderProductVOList = []; settlementBean.orderProductVOList = [];
shopCarGoods.forEach((e0) {
OrderProductVOList orderProductVOListBean = OrderProductVOList();
orderProductVOListBean.skuId = e0.skuId;
orderProductVOListBean.buyNum = e0.count;
ActInfo actInfoBean = ActInfo();
actInfoBean.couponDiscountAmount = 0;
actInfoBean.couponDiscountRate = 0;
actInfoBean.couponId = 0;
actInfoBean.couponType = 0;
actInfoBean.discountAmount = 0;
actInfoBean.discountRate = 0;
actInfoBean.promotionId = 0;
actInfoBean.promotionType = 0;
AdditionalComment additionalCommentBean = AdditionalComment();
additionalCommentBean.bizType = 0;
additionalCommentBean.commentImgs = "";
additionalCommentBean.commentImgsFlag = false;
additionalCommentBean.commentStar = 0;
additionalCommentBean.commentText = "";
additionalCommentBean.descStar = 0;
additionalCommentBean.hideFlag = true;
additionalCommentBean.id = 0;
additionalCommentBean.isDelete = true;
additionalCommentBean.likeNum = 0;
additionalCommentBean.logisticsStar = 0;
additionalCommentBean.mid = 0;
additionalCommentBean.orderProductId = 0;
additionalCommentBean.parentId = 0;
additionalCommentBean.productId = 0;
additionalCommentBean.sensitiveFlag = true;
additionalCommentBean.serviceStar = 0;
additionalCommentBean.storeId = 0;
settlementBean.buyNum = 0;
Comment commentBean = Comment();
commentBean.bizType = 0;
commentBean.commentImgs = "";
commentBean.commentImgsFlag = true;
commentBean.commentStar = 0;
commentBean.commentText = "";
commentBean.descStar = 0;
commentBean.hideFlag = true;
commentBean.id = 0;
commentBean.isDelete = true;
commentBean.logisticsStar = 0;
commentBean.mid = 0;
commentBean.orderProductId = 0;
commentBean.parentId = 0;
commentBean.productId = 0;
commentBean.sensitiveFlag = true;
commentBean.serviceStar = 0;
commentBean.storeId = 0;
orderProductVOListBean.commentStatus = 0;
orderProductVOListBean.discountAmount = 0;
orderProductVOListBean.id = 0;
orderProductVOListBean.productId = 0;
orderProductVOListBean.productName = "";
orderProductVOListBean.returnCode = "";
orderProductVOListBean.returnStatus = 0;
orderProductVOListBean.returnType = 0;
orderProductVOListBean.sellPrice = 0;
orderProductVOListBean.skuId = "0";
orderProductVOListBean.skuImg = "";
orderProductVOListBean.skuNameStr = "";
settlementBean.orderProductVOList.add(orderProductVOListBean);
});
settlementBean.payChannel = 0; settlementBean.payChannel = 0;
settlementBean.promotionInfoDTO = PromotionInfoDTO(); settlementBean.promotionInfoDTO = PromotionInfoDTO();
settlementBean.promotionInfoDTO.couponId = 0; settlementBean.promotionInfoDTO.couponId = 0;
settlementBean.promotionInfoDTO.promotionId = 0; settlementBean.promotionInfoDTO.promotionId = 0;
BaseData baseData = await minService.settlementApi({ BaseData baseData =
}).catchError((error) {}); await minService.settlementApi({}).catchError((error) {});
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {}
}
} }
bool isEdit = false; bool isEdit = false;
String totalPrice(bool discountFlag) {
if (shopCarGoods == null) return "";
double totalPrice = 0;
shopCarGoods.forEach((element) {
totalPrice += double.tryParse(element.price) * element.count;
});
if(selectedCouponIndex != -1 && discountFlag){
double discountA = double.parse(settleOrderInfo.couponList[selectedCouponIndex].discountAmount);
totalPrice -= discountA;
}
return totalPrice.toStringAsFixed(2);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack( return Stack(
@ -267,32 +264,86 @@ class _Settlement extends State<Settlement> {
titleSize: 18.sp, titleSize: 18.sp,
), ),
body: Container( body: Container(
child: SingleChildScrollView( child: Column(
physics: BouncingScrollPhysics(), children: [
child: Container( Expanded(
child: Column( child: Container(
children: [ child: SingleChildScrollView(
distributionMode(), physics: BouncingScrollPhysics(),
SizedBox( child: Container(
height: 16, child: Column(
), children: [
distributionMode(),
SizedBox(
height: 16,
),
/// ///
phoneWidget(), phoneWidget(),
/// ///
SettlementOrderCommodity(shopCar, 0, shopCarGoods, settleOrderInfo), SettlementOrderCommodity(
// if (payStatus == 0) couponRemarks(), 0,
/*(payStatus == 0) ? paySelector() : */ settleOrderInfo,
),
// if (payStatus == 0) couponRemarks(),
/*(payStatus == 0) ? paySelector() : */
//// ////
activityRemarks(), activityRemarks(),
/// ///
payMethod(), payMethod(),
], ],
),
),
),
),
flex: 1,
), ),
), Container(
height: 54.h,
color: Colors.white,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Spacer(),
Text(
S.of(context).heji,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Colors.black,
),
),
Text(
"${settleOrderInfo.orderSum}",
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
SizedBox(
width: 28,
),
RoundButton(
width: 103.w,
height: 54.h,
text: S.current.jiesuan,
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060),
fontSize: 16.sp,
padding: EdgeInsets.symmetric(
vertical: 5.h,
),
callback: () {},
),
],
),
),
],
), ),
), ),
), ),
@ -301,51 +352,6 @@ class _Settlement extends State<Settlement> {
top: 0, top: 0,
bottom: 0, bottom: 0,
), ),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 54.h,
color: Colors.white,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Spacer(),
Text(
S.of(context).heji,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Colors.black,
),
),
Text(
"¥19.00",
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF32A060),
),
),
SizedBox(
width: 28,
),
RoundButton(
width: 103.w,
height: 54.h,
text: S.current.jiesuan,
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060),
fontSize: 16.sp,
padding: EdgeInsets.symmetric(vertical: 5.h,),
callback: () {},
),
],
),
),
)
], ],
); );
} }
@ -504,9 +510,8 @@ class _Settlement extends State<Settlement> {
flex: 1, flex: 1,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
setState(() { selectedBtn = 0;
selectedBtn = 0; queryOrderInfo(null, selectedBtn, null, 0, null);
});
}, },
child: Container( child: Container(
height: 50.h, height: 50.h,
@ -526,9 +531,8 @@ class _Settlement extends State<Settlement> {
flex: 1, flex: 1,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
setState(() { selectedBtn = 1;
selectedBtn = 1; queryAddress();
});
}, },
child: Container( child: Container(
height: 50.h, height: 50.h,
@ -579,8 +583,9 @@ class _Settlement extends State<Settlement> {
Expanded( Expanded(
child: Column( child: Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceBetween, MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [ children: [
Text( Text(
storeInfo != null storeInfo != null
@ -594,7 +599,7 @@ class _Settlement extends State<Settlement> {
), ),
), ),
SizedBox( SizedBox(
height: 4, height: 6,
), ),
Text( Text(
storeInfo != null storeInfo != null
@ -608,9 +613,6 @@ class _Settlement extends State<Settlement> {
color: Color(0xFF727272), color: Color(0xFF727272),
), ),
), ),
SizedBox(
height: 12,
),
], ],
), ),
), ),
@ -634,7 +636,9 @@ class _Settlement extends State<Settlement> {
RoundButton( RoundButton(
width: 41.w, width: 41.w,
height: 13, height: 13,
text: "距离您11m", text: distance.length > 3
? "${distance}km"
: "距离您${distance}km",
textColor: Color(0xFF34A262), textColor: Color(0xFF34A262),
fontWeight: MyFontWeight.semi_bold, fontWeight: MyFontWeight.semi_bold,
radius: 7.5, radius: 7.5,
@ -649,8 +653,11 @@ class _Settlement extends State<Settlement> {
], ],
), ),
], ],
) ),
], ],
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
), ),
], ],
), ),
@ -692,13 +699,15 @@ class _Settlement extends State<Settlement> {
color: Color(0xFF4C4C4C), color: Color(0xFF4C4C4C),
), ),
), ),
), InkWell( ),
InkWell(
onTap: () { onTap: () {
setState(() { setState(() {
Navigator.of(context).popAndPushNamed('/router/manage_address_page'); Navigator.of(context).popAndPushNamed(
'/router/manage_address_page');
}); });
}, },
child:Icon( child: Icon(
Icons.keyboard_arrow_right, Icons.keyboard_arrow_right,
size: 24, size: 24,
), ),
@ -772,10 +781,13 @@ class _Settlement extends State<Settlement> {
), ),
), ),
Text( Text(
(settleOrderInfo?.couponList == null || settleOrderInfo.couponList.length == 0) (settleOrderInfo?.couponList == null ||
? "暂无可用优惠券" : (selectedCouponIndex == -1 settleOrderInfo.couponList.length == 0)
? "拥有${settleOrderInfo.couponList.length}张优惠券": ? "暂无可用优惠券"
settleOrderInfo.couponList[selectedCouponIndex].promotionName), : (selectedCouponIndex == -1
? "拥有${settleOrderInfo.couponList.length}张优惠券"
: settleOrderInfo
.couponList[selectedCouponIndex].promotionName),
textAlign: TextAlign.end, textAlign: TextAlign.end,
style: TextStyle( style: TextStyle(
fontSize: 14.sp, fontSize: 14.sp,
@ -956,117 +968,105 @@ class _Settlement extends State<Settlement> {
); );
} }
///
// showAlertDialog() {
// //
// showDialog(
// barrierDismissible: false,
// context: context,
// builder: (context) {
// return RenameDialog(
// contentWidget: RenameDialogContent(
// title: "请输入新的手机号码",
// okBtnTap: () {
// // print(
// // "输入框中的文字为:${_vc.text}",
// // );
// },
// vc: _vc,
// cancelBtnTap: () {},
// ),
// );
// });
// }
/// ///
couponCart() { couponCart() {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
builder: (context) { builder: (context) {
return StatefulBuilder(builder: (context1, state) { return StatefulBuilder(
return Container( builder: (context1, state) {
alignment: Alignment.topCenter, return Container(
width: double.infinity, alignment: Alignment.topCenter,
height: MediaQuery.of(context).size.height / 2, width: double.infinity,
decoration: BoxDecoration( height: MediaQuery.of(context).size.height / 2,
color: Colors.white, decoration: BoxDecoration(
borderRadius: BorderRadius.only( color: Colors.white,
topLeft: Radius.circular(8), borderRadius: BorderRadius.only(
topRight: Radius.circular(8), topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
), ),
), child: Column(
child: Column( mainAxisAlignment: MainAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ Container(
Container( padding: EdgeInsets.only(
padding: EdgeInsets.only( top: 16,
top: 16, left: 16,
left: 16, right: 16,
right: 16, bottom: 8,
bottom: 8, ),
), child: Row(
child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ Expanded(
Expanded( child: Text(
child: Text( (settleOrderInfo?.couponList == null ||
(settleOrderInfo?.couponList == null || settleOrderInfo.couponList.length == 0) settleOrderInfo.couponList.length == 0)
? "暂无可用优惠券" : (selectedCouponIndex == -1 ? "暂无可用优惠券"
? "拥有${settleOrderInfo.couponList.length}张优惠券": : (selectedCouponIndex == -1
settleOrderInfo.couponList[selectedCouponIndex].promotionName), ? "拥有${settleOrderInfo.couponList.length}张优惠券"
style: TextStyle( : settleOrderInfo
color: Color(0xFF000000), .couponList[selectedCouponIndex]
fontSize: 14.sp, .promotionName),
fontWeight: MyFontWeight.medium, style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
),
), ),
), ),
InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: Image.asset(
"assets/image/cancel.png",
width: 24,
height: 24,
),
),
],
),
),
Expanded(
child: Container(
padding: EdgeInsets.only(
top: 8,
left: 16,
right: 16,
), ),
InkWell( child: ListView.builder(
onTap: () { itemCount: settleOrderInfo == null
Navigator.of(context).pop(); ? 0
: settleOrderInfo.couponList.length,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {},
child: couponItem(
settleOrderInfo.couponList[position],
position,
),
);
}, },
child: Image.asset(
"assets/image/cancel.png",
width: 24,
height: 24,
),
), ),
],
),
),
Expanded(
child: Container(
padding: EdgeInsets.only(
top: 8,
left: 16,
right: 16,
),
child: ListView.builder(
itemCount:settleOrderInfo == null ? 0 : settleOrderInfo.couponList.length,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
// return shoppGoodsItem();
return GestureDetector(
onTap: () {},
child: couponItem(settleOrderInfo.couponList[position],position),
);
},
), ),
), ),
), ],
], ),
), );
); },
}); );
}, },
); );
} }
/// ///
Widget couponItem(CouponListBean couponList,int index) { Widget couponItem(CouponListBean couponList, int index) {
return StatefulBuilder(builder: (context1, state) { return StatefulBuilder(builder: (context1, state) {
return Container( return Container(
height: 170, height: 170,
@ -1212,16 +1212,20 @@ class _Settlement extends State<Settlement> {
// SmartDialog.showToast("当前优惠券不可用", alignment: Alignment.center); // SmartDialog.showToast("当前优惠券不可用", alignment: Alignment.center);
// return; // return;
// } // }
double toPrice = double.parse(totalPrice(false)); double toPrice = double.parse("0");
double amount = double.parse(couponList.fullAmount); double amount =
if(toPrice <= amount){ double.parse(couponList.fullAmount);
SmartDialog.showToast("当前金额不够使用优惠券", alignment: Alignment.center); if (toPrice <= amount) {
SmartDialog.showToast("当前金额不够使用优惠券",
alignment: Alignment.center);
return; return;
} }
state(() { state(() {
if(selectedCouponIndex == index) if (selectedCouponIndex == index)
selectedCouponIndex = -1; selectedCouponIndex = -1;
else {selectedCouponIndex = index;} else {
selectedCouponIndex = index;
}
}); });
Navigator.of(context).pop(); Navigator.of(context).pop();
}); });
@ -1243,7 +1247,7 @@ class _Settlement extends State<Settlement> {
], ],
), ),
), ),
flex: (couponList?.isEx??false) ? 97 : 97, flex: (couponList?.isEx ?? false) ? 97 : 97,
), ),
Container( Container(
padding: EdgeInsets.symmetric(horizontal: 23.w), padding: EdgeInsets.symmetric(horizontal: 23.w),
@ -1254,7 +1258,7 @@ class _Settlement extends State<Settlement> {
), ),
), ),
Expanded( Expanded(
flex: (couponList?.isEx??false) ? 56 : 42, flex: (couponList?.isEx ?? false) ? 56 : 42,
child: Container( child: Container(
margin: EdgeInsets.symmetric(horizontal: 23.w, vertical: 8.h), margin: EdgeInsets.symmetric(horizontal: 23.w, vertical: 8.h),
child: Column( child: Column(
@ -1273,23 +1277,28 @@ class _Settlement extends State<Settlement> {
), ),
GestureDetector( GestureDetector(
child: Icon( child: Icon(
(!(couponList?.isEx??false)) (!(couponList?.isEx ?? false))
? Icons.keyboard_arrow_down ? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up, : Icons.keyboard_arrow_up,
color: Colors.black, color: Colors.black,
size: 18, size: 18,
), // ), //
onTap: (){ onTap: () {
setState(() { setState(() {
state((){ state(() {
this.settleOrderInfo.couponList[index].isEx = !(this.settleOrderInfo.couponList[index].isEx??false); this.settleOrderInfo.couponList[index].isEx =
!(this
.settleOrderInfo
.couponList[index]
.isEx ??
false);
}); });
}); });
}, },
), ),
], ],
), ),
if (couponList?.isEx??false) if (couponList?.isEx ?? false)
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -1302,7 +1311,7 @@ class _Settlement extends State<Settlement> {
), ),
Text( Text(
(couponList.useStartTime == null && (couponList.useStartTime == null &&
couponList.useEndTime == null) couponList.useEndTime == null)
? S.of(context).quantian ? S.of(context).quantian
: "${couponList.useStartTime.replaceAll("-", ".").split(" ")[0]} - ${couponList.useEndTime.replaceAll("-", ".").split(" ")[0]}", : "${couponList.useStartTime.replaceAll("-", ".").split(" ")[0]} - ${couponList.useEndTime.replaceAll("-", ".").split(" ")[0]}",
style: TextStyle( style: TextStyle(

41
lib/store/store_view/settlement_order_commodity.dart → lib/settlement/settlement_view/settlement_order_commodity.dart

@ -3,18 +3,16 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/retrofit/data/settleOrderInfo.dart'; import 'package:huixiang/retrofit/data/settleOrderInfo.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/separator.dart'; import 'package:huixiang/view_widget/separator.dart';
class SettlementOrderCommodity extends StatefulWidget { class SettlementOrderCommodity extends StatefulWidget {
final int isTakeOut; final int isTakeOut;
final List<ProductListBean> orderInfo;
final List<Sku> shopCarGood;
final SettleOrderInfo settleOrderInfo; final SettleOrderInfo settleOrderInfo;
SettlementOrderCommodity(this.orderInfo, this.isTakeOut,this.shopCarGood,this.settleOrderInfo); SettlementOrderCommodity(this.isTakeOut,this.settleOrderInfo);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -67,11 +65,11 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
} }
List<Widget> commodityList() { List<Widget> commodityList() {
if (widget.orderInfo == null) return []; if (widget.settleOrderInfo == null) return [];
List<Widget> widgets = []; List<Widget> widgets = [];
if (widget.orderInfo != null) { if (widget.settleOrderInfo != null) {
widgets.addAll( widgets.addAll(
widget.orderInfo.map((e) => commodityItem(e)).toList()); widget.settleOrderInfo.orderProductList.map((e) => commodityItem(e)).toList());
} }
widgets.add(SizedBox(height: 20.h)); widgets.add(SizedBox(height: 20.h));
@ -102,20 +100,14 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
return widgets; return widgets;
} }
Widget commodityItem(ProductListBean productList) { Widget commodityItem(OrderProductListBean productList) {
Sku goodsBuyInfo;
widget.shopCarGood.forEach((element) {
if(element.id == productList.id){
goodsBuyInfo = element;
return;
}
});
return Container( return Container(
margin: EdgeInsets.only(top: 8.h, bottom: 8.h), margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
child: Row( child: Row(
children: [ children: [
MImage( MImage(
productList.imgPath, productList.skuImg,
width: 44.w, width: 44.w,
height: 44, height: 44,
fit: BoxFit.cover, fit: BoxFit.cover,
@ -146,7 +138,7 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
), ),
), ),
Text( Text(
"x${goodsBuyInfo.count}", "x${productList.buyNum}",
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
color: Color(0xFF727272), color: Color(0xFF727272),
@ -172,7 +164,7 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
), ),
), ),
Text( Text(
S.of(context).yuan_(productList.price), S.of(context).yuan_(productList.sellPrice),
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 12.sp, fontSize: 12.sp,
@ -319,9 +311,8 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
S.of(context).gongjijianshangpin((widget.orderInfo != null && S.of(context).gongjijianshangpin((widget.settleOrderInfo != null)
widget.orderInfo != null) ? widget.settleOrderInfo.orderProductList.length
? widget.orderInfo.length
: "0"), : "0"),
style: TextStyle( style: TextStyle(
fontSize: 10.sp, fontSize: 10.sp,
@ -356,11 +347,7 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
} }
String totalPrice() { String totalPrice() {
if (widget.shopCarGood == null) return ""; if (widget.settleOrderInfo.orderProductList == null) return "";
double totalPrice = 0; return "${widget.settleOrderInfo.price}";
widget.shopCarGood.forEach((element) {
totalPrice += double.tryParse(element.price) * element.count;
});
return "$totalPrice";
} }
} }

71
lib/store/sku.dart

@ -1,71 +0,0 @@
class Sku {
Sku(
this.id,
this.count,
this.price,
);
String id;
int count;
String price;
String name;
String skuId;
String skuValue;
List<Attr> attr = [];
bool compareTo(List<Attr> attr) {
bool attrY = true;
for (int i = 0; i < this.attr.length; i++) {
if (!this.attr[i].compareTo(attr[i])) {
attrY = false;
return attrY;
}
}
return attrY;
}
Map toJson() => {
"id": id,
"count": count,
"price": price,
"skuId": skuId,
"name": name,
"value": skuValue,
"attr": attr.map((e) => e.toJson()).toList(),
};
Sku copy() {
return Sku(
this.id,
this.count,
this.price,
)
..name = this.name
..skuValue = this.skuValue
..attr = attr.map((e) => e.copy()).toList();
}
}
class Attr {
Attr(this.attrId, this.attrValue);
String attrId;
String attrValue;
bool compareTo(Attr attr) {
return attrId == attr.attrId && attrValue == attr.attrValue;
}
Map toJson() => {
"attrId": attrId,
"attrValue": attrValue,
};
Attr copy() {
return Attr(
this.attrId,
this.attrValue,
);
}
}

248
lib/store/store_order.dart

@ -9,13 +9,11 @@ import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/activity.dart';
import 'package:huixiang/retrofit/data/base_data.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/miNiDetail.dart';
import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/retrofit/retrofit_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/product_sku.dart';
import 'package:huixiang/store/store_view/shop_car.dart'; import 'package:huixiang/store/store_view/shop_car.dart';
import 'package:huixiang/store/store_view/store_activity.dart'; import 'package:huixiang/store/store_view/store_activity.dart';
@ -53,8 +51,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
StoreOrderListPage storeOrderListPage; StoreOrderListPage storeOrderListPage;
ScrollController controller = ScrollController(); ScrollController controller = ScrollController();
ShoppingCart shopCarGoods;
List<ShoppingCart> shopCarGoods;
@override @override
void initState() { void initState() {
@ -112,6 +109,10 @@ class _StoreOrderPage extends State<StoreOrderPage>
tenant: tenant, tenant: tenant,
storeId: storeId, storeId: storeId,
); );
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
} }
}); });
} }
@ -314,7 +315,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
shopCarGoods, shopCarGoods,
controller, controller,
_queryMiNiDetail, _queryMiNiDetail,
_productListResult, // _productListResult,
_fc, _fc,
), ),
@ -352,7 +353,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
), ),
), ),
Text( Text(
"$allPrice", "${shopCarGoods != null ? shopCarGoods.cartSum : "0.0"}",
style: TextStyle( style: TextStyle(
fontSize: 20.sp, fontSize: 20.sp,
fontWeight: MyFontWeight.medium, fontWeight: MyFontWeight.medium,
@ -398,7 +399,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
child: RoundButton( child: RoundButton(
width: 17, width: 17,
height: 17, height: 17,
text: "${allCount}", text: "${count()}",
textColor: Colors.white, textColor: Colors.white,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060), backgroup: Color(0xFF32A060),
@ -415,9 +416,24 @@ class _StoreOrderPage extends State<StoreOrderPage>
); );
} }
///
int count() {
if (shopCarGoods == null ||
shopCarGoods.shoppingCartSkuItemList == null ||
shopCarGoods.shoppingCartSkuItemList.length == 0) return 0;
int count = 0;
shopCarGoods.shoppingCartSkuItemList.forEach((element) {
count += element.buyNum;
});
return count;
}
///
toDownOrder() { toDownOrder() {
if (shopCarGoods == null || shopCarGoods.length == 0) { int num = count();
SmartDialog.showToast("请选择要购买的商品~");
if (num == 0) {
SmartDialog.showToast("请先选择您要购买的商品!~");
return; return;
} }
@ -425,7 +441,6 @@ class _StoreOrderPage extends State<StoreOrderPage>
'/router/settlement', '/router/settlement',
arguments: { arguments: {
"storeInfo": storeInfo, "storeInfo": storeInfo,
"shopGoods": shopCarGoods,
}, },
); );
} }
@ -467,25 +482,26 @@ class _StoreOrderPage extends State<StoreOrderPage>
); );
} }
GlobalKey shopCartKey = GlobalKey();
/// ///
showShoppingCart() { showShoppingCart() {
queryShopCar().then((value) { queryShopCar().then((value) {
this.shopCarGoods = value;
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
builder: (context) { builder: (context) {
return ShopCar( return ShopCar(
value, shopCartKey,
this.shopCarGoods,
clearShopCar, clearShopCar,
toDownOrder, toDownOrder,
(int count, String productId, allCount, allPrice) { shopCartAdd,
// print("shopCarCount: $allCount allPrice: $allPrice "); shopCartReduce,
},
); );
}, },
); );
}); });
} }
@ -493,7 +509,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
clearShopCar() async { clearShopCar() async {
BaseData<bool> baseData = await minService.clearShoppingCart(); BaseData<bool> baseData = await minService.clearShoppingCart();
if (baseData.isSuccess) { if (baseData.isSuccess) {
shopCarGoods = null;
setState(() {}); setState(() {});
} }
} }
@ -506,58 +522,198 @@ class _StoreOrderPage extends State<StoreOrderPage>
} }
} }
///
showStoreSelector(MiNiDetail miNiDetail, String id) async {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return ProductSku(
miNiDetail,
shopCarGoods,
id,
_addShopCar,
add,
reduce,
);
},
);
}
/// ///
_addShopCar(Sku sku) async { Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async {
if (sku != null) { ProductSkuVOListBean productSku = miNiDetail.productSkuVOList.firstWhere((element) {
bool gg = true;
selectSkus.forEach((element1) {
if (element.skuNameStr.indexOf(element1) < 0) {
gg = false;
return gg;
}
});
return gg;
});
if (productSku == null) return;
String skuId = productSku.id;
String skuValue = selectSkus.toString().replaceAll("[", "").replaceAll("]", "").replaceAll(",", "");
if (miNiDetail != null) {
BaseData<List<ShoppingCart>> baseDate = await minService.addShoppingCart({ BaseData<List<ShoppingCart>> baseDate = await minService.addShoppingCart({
"storeId": storeInfo.id, "storeId": storeInfo.id,
"storeName": storeInfo.storeName ?? "", "storeName": storeInfo.storeName ?? "",
"tableId": 0, "tableId": 0,
"shoppingCartSkuItemList": [ "shoppingCartSkuItemList": [
{ {
"buyNum": sku.count, "buyNum": count,
"id": sku.skuId, "id": skuId,
"platterList": [ "productId": miNiDetail.id,
{ "productName": miNiDetail.productName,
"skuId": sku.skuId "skuName": skuValue,
}
],
"productId": sku.id,
"productName": sku.name,
"skuName": "",
"storeId": storeInfo.id, "storeId": storeInfo.id,
} "skuPrice": productSku.applyPrice,
"skuStock": productSku.skuStock,
"tableId": 0,
},
], ],
}); });
if (baseDate != null && baseDate.isSuccess) { if (baseDate != null && baseDate.isSuccess) {
queryShopCar(); queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
} }
} }
} }
/// ///
Future<List<ShoppingCart>> queryShopCar() async { Future<ShoppingCart> queryShopCar() async {
BaseData<List<ShoppingCart>> baseDate = await minService.getShoppingCart(0); BaseData<List<ShoppingCart>> baseDate = await minService.getShoppingCart(0);
if (baseDate != null && baseDate.isSuccess) { if (baseDate != null &&
return baseDate.data; baseDate.isSuccess &&
baseDate.data != null &&
baseDate.data.length > 0) {
return baseDate.data[0];
} else { } else {
return []; return null;
} }
} }
/// ///1
showStoreSelector(MiNiDetail miNiDetail, String id) async { shopCartAdd(ShoppingCartSkuItemListBean cartSkuItem) async {
showModalBottomSheet( Map<String, dynamic> shopCarTemp = shopCarGoods.toJson();
context: context, cartSkuItem.buyNum += 1;
backgroundColor: Colors.transparent, shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
builder: (context) { BaseData<List<ShoppingCart>> baseDate = await minService.shoppingCartSingle(shopCarTemp);
return ProductSku(miNiDetail, id, _addShopCar); if (baseDate.isSuccess) {
}, queryShopCar().then((value) {
); this.shopCarGoods = value;
if (shopCartKey != null) {
shopCartKey.currentState.setState(() {});
}
setState(() {});
});
}
}
///1
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) {
queryShopCar().then((value) {
this.shopCarGoods = value;
if (shopCartKey != null) {
shopCartKey.currentState.setState(() {});
}
setState(() {});
});
}
}
///1
add(MiNiDetail miNiDetail, selectSkus) async {
ProductSkuVOListBean productSku = miNiDetail.productSkuVOList.firstWhere((element) {
return skuY(element, selectSkus);
});
if (productSku == null) return;
String skuId = productSku.id;
if (shopCarGoods == null) {
await _addShopCar(miNiDetail, selectSkus, 2);
return;
}
int shopSkuIndex = shopCarGoods.shoppingCartSkuItemList.indexWhere((element) => skuId == element.id);
Map<String, dynamic> shopCarTemp = shopCarGoods.toJson();
shopCarGoods.tableId = "0";
if (shopSkuIndex >= 0) {
shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum += 1;
ShoppingCartSkuItemListBean cartSkuItem = shopCarGoods.shoppingCartSkuItemList.firstWhere((element) => skuId == element.id);
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
} else {
await _addShopCar(miNiDetail, selectSkus, 2);
return;
}
BaseData<List<ShoppingCart>> baseDate = await minService.shoppingCartSingle(shopCarTemp);
if (baseDate.isSuccess) {
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
}
}
///1
reduce(MiNiDetail miNiDetail, selectSkus) async {
ProductSkuVOListBean productSku = miNiDetail.productSkuVOList.firstWhere((element) {
return skuY(element, selectSkus);
});
if (productSku == null) return;
String skuId = productSku.id;
if (shopCarGoods == null) {
await _addShopCar(miNiDetail, selectSkus, 2);
return;
}
ShoppingCartSkuItemListBean shopSkuItem = shopCarGoods.shoppingCartSkuItemList.firstWhere((element) => skuId == element.skuId);
int shopSkuIndex = shopCarGoods.shoppingCartSkuItemList.indexWhere((element) => skuId == element.skuId);
if (shopSkuItem != null) {
if (shopSkuItem.buyNum > 1) {
shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum -= 1;
}
} else {
await _addShopCar(miNiDetail, selectSkus, 2);
return;
}
shopCarGoods.tableId = "0";
Map<String, dynamic> shopCarTemp = shopCarGoods.toJson();
ShoppingCartSkuItemListBean cartSkuItem = shopCarGoods.shoppingCartSkuItemList.firstWhere((element) => skuId == element.id);
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
BaseData<List<ShoppingCart>> baseDate = await minService.shoppingCartSingle(shopCarTemp);
if (baseDate.isSuccess) {
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
}
}
bool skuY(ProductSkuVOListBean productSku, selectSkus) {
bool gg = true;
selectSkus.forEach((element1) {
if (productSku.skuNameStr.indexOf(element1) < 0) {
gg = false;
return gg;
}
});
return gg;
} }
// @override
// bool get wantKeepAlive => true;
} }
class Title extends StatefulWidget { class Title extends StatefulWidget {

116
lib/store/store_view/product_sku.dart

@ -2,16 +2,28 @@ import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/retrofit/data/miNiDetail.dart'; import 'package:huixiang/retrofit/data/miNiDetail.dart';
import 'package:huixiang/store/sku.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
class ProductSku extends StatefulWidget { class ProductSku extends StatefulWidget {
final MiNiDetail miNiDetail; final MiNiDetail miNiDetail;
final String productId; final String productId;
final Function(Sku sku) addShopCar; final Function(MiNiDetail miNiDetail, List<String> selectSkus, int count) addShopCar;
ProductSku(this.miNiDetail, this.productId, this.addShopCar); final Function(MiNiDetail miNiDetail, List<String> selectSkus) add;
final Function(MiNiDetail miNiDetail, List<String> selectSkus) reduce;
final ShoppingCart shopCarGoods;
ProductSku(
this.miNiDetail,
this.shopCarGoods,
this.productId,
this.addShopCar,
this.add,
this.reduce,
);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -21,29 +33,47 @@ class ProductSku extends StatefulWidget {
class _ProductSku extends State<ProductSku> { class _ProductSku extends State<ProductSku> {
List<String> selectSkus = []; List<String> selectSkus = [];
int selectCount = 1;
Sku tempSelected; int count = 1;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.miNiDetail != null) { widget.miNiDetail.attrList.forEach((element) {
tempSelected = Sku(widget.productId, 1, widget.miNiDetail.price); selectSkus.add(element.attrValueList[0].attrValue);
tempSelected.name = widget.miNiDetail.productName; });
widget.miNiDetail.attrList.forEach((element) { buildCount();
selectSkus.add(element.attrValueList[0].attrValue); }
tempSelected.attr.add(
Attr( buildCount() {
"${element.id}", count = 1;
"${element.attrValueList[0].id}", ProductSkuVOListBean productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) {
), return skuY(element, selectSkus);
); });
}); if (productSku == null) return;
String skuId = productSku.id;
if (widget.shopCarGoods == null || widget.shopCarGoods.shoppingCartSkuItemList == null) return;
int shopSkuIndex = widget.shopCarGoods.shoppingCartSkuItemList.indexWhere((element) => skuId == element.id);
if (shopSkuIndex >= 0) {
count = widget.shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum;
} }
}
bool skuY(ProductSkuVOListBean productSku, selectSkus) {
bool gg = true;
selectSkus.forEach((element1) {
if (productSku.skuNameStr.indexOf(element1) < 0) {
gg = false;
return gg;
}
});
return gg;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return StatefulBuilder(builder: (context1, state) { return StatefulBuilder(builder: (context1, state) {
@ -150,22 +180,10 @@ class _ProductSku extends State<ProductSku> {
itemBuilder: (context, position) { itemBuilder: (context, position) {
return attrItem( return attrItem(
(index) { (index) {
if (tempSelected.attr == null) {
tempSelected.attr = [];
}
tempSelected.attr.forEach((e0) {
if (e0.attrId == widget.miNiDetail.attrList[position].id) {
String valueId = widget.miNiDetail.attrList[position].attrValueList[index].id;
if (e0.attrValue != valueId) {
tempSelected.attr[tempSelected.attr.indexOf(e0)].attrValue = valueId;
}
}
});
state(() { state(() {
selectSkus[position] = widget.miNiDetail selectSkus[position] = widget.miNiDetail
.attrList[position].attrValueList[index].attrValue; .attrList[position].attrValueList[index].attrValue;
buildCount();
}); });
}, },
widget.miNiDetail.attrList[position], widget.miNiDetail.attrList[position],
@ -192,10 +210,11 @@ class _ProductSku extends State<ProductSku> {
), ),
InkWell( InkWell(
onTap: () { onTap: () {
state(() { if (count > 1)
if (selectCount > 1) selectCount--; setState(() {
}); count -= 1;
tempSelected.count = selectCount; });
widget.reduce(widget.miNiDetail, selectSkus);
}, },
child: Image.asset( child: Image.asset(
"assets/image/reduce.png", "assets/image/reduce.png",
@ -206,7 +225,7 @@ class _ProductSku extends State<ProductSku> {
Padding( Padding(
padding: EdgeInsets.only(left: 8, right: 8), padding: EdgeInsets.only(left: 8, right: 8),
child: Text( child: Text(
selectCount.toString(), "$count",
style: TextStyle( style: TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 14.sp, fontSize: 14.sp,
@ -216,10 +235,10 @@ class _ProductSku extends State<ProductSku> {
), ),
InkWell( InkWell(
onTap: () { onTap: () {
state(() { setState(() {
selectCount++; count += 1;
tempSelected.count = selectCount;
}); });
widget.add(widget.miNiDetail, selectSkus);
}, },
child: Image.asset( child: Image.asset(
"assets/image/add.png", "assets/image/add.png",
@ -242,7 +261,7 @@ class _ProductSku extends State<ProductSku> {
backgroup: Color(0xFF32A060), backgroup: Color(0xFF32A060),
fontSize: 16.sp, fontSize: 16.sp,
callback: () { callback: () {
_result(); widget.addShopCar(widget.miNiDetail, selectSkus, 1);
}, },
), ),
SizedBox( SizedBox(
@ -254,25 +273,6 @@ class _ProductSku extends State<ProductSku> {
}); });
} }
_result() async {
ProductSkuVOListBean productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) {
bool gg = true;
selectSkus.forEach((element1) {
if (element.skuNameStr.indexOf(element1) < 0) {
gg = false;
return gg;
}
});
return gg;
});
// print("productSku: ${selectSkus.toString()}");
print("productSku: ${tempSelected.toJson()}");
if (productSku == null) return;
tempSelected.skuId = productSku.id;
tempSelected.skuValue = selectSkus.toString();
widget.addShopCar(tempSelected);
}
Widget attrItem(Function fc, AttrListBean attrListBean, position) { Widget attrItem(Function fc, AttrListBean attrListBean, position) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,

89
lib/store/store_view/shop_car.dart

@ -1,9 +1,6 @@
import 'package:ai_decimal_accuracy/ai_decimal_accuracy.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/store/store_view/shop_goods.dart'; import 'package:huixiang/store/store_view/shop_goods.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
@ -13,18 +10,20 @@ class ShopCar extends StatefulWidget {
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function() clearShopCar; final Function() clearShopCar;
final Function() toDownOrder; final Function() toDownOrder;
final Function(ShoppingCartSkuItemListBean cart) shopCartAdd;
final Function(ShoppingCartSkuItemListBean cart) shopCartReduce;
final List<ShoppingCart> shopingCar; ShoppingCart shopingCar;
final Function(int count, String productId, int allCount, double allPrice) fc;
ShopCar( ShopCar(
Key key,
this.shopingCar, this.shopingCar,
this.clearShopCar, this.clearShopCar,
this.toDownOrder, this.toDownOrder,
this.fc, { this.shopCartAdd,
this.shopCartReduce, {
this.queryMiNiDetail, this.queryMiNiDetail,
}); }) : super(key: key);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -33,13 +32,6 @@ class ShopCar extends StatefulWidget {
} }
class _ShopCar extends State<ShopCar> { class _ShopCar extends State<ShopCar> {
int allCount = 0;
double allPrice = 0.0;
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -81,9 +73,7 @@ class _ShopCar extends State<ShopCar> {
), ),
InkWell( InkWell(
onTap: () { onTap: () {
allPrice = 0; widget.shopingCar.shoppingCartSkuItemList.clear();
allCount = 0;
state(() {}); state(() {});
widget.clearShopCar(); widget.clearShopCar();
}, },
@ -111,27 +101,17 @@ class _ShopCar extends State<ShopCar> {
right: 16, right: 16,
), ),
child: ListView.builder( child: ListView.builder(
itemCount: widget.shopingCar == null itemCount: itemCount(),
? 0
: widget.shopingCar.length,
physics: BouncingScrollPhysics(), physics: BouncingScrollPhysics(),
itemBuilder: (context, position) { itemBuilder: (context, position) {
return GestureDetector( return ShopGoods(
onTap: () {}, widget.shopCartAdd,
child: ShopGoods( widget.shopCartReduce,
widget.shopingCar[position], count: widget.shopingCar
(int count, List<Attr> attr, String productId) { .shoppingCartSkuItemList[position].buyNum,
shoppingCartSkuItemListBean:
widget.shopingCar.shoppingCartSkuItemList[position],
widget.fc( queryMiNiDetail: widget.queryMiNiDetail,
count, productId, allCount, allPrice);
state(() {});
},
count: _shopCarGoods(position).count,
shopCarGoods: _shopCarGoods(position),
queryMiNiDetail: widget.queryMiNiDetail,
),
); );
}, },
), ),
@ -169,7 +149,10 @@ class _ShopCar extends State<ShopCar> {
), ),
), ),
Text( Text(
"" + allPrice.toString(), "" +
(widget.shopingCar == null
? "0.0"
: widget.shopingCar.cartSum),
style: TextStyle( style: TextStyle(
fontSize: 20.sp, fontSize: 20.sp,
fontWeight: MyFontWeight.medium, fontWeight: MyFontWeight.medium,
@ -215,7 +198,7 @@ class _ShopCar extends State<ShopCar> {
child: RoundButton( child: RoundButton(
width: 17, width: 17,
height: 17, height: 17,
text: allCount.toString(), text: "${count()}",
textColor: Colors.white, textColor: Colors.white,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060), backgroup: Color(0xFF32A060),
@ -243,14 +226,24 @@ class _ShopCar extends State<ShopCar> {
); );
} }
Sku _shopCarGoods(int position) { int itemCount() {
Sku map = widget.shopCarGoods[position]; if (widget.shopingCar == null || widget.shopingCar.shoppingCartSkuItemList == null || widget.shopingCar.shoppingCartSkuItemList.length == 0) return 0;
// widget.shopCarGoods.forEach((element) { int index = widget.shopingCar.shoppingCartSkuItemList.indexWhere((element) => element.buyNum == 0);
// if (widget.productLists[position].id == element.id) { if (index >= 0) {
// map = element; widget.shopingCar.shoppingCartSkuItemList.removeAt(index);
// } }
// }); int count = widget.shopingCar.shoppingCartSkuItemList.length;
// print("shopCarGoods123123: ${map.toJson()}"); return count;
return map; }
int count() {
if (widget.shopingCar == null ||
widget.shopingCar.shoppingCartSkuItemList == null ||
widget.shopingCar.shoppingCartSkuItemList.length == 0) return 0;
int count = 0;
widget.shopingCar.shoppingCartSkuItemList.forEach((element) {
count += element.buyNum;
});
return count;
} }
} }

55
lib/store/store_view/shop_goods.dart

@ -1,36 +1,37 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/store/sku.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
class ShopGoods extends StatefulWidget { class ShopGoods extends StatefulWidget {
final ProductListBean product;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(int count, List<Attr> attr, String productId) fc; final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) add;
final Sku shopCarGoods; final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) reduce;
final ProductListBean productListBean;
final ShoppingCartSkuItemListBean shoppingCartSkuItemListBean;
final int count; final int count;
ShopGoods( ShopGoods(
this.product, this.add,
this.fc, { this.reduce, {
this.productListBean,
this.count = 0, this.count = 0,
this.queryMiNiDetail, this.queryMiNiDetail,
this.shopCarGoods, this.shoppingCartSkuItemListBean,
}); });
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
return _ShopGoods(); return _ShopGoods();
} }
} }
class _ShopGoods extends State<ShopGoods> { class _ShopGoods extends State<ShopGoods> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -47,7 +48,10 @@ class _ShopGoods extends State<ShopGoods> {
children: [ children: [
SizedBox(width: 12.w), SizedBox(width: 12.w),
MImage( MImage(
widget.product != null ? widget.product.imgPath : "", widget.productListBean != null ? widget.productListBean.imgPath :
(widget.shoppingCartSkuItemListBean != null
? widget.shoppingCartSkuItemListBean.skuImg
: ""),
width: 70, width: 70,
height: 70, height: 70,
fit: BoxFit.cover, fit: BoxFit.cover,
@ -62,7 +66,7 @@ class _ShopGoods extends State<ShopGoods> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
widget.product.productName, widget.productListBean != null ? widget.productListBean.productName : widget.shoppingCartSkuItemListBean.productName,
style: TextStyle( style: TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 13.sp, fontSize: 13.sp,
@ -72,11 +76,13 @@ class _ShopGoods extends State<ShopGoods> {
SizedBox( SizedBox(
height: 2, height: 2,
), ),
///{"id":"1442420413828169728","productId":"1432652566000304128","productName":"桂花乌龙茶","skuName":null,"buyNum":1,"skuStock":1000,"skuImg":"https://pos.upload.gznl.top/1177/2021/08/f855ffb8-d473-4f5f-93c9-5907b539b2fd.jpg",
///"skuPrice":"0.00","selected":1,"storeId":null,"groupId":"1426067376096411648","createTime":"2021-10-20 10:27:46","tableId":null,"platterList":null}
Row( Row(
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
widget.product.shortName, (widget.productListBean != null ? widget.productListBean.shortName : widget.shoppingCartSkuItemListBean.skuName ?? ""),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 2, maxLines: 2,
style: TextStyle( style: TextStyle(
@ -113,7 +119,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4, width: 4,
), ),
Text( Text(
"¥${widget.product.price}", "¥${widget.productListBean != null ? widget.productListBean.price : widget.shoppingCartSkuItemListBean.skuPrice}",
style: TextStyle( style: TextStyle(
color: Color(0xFFFF7A1A), color: Color(0xFFFF7A1A),
fontSize: 11.sp, fontSize: 11.sp,
@ -136,7 +142,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4, width: 4,
), ),
Text( Text(
"¥${widget.product.applyPrice}", "¥${widget.productListBean != null ? widget.productListBean.applyPrice : widget.shoppingCartSkuItemListBean.skuPrice}",
style: TextStyle( style: TextStyle(
color: Color(0xFFA29E9E), color: Color(0xFFA29E9E),
fontSize: 10.sp, fontSize: 10.sp,
@ -159,15 +165,14 @@ class _ShopGoods extends State<ShopGoods> {
fontSize: 11.sp, fontSize: 11.sp,
padding: EdgeInsets.symmetric(vertical: 5.h), padding: EdgeInsets.symmetric(vertical: 5.h),
callback: () { callback: () {
widget.queryMiNiDetail(widget.product.id); widget.queryMiNiDetail(
widget.productListBean != null ? widget.productListBean.id : widget.shoppingCartSkuItemListBean.productId);
}, },
), ),
if (widget.count > 0) if (widget.count > 0)
InkWell( InkWell(
onTap: () { onTap: () {
reduceCount(); widget.reduce(widget.shoppingCartSkuItemListBean);
widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id);
setState(() {});
}, },
child: Image.asset( child: Image.asset(
"assets/image/reduce.png", "assets/image/reduce.png",
@ -191,9 +196,7 @@ class _ShopGoods extends State<ShopGoods> {
if (widget.count > 0) if (widget.count > 0)
InkWell( InkWell(
onTap: () { onTap: () {
addCount(); widget.add(widget.shoppingCartSkuItemListBean);
widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id);
setState(() {});
}, },
child: Image.asset( child: Image.asset(
"assets/image/add.png", "assets/image/add.png",
@ -210,14 +213,4 @@ class _ShopGoods extends State<ShopGoods> {
), ),
); );
} }
addCount() {
widget.shopCarGoods.count += 1;
}
reduceCount() {
widget.shopCarGoods.count -= 1;
}
} }

65
lib/store/store_view/store_order_list.dart

@ -8,7 +8,6 @@ import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/store/store_view/shop_goods.dart'; import 'package:huixiang/store/store_view/shop_goods.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -22,8 +21,8 @@ class StoreOrderListPage extends StatefulWidget {
final ScrollController controller; final ScrollController controller;
final Function(int count, String productId, int allCount, double allPrice) fc; final Function(int count, String productId, int allCount, double allPrice) fc;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(List<FindMiNiGroupList> appletProducts) productListResult; // final Function(List<FindMiNiGroupList> appletProducts) productListResult;
List<ShoppingCart> shopCarGoods; ShoppingCart shopCarGoods;
StoreOrderListPage( StoreOrderListPage(
this.arguments, this.arguments,
@ -32,7 +31,7 @@ class StoreOrderListPage extends StatefulWidget {
this.shopCarGoods, this.shopCarGoods,
this.controller, this.controller,
this.queryMiNiDetail, this.queryMiNiDetail,
this.productListResult, // this.productListResult,
this.fc); this.fc);
@override @override
@ -77,7 +76,7 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
setState(() { setState(() {
appletProducts = baseData.data; appletProducts = baseData.data;
widget.productListResult(appletProducts); // widget.productListResult(appletProducts);
productListBeans.clear(); productListBeans.clear();
if (appletProducts.length > 0) if (appletProducts.length > 0)
productListBeans.addAll(appletProducts[0].productList); productListBeans.addAll(appletProducts[0].productList);
@ -198,11 +197,12 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
} }
int calculateItemCount(FindMiNiGroupList findMiNiGroupList) { int calculateItemCount(FindMiNiGroupList findMiNiGroupList) {
if (widget.shopCarGoods == null) return 0;
int count = 0; int count = 0;
findMiNiGroupList.productList.forEach((element) { findMiNiGroupList.productList.forEach((element) {
widget.shopCarGoods.forEach((element1) { widget.shopCarGoods.shoppingCartSkuItemList.forEach((element1) {
if (element.id == element1.id) { if (element.id == element1.productId) {
count += element1.count; count += element1.buyNum;
} }
}); });
}); });
@ -210,46 +210,35 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
} }
Widget goodsItem(position) { Widget goodsItem(position) {
Sku map; ShoppingCartSkuItemListBean shoppingCartSkuItemListBean;
int count = 0; int count = 0;
widget.shopCarGoods.forEach((element) { if (widget.shopCarGoods != null) {
if (productListBeans[position].id == element.id) { widget.shopCarGoods.shoppingCartSkuItemList.forEach((element) {
if (map == null) { if (productListBeans[position].id == element.productId) {
map = element; if (shoppingCartSkuItemListBean == null) {
count = map.count; shoppingCartSkuItemListBean = element;
} else { count = shoppingCartSkuItemListBean.buyNum;
count += element.count; } else {
count += element.buyNum;
}
} }
} });
}); }
return InkWell( return InkWell(
onTap: () { onTap: () {
widget.queryMiNiDetail(productListBeans[position].id); widget.queryMiNiDetail(productListBeans[position].id);
}, },
child: ShopGoods( child: ShopGoods(
productListBeans[position], (ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) {
(int count, List<Attr> attr, String productId) { widget.queryMiNiDetail(productListBeans[position].id);
int allCount = 0; },
AiDecimalAccuracy allPrice = AiDecimalAccuracy.zero; (ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) {
widget.shopCarGoods.forEach((element2) { widget.queryMiNiDetail(productListBeans[position].id);
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");
allPrice += (aiPrice * aiDecimalAccuracy);
}
});
widget.fc(count, productId, allCount, allPrice.toDouble());
setState(() {});
}, },
productListBean: productListBeans[position],
count: count, count: count,
queryMiNiDetail: widget.queryMiNiDetail, queryMiNiDetail: widget.queryMiNiDetail,
shopCarGoods: map, shoppingCartSkuItemListBean: shoppingCartSkuItemListBean,
), ),
); );
} }

Loading…
Cancel
Save