From e4cd9fd2549c959f13a6d08d13c5efc1c71f8cb0 Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Mon, 10 Oct 2022 16:51:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A5=97=E9=A4=90=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E9=80=89=E6=8B=A9=EF=BC=9B=20=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=90=9C=E7=B4=A2=E6=9B=B4=E6=94=B9=EF=BC=9B?= =?UTF-8?q?=20=E5=AE=89=E5=8D=93=E7=94=A8=E6=88=B7bug=E7=9A=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mine/recharge_page.dart | 6 +- lib/retrofit/data/miNiDetail.dart | 19 +- lib/retrofit/data/shoppingCart.dart | 115 ++ lib/settlement/settlement.dart | 4 +- lib/store/store_order.dart | 11 +- lib/store/store_view/product_meals_sku.dart | 1255 +++++-------------- lib/store/store_view/shop_car.dart | 5 +- lib/store/store_view/shop_goods.dart | 79 +- lib/store/store_view/shop_goods_car.dart | 334 +++++ lib/store/store_view/store_order_list.dart | 4 + lib/view_widget/selector_store_dialog.dart | 2 +- 11 files changed, 888 insertions(+), 946 deletions(-) create mode 100644 lib/store/store_view/shop_goods_car.dart diff --git a/lib/mine/recharge_page.dart b/lib/mine/recharge_page.dart index 848d0bb6..748e19fb 100644 --- a/lib/mine/recharge_page.dart +++ b/lib/mine/recharge_page.dart @@ -665,9 +665,6 @@ class _RechargePage extends State { // alignment: Alignment.center); // return; // } - - - BaseData baseData = await apiService.recharge({ "amount": 0, "rechargeActId": rechargeA[selectIndex].id, @@ -703,9 +700,10 @@ class _RechargePage extends State { if (!value) { SmartDialog.showToast("请安装支付宝", alignment: Alignment.center) }else{ - tobias.aliPay(baseData.data["body"],evn: AliPayEvn.SANDBOX).then((payRes) { + tobias.aliPay(baseData.data["body"]).then((payRes) { if (payRes['resultStatus'] == 9000 || payRes['resultStatus'] == '9000') { + SmartDialog.showToast("充值成功", alignment: Alignment.center); Navigator.of(context).pop(); } else { SmartDialog.showToast(payRes['memo'], alignment: Alignment.center); diff --git a/lib/retrofit/data/miNiDetail.dart b/lib/retrofit/data/miNiDetail.dart index 9c716055..c2f2a725 100644 --- a/lib/retrofit/data/miNiDetail.dart +++ b/lib/retrofit/data/miNiDetail.dart @@ -472,6 +472,7 @@ class ProductInfoList { List _skuInfoList; List _productAttrInfoList; int _number; + int _count = 0; ProductInfoList copyWith({ String productId, String productName, String productImg, @@ -493,7 +494,15 @@ class ProductInfoList { bool get allSku => _allSku; List get skuInfoList => _skuInfoList; List get productAttrInfoList => _productAttrInfoList; - int get number => _number; + int number; + + int get count => _count; + + set count(int value) { + _count = value; + } + + Map toJson() { final map = {}; @@ -540,6 +549,7 @@ class ProductAttrInfoList { String _attrId; String _attrName; List _attrValueList; + String _selectSku; ProductAttrInfoList copyWith({ String attrId, String attrName, List attrValueList, @@ -551,6 +561,13 @@ class ProductAttrInfoList { String get attrName => _attrName; List get attrValueList => _attrValueList; + + String get selectSku => _selectSku; + + set selectSku(String value) { + _selectSku = value; + } + Map toJson() { final map = {}; map['attrId'] = _attrId; diff --git a/lib/retrofit/data/shoppingCart.dart b/lib/retrofit/data/shoppingCart.dart index efac9390..521b7f3d 100644 --- a/lib/retrofit/data/shoppingCart.dart +++ b/lib/retrofit/data/shoppingCart.dart @@ -77,6 +77,7 @@ class ShoppingCartSkuItemListBean { String groupId; String id; List platterList; + List setMealDataList; String productId; String productName; String skuId; @@ -98,6 +99,9 @@ class ShoppingCartSkuItemListBean { shoppingCartSkuItemListBean.platterList = []..addAll( (map['platterList'] as List ?? []).map((o) => PlatterListBean.fromJson(o)) ); + shoppingCartSkuItemListBean.setMealDataList = []..addAll( + (map['setMealDataList'] as List ?? []).map((o) => SetMealDataList.fromJson(o)) + ); shoppingCartSkuItemListBean.productId = map['productId']; shoppingCartSkuItemListBean.skuId = map['skuId']; shoppingCartSkuItemListBean.productName = map['productName']; @@ -117,6 +121,7 @@ class ShoppingCartSkuItemListBean { "groupId": groupId, "id": id, "platterList": platterList, + "setMealDataList":setMealDataList, "productId": productId, "skuId": skuId, "productName": productName, @@ -162,6 +167,116 @@ class PlatterListBean { "skuId": skuId, }; } +/// groupName : "锅底2选1" +/// productInfoList : [{"skuId":"1491652895857180672","skuName":"中辣","buyNumber":1,"productId":"1315903449707053056","sellPrice":48.0,"productName":"牛棒骨汤鸳鸯锅"}] + +class SetMealDataList { + SetMealDataList({ + String groupName, + List productInfoList,}){ + _groupName = groupName; + _productInfoList = productInfoList; + } + + SetMealDataList.fromJson(dynamic json) { + _groupName = json['groupName']; + if (json['productInfoList'] != null) { + _productInfoList = []; + json['productInfoList'].forEach((v) { + _productInfoList.add(ProductInfoList.fromJson(v)); + }); + } + } + String _groupName; + List _productInfoList; + SetMealDataList copyWith({ String groupName, + List productInfoList, + }) => SetMealDataList( groupName: groupName ?? _groupName, + productInfoList: productInfoList ?? _productInfoList, + ); + String get groupName => _groupName; + List get productInfoList => _productInfoList; + + Map toJson() { + final map = {}; + map['groupName'] = _groupName; + if (_productInfoList != null) { + map['productInfoList'] = _productInfoList.map((v) => v.toJson()).toList(); + } + return map; + } + +} + +/// skuId : "1491652895857180672" +/// skuName : "中辣" +/// buyNumber : 1 +/// productId : "1315903449707053056" +/// sellPrice : 48.0 +/// productName : "牛棒骨汤鸳鸯锅" + +class ProductInfoList { + ProductInfoList({ + String skuId, + String skuName, + int buyNumber, + String productId, + double sellPrice, + String productName,}){ + _skuId = skuId; + _skuName = skuName; + _buyNumber = buyNumber; + _productId = productId; + _sellPrice = sellPrice; + _productName = productName; + } + + ProductInfoList.fromJson(dynamic json) { + _skuId = json['skuId']; + _skuName = json['skuName']; + _buyNumber = json['buyNumber']; + _productId = json['productId']; + _sellPrice = json['sellPrice']; + _productName = json['productName']; + } + String _skuId; + String _skuName; + int _buyNumber; + String _productId; + double _sellPrice; + String _productName; + ProductInfoList copyWith({ String skuId, + String skuName, + int buyNumber, + String productId, + double sellPrice, + String productName, + }) => ProductInfoList( skuId: skuId ?? _skuId, + skuName: skuName ?? _skuName, + buyNumber: buyNumber ?? _buyNumber, + productId: productId ?? _productId, + sellPrice: sellPrice ?? _sellPrice, + productName: productName ?? _productName, + ); + String get skuId => _skuId; + String get skuName => _skuName; + int get buyNumber => _buyNumber; + String get productId => _productId; + double get sellPrice => _sellPrice; + String get productName => _productName; + + Map toJson() { + final map = {}; + map['skuId'] = _skuId; + map['skuName'] = _skuName; + map['buyNumber'] = _buyNumber; + map['productId'] = _productId; + map['sellPrice'] = _sellPrice; + map['productName'] = _productName; + return map; + } + +} /// id : "1437254523520286720" /// createTime : "2021-09-13 11:19:16" diff --git a/lib/settlement/settlement.dart b/lib/settlement/settlement.dart index e0c8fbe1..d52a50f8 100644 --- a/lib/settlement/settlement.dart +++ b/lib/settlement/settlement.dart @@ -115,7 +115,7 @@ class _Settlement extends State { token: minToken, tenant: tenant, storeId: storeId, - showLoading: true); + ); if (promotions != null && promotions != "" && tableId <= 0) { queryOrderInfo( address != null ? address.id : null, @@ -478,6 +478,7 @@ class _Settlement extends State { print("error: $error"); }); if (baseData != null && baseData.isSuccess) { + EasyLoading.show(status: S.current.zhengzaijiazai); placeOrder = true; this.downOrder = DownOrder.fromJson(baseData.data); querySettlement(); @@ -642,6 +643,7 @@ class _Settlement extends State { } toOrderDetails(String orderId) { + EasyLoading.dismiss(); Navigator.of(context).pushReplacementNamed( '/router/order_details', arguments: { diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index afcd9e59..2fcff32e 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -425,6 +425,7 @@ class _StoreOrderPage extends State controller, minToken, tenant, + tableId, _queryMiNiDetail, () { queryShopCar().then((value) { this.shopCarGoods = value; @@ -499,12 +500,12 @@ class _StoreOrderPage extends State Spacer(), GestureDetector( onTap: () { - if(AppUtils.compareTime(storeInfo.openStartTime,DateFormat('HH:mm:ss').format(DateTime.now())) - &&(!AppUtils.compareTime(storeInfo.openEndTime,DateFormat('HH:mm:ss').format(DateTime.now())))){ + // if(AppUtils.compareTime(storeInfo.openStartTime,DateFormat('HH:mm:ss').format(DateTime.now())) + // &&(!AppUtils.compareTime(storeInfo.openEndTime,DateFormat('HH:mm:ss').format(DateTime.now())))){ toDownOrder(); - } - else - SmartDialog.showToast("营业时间:${storeInfo.openStartTime}-${storeInfo.openEndTime}", alignment: Alignment.center); + // } + // else + // SmartDialog.showToast("营业时间:${storeInfo.openStartTime}-${storeInfo.openEndTime}", alignment: Alignment.center); }, child: RoundButton( width: 103.w, diff --git a/lib/store/store_view/product_meals_sku.dart b/lib/store/store_view/product_meals_sku.dart index 6ac406f5..ce8c2eb1 100644 --- a/lib/store/store_view/product_meals_sku.dart +++ b/lib/store/store_view/product_meals_sku.dart @@ -31,36 +31,24 @@ class ProductMealsSku extends StatefulWidget { } } - - class _ProductMealsSku extends State { ApiService apiService; MinApiService minService; - final ScrollController scrollController = ScrollController(); final RefreshController refreshController = RefreshController(); String id; MiNiDetail miNiDetail; - ShoppingCart shopCarGoods; - bool dialogShowing = false; - StoreInfo storeInfo; String parentCode = ""; int tableId = 0; - String pName; - String pid; - String cName; - String cid; - List selectSkus = []; - List activitys; - int counts = 1; - String selectedPrice = ""; String storeId; String parentId; int numberOfPeople = 0; List productSetMeals; + List setMealData; @override void initState() { super.initState(); + tableId = widget.arguments["tableId"]; id = widget.arguments["id"]; storeId = widget.arguments["storeId"]; SharedPreferences.getInstance().then((value) { @@ -74,27 +62,18 @@ class _ProductMealsSku extends State { storeId: storeId, showLoading: true); queryMiNiDetail(id); - queryShopCar().then((value) { - this.shopCarGoods = value; - setState(() {}); - }); }); - queryStoreInfo(); - buildCount(); } ///商品详情 queryMiNiDetail(id) async { BaseData baseData = - await minService.miNiDetail(id).catchError((error) { + await minService.miNiDetail(id).catchError((error) { refreshController.refreshFailed(); }); if (baseData != null && baseData.isSuccess) { setState(() { miNiDetail = baseData.data; - miNiDetail.attrList.forEach((element) { - selectSkus.add(element.attrValueList[0].attrValue); - }); productSetMeals = miNiDetail.productSkuVOList[0].productSetMeals; }); refreshController.refreshCompleted(); @@ -103,439 +82,49 @@ class _ProductMealsSku extends State { } } - _onRefresh() { - queryMiNiDetail(id); - } - - /// 查询店铺信息 - queryStoreInfo() async { - SharedPreferences value = await SharedPreferences.getInstance(); - if (apiService == null) - apiService = ApiService( - Dio(), - context: context, - token: value.getString("token"), - ); - BaseData baseData = await apiService.queryStoreInfo(storeId).catchError((error) { - debugPrint(error); - }); - if (baseData != null && baseData.isSuccess) { - storeInfo = StoreInfo.fromJson(baseData.data); - activitys = storeInfo.informationVOPageVO.list - .map((e) => Activity.fromJson(e)) - .toList(); - if (mounted) { - setState(() {}); - } - } - EasyLoading.dismiss(); - } - - ///获取父订单(火锅订单加菜前调用) - getParentInfo() async { - BaseData baseData = await minService.getParentInfo("$tableId") - .catchError((error) {debugPrint(error);}); - if (baseData != null && baseData.isSuccess) { - if (baseData.data != null) { - parentId = baseData.data["id"]; - parentCode = baseData.data["parentCode"]; - } else { - ///TODO: 没有父订单, - queryStoreInfo1(); - } - } - } - - ///显示选择人数的弹窗 - showPeopleNum(String tableName) async { - var people = await showDialog( - context: context, - barrierDismissible: false, - builder: (context) { - return PeopleNumView(tableName); - }, - ); - - if (people != null && people > 0) { - setState(() { - this.numberOfPeople = people; + ///添加购物车 + addShopCar() async { + + List setMealDataList = []; + productSetMeals.forEach((element) { + List productInfoListBean = []; + element.productInfoList.forEach((ele) { + if(ele.count > 0) + productInfoListBean.add({ + "productId":ele.productId, + "skuId":(ele.productAttrInfoList[0].attrName == "") ? (ele.skuInfoList[0].productSkuAttrList[0].skuId): + (ele.skuInfoList.firstWhere((e1) => e1.skuName == ele.productAttrInfoList[0].selectSku).id) + }); + }); + setMealDataList.add({ + "groupName":element.groupName, + "productInfoList":productInfoListBean }); - } else { - Navigator.of(context).pop(); - } - } - - ///获取桌子信息 - queryStoreInfo1() async { - BaseData baseData = await minService.queryStoreInfo1({ - "getCoupon": true, - "storeId": storeId, - "tableId": tableId, - }).catchError((error) { - debugPrint(error); - }); - if (baseData != null && baseData.isSuccess) { - StoreInfo storeInfo = StoreInfo.fromJson(baseData.data); - if (storeInfo.storeTable != null) { - showPeopleNum(storeInfo.storeTable.tableName); - } - } - } - - ///计算个数 - 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() async { - int num = count(); - - if (parentId == null || parentId == "") { - if (num == 0) { - SmartDialog.showToast("请先选择您要购买的商品!~"); - return; - } - } - - await Navigator.of(context).pushNamed( - '/router/settlement', - arguments: { - "storeInfo": storeInfo, - "tableId": tableId, - "parentCode": parentCode, - "parentId": parentId, - // "pName": pName, - "pid": pid, - // "cName": cName, - "cid": cid, - "shoppingCart": shopCarGoods, - "numberOfPeople": numberOfPeople, - }, - ); - if (tableId > 0) { - getParentInfo(); - } - queryShopCar().then((value) { - this.shopCarGoods = value; - setState(() {}); }); - } - - /// 购物车的key,用于刷新UI - GlobalKey shopCartKey = GlobalKey(); - ///购物车弹窗 - showShoppingCart() { - queryShopCar().then((value) { - this.shopCarGoods = value; - dialogShowing = true; - SmartDialog.show( - widget: ShopCar( - shopCartKey, - this.shopCarGoods, - clearShopCar, - toDownOrder, - shopCartAdd, - shopCartReduce, - ), - onDismiss: () { - dialogShowing = false; + var requestData = { + "storeId": miNiDetail.storeId, + "tableId": tableId, + "parentId": 0, + "shoppingCartSkuItemList": [ + { + "buyNum": 1, + "id": miNiDetail.productSkuVOList[0].id, + "productName": miNiDetail.productName, + "skuPrice": miNiDetail.productSkuVOList[0].skuPrice, + "skuStock": miNiDetail.productSkuVOList[0].skuStock, + "skuImg": miNiDetail.productSkuVOList[0].skuImg, + "setMealDataList":setMealDataList }, - alignmentTemp: Alignment.bottomCenter, - ); - }); - } + ], + }; - ///清空购物车 - clearShopCar() async { - BaseData baseData = await minService.clearShoppingCart(); - if (baseData.isSuccess) { - shopCarGoods = null; - setState(() {}); - } - } - - ///选规格 - _queryMiNiDetail(String id, int count) async { - EasyLoading.show(status: S.current.zhengzaijiazai); - if(count < 0){ - shopCarGoods.shoppingCartSkuItemList.forEach((element) { - if(element.productId == id){ - shopCartReduce(element); - setState(() { - }); - } - }); - return; - } - BaseData baseData = await minService.miNiDetail(id); - if (baseData != null && baseData.isSuccess) { - showStoreSelector(baseData.data, id, count); - } - } - - ///选规格弹窗 - showStoreSelector(MiNiDetail miNiDetail, String id, int count) async { - if (miNiDetail.attrList != null && - miNiDetail.attrList.length == 1 && - miNiDetail.attrList[0].attrValueList.length == 1) { - _addShopCar(miNiDetail, [], counts); - } else { - showSpanDialog(); - } - } - - ///添加购物车 - Future _addShopCar(MiNiDetail miNiDetail, selectSkus, int count) async { - ProductSkuVOListBean productSku; - if (selectSkus != null && selectSkus.length == 0) { - productSku = miNiDetail.productSkuVOList.first; - } else { - 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> baseDate = await minService.addShoppingCart({ - "storeId": storeInfo.id, - "storeName": storeInfo.storeName ?? "", - "numberOfPeople": numberOfPeople, - "tableId": tableId, - "parentId": parentId, - "parentCode": parentCode, - "shoppingCartSkuItemList": [ - { - "buyNum": count, - "id": skuId, - "productId": miNiDetail.id, - "productName": miNiDetail.productName, - "skuName": skuValue, - "storeId": storeInfo.id, - "skuPrice": productSku.skuPrice, - "skuStock": productSku.skuStock, - "tableId": tableId, - }, - ], - }); + BaseData> baseDate = await minService.addShoppingCart(requestData); EasyLoading.dismiss(); if (baseDate != null && baseDate.isSuccess) { - queryShopCar().then((value) { - this.shopCarGoods = value; - setState(() {}); - }); - } - else { + Navigator.of(context).pop(); + } else { SmartDialog.showToast(baseDate?.msg, alignment: Alignment.center); - } - } - } - - ///查询购物车 - Future queryShopCar() async { - pName = ""; //活动 - pid = ""; //活动 - cName = ""; //优惠券 - cid = ""; //优惠券 - BaseData> baseDate = - await minService.getShoppingCart(tableId); - if (baseDate != null && - baseDate.isSuccess && - baseDate.data != null && - baseDate.data.length > 0) { - if (baseDate.data[0].selectDiscount == 1) { - baseDate.data[0].couponList.forEach((element) { - if (element.isMaxCoupon) { - // cName = element.promotionName; - cid = element.id; - } - }); - } else if (baseDate.data[0].selectDiscount == 2) { - baseDate.data[0].promotionInfoList.forEach((element) { - if (element.isMaxPromotion) { - // pName = element.name; - pid = element.id; - } - }); - } - return baseDate.data[0]; - } else { - return null; - } - } - - ///购物车➕1 - Future shopCartAdd( - ShoppingCartSkuItemListBean cartSkuItem) async { - Map shopCarTemp = shopCarGoods.toJson(); - cartSkuItem.buyNum += 1; - shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - BaseData> baseDate = - await minService.shoppingCartSingle(shopCarTemp); - if (baseDate.isSuccess) { - this.shopCarGoods = await queryShopCar(); - if (shopCartKey != null) { - shopCartKey.currentState.setState(() {}); - } - setState(() {}); - } - return this.shopCarGoods; - } - - ///购物车➖1 - Future shopCartReduce( - ShoppingCartSkuItemListBean cartSkuItem) async { - Map shopCarTemp = shopCarGoods.toJson(); - cartSkuItem.buyNum -= 1; - shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - BaseData> baseDate = - await minService.shoppingCartSingle(shopCarTemp); - if (baseDate.isSuccess) { - EasyLoading.dismiss(); - this.shopCarGoods = await queryShopCar(); - if (shopCartKey?.currentState != null) { - shopCartKey.currentState.setState(() {}); - } - setState(() { - }); - } - return this.shopCarGoods; - } - - ///商品➕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 shopCarTemp = shopCarGoods.toJson(); - shopCarGoods.tableId = "$tableId"; - - 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> 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.id); - int shopSkuIndex = shopCarGoods.shoppingCartSkuItemList - .indexWhere((element) => skuId == element.id); - - if (shopSkuItem != null) { - if (shopSkuItem.buyNum > 1) { - shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum -= 1; - } - } else { - await _addShopCar(miNiDetail, selectSkus, 2); - return; - } - shopCarGoods.tableId = "$tableId"; - - Map shopCarTemp = shopCarGoods.toJson(); - ShoppingCartSkuItemListBean cartSkuItem = shopCarGoods - .shoppingCartSkuItemList - .firstWhere((element) => skuId == element.id); - shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()]; - - BaseData> 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; - } - - buildCount() { - counts = 1; - ProductSkuVOListBean productSku; - try { - productSku = miNiDetail.productSkuVOList.firstWhere((element) { - return skuY(element, selectSkus); - }); - }catch(ex){ - return; - } - if (productSku == null) return; - selectedPrice = productSku.skuPrice; - String skuId = productSku.id; - if (shopCarGoods == null || shopCarGoods.shoppingCartSkuItemList == null) return; - int shopSkuIndex = shopCarGoods.shoppingCartSkuItemList.indexWhere((element) => skuId == element.id); - if (shopSkuIndex >= 0) { - counts = shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum; } } @@ -546,9 +135,6 @@ class _ProductMealsSku extends State { child: Stack( children: [ Container( - // height: 175.h, - // color: Color(0xFF3A405A), - // width: MediaQuery.of(context).size.width, decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.fill, @@ -558,258 +144,198 @@ class _ProductMealsSku extends State { width: double.infinity, height: 375.h, ), - Container( - child: Column( - children: [ - Expanded( - child: Container( - child: SingleChildScrollView( - physics: BouncingScrollPhysics(), - child: Container( - child: Column( - children: [ - GestureDetector( - child: Container( + if (productSetMeals != null) + Container( + child: Column( + children: [ + GestureDetector( + child: Container( + margin: EdgeInsets.only( + top: 50.h, left: 16.w, right: 16.w, bottom: 10.h), + decoration: BoxDecoration( + color: Colors.transparent, + ), + alignment: Alignment.centerLeft, + child: Image.asset( + "assets/image/integral_return.webp", + width: 24, + height: 24, + ), + ), + onTap: () { + Navigator.of(context).pop(); + }, + ), + Expanded( + child: Container( + child: SingleChildScrollView( + physics: BouncingScrollPhysics(), + child: Container( + child: Column( + children: [ + Container( + width: double.infinity, margin: EdgeInsets.only( - top: 50.h, left: 16.w, right: 16.w), + left: 16.w, + right: 16.w, + top: 26.h, + bottom: 16.h, + ), + padding: EdgeInsets.only( + left: 10.w, + right: 13.w, + top: 16.h, + bottom: 12.h, + ), decoration: BoxDecoration( - color: Colors.transparent, + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Color(0x08203303).withAlpha(12), + offset: Offset(0, 2), + blurRadius: 3, + spreadRadius: 0, + ), + ], + borderRadius: BorderRadius.circular(8), ), - alignment: Alignment.centerLeft, - child: Image.asset( - "assets/image/integral_return.webp", - width: 24, - height: 24, - ), - ), - onTap: () { - Navigator.of(context).pop(); - }, - ), - Container( - width: double.infinity, - margin: EdgeInsets.only( - left: 16.w, - right: 16.w, - top: 26.h, - bottom: 16.h, - ), - padding: EdgeInsets.only( - left: 10.w, - right: 13.w, - top: 16.h, - bottom: 12.h, - ), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Color(0x08203303).withAlpha(12), - offset: Offset(0, 2), - blurRadius: 3, - spreadRadius: 0, - ), - ], - borderRadius: BorderRadius.circular(8), - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // ListView.builder( - // itemCount:miNiDetail.productSkuVOList[0].productSetMeals.length, - // scrollDirection: Axis.vertical, - // physics: BouncingScrollPhysics(), - // shrinkWrap: true, - // padding: EdgeInsets.zero, - // itemBuilder: (context, position) { - // return productMealsList(); - // }, - // ), - // // Text( - // // "五选二", - // // style: TextStyle( - // // fontSize: 15.sp, - // // color: Colors.black, - // // fontWeight: FontWeight.w600, - // // ), - // // ), - // SizedBox(height: 8.h,), - ListView.builder( - itemCount:productSetMeals?.length??0, - scrollDirection: Axis.vertical, - physics: BouncingScrollPhysics(), - shrinkWrap: true, - padding: EdgeInsets.zero, - itemBuilder: (context, position) { - return productMealsList(productSetMeals[position]); - }, - ), - ], - ), - ) - ], + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ListView.builder( + itemCount: productSetMeals?.length ?? 0, + scrollDirection: Axis.vertical, + physics: BouncingScrollPhysics(), + shrinkWrap: true, + padding: EdgeInsets.zero, + itemBuilder: (context, position) { + return productMealsList( + position); + }, + ), + ], + ), + ) + ], + ), ), ), ), + flex: 1, ), - flex: 1, - ), - Stack( - alignment: Alignment.bottomLeft, - children: [ - Container( - margin: EdgeInsets.symmetric(horizontal: 14), - height: 45.h, - // color: Color(0xFFFAFAFA), - decoration: BoxDecoration( - color: Color(0xFF383A38), - borderRadius: BorderRadius.circular(100), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox(width:45.w,), - Text.rich( - TextSpan(children: [ - TextSpan( - text: "¥ ", - style: TextStyle( - fontSize: 12.sp, - color: Color(0xFFFFFFFF), - fontWeight: MyFontWeight.bold), - ), - TextSpan( - text: - shopCarGoods != null ? shopCarGoods.cartSum : "0.0", - style: TextStyle( - fontSize: 20.sp, - color: Color(0xFFFFFFFF), - fontWeight: MyFontWeight.semi_bold), - ), - ]), - ), - Spacer(), - GestureDetector( - onTap: () { - toDownOrder(); - }, - child: RoundButton( - width: 103.w, - height: 54.h, - text: S.current.jiesuan, - textColor: Colors.white, - fontWeight: MyFontWeight.bold, - backgroup: Color(0xFF32A060), - radius: 100, - fontSize: 16.sp, - padding: EdgeInsets.symmetric(vertical: 5.h), - ), - ), - ], - ), - ), - Stack( - children: [ - InkWell( - onTap: () { - if(count() != 0) - showShoppingCart(); - }, - child: Image.asset( - "assets/image/shopping_bag.webp", - width: 66, - height: 66, - fit: BoxFit.fitWidth, + Stack( + alignment: Alignment.bottomLeft, + children: [ + Container( + margin: EdgeInsets.only( + left: 14.w, + right: 14.w, + bottom: 30.h, ), - ), - if(count() != 0) - Positioned( - right: 5, - // top: 14, - child: RoundButton( - width: 17.w, - height: 17.h, - text: "${count()}", - textColor: Colors.white, - fontWeight: MyFontWeight.regular, - backgroup: Color(0xFFF65720), - fontSize: 12.sp, - radius: 100, - ), + height: 45.h, + // color: Color(0xFFFAFAFA), + decoration: BoxDecoration( + color: Color(0xFF383A38), + borderRadius: BorderRadius.circular(100), ), - ], - ), - ], - ), - ], - ), - ) + child: RoundButton( + width: double.infinity, + height: 54.h, + text: "加入购物车", + textColor: Colors.white, + fontWeight: MyFontWeight.semi_bold, + radius: 27, + backgroup: Color(0xFF32A060), + fontSize: 16.sp, + callback: () { + bool flag = true; + productSetMeals.forEach((element) { + int pInfoTotal = 0; + element.productInfoList.forEach((ele) { + pInfoTotal += ele.count; + }); + if (pInfoTotal != element.optionalNumber) { + flag = false; + return; + } + }); + if (!flag) { + SmartDialog.showToast("抱歉,还有商品未加购", + alignment: Alignment.center); + return; + } else { + addShopCar(); + } + }, + )), + ], + ), + ], + ), + ) ], ), ); } - Widget productMealsList(ProductSetMeals productSetMeals){ + Widget productMealsList(int position) { return Container( - margin: EdgeInsets.symmetric(vertical: 16.h), - child:Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "${productSetMeals.groupName}(${productSetMeals.totalNumber}选${productSetMeals.optionalNumber})", - style: TextStyle( - fontSize: 15.sp, - color: Colors.black, - fontWeight: FontWeight.w600, + margin: EdgeInsets.symmetric(vertical: 16.h), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "${productSetMeals[position].groupName}(${productSetMeals[position].totalNumber}选${productSetMeals[position].optionalNumber})", + style: TextStyle( + fontSize: 15.sp, + color: Colors.black, + fontWeight: FontWeight.w600, + ), ), - ), - SizedBox(height: 8.h,), - ListView.builder( - itemCount:productSetMeals.productInfoList.length, - scrollDirection: Axis.vertical, - physics: BouncingScrollPhysics(), - shrinkWrap: true, - padding: EdgeInsets.zero, - itemBuilder: (context, position) { - return productMealsItem(); - }, - ), - ], - ) - ); + SizedBox( + height: 8.h, + ), + ListView.builder( + itemCount: productSetMeals[position].productInfoList.length, + scrollDirection: Axis.vertical, + physics: BouncingScrollPhysics(), + shrinkWrap: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + return productMealsItem(position,index); + }, + ), + ], + )); } - Widget productMealsItem(){ + Widget productMealsItem(int position,int index) { return Container( margin: EdgeInsets.symmetric(vertical: 16.h), child: Row( children: [ - Image.asset( - "assets/image/hot_list.webp", - height: 70.h, - width: 70.h,), - // MImage( - // "", - // width: 70.h, - // height: 70.h, - // radius: BorderRadius.circular(4), - // fit: BoxFit.cover, - // errorSrc: "assets/image/default_1.webp", - // fadeSrc: "assets/image/default_1.webp", - // ), - SizedBox(width:12.h), + MImage( + productSetMeals[position].productInfoList[index].productImg ?? "", + width: 70.h, + height: 70.h, + radius: BorderRadius.circular(4), + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.webp", + fadeSrc: "assets/image/default_1.webp", + ), + SizedBox(width: 12.h), Expanded( child: Column( + mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Expanded( child: Text( - "哈哈哈", + productSetMeals[position].productInfoList[index].productName ?? "", overflow: TextOverflow.ellipsis, maxLines: 1, style: TextStyle( @@ -819,78 +345,95 @@ class _ProductMealsSku extends State { ), ), ), - // GestureDetector(child: - Text( - "选规则", - style: TextStyle( + if (productSetMeals[position].productInfoList[index].productAttrInfoList[0].attrName != "") + GestureDetector( + child: Text( + "选规格", + style: TextStyle( + color: Colors.black, + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + ), + ), + onTap: () { + showSkuDialog(position,index); + }, + ), + if (productSetMeals[position].productInfoList[index].productAttrInfoList[0].attrName != "") + Icon( + Icons.chevron_right, color: Colors.black, - fontSize: 13.sp, - fontWeight: MyFontWeight.regular, + size: 18, ), - ), - // onTap: showSpanDialog,), - Icon( - Icons.chevron_right, - color: Colors.black, - size: 18, - ), ], ), - SizedBox(height:8.h), - Text( - "¥222", - style: TextStyle( - color: Color(0xFFF55620), - fontSize: 16.sp, - fontWeight: MyFontWeight.medium, - ), - ), - SizedBox( - height: 4.h, - ), + SizedBox(height: 8.h), Row( children: [ - Text( - "常温/半分糖/500ml", - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: TextStyle( - color: Color(0xFFA29E9E), - fontSize: 13.sp, - fontWeight: MyFontWeight.regular, + if (productSetMeals[position].productInfoList[index].productAttrInfoList[0].attrName != "" + && productSetMeals[position].productInfoList[index].count > 0) + Text( + productSetMeals[position].productInfoList[index].productAttrInfoList[0].selectSku ?? "", + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + ), ), - ), Spacer(), - InkWell( - onTap: () { - }, - child: Image.asset( - "assets/image/reduce.webp", - width: 22, - height: 22.h, - ), + InkWell( + onTap: () { + setState(() { + if (productSetMeals[position].productInfoList[index].count >= 1) + productSetMeals[position].productInfoList[index].count -= 1; + }); + }, + child: Image.asset( + "assets/image/reduce.webp", + width: 22, + height: 22.h, ), - Container( - width: 30, - alignment: Alignment.center, - child: Text( - "0", - style: TextStyle( - color: Colors.black, - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - ), + ), + Container( + width: 30, + alignment: Alignment.center, + child: Text( + productSetMeals[position].productInfoList[index].count.toString(), + style: TextStyle( + color: Colors.black, + fontSize: 14.sp, + fontWeight: MyFontWeight.medium, ), ), - GestureDetector( - onTap: () { - }, - child: Image.asset( - "assets/image/add.webp", - width: 22, - height: 22.h, - ), + ), + GestureDetector( + onTap: () { + setState(() { + if(productSetMeals[position].productInfoList[index].productAttrInfoList[0].attrName != ""){ + showSkuDialog(position,index); + return; + } + int total = 0; + productSetMeals[position].productInfoList.forEach((element) { + total += element.count; + }); + if (total >= productSetMeals[position].optionalNumber) { + SmartDialog.showToast("抱歉,无法加购更多", + alignment: Alignment.center); + return; + } + if (productSetMeals[position].productInfoList[index].count == 0) + productSetMeals[position].productInfoList[index].count += 1; + }); + }, + child: Image.asset( + "assets/image/add.webp", + width: 22, + height: 22.h, ), + ), ], ), SizedBox( @@ -904,15 +447,16 @@ class _ProductMealsSku extends State { ); } - Widget attrItem(Function fc, AttrListBean attrListBean, position) { - if (attrListBean.attrValueList != null && attrListBean.attrValueList.length > 0) + Widget porAttrItem(int position,int index,int pos,state) { + if (productSetMeals[position].productInfoList[index].productAttrInfoList[pos].attrValueList != null && + productSetMeals[position].productInfoList[index].productAttrInfoList[pos].attrValueList.length > 0) return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: EdgeInsets.only(top: 16, bottom: 16), child: Text( - attrListBean.attrName, + productSetMeals[position].productInfoList[index].productAttrInfoList[pos].attrName, style: TextStyle( color: Color(0xFFB3B3B3), fontSize: 14.sp, @@ -920,8 +464,7 @@ class _ProductMealsSku extends State { ), ), ), - sweetnessStore(fc,attrListBean.attrValueList, position), - // sweetnessStore(fc, attrListBean.attrValueList, position), + sweetnessStore(position,index, pos,state), ], ); else { @@ -929,30 +472,35 @@ class _ProductMealsSku extends State { } } - Widget sweetnessStore(Function fc,List arrays, position){ + Widget sweetnessStore(int position,int index,int pos,state) { return Wrap( runSpacing: 10.0, spacing: 10.0, - children: arrays.take(arrays.length).map((AttrValueListBean tag) { + children: productSetMeals[position].productInfoList[index].productAttrInfoList[pos].attrValueList + .take(productSetMeals[position].productInfoList[index].productAttrInfoList[pos].attrValueList.length) + .map((AttrValueList tag) { return GestureDetector( onTap: () { - fc(tag.attrValue); + state(() { + productSetMeals[position].productInfoList[index].productAttrInfoList[pos].selectSku = + tag.attrName; + }); }, - child:sweetnessItem( - tag.attrValue, - (selectSkus.length > position && tag.attrValue == selectSkus[position]), + child: sweetnessItem( + tag.attrName, + (productSetMeals[position].productInfoList[index].productAttrInfoList[pos].selectSku == tag.attrName), )); }).toList()); } Widget sweetnessItem(String name, bool isCheck) { return Container( - padding: const EdgeInsets.symmetric(vertical:5.0,horizontal: 12.0), + padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 12.0), decoration: BoxDecoration( color: !isCheck ? Color(0xFFF2F2F2) : Color(0xFFF0FAF4), border: Border.all( - width: !isCheck ? 0:1, - color: !isCheck ? Color(0xFFF2F2F2):Color(0xFF32A060), + width: !isCheck ? 0 : 1, + color: !isCheck ? Color(0xFFF2F2F2) : Color(0xFF32A060), style: BorderStyle.solid, ), borderRadius: const BorderRadius.all( @@ -963,7 +511,7 @@ class _ProductMealsSku extends State { name, overflow: TextOverflow.ellipsis, style: TextStyle( - color:!isCheck ? Color(0xFF4D4D4D) : Color(0xFF32A060), + color: !isCheck ? Color(0xFF4D4D4D) : Color(0xFF32A060), fontSize: 14.sp, fontWeight: MyFontWeight.regular, ), @@ -971,192 +519,60 @@ class _ProductMealsSku extends State { } ///选择規格弹窗 - showSpanDialog() { + showSkuDialog(int position,int index) async { showDialog( context: context, builder: (context) { return StatefulBuilder(builder: ( - context, - state, - ) - { + context, + state, + ) { return AlertDialog( content: Container( - width: MediaQuery - .of(context) - .size - .width - 84, - height: 500.h, + width: MediaQuery.of(context).size.width - 84, + height: 350.h, child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ClipRRect( - child: MImage( - miNiDetail.imgs[0], - fit: BoxFit.cover, - width: 70, - height: 70, - errorSrc: "assets/image/default_2_1.webp", - fadeSrc: "assets/image/default_2_1.webp", - ), - borderRadius: BorderRadius.circular(4), - ), - SizedBox( - width: 10.w, - ), - Expanded( - child: Container( - height: 70, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment - .spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - miNiDetail?.productName ?? "", - style: TextStyle( - fontSize: 13.sp, - fontWeight: FontWeight.bold, - color: Color(0xFF000000), - ), - ), - GestureDetector( - onTap: () { - Navigator.of(context).pop(); - }, - child: Image.asset( - "assets/image/cancel.webp", - fit: BoxFit.cover, - height: 24, - width: 24, - ), - ), - ], - ), - Text( - "¥${miNiDetail?.price ?? ""}", - style: TextStyle( - fontSize: 12.sp, - fontWeight: FontWeight.bold, - color: Color(0xFFF65720), - ), - ), - ], - ), - )), - ], - ), - if (miNiDetail.attrList != null && - miNiDetail.attrList.length > 0) - SizedBox( - height: 10, - ), - if (miNiDetail.attrList != null && - miNiDetail.attrList.length > 0) - Expanded( - child: ListView.builder( - itemCount: miNiDetail.attrList.length, - scrollDirection: Axis.vertical, - physics: BouncingScrollPhysics(), - padding: EdgeInsets.zero, - itemBuilder: (context, position) { - return attrItem( - (attrValue) { - state(() { - // if(selectSkus.length > position) - selectSkus[position] = attrValue; - buildCount(); - }); - }, - miNiDetail.attrList[position], - position, - ); - }, - ), + Expanded( + child: ListView.builder( + itemCount: productSetMeals[position].productInfoList[index] + .productAttrInfoList + .length, + scrollDirection: Axis.vertical, + physics: BouncingScrollPhysics(), + padding: EdgeInsets.zero, + itemBuilder: (context, pos) { + return porAttrItem( + position,index, + pos, + state + ); + }, ), - SizedBox( - height: 24, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - "数量", - style: TextStyle( - color: Color(0xFFB3B3B3), - fontSize: 12.sp, - fontWeight: MyFontWeight.regular, - ), - ), - SizedBox(height: 10,), - Row( - children: [ - InkWell( - onTap: () { - state(() { - if (counts > 1) - setState(() { - counts -= 1; - }); - reduce(miNiDetail, selectSkus); - }); - }, - child: Icon( - Icons.remove, - color: Color(0xFF32A060), - size: 24, - ) - // Image.asset( - // "assets/image/reduce.webp", - // width: 22, - // height: 22, - // ), - ), - Padding( - padding: EdgeInsets.only(left: 8, right: 8), - child: Text( - "$counts", - style: TextStyle( - color: Colors.black, - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - ), - ), - ), - InkWell( - onTap: () { - state(() { - counts += 1; - add(miNiDetail, selectSkus); - }); - }, - child: Icon( - Icons.add, - color: Color(0xFF32A060), - size: 24, - ) - ), - ], - ) - ], ), SizedBox( height: 24, ), GestureDetector( onTap: () { - state(() { - _addShopCar(miNiDetail, selectSkus, counts); + setState(() { + int total = 0; + productSetMeals[position].productInfoList.forEach((element) { + total += element.count; + }); + if(productSetMeals[position].productInfoList[index].productAttrInfoList[0].selectSku == null){ + SmartDialog.showToast("请先选择规格", + alignment: Alignment.center); + return; + } + if (total >= productSetMeals[position].optionalNumber && productSetMeals[position].productInfoList[index].count != 1) { + SmartDialog.showToast("抱歉,无法加购更多", + alignment: Alignment.center); + return; + } + productSetMeals[position].productInfoList[index].count = 1; Navigator.of(context).pop(); }); }, @@ -1169,7 +585,7 @@ class _ProductMealsSku extends State { ), padding: EdgeInsets.symmetric(vertical: 6), child: Text( - "加入购物车", + "选好啦", style: TextStyle( fontSize: 15.sp, fontWeight: MyFontWeight.bold, @@ -1186,5 +602,4 @@ class _ProductMealsSku extends State { }, ); } - } diff --git a/lib/store/store_view/shop_car.dart b/lib/store/store_view/shop_car.dart index 8d5b1150..bc5ffacd 100644 --- a/lib/store/store_view/shop_car.dart +++ b/lib/store/store_view/shop_car.dart @@ -3,6 +3,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/store/store_view/shop_goods.dart'; +import 'package:huixiang/store/store_view/shop_goods_car.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/round_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -99,7 +100,7 @@ class _ShopCar extends State { top: 0, left: 0, right: 0, - bottom: 54, + bottom: 100.h, child: Container( padding: EdgeInsets.only( left: 16, @@ -109,7 +110,7 @@ class _ShopCar extends State { itemCount: itemCount(), physics: BouncingScrollPhysics(), itemBuilder: (context, position) { - return ShopGoods( + return ShopGoodsCar( (ShoppingCartSkuItemListBean cart) async { widget.shopingCar = await widget.shopCartAdd(cart); diff --git a/lib/store/store_view/shop_goods.dart b/lib/store/store_view/shop_goods.dart index 77fe3592..fbd2e0b2 100644 --- a/lib/store/store_view/shop_goods.dart +++ b/lib/store/store_view/shop_goods.dart @@ -1,3 +1,4 @@ +import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; @@ -7,15 +8,22 @@ 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'; +import 'package:shared_preferences/shared_preferences.dart'; + +import '../../retrofit/data/base_data.dart'; +import '../../retrofit/data/miNiDetail.dart'; +import '../../retrofit/min_api.dart'; class ShopGoods extends StatefulWidget { final Function(String id, int count) queryMiNiDetail; final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) add; final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) reduce; + final Function queryShoppingCart; final ProductListBean productListBean; final ShoppingCartSkuItemListBean shoppingCartSkuItemListBean; final int count; + final int tableId; final bool isShopCart; ShopGoods( @@ -24,6 +32,8 @@ class ShopGoods extends StatefulWidget { this.productListBean, this.count = 0, this.isShopCart = false, + this.tableId, + this.queryShoppingCart, this.queryMiNiDetail, this.shoppingCartSkuItemListBean, }); @@ -34,8 +44,46 @@ class ShopGoods extends StatefulWidget { } } + class _ShopGoods extends State { - @override + int _jumpType = -1; + + ///商品详情 + queryMiNiDetail(id) async { + MinApiService minService; + await 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,); + }); + BaseData baseData = + await minService.miNiDetail(id).catchError((error) { + }); + if (baseData != null && baseData.isSuccess) { + if(baseData.data.productSkuVOList[0].productSetMeals.length == 0){ + _jumpType = 0; + widget.add(widget.shoppingCartSkuItemListBean); + }else{ + _jumpType = 1; + await Navigator.of(context) + .pushNamed('/router/product_meals_sku', arguments: { + "id":widget.productListBean.id, + "storeId":widget.productListBean.storeId, + "tableId":widget.tableId + }); + widget.queryShoppingCart(); + } + } else { + // refreshController.refreshFailed(); + } + } + + @override Widget build(BuildContext context) { return Container( color: Colors.white, @@ -44,7 +92,7 @@ class _ShopGoods extends State { // bottom: 20.h, ), height: 123.h, - child: Row( + child: Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, @@ -54,8 +102,8 @@ class _ShopGoods extends State { widget.productListBean != null ? widget.productListBean.imgPath : (widget.shoppingCartSkuItemListBean != null - ? widget.shoppingCartSkuItemListBean.skuImg - : ""), + ? widget.shoppingCartSkuItemListBean.skuImg + : ""), width: 70.h, height: 70.h, radius: BorderRadius.circular(4), @@ -184,7 +232,7 @@ class _ShopGoods extends State { widget.productListBean != null ? widget.productListBean.id : widget.shoppingCartSkuItemListBean - .productId, + .productId, 0); }, ), @@ -236,13 +284,19 @@ class _ShopGoods extends State { if (widget.isShopCart || (widget.productListBean?.attrStyle ?? 0) == 0) GestureDetector( - onTap: () { - widget.add(widget.shoppingCartSkuItemListBean); - Navigator.of(context) - .pushNamed('/router/product_meals_sku', arguments: { - "id":widget.productListBean.id, - "storeId":widget.productListBean.storeId - }); + onTap: () async{ + if(_jumpType == -1) + queryMiNiDetail(widget.productListBean.id); + else if(_jumpType == 0) + widget.add(widget.shoppingCartSkuItemListBean); + else if(_jumpType == 1) + await Navigator.of(context) + .pushNamed('/router/product_meals_sku', arguments: { + "id":widget.productListBean.id, + "storeId":widget.productListBean.storeId, + "tableId":widget.tableId + }); + widget.queryShoppingCart(); }, child: Image.asset( "assets/image/add.webp", @@ -271,4 +325,5 @@ class _ShopGoods extends State { ), ); } + } diff --git a/lib/store/store_view/shop_goods_car.dart b/lib/store/store_view/shop_goods_car.dart new file mode 100644 index 00000000..f2cd0dba --- /dev/null +++ b/lib/store/store_view/shop_goods_car.dart @@ -0,0 +1,334 @@ +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/utils/flutter_utils.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 ShopGoodsCar extends StatefulWidget { + final Function(String id, int count) queryMiNiDetail; + final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) add; + final Function(ShoppingCartSkuItemListBean shoppingCartSkuItemListBean) + reduce; + final ProductListBean productListBean; + final ShoppingCartSkuItemListBean shoppingCartSkuItemListBean; + final int count; + final bool isShopCart; + + ShopGoodsCar( + this.add, + this.reduce, { + this.productListBean, + this.count = 0, + this.isShopCart = false, + this.queryMiNiDetail, + this.shoppingCartSkuItemListBean, + }); + + @override + State createState() { + return _ShopGoodsCar(); + } +} + +class _ShopGoodsCar extends State { + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + padding: EdgeInsets.only( + right: 16.w, + // bottom: 20.h, + ), + child:Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + SizedBox(width: 12.w), + MImage( + widget.productListBean != null + ? widget.productListBean.imgPath + : (widget.shoppingCartSkuItemListBean != null + ? widget.shoppingCartSkuItemListBean.skuImg + : ""), + width: 70.h, + height: 70.h, + radius: BorderRadius.circular(4), + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.webp", + fadeSrc: "assets/image/default_1.webp", + ), + SizedBox( + width: 10, + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: Text( + widget.productListBean != null + ? widget.productListBean.productName + : widget.shoppingCartSkuItemListBean.productName, + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + color: Colors.black, + fontSize: 13.sp, + fontWeight: MyFontWeight.medium, + ), + ), + ), + // Image.asset( + // "assets/image/green_leaf.webp", + // fit: BoxFit.cover, + // width: 12, + // height: 12, + // ), + // Text( + // "X300", + // style: TextStyle( + // color: Color(0xFF55BC51), + // fontSize: 10.sp, + // fontWeight: MyFontWeight.semi_bold, + // ), + // ), + ], + ), + SizedBox( + height: 2.h, + ), + Row( + children: [ + Expanded( + child: Text( + (widget.productListBean != null + ? widget.productListBean.shortName + : ((widget.shoppingCartSkuItemListBean.skuName == "0") ? "": widget.shoppingCartSkuItemListBean.skuName ) ?? ""), + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + color: Color(0xFF4C4C4C), + fontSize: 10.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ), + SizedBox( + width: 10, + ), + ], + ), + SizedBox( + height: 7.h, + ), + Row( + children: [ + Row( + children: [ + Text( + "¥${AppUtils.calculateDouble(double.tryParse(widget.isShopCart ? widget.shoppingCartSkuItemListBean.skuPrice : widget.productListBean.price) ?? 0)}", + style: TextStyle( + color: Color(0xFFFF7A1A), + fontSize: 16.sp, + fontWeight: MyFontWeight.medium, + ), + ), + SizedBox( + width: 2.w, + ), + // Container( + // width: 44.w, + // height: 18.h, + // decoration: BoxDecoration( + // color: Color(0xFFFF4500), + // borderRadius: BorderRadius.circular(2), + // ), + // alignment: Alignment.center, + // child: Text( + // "APP专享", + // style: TextStyle( + // color: Color(0xFFFFFFFF), + // fontSize: 10.sp, + // fontWeight: MyFontWeight.medium, + // ), + // ), + // ), + ], + ), + Spacer(), + if (!widget.isShopCart && + (widget.productListBean?.attrStyle ?? 0) == 1) + Stack( + children: [ + Container( + margin: EdgeInsets.only(right: 8, top: 4), + child: RoundButton( + width: 49.w, + text: S.of(context).xuanguige, + textColor: Colors.white, + fontWeight: MyFontWeight.medium, + radius: 3, + backgroup: Color(0xFF32A060), + fontSize: 11.sp, + padding: EdgeInsets.symmetric(vertical: 5.h), + callback: () { + widget.queryMiNiDetail( + widget.productListBean != null + ? widget.productListBean.id + : widget.shoppingCartSkuItemListBean + .productId, + 0); + }, + ), + ), + Positioned( + right: 0, + child: Visibility( + visible: widget.count > 0, + child: RoundButton( + width: 17, + height: 17.h, + text: "${widget.count}", + textColor: Color(0xFF32A060), + fontWeight: MyFontWeight.regular, + backgroup: Colors.white, + fontSize: 12.sp, + radius: 100, + ), + ), + ), + ], + ), + if (widget.isShopCart || + (widget.productListBean?.attrStyle ?? 0) == 0) + InkWell( + onTap: () { + widget.reduce(widget.shoppingCartSkuItemListBean); + }, + child: Image.asset( + "assets/image/reduce.webp", + width: 22, + height: 22.h, + ), + ), + if (widget.isShopCart || + (widget.productListBean?.attrStyle ?? 0) == 0) + Container( + width: 30, + alignment: Alignment.center, + child: Text( + "${widget.count}", + style: TextStyle( + color: Colors.black, + fontSize: 14.sp, + fontWeight: MyFontWeight.medium, + ), + ), + ), + if (widget.isShopCart || + (widget.productListBean?.attrStyle ?? 0) == 0) + GestureDetector( + onTap: () { + widget.add(widget.shoppingCartSkuItemListBean); + }, + child: Image.asset( + "assets/image/add.webp", + width: 22, + height: 22.h, + ), + ), + ], + ), + SizedBox( + height: 4.h, + ), + Text( + "¥${AppUtils.calculateDouble(double.tryParse(widget.isShopCart ? widget.shoppingCartSkuItemListBean.skuPrice : widget.productListBean.applyPrice) ?? 0)}", + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 12.sp, + decoration: TextDecoration.lineThrough, + fontWeight: MyFontWeight.regular, + ), + ), + ], + ), + ), + ], + ), + if(widget.shoppingCartSkuItemListBean.setMealDataList.length != 0) + ListView.builder( + itemCount: widget.shoppingCartSkuItemListBean.setMealDataList.length, + scrollDirection: Axis.vertical, + physics: BouncingScrollPhysics(), + shrinkWrap: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + return shopCarMealsItem(widget.shoppingCartSkuItemListBean.setMealDataList[index]); + }, + ), + SizedBox(height:15.h,) + ], + ) + ); + } + + + Widget shopCarMealsItem(SetMealDataList setMealDataList) { + return Container( + margin: EdgeInsets.symmetric(vertical:10.h,horizontal: 16.w), + child: Row( + children: [ + Expanded( + flex: 3, + child: Text( + setMealDataList.productInfoList[0].productName, + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle( + color: Color(0xffA29E9E), + fontSize: 14.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ), + Expanded(flex: 2, + child: Text( + "${(setMealDataList.productInfoList[0].skuName == "") ? "默认": setMealDataList.productInfoList[0].skuName}", + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle( + color: Color(0xffA29E9E), + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ), + Expanded( + flex: 1, + child: Text( + "x1", + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle( + color: Color(0xffFF7A1A), + fontSize: 13.sp, + fontWeight: MyFontWeight.regular, + ), + ), + ), + ], + ), + ); + } + +} diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index b0dd6257..6aa76117 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -21,6 +21,7 @@ class StoreOrderListPage extends StatefulWidget { final ScrollController controller; final String minToken; final String tenant; + final int tableId; final Function(String id, int count) queryMiNiDetail; final Function queryShoppingCart; @@ -34,6 +35,7 @@ class StoreOrderListPage extends StatefulWidget { this.controller, this.minToken, this.tenant, + this.tableId, this.queryMiNiDetail, this.queryShoppingCart, ); @@ -341,6 +343,8 @@ class _StoreOrderListPage extends State { productListBean: e, count: count, isShopCart: false, + tableId:widget.tableId, + queryShoppingCart:widget.queryShoppingCart, queryMiNiDetail: widget.queryMiNiDetail, shoppingCartSkuItemListBean: shoppingCartSkuItemListBean, ); diff --git a/lib/view_widget/selector_store_dialog.dart b/lib/view_widget/selector_store_dialog.dart index 061e20cd..bd7fa585 100644 --- a/lib/view_widget/selector_store_dialog.dart +++ b/lib/view_widget/selector_store_dialog.dart @@ -117,7 +117,7 @@ class _SelectorStoreWidget extends State { widget.stores[selectIndex].storeName, ); } else { - Navigator.of(context).pushNamed( + Navigator.of(context).pushReplacementNamed( '/router/store_order', arguments: { "id": widget.stores[selectIndex].id,