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. 385
      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. 110
      lib/store/store_view/product_sku.dart
  11. 87
      lib/store/store_view/shop_car.dart
  12. 55
      lib/store/store_view/shop_goods.dart
  13. 59
      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/treaty_page.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/union/location_map_page.dart';

1
lib/retrofit/data/settlement_bean.dart

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

4
lib/retrofit/data/shoppingCart.dart

@ -30,7 +30,7 @@ class ShoppingCart {
return shoppingCartBean;
}
Map toJson() => {
Map<String, dynamic> toJson() => {
"cartSum": cartSum,
"numberOfPeople": numberOfPeople,
"selected": selected,
@ -71,7 +71,7 @@ class ShoppingCartSkuItemListBean {
String skuPrice;
int skuStock;
String storeId;
int tableId;
String tableId;
static ShoppingCartSkuItemListBean fromJson(Map<String, dynamic> map) {
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_smart_dialog/flutter_smart_dialog.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/placeOrderFirst.dart';
import 'package:huixiang/retrofit/data/settlement_bean.dart';
@ -164,9 +165,11 @@ abstract class MinApiService {
///
@POST("order/getOrderInfo")
Future<BaseData<SettleOrderInfo>> getOrderInfo(
@Body() Map<String, dynamic> param);
Future<BaseData<SettleOrderInfo>> getOrderInfo(@Body() Map<String, dynamic> param);
///
@GET("address/queryMemberAddress")
Future<BaseData<List<Address>>> queryAddress();
///
@POST("order/placeOrderFirst")
@ -175,4 +178,5 @@ abstract class MinApiService {
///
@POST("order/settlement")
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;
}
@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
Future<BaseData<dynamic>> placeOrderFirst(param) async {
ArgumentError.checkNotNull(param, 'param');

385
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/material.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_svg/flutter_svg.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/order/order_view/order_commodity.dart';
import 'package:huixiang/order/order_view/order_info.dart';
import 'package:huixiang/retrofit/data/address.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.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/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/store/store_view/settlement_order_commodity.dart';
import 'package:huixiang/settlement/settlement_view/settlement_order_commodity.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/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/separator.dart';
import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -45,9 +45,6 @@ class _Settlement extends State<Settlement> {
SettleOrderInfo settleOrderInfo;
int selectedCouponIndex = -1;
List<ProductListBean> shopCar = [];
List<Sku> shopCarGoods = [];
TextEditingController _vc;
List<String> addressBgs = [
"assets/svg/dingdan_ziqu.svg",
@ -59,8 +56,6 @@ class _Settlement extends State<Settlement> {
void initState() {
super.initState();
storeInfo = widget.arguments["storeInfo"];
shopCar = widget.arguments["shopProduct"];
shopCarGoods = widget.arguments["shopGoods"];
_vc = TextEditingController(
text: storeInfo != null ? storeInfo.headMobile : "");
@ -68,24 +63,69 @@ class _Settlement extends State<Settlement> {
SharedPreferences.getInstance().then((value) {
String minToken = value.getString("minToken");
String tenant = value.getString("tenant");
String storeId = value.getString("storeId");
minService = MinApiService(
Dio(),
context: context,
token: minToken,
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({
"addressId": null,
"isTake": 0,
"memberCouponId": null,
"orderId": 0,
"promotionId": null
"addressId": addressId,
"isTake": isTake,
"memberCouponId": memberCouponId,
"orderId": orderId,
"promotionId": promotionId
});
if (baseData != null && baseData.isSuccess) {
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 {
PlaceOrderFirst placeOrderFirst = PlaceOrderFirst();
@ -109,34 +198,21 @@ class _Settlement extends State<Settlement> {
placeOrderFirst.parentId = 0;
placeOrderFirst.payChannel = 1;
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.recMobile = storeInfo.headMobile;
placeOrderFirst.shoppingCartSkuItemList = [];
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.storeId = storeInfo.id;
placeOrderFirst.subcribeTime = null;
placeOrderFirst.tableId = 0;
BaseData baseData = await minService.placeOrderFirst(
placeOrderFirst.toJson()).catchError((error) {});
BaseData baseData = await minService
.placeOrderFirst(placeOrderFirst.toJson())
.catchError((error) {});
if (baseData != null && baseData.isSuccess) {
querySettlement();
}
@ -150,97 +226,18 @@ class _Settlement extends State<Settlement> {
settlementBean.id = 0;
settlementBean.isLogistics = true;
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.promotionInfoDTO = PromotionInfoDTO();
settlementBean.promotionInfoDTO.couponId = 0;
settlementBean.promotionInfoDTO.promotionId = 0;
BaseData baseData = await minService.settlementApi({
}).catchError((error) {});
if (baseData != null && baseData.isSuccess) {
}
BaseData baseData =
await minService.settlementApi({}).catchError((error) {});
if (baseData != null && baseData.isSuccess) {}
}
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
Widget build(BuildContext context) {
return Stack(
@ -267,6 +264,10 @@ class _Settlement extends State<Settlement> {
titleSize: 18.sp,
),
body: Container(
child: Column(
children: [
Expanded(
child: Container(
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Container(
@ -281,7 +282,10 @@ class _Settlement extends State<Settlement> {
phoneWidget(),
///
SettlementOrderCommodity(shopCar, 0, shopCarGoods, settleOrderInfo),
SettlementOrderCommodity(
0,
settleOrderInfo,
),
// if (payStatus == 0) couponRemarks(),
/*(payStatus == 0) ? paySelector() : */
@ -295,17 +299,9 @@ class _Settlement extends State<Settlement> {
),
),
),
flex: 1,
),
left: 0,
right: 0,
top: 0,
bottom: 0,
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
Container(
height: 54.h,
color: Colors.white,
child: Row(
@ -321,7 +317,7 @@ class _Settlement extends State<Settlement> {
),
),
Text(
"¥19.00",
"${settleOrderInfo.orderSum}",
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.semi_bold,
@ -339,13 +335,23 @@ class _Settlement extends State<Settlement> {
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060),
fontSize: 16.sp,
padding: EdgeInsets.symmetric(vertical: 5.h,),
padding: EdgeInsets.symmetric(
vertical: 5.h,
),
callback: () {},
),
],
),
),
)
],
),
),
),
left: 0,
right: 0,
top: 0,
bottom: 0,
),
],
);
}
@ -504,9 +510,8 @@ class _Settlement extends State<Settlement> {
flex: 1,
child: GestureDetector(
onTap: () {
setState(() {
selectedBtn = 0;
});
queryOrderInfo(null, selectedBtn, null, 0, null);
},
child: Container(
height: 50.h,
@ -526,9 +531,8 @@ class _Settlement extends State<Settlement> {
flex: 1,
child: GestureDetector(
onTap: () {
setState(() {
selectedBtn = 1;
});
queryAddress();
},
child: Container(
height: 50.h,
@ -579,8 +583,9 @@ class _Settlement extends State<Settlement> {
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text(
storeInfo != null
@ -594,7 +599,7 @@ class _Settlement extends State<Settlement> {
),
),
SizedBox(
height: 4,
height: 6,
),
Text(
storeInfo != null
@ -608,9 +613,6 @@ class _Settlement extends State<Settlement> {
color: Color(0xFF727272),
),
),
SizedBox(
height: 12,
),
],
),
),
@ -634,7 +636,9 @@ class _Settlement extends State<Settlement> {
RoundButton(
width: 41.w,
height: 13,
text: "距离您11m",
text: distance.length > 3
? "${distance}km"
: "距离您${distance}km",
textColor: Color(0xFF34A262),
fontWeight: MyFontWeight.semi_bold,
radius: 7.5,
@ -649,8 +653,11 @@ class _Settlement extends State<Settlement> {
],
),
],
)
),
],
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
),
],
),
@ -692,10 +699,12 @@ class _Settlement extends State<Settlement> {
color: Color(0xFF4C4C4C),
),
),
), InkWell(
),
InkWell(
onTap: () {
setState(() {
Navigator.of(context).popAndPushNamed('/router/manage_address_page');
Navigator.of(context).popAndPushNamed(
'/router/manage_address_page');
});
},
child: Icon(
@ -772,10 +781,13 @@ class _Settlement extends State<Settlement> {
),
),
Text(
(settleOrderInfo?.couponList == null || settleOrderInfo.couponList.length == 0)
? "暂无可用优惠券" : (selectedCouponIndex == -1
? "拥有${settleOrderInfo.couponList.length}张优惠券":
settleOrderInfo.couponList[selectedCouponIndex].promotionName),
(settleOrderInfo?.couponList == null ||
settleOrderInfo.couponList.length == 0)
? "暂无可用优惠券"
: (selectedCouponIndex == -1
? "拥有${settleOrderInfo.couponList.length}张优惠券"
: settleOrderInfo
.couponList[selectedCouponIndex].promotionName),
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 14.sp,
@ -956,35 +968,14 @@ 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() {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return StatefulBuilder(builder: (context1, state) {
return StatefulBuilder(
builder: (context1, state) {
return Container(
alignment: Alignment.topCenter,
width: double.infinity,
@ -1013,10 +1004,14 @@ class _Settlement extends State<Settlement> {
children: [
Expanded(
child: Text(
(settleOrderInfo?.couponList == null || settleOrderInfo.couponList.length == 0)
? "暂无可用优惠券" : (selectedCouponIndex == -1
? "拥有${settleOrderInfo.couponList.length}张优惠券":
settleOrderInfo.couponList[selectedCouponIndex].promotionName),
(settleOrderInfo?.couponList == null ||
settleOrderInfo.couponList.length == 0)
? "暂无可用优惠券"
: (selectedCouponIndex == -1
? "拥有${settleOrderInfo.couponList.length}张优惠券"
: settleOrderInfo
.couponList[selectedCouponIndex]
.promotionName),
style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
@ -1045,13 +1040,17 @@ class _Settlement extends State<Settlement> {
right: 16,
),
child: ListView.builder(
itemCount:settleOrderInfo == null ? 0 : settleOrderInfo.couponList.length,
itemCount: settleOrderInfo == null
? 0
: settleOrderInfo.couponList.length,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
// return shoppGoodsItem();
return GestureDetector(
onTap: () {},
child: couponItem(settleOrderInfo.couponList[position],position),
child: couponItem(
settleOrderInfo.couponList[position],
position,
),
);
},
),
@ -1060,7 +1059,8 @@ class _Settlement extends State<Settlement> {
],
),
);
});
},
);
},
);
}
@ -1212,16 +1212,20 @@ class _Settlement extends State<Settlement> {
// SmartDialog.showToast("当前优惠券不可用", alignment: Alignment.center);
// return;
// }
double toPrice = double.parse(totalPrice(false));
double amount = double.parse(couponList.fullAmount);
double toPrice = double.parse("0");
double amount =
double.parse(couponList.fullAmount);
if (toPrice <= amount) {
SmartDialog.showToast("当前金额不够使用优惠券", alignment: Alignment.center);
SmartDialog.showToast("当前金额不够使用优惠券",
alignment: Alignment.center);
return;
}
state(() {
if (selectedCouponIndex == index)
selectedCouponIndex = -1;
else {selectedCouponIndex = index;}
else {
selectedCouponIndex = index;
}
});
Navigator.of(context).pop();
});
@ -1282,7 +1286,12 @@ class _Settlement extends State<Settlement> {
onTap: () {
setState(() {
state(() {
this.settleOrderInfo.couponList[index].isEx = !(this.settleOrderInfo.couponList[index].isEx??false);
this.settleOrderInfo.couponList[index].isEx =
!(this
.settleOrderInfo
.couponList[index]
.isEx ??
false);
});
});
},

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

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/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';
@ -53,8 +51,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
StoreOrderListPage storeOrderListPage;
ScrollController controller = ScrollController();
List<ShoppingCart> shopCarGoods;
ShoppingCart shopCarGoods;
@override
void initState() {
@ -112,6 +109,10 @@ class _StoreOrderPage extends State<StoreOrderPage>
tenant: tenant,
storeId: storeId,
);
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
}
});
}
@ -314,7 +315,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
shopCarGoods,
controller,
_queryMiNiDetail,
_productListResult,
// _productListResult,
_fc,
),
@ -352,7 +353,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
),
),
Text(
"$allPrice",
"${shopCarGoods != null ? shopCarGoods.cartSum : "0.0"}",
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.medium,
@ -398,7 +399,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
child: RoundButton(
width: 17,
height: 17,
text: "${allCount}",
text: "${count()}",
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
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() {
if (shopCarGoods == null || shopCarGoods.length == 0) {
SmartDialog.showToast("请选择要购买的商品~");
int num = count();
if (num == 0) {
SmartDialog.showToast("请先选择您要购买的商品!~");
return;
}
@ -425,7 +441,6 @@ class _StoreOrderPage extends State<StoreOrderPage>
'/router/settlement',
arguments: {
"storeInfo": storeInfo,
"shopGoods": shopCarGoods,
},
);
}
@ -467,25 +482,26 @@ class _StoreOrderPage extends State<StoreOrderPage>
);
}
GlobalKey shopCartKey = GlobalKey();
///
showShoppingCart() {
queryShopCar().then((value) {
this.shopCarGoods = value;
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return ShopCar(
value,
shopCartKey,
this.shopCarGoods,
clearShopCar,
toDownOrder,
(int count, String productId, allCount, allPrice) {
// print("shopCarCount: $allCount allPrice: $allPrice ");
},
shopCartAdd,
shopCartReduce,
);
},
);
});
}
@ -493,7 +509,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
clearShopCar() async {
BaseData<bool> baseData = await minService.clearShoppingCart();
if (baseData.isSuccess) {
shopCarGoods = null;
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 {
if (sku != null) {
Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async {
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({
"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": "",
"buyNum": count,
"id": skuId,
"productId": miNiDetail.id,
"productName": miNiDetail.productName,
"skuName": skuValue,
"storeId": storeInfo.id,
}
"skuPrice": productSku.applyPrice,
"skuStock": productSku.skuStock,
"tableId": 0,
},
],
});
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);
if (baseDate != null && baseDate.isSuccess) {
return baseDate.data;
if (baseDate != null &&
baseDate.isSuccess &&
baseDate.data != null &&
baseDate.data.length > 0) {
return baseDate.data[0];
} else {
return [];
return null;
}
}
///
showStoreSelector(MiNiDetail miNiDetail, String id) async {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
builder: (context) {
return ProductSku(miNiDetail, id, _addShopCar);
},
);
///1
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) {
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 {

110
lib/store/store_view/product_sku.dart

@ -2,16 +2,28 @@ import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:flutter_screenutil/flutter_screenutil.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/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/round_button.dart';
class ProductSku extends StatefulWidget {
final MiNiDetail miNiDetail;
final String productId;
final Function(Sku sku) addShopCar;
ProductSku(this.miNiDetail, this.productId, this.addShopCar);
final Function(MiNiDetail miNiDetail, List<String> selectSkus, int count) 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
State<StatefulWidget> createState() {
@ -21,29 +33,47 @@ class ProductSku extends StatefulWidget {
class _ProductSku extends State<ProductSku> {
List<String> selectSkus = [];
int selectCount = 1;
Sku tempSelected;
int count = 1;
@override
void initState() {
super.initState();
if (widget.miNiDetail != null) {
tempSelected = Sku(widget.productId, 1, widget.miNiDetail.price);
tempSelected.name = widget.miNiDetail.productName;
widget.miNiDetail.attrList.forEach((element) {
selectSkus.add(element.attrValueList[0].attrValue);
tempSelected.attr.add(
Attr(
"${element.id}",
"${element.attrValueList[0].id}",
),
);
});
buildCount();
}
buildCount() {
count = 1;
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
Widget build(BuildContext context) {
return StatefulBuilder(builder: (context1, state) {
@ -150,22 +180,10 @@ class _ProductSku extends State<ProductSku> {
itemBuilder: (context, position) {
return attrItem(
(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(() {
selectSkus[position] = widget.miNiDetail
.attrList[position].attrValueList[index].attrValue;
buildCount();
});
},
widget.miNiDetail.attrList[position],
@ -192,10 +210,11 @@ class _ProductSku extends State<ProductSku> {
),
InkWell(
onTap: () {
state(() {
if (selectCount > 1) selectCount--;
if (count > 1)
setState(() {
count -= 1;
});
tempSelected.count = selectCount;
widget.reduce(widget.miNiDetail, selectSkus);
},
child: Image.asset(
"assets/image/reduce.png",
@ -206,7 +225,7 @@ class _ProductSku extends State<ProductSku> {
Padding(
padding: EdgeInsets.only(left: 8, right: 8),
child: Text(
selectCount.toString(),
"$count",
style: TextStyle(
color: Colors.black,
fontSize: 14.sp,
@ -216,10 +235,10 @@ class _ProductSku extends State<ProductSku> {
),
InkWell(
onTap: () {
state(() {
selectCount++;
tempSelected.count = selectCount;
setState(() {
count += 1;
});
widget.add(widget.miNiDetail, selectSkus);
},
child: Image.asset(
"assets/image/add.png",
@ -242,7 +261,7 @@ class _ProductSku extends State<ProductSku> {
backgroup: Color(0xFF32A060),
fontSize: 16.sp,
callback: () {
_result();
widget.addShopCar(widget.miNiDetail, selectSkus, 1);
},
),
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) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,

87
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:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.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/utils/font_weight.dart';
import 'package:huixiang/view_widget/round_button.dart';
@ -13,18 +10,20 @@ class ShopCar extends StatefulWidget {
final Function(String id) queryMiNiDetail;
final Function() clearShopCar;
final Function() toDownOrder;
final Function(ShoppingCartSkuItemListBean cart) shopCartAdd;
final Function(ShoppingCartSkuItemListBean cart) shopCartReduce;
final List<ShoppingCart> shopingCar;
final Function(int count, String productId, int allCount, double allPrice) fc;
ShoppingCart shopingCar;
ShopCar(
Key key,
this.shopingCar,
this.clearShopCar,
this.toDownOrder,
this.fc, {
this.shopCartAdd,
this.shopCartReduce, {
this.queryMiNiDetail,
});
}) : super(key: key);
@override
State<StatefulWidget> createState() {
@ -33,13 +32,6 @@ class ShopCar extends StatefulWidget {
}
class _ShopCar extends State<ShopCar> {
int allCount = 0;
double allPrice = 0.0;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
@ -81,9 +73,7 @@ class _ShopCar extends State<ShopCar> {
),
InkWell(
onTap: () {
allPrice = 0;
allCount = 0;
widget.shopingCar.shoppingCartSkuItemList.clear();
state(() {});
widget.clearShopCar();
},
@ -111,27 +101,17 @@ class _ShopCar extends State<ShopCar> {
right: 16,
),
child: ListView.builder(
itemCount: widget.shopingCar == null
? 0
: widget.shopingCar.length,
itemCount: itemCount(),
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {},
child: ShopGoods(
widget.shopingCar[position],
(int count, List<Attr> attr, String productId) {
widget.fc(
count, productId, allCount, allPrice);
state(() {});
},
count: _shopCarGoods(position).count,
shopCarGoods: _shopCarGoods(position),
return ShopGoods(
widget.shopCartAdd,
widget.shopCartReduce,
count: widget.shopingCar
.shoppingCartSkuItemList[position].buyNum,
shoppingCartSkuItemListBean:
widget.shopingCar.shoppingCartSkuItemList[position],
queryMiNiDetail: widget.queryMiNiDetail,
),
);
},
),
@ -169,7 +149,10 @@ class _ShopCar extends State<ShopCar> {
),
),
Text(
"" + allPrice.toString(),
"" +
(widget.shopingCar == null
? "0.0"
: widget.shopingCar.cartSum),
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.medium,
@ -215,7 +198,7 @@ class _ShopCar extends State<ShopCar> {
child: RoundButton(
width: 17,
height: 17,
text: allCount.toString(),
text: "${count()}",
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060),
@ -243,14 +226,24 @@ class _ShopCar extends State<ShopCar> {
);
}
Sku _shopCarGoods(int position) {
Sku map = widget.shopCarGoods[position];
// widget.shopCarGoods.forEach((element) {
// if (widget.productLists[position].id == element.id) {
// map = element;
// }
// });
// print("shopCarGoods123123: ${map.toJson()}");
return map;
int itemCount() {
if (widget.shopingCar == null || widget.shopingCar.shoppingCartSkuItemList == null || widget.shopingCar.shoppingCartSkuItemList.length == 0) return 0;
int index = widget.shopingCar.shoppingCartSkuItemList.indexWhere((element) => element.buyNum == 0);
if (index >= 0) {
widget.shopingCar.shoppingCartSkuItemList.removeAt(index);
}
int count = widget.shopingCar.shoppingCartSkuItemList.length;
return count;
}
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:huixiang/generated/l10n.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:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/round_button.dart';
class ShopGoods extends StatefulWidget {
final ProductListBean product;
final Function(String id) queryMiNiDetail;
final Function(int count, List<Attr> attr, String productId) fc;
final Sku shopCarGoods;
final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) add;
final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) reduce;
final ProductListBean productListBean;
final ShoppingCartSkuItemListBean shoppingCartSkuItemListBean;
final int count;
ShopGoods(
this.product,
this.fc, {
this.add,
this.reduce, {
this.productListBean,
this.count = 0,
this.queryMiNiDetail,
this.shopCarGoods,
this.shoppingCartSkuItemListBean,
});
@override
State<StatefulWidget> createState() {
return _ShopGoods();
}
}
class _ShopGoods extends State<ShopGoods> {
@override
Widget build(BuildContext context) {
return Container(
@ -47,7 +48,10 @@ class _ShopGoods extends State<ShopGoods> {
children: [
SizedBox(width: 12.w),
MImage(
widget.product != null ? widget.product.imgPath : "",
widget.productListBean != null ? widget.productListBean.imgPath :
(widget.shoppingCartSkuItemListBean != null
? widget.shoppingCartSkuItemListBean.skuImg
: ""),
width: 70,
height: 70,
fit: BoxFit.cover,
@ -62,7 +66,7 @@ class _ShopGoods extends State<ShopGoods> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.product.productName,
widget.productListBean != null ? widget.productListBean.productName : widget.shoppingCartSkuItemListBean.productName,
style: TextStyle(
color: Colors.black,
fontSize: 13.sp,
@ -72,11 +76,13 @@ class _ShopGoods extends State<ShopGoods> {
SizedBox(
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(
children: [
Expanded(
child: Text(
widget.product.shortName,
(widget.productListBean != null ? widget.productListBean.shortName : widget.shoppingCartSkuItemListBean.skuName ?? ""),
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(
@ -113,7 +119,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4,
),
Text(
"¥${widget.product.price}",
"¥${widget.productListBean != null ? widget.productListBean.price : widget.shoppingCartSkuItemListBean.skuPrice}",
style: TextStyle(
color: Color(0xFFFF7A1A),
fontSize: 11.sp,
@ -136,7 +142,7 @@ class _ShopGoods extends State<ShopGoods> {
width: 4,
),
Text(
"¥${widget.product.applyPrice}",
"¥${widget.productListBean != null ? widget.productListBean.applyPrice : widget.shoppingCartSkuItemListBean.skuPrice}",
style: TextStyle(
color: Color(0xFFA29E9E),
fontSize: 10.sp,
@ -159,15 +165,14 @@ class _ShopGoods extends State<ShopGoods> {
fontSize: 11.sp,
padding: EdgeInsets.symmetric(vertical: 5.h),
callback: () {
widget.queryMiNiDetail(widget.product.id);
widget.queryMiNiDetail(
widget.productListBean != null ? widget.productListBean.id : widget.shoppingCartSkuItemListBean.productId);
},
),
if (widget.count > 0)
InkWell(
onTap: () {
reduceCount();
widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id);
setState(() {});
widget.reduce(widget.shoppingCartSkuItemListBean);
},
child: Image.asset(
"assets/image/reduce.png",
@ -191,9 +196,7 @@ class _ShopGoods extends State<ShopGoods> {
if (widget.count > 0)
InkWell(
onTap: () {
addCount();
widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id);
setState(() {});
widget.add(widget.shoppingCartSkuItemListBean);
},
child: Image.asset(
"assets/image/add.png",
@ -210,14 +213,4 @@ class _ShopGoods extends State<ShopGoods> {
),
);
}
addCount() {
widget.shopCarGoods.count += 1;
}
reduceCount() {
widget.shopCarGoods.count -= 1;
}
}

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

Loading…
Cancel
Save