Browse Source

safety

master
fmk 3 years ago
parent
commit
f2bc610020
  1. 61
      lib/community/community_child_page.dart
  2. 8
      lib/retrofit/data/settlement_bean.dart
  3. 14
      lib/retrofit/data/shoppingCart.dart
  4. 33
      lib/retrofit/min_api.dart
  5. 110
      lib/retrofit/min_api.g.dart
  6. 8
      lib/retrofit/retrofit_api.dart
  7. 71
      lib/store/sku.dart
  8. 210
      lib/store/store_order.dart
  9. 75
      lib/store/store_view/product_sku.dart
  10. 29
      lib/store/store_view/settlement.dart
  11. 11
      lib/store/store_view/settlement_order_commodity.dart
  12. 317
      lib/store/store_view/shop_car.dart
  13. 36
      lib/store/store_view/shop_goods.dart
  14. 68
      lib/store/store_view/store_order_list.dart

61
lib/community/community_child_page.dart

@ -77,37 +77,38 @@ class _CommunityChildPage extends State<CommunityChildPage> {
future: queryCommunity(), future: queryCommunity(),
builder: (context, position) { builder: (context, position) {
return SmartRefresher( return SmartRefresher(
controller: refreshController, controller: refreshController,
enablePullDown: true, enablePullDown: true,
enablePullUp: true, enablePullUp: true,
physics: BouncingScrollPhysics(), physics: BouncingScrollPhysics(),
header: MyHeader(), header: MyHeader(),
footer: CustomFooter( footer: CustomFooter(
builder: (context, mode) { builder: (context, mode) {
return MyFooter(mode); return MyFooter(mode);
},
),
onRefresh: _onRefresh,
onLoading: () {
setState(() {});
}, },
child: ListView.builder( ),
physics: NeverScrollableScrollPhysics(), onRefresh: _onRefresh,
itemBuilder: (context, position) { onLoading: () {
return InkWell( setState(() {});
child: CommunityDynamic(comments[position]), },
onTap: () { child: ListView.builder(
Navigator.of(context).pushNamed( physics: NeverScrollableScrollPhysics(),
'/router/community_details', itemBuilder: (context, position) {
arguments: { return InkWell(
"comment": comments[position], child: CommunityDynamic(comments[position]),
}, onTap: () {
); Navigator.of(context).pushNamed(
}, '/router/community_details',
); arguments: {
}, "comment": comments[position],
itemCount: comments.length, },
)); );
},
);
},
itemCount: comments.length,
),
);
}, },
); );
} }

8
lib/retrofit/data/settlement_bean.dart

@ -172,7 +172,7 @@ class OrderProductVOList {
int returnStatus, int returnStatus,
int returnType, int returnType,
int sellPrice, int sellPrice,
int skuId, String skuId,
String skuImg, String skuImg,
String skuNameStr,}){ String skuNameStr,}){
_actInfo = actInfo; _actInfo = actInfo;
@ -227,7 +227,7 @@ class OrderProductVOList {
int _returnStatus; int _returnStatus;
int _returnType; int _returnType;
int _sellPrice; int _sellPrice;
int _skuId; String _skuId;
String _skuImg; String _skuImg;
String _skuNameStr; String _skuNameStr;
@ -245,7 +245,7 @@ class OrderProductVOList {
int get returnStatus => _returnStatus; int get returnStatus => _returnStatus;
int get returnType => _returnType; int get returnType => _returnType;
int get sellPrice => _sellPrice; int get sellPrice => _sellPrice;
int get skuId => _skuId; String get skuId => _skuId;
String get skuImg => _skuImg; String get skuImg => _skuImg;
String get skuNameStr => _skuNameStr; String get skuNameStr => _skuNameStr;
@ -334,7 +334,7 @@ class OrderProductVOList {
_sellPrice = value; _sellPrice = value;
} }
set skuId(int value) { set skuId(String value) {
_skuId = value; _skuId = value;
} }

14
lib/retrofit/data/shoppingCart.dart

@ -7,13 +7,13 @@
/// tableId : 0 /// tableId : 0
class ShoppingCart { class ShoppingCart {
int cartSum; String cartSum;
int numberOfPeople; int numberOfPeople;
int selected; int selected;
List<ShoppingCartSkuItemListBean> shoppingCartSkuItemList; List<ShoppingCartSkuItemListBean> shoppingCartSkuItemList;
int storeId; String storeId;
String storeName; String storeName;
int tableId; String tableId;
static ShoppingCart fromJson(Map<String, dynamic> map) { static ShoppingCart fromJson(Map<String, dynamic> map) {
if (map == null) return null; if (map == null) return null;
@ -59,8 +59,8 @@ class ShoppingCart {
class ShoppingCartSkuItemListBean { class ShoppingCartSkuItemListBean {
int buyNum; int buyNum;
String createTime; String createTime;
int groupId; String groupId;
int id; String id;
List<PlatterListBean> platterList; List<PlatterListBean> platterList;
String productId; String productId;
String productName; String productName;
@ -68,7 +68,7 @@ class ShoppingCartSkuItemListBean {
int selected; int selected;
String skuImg; String skuImg;
String skuName; String skuName;
int skuPrice; String skuPrice;
int skuStock; int skuStock;
String storeId; String storeId;
int tableId; int tableId;
@ -126,7 +126,7 @@ class PlatterListBean {
int id; int id;
int productId; int productId;
bool required; bool required;
int skuId; String skuId;
static PlatterListBean fromJson(Map<String, dynamic> map) { static PlatterListBean fromJson(Map<String, dynamic> map) {
if (map == null) return null; if (map == null) return null;

33
lib/retrofit/min_api.dart

@ -42,6 +42,7 @@ abstract class MinApiService {
BuildContext context, BuildContext context,
String token, String token,
String tenant, String tenant,
String storeId,
bool showLoading = true, bool showLoading = true,
bool pay = false, bool pay = false,
}) { }) {
@ -50,6 +51,9 @@ abstract class MinApiService {
if (tenant != null && tenant != "") { if (tenant != null && tenant != "") {
headers["tenant"] = tenant; headers["tenant"] = tenant;
} }
if (storeId != null && storeId != "") {
headers["store_id"] = storeId;
}
if (pay) { if (pay) {
headers["Environment"] = "app"; headers["Environment"] = "app";
} }
@ -83,10 +87,9 @@ abstract class MinApiService {
EasyLoading.dismiss(); EasyLoading.dismiss();
} }
debugPrint("code = ${response.statusCode}"); debugPrint("code = ${response.statusCode}");
// p(jsonEncode(response.data)); p(jsonEncode(response.data));
debugPrint(jsonEncode(response.data), // debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length);
wrapWidth: response.data.toString().length);
Map map = response.data; Map map = response.data;
if (map["code"] != 0) { if (map["code"] != 0) {
@ -124,10 +127,10 @@ abstract class MinApiService {
static void p(String msg) { static void p(String msg) {
int maxStrLength = 900; int maxStrLength = 900;
while (msg.length > maxStrLength) { while (msg.length > maxStrLength) {
debugPrint(msg.substring(0, maxStrLength)); debugPrint(msg.substring(0, maxStrLength), wrapWidth: maxStrLength);
msg = msg.substring(maxStrLength); msg = msg.substring(maxStrLength);
} }
debugPrint(msg); debugPrint(msg, wrapWidth: maxStrLength);
} }
/// ///
@ -141,8 +144,23 @@ abstract class MinApiService {
/// ///
@POST("shoppingcart") @POST("shoppingcart")
Future<BaseData<ShoppingCart>> shoppingCart( Future<BaseData<List<ShoppingCart>>> addShoppingCart(@Body() Map<String, dynamic> param);
@Body() Map<String, dynamic> param, Map<String, dynamic> header);
///
@GET("shoppingcart") ///?tableId={tableId}
Future<BaseData<List<ShoppingCart>>> getShoppingCart(@Query("tableId") int tableId);
///
@GET("shoppingcart/delCart")
Future<BaseData<bool>> clearShoppingCart();
///
@PUT("shoppingcart")
Future<BaseData<List<ShoppingCart>>> shoppingCart1(@Body() Map<String, dynamic> param);
///
@PUT("shoppingcart/single")
Future<BaseData<List<ShoppingCart>>> shoppingCartSingle(@Body() Map<String, dynamic> param);
/// ///
@POST("order/getOrderInfo") @POST("order/getOrderInfo")
@ -154,7 +172,6 @@ abstract class MinApiService {
@POST("order/placeOrderFirst") @POST("order/placeOrderFirst")
Future<BaseData> placeOrderFirst(@Body() Map<String, dynamic> param); Future<BaseData> placeOrderFirst(@Body() Map<String, dynamic> param);
/// ///
@POST("order/settlement") @POST("order/settlement")
Future<BaseData> settlementApi(@Body() Map<String, dynamic> param); Future<BaseData> settlementApi(@Body() Map<String, dynamic> param);

110
lib/retrofit/min_api.g.dart

@ -64,9 +64,8 @@ class _MinApiService implements MinApiService {
} }
@override @override
Future<BaseData<ShoppingCart>> shoppingCart(param, header) async { Future<BaseData<List<ShoppingCart>>> addShoppingCart(param) async {
ArgumentError.checkNotNull(param, 'param'); ArgumentError.checkNotNull(param, 'param');
ArgumentError.checkNotNull(header, 'header');
const _extra = <String, dynamic>{}; const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{}; final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{}; final _data = <String, dynamic>{};
@ -79,13 +78,108 @@ class _MinApiService implements MinApiService {
extra: _extra, extra: _extra,
baseUrl: baseUrl), baseUrl: baseUrl),
data: _data); data: _data);
final value = BaseData<ShoppingCart>.fromJson( final value = BaseData<List<ShoppingCart>>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<ShoppingCart>(
(i) => ShoppingCart.fromJson(i as Map<String, dynamic>))
.toList());
return value;
}
@override
Future<BaseData<List<ShoppingCart>>> getShoppingCart(tableId) async {
ArgumentError.checkNotNull(tableId, 'tableId');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{r'tableId': tableId};
final _data = <String, dynamic>{};
final _result = await _dio.request<Map<String, dynamic>>('shoppingcart',
queryParameters: queryParameters,
options: RequestOptions(
method: 'GET',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<List<ShoppingCart>>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<ShoppingCart>(
(i) => ShoppingCart.fromJson(i as Map<String, dynamic>))
.toList());
return value;
}
@override
Future<BaseData<bool>> clearShoppingCart() async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
final _result = await _dio.request<Map<String, dynamic>>(
'shoppingcart/delCart',
queryParameters: queryParameters,
options: RequestOptions(
method: 'GET',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<bool>.fromJson(
_result.data, _result.data,
(json) => ShoppingCart.fromJson(json), (json) => json as bool,
); );
return value; return value;
} }
@override
Future<BaseData<List<ShoppingCart>>> shoppingCart1(param) async {
ArgumentError.checkNotNull(param, 'param');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(param ?? <String, dynamic>{});
final _result = await _dio.request<Map<String, dynamic>>('shoppingcart',
queryParameters: queryParameters,
options: RequestOptions(
method: 'PUT',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<List<ShoppingCart>>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<ShoppingCart>(
(i) => ShoppingCart.fromJson(i as Map<String, dynamic>))
.toList());
return value;
}
@override
Future<BaseData<List<ShoppingCart>>> shoppingCartSingle(param) async {
ArgumentError.checkNotNull(param, 'param');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(param ?? <String, dynamic>{});
final _result = await _dio.request<Map<String, dynamic>>(
'shoppingcart/single',
queryParameters: queryParameters,
options: RequestOptions(
method: 'PUT',
headers: <String, dynamic>{},
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<List<ShoppingCart>>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<ShoppingCart>(
(i) => ShoppingCart.fromJson(i as Map<String, dynamic>))
.toList());
return value;
}
@override @override
Future<BaseData<SettleOrderInfo>> getOrderInfo(param) async { Future<BaseData<SettleOrderInfo>> getOrderInfo(param) async {
ArgumentError.checkNotNull(param, 'param'); ArgumentError.checkNotNull(param, 'param');
@ -127,7 +221,7 @@ class _MinApiService implements MinApiService {
data: _data); data: _data);
final value = BaseData<dynamic>.fromJson( final value = BaseData<dynamic>.fromJson(
_result.data, _result.data,
(json) => json as dynamic, (json) => json as dynamic,
); );
return value; return value;
} }
@ -139,8 +233,7 @@ class _MinApiService implements MinApiService {
final queryParameters = <String, dynamic>{}; final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{}; final _data = <String, dynamic>{};
_data.addAll(param ?? <String, dynamic>{}); _data.addAll(param ?? <String, dynamic>{});
final _result = await _dio.request<Map<String, dynamic>>( final _result = await _dio.request<Map<String, dynamic>>('order/settlement',
'order/settlement',
queryParameters: queryParameters, queryParameters: queryParameters,
options: RequestOptions( options: RequestOptions(
method: 'POST', method: 'POST',
@ -150,9 +243,8 @@ class _MinApiService implements MinApiService {
data: _data); data: _data);
final value = BaseData<dynamic>.fromJson( final value = BaseData<dynamic>.fromJson(
_result.data, _result.data,
(json) => json as dynamic, (json) => json as dynamic,
); );
return value; return value;
} }
} }

8
lib/retrofit/retrofit_api.dart

@ -90,9 +90,9 @@ abstract class ApiService {
EasyLoading.dismiss(); EasyLoading.dismiss();
} }
debugPrint("code = ${response.statusCode}"); debugPrint("code = ${response.statusCode}");
// p(jsonEncode(response.data)); p(jsonEncode(response.data));
debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length); // debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length * 10);
Map map = response.data; Map map = response.data;
if (map["code"] != 0) { if (map["code"] != 0) {
@ -131,11 +131,11 @@ abstract class ApiService {
int maxStrLength = 900; int maxStrLength = 900;
//1000 //1000
while (msg.length > maxStrLength) { while (msg.length > maxStrLength) {
debugPrint(msg.substring(0, maxStrLength)); debugPrint(msg.substring(0, maxStrLength), wrapWidth: maxStrLength);
msg = msg.substring(maxStrLength); msg = msg.substring(maxStrLength);
} }
// //
print(msg); debugPrint(msg, wrapWidth: maxStrLength);
} }
/// ///

71
lib/store/sku.dart

@ -0,0 +1,71 @@
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,
);
}
}

210
lib/store/store_order.dart

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

75
lib/store/store_view/product_sku.dart

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/retrofit/data/miNiDetail.dart'; import 'package:huixiang/retrofit/data/miNiDetail.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
@ -9,8 +10,8 @@ import 'package:huixiang/view_widget/round_button.dart';
class ProductSku extends StatefulWidget { class ProductSku extends StatefulWidget {
final MiNiDetail miNiDetail; final MiNiDetail miNiDetail;
final String productId; final String productId;
final Function(Sku sku) addShopCar;
ProductSku(this.miNiDetail, this.productId); ProductSku(this.miNiDetail, this.productId, this.addShopCar);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
@ -22,24 +23,23 @@ class _ProductSku extends State<ProductSku> {
List<String> selectSkus = []; List<String> selectSkus = [];
int selectCount = 1; int selectCount = 1;
Map<String, dynamic> tempSelected = {}; Sku tempSelected;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.miNiDetail != null) { if (widget.miNiDetail != null) {
tempSelected["id"] = widget.productId; tempSelected = Sku(widget.productId, 1, widget.miNiDetail.price);
tempSelected["count"] = 1; tempSelected.name = widget.miNiDetail.productName;
tempSelected["price"] = widget.miNiDetail.price;
if (tempSelected["attr"] == null)
tempSelected["attr"] = [];
widget.miNiDetail.attrList.forEach((element) { widget.miNiDetail.attrList.forEach((element) {
selectSkus.add(element.attrValueList[0].attrValue); selectSkus.add(element.attrValueList[0].attrValue);
(tempSelected["attr"] as List).add({ tempSelected.attr.add(
"attrId": "${element.id}", Attr(
"attrValue": "${element.attrValueList[0].id}", "${element.id}",
}); "${element.attrValueList[0].id}",
),
);
}); });
} }
} }
@ -95,7 +95,8 @@ class _ProductSku extends State<ProductSku> {
Padding( Padding(
padding: EdgeInsets.only(top: 4, bottom: 7), padding: EdgeInsets.only(top: 4, bottom: 7),
child: Text( child: Text(
"已选: " + (selectSkus.map((e) => "$e").toList().toString()), "已选: " +
(selectSkus.map((e) => "$e").toList().toString()),
style: TextStyle( style: TextStyle(
color: Color(0xFF727272), color: Color(0xFF727272),
fontSize: 11.sp, fontSize: 11.sp,
@ -149,21 +150,18 @@ class _ProductSku extends State<ProductSku> {
itemBuilder: (context, position) { itemBuilder: (context, position) {
return attrItem( return attrItem(
(index) { (index) {
if (tempSelected["attr"] == null) { if (tempSelected.attr == null) {
tempSelected["attr"] = []; tempSelected.attr = [];
} }
bool flag = false;
(tempSelected["attr"] as List).forEach((e0) { tempSelected.attr.forEach((e0) {
if(e0["attrId"] == widget.miNiDetail.attrList[position].id){ if (e0.attrId == widget.miNiDetail.attrList[position].id) {
e0["attrValue"] = widget.miNiDetail.attrList[position].attrValueList[index].id; String valueId = widget.miNiDetail.attrList[position].attrValueList[index].id;
flag = true; if (e0.attrValue != valueId) {
tempSelected.attr[tempSelected.attr.indexOf(e0)].attrValue = valueId;
}
} }
}); });
if(!flag)
(tempSelected["attr"] as List).add({
"attrId": "${widget.miNiDetail.attrList[position].id}",
"attrValue": "${widget.miNiDetail.attrList[position].attrValueList[index].id}",
});
state(() { state(() {
selectSkus[position] = widget.miNiDetail selectSkus[position] = widget.miNiDetail
@ -197,7 +195,7 @@ class _ProductSku extends State<ProductSku> {
state(() { state(() {
if (selectCount > 1) selectCount--; if (selectCount > 1) selectCount--;
}); });
tempSelected["count"] = selectCount; tempSelected.count = selectCount;
}, },
child: Image.asset( child: Image.asset(
"assets/image/reduce.png", "assets/image/reduce.png",
@ -220,7 +218,7 @@ class _ProductSku extends State<ProductSku> {
onTap: () { onTap: () {
state(() { state(() {
selectCount++; selectCount++;
tempSelected["count"] = selectCount; tempSelected.count = selectCount;
}); });
}, },
child: Image.asset( child: Image.asset(
@ -244,7 +242,7 @@ class _ProductSku extends State<ProductSku> {
backgroup: Color(0xFF32A060), backgroup: Color(0xFF32A060),
fontSize: 16.sp, fontSize: 16.sp,
callback: () { callback: () {
Navigator.of(context).pop(tempSelected); _result();
}, },
), ),
SizedBox( SizedBox(
@ -256,6 +254,25 @@ class _ProductSku extends State<ProductSku> {
}); });
} }
_result() async {
ProductSkuVOListBean productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) {
bool gg = true;
selectSkus.forEach((element1) {
if (element.skuNameStr.indexOf(element1) < 0) {
gg = false;
return gg;
}
});
return gg;
});
// print("productSku: ${selectSkus.toString()}");
print("productSku: ${tempSelected.toJson()}");
if (productSku == null) return;
tempSelected.skuId = productSku.id;
tempSelected.skuValue = selectSkus.toString();
widget.addShopCar(tempSelected);
}
Widget attrItem(Function fc, AttrListBean attrListBean, position) { Widget attrItem(Function fc, AttrListBean attrListBean, position) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,

29
lib/store/store_view/settlement.dart

@ -15,6 +15,7 @@ import 'package:huixiang/retrofit/data/settlement_bean.dart';
import 'package:huixiang/retrofit/data/shoppingCart.dart'; import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/store/store_view/settlement_order_commodity.dart'; import 'package:huixiang/store/store_view/settlement_order_commodity.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_appbar.dart';
@ -45,7 +46,7 @@ class _Settlement extends State<Settlement> {
int selectedCouponIndex = -1; int selectedCouponIndex = -1;
List<ProductListBean> shopCar = []; List<ProductListBean> shopCar = [];
List<Map<String, dynamic>> shopCarGoods = []; List<Sku> shopCarGoods = [];
TextEditingController _vc; TextEditingController _vc;
List<String> addressBgs = [ List<String> addressBgs = [
@ -115,19 +116,19 @@ class _Settlement extends State<Settlement> {
placeOrderFirst.skuItemDTOList = []; placeOrderFirst.skuItemDTOList = [];
shopCarGoods.forEach((e0) { shopCarGoods.forEach((e0) {
SkuItemDTOList skuItemDTOListBean = SkuItemDTOList(); SkuItemDTOList skuItemDTOListBean = SkuItemDTOList();
skuItemDTOListBean.skuId = e0["skuId"]; skuItemDTOListBean.skuId = e0.skuId;
skuItemDTOListBean.buyNum = e0["count"]; skuItemDTOListBean.buyNum = e0.count;
PlatterList platterListBean = PlatterList(); PlatterList platterListBean = PlatterList();
platterListBean.skuId = e0["skuId"]; platterListBean.skuId = e0.skuId;
platterListBean.productId = e0["id"]; platterListBean.productId = e0.id;
skuItemDTOListBean.platterList = []; skuItemDTOListBean.platterList = [];
skuItemDTOListBean.platterList.add(platterListBean); skuItemDTOListBean.platterList.add(platterListBean);
placeOrderFirst.skuItemDTOList.add(skuItemDTOListBean); placeOrderFirst.skuItemDTOList.add(skuItemDTOListBean);
ShoppingCartSkuItemListBean shoppingCartSkuItemListBean = ShoppingCartSkuItemListBean(); ShoppingCartSkuItemListBean shoppingCartSkuItemListBean = ShoppingCartSkuItemListBean();
shoppingCartSkuItemListBean.buyNum = e0["count"]; shoppingCartSkuItemListBean.buyNum = e0.count;
shoppingCartSkuItemListBean.productId = e0["id"]; shoppingCartSkuItemListBean.productId = e0.id;
shoppingCartSkuItemListBean.productName = e0["name"]; shoppingCartSkuItemListBean.productName = e0.name;
shoppingCartSkuItemListBean.skuId = e0["skuId"]; shoppingCartSkuItemListBean.skuId = e0.skuId;
placeOrderFirst.shoppingCartSkuItemList.add(shoppingCartSkuItemListBean); placeOrderFirst.shoppingCartSkuItemList.add(shoppingCartSkuItemListBean);
}); });
placeOrderFirst.source = 1; placeOrderFirst.source = 1;
@ -151,8 +152,8 @@ class _Settlement extends State<Settlement> {
settlementBean.orderProductVOList = []; settlementBean.orderProductVOList = [];
shopCarGoods.forEach((e0) { shopCarGoods.forEach((e0) {
OrderProductVOList orderProductVOListBean = OrderProductVOList(); OrderProductVOList orderProductVOListBean = OrderProductVOList();
orderProductVOListBean.skuId = e0["skuId"]; orderProductVOListBean.skuId = e0.skuId;
orderProductVOListBean.buyNum = e0["count"]; orderProductVOListBean.buyNum = e0.count;
ActInfo actInfoBean = ActInfo(); ActInfo actInfoBean = ActInfo();
actInfoBean.couponDiscountAmount = 0; actInfoBean.couponDiscountAmount = 0;
actInfoBean.couponDiscountRate = 0; actInfoBean.couponDiscountRate = 0;
@ -209,7 +210,7 @@ class _Settlement extends State<Settlement> {
orderProductVOListBean.returnStatus = 0; orderProductVOListBean.returnStatus = 0;
orderProductVOListBean.returnType = 0; orderProductVOListBean.returnType = 0;
orderProductVOListBean.sellPrice = 0; orderProductVOListBean.sellPrice = 0;
orderProductVOListBean.skuId = 0; orderProductVOListBean.skuId = "0";
orderProductVOListBean.skuImg = ""; orderProductVOListBean.skuImg = "";
orderProductVOListBean.skuNameStr = ""; orderProductVOListBean.skuNameStr = "";
settlementBean.orderProductVOList.add(orderProductVOListBean); settlementBean.orderProductVOList.add(orderProductVOListBean);
@ -231,7 +232,7 @@ class _Settlement extends State<Settlement> {
if (shopCarGoods == null) return ""; if (shopCarGoods == null) return "";
double totalPrice = 0; double totalPrice = 0;
shopCarGoods.forEach((element) { shopCarGoods.forEach((element) {
totalPrice += double.tryParse(element["price"]) * element["count"]; totalPrice += double.tryParse(element.price) * element.count;
}); });
if(selectedCouponIndex != -1 && discountFlag){ if(selectedCouponIndex != -1 && discountFlag){
double discountA = double.parse(settleOrderInfo.couponList[selectedCouponIndex].discountAmount); double discountA = double.parse(settleOrderInfo.couponList[selectedCouponIndex].discountAmount);
@ -280,7 +281,7 @@ class _Settlement extends State<Settlement> {
phoneWidget(), phoneWidget(),
/// ///
SettlementOrderCommodity(shopCar, 0,shopCarGoods,settleOrderInfo), SettlementOrderCommodity(shopCar, 0, shopCarGoods, settleOrderInfo),
// if (payStatus == 0) couponRemarks(), // if (payStatus == 0) couponRemarks(),
/*(payStatus == 0) ? paySelector() : */ /*(payStatus == 0) ? paySelector() : */

11
lib/store/store_view/settlement_order_commodity.dart

@ -3,6 +3,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/retrofit/data/settleOrderInfo.dart'; import 'package:huixiang/retrofit/data/settleOrderInfo.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/separator.dart'; import 'package:huixiang/view_widget/separator.dart';
@ -10,7 +11,7 @@ import 'package:huixiang/view_widget/separator.dart';
class SettlementOrderCommodity extends StatefulWidget { class SettlementOrderCommodity extends StatefulWidget {
final int isTakeOut; final int isTakeOut;
final List<ProductListBean> orderInfo; final List<ProductListBean> orderInfo;
final List<Map<String, dynamic>> shopCarGood; final List<Sku> shopCarGood;
final SettleOrderInfo settleOrderInfo; final SettleOrderInfo settleOrderInfo;
SettlementOrderCommodity(this.orderInfo, this.isTakeOut,this.shopCarGood,this.settleOrderInfo); SettlementOrderCommodity(this.orderInfo, this.isTakeOut,this.shopCarGood,this.settleOrderInfo);
@ -102,9 +103,9 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
} }
Widget commodityItem(ProductListBean productList) { Widget commodityItem(ProductListBean productList) {
Map<String,dynamic> goodsBuyInfo; Sku goodsBuyInfo;
widget.shopCarGood.forEach((element) { widget.shopCarGood.forEach((element) {
if(element["id"] == productList.id){ if(element.id == productList.id){
goodsBuyInfo = element; goodsBuyInfo = element;
return; return;
} }
@ -145,7 +146,7 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
), ),
), ),
Text( Text(
"x${goodsBuyInfo["count"]}", "x${goodsBuyInfo.count}",
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
color: Color(0xFF727272), color: Color(0xFF727272),
@ -358,7 +359,7 @@ class _SettlementOrderCommodity extends State<SettlementOrderCommodity> {
if (widget.shopCarGood == null) return ""; if (widget.shopCarGood == null) return "";
double totalPrice = 0; double totalPrice = 0;
widget.shopCarGood.forEach((element) { widget.shopCarGood.forEach((element) {
totalPrice += double.tryParse(element["price"]) * element["count"]; totalPrice += double.tryParse(element.price) * element.count;
}); });
return "$totalPrice"; return "$totalPrice";
} }

317
lib/store/store_view/shop_car.dart

@ -2,23 +2,24 @@ import 'package:ai_decimal_accuracy/ai_decimal_accuracy.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/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/store/store_view/shop_goods.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/round_button.dart'; import 'package:huixiang/view_widget/round_button.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
class ShopCar extends StatefulWidget { class ShopCar extends StatefulWidget {
final List<ProductListBean> productLists;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function() clearShopCar; final Function() clearShopCar;
final Function() toDownOrder; final Function() toDownOrder;
final List<Map<String, dynamic>> shopCarGoods;
final List<ShoppingCart> shopingCar;
final Function(int count, String productId, int allCount, double allPrice) fc; final Function(int count, String productId, int allCount, double allPrice) fc;
ShopCar( ShopCar(
this.productLists, this.shopingCar,
this.shopCarGoods,
this.clearShopCar, this.clearShopCar,
this.toDownOrder, this.toDownOrder,
this.fc, { this.fc, {
@ -27,7 +28,7 @@ class ShopCar extends StatefulWidget {
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
return _ShopCar(this.shopCarGoods); return _ShopCar();
} }
} }
@ -35,30 +36,9 @@ class _ShopCar extends State<ShopCar> {
int allCount = 0; int allCount = 0;
double allPrice = 0.0; double allPrice = 0.0;
final List<Map<String, dynamic>> shopCarGoods;
_ShopCar(this.shopCarGoods);
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (shopCarGoods != null) {
AiDecimalAccuracy allPriceDecimal = AiDecimalAccuracy.zero;
shopCarGoods.forEach((element) {
if (element["price"] != null && element["price"] != "") {
double singlePrice = double.tryParse(element["price"]);
allCount += element["count"];
AiDecimalAccuracy aiDecimalAccuracy = AiDecimalAccuracy.fromInt(element["count"]);
AiDecimalAccuracy aiPrice = AiDecimalAccuracy.tryParse("$singlePrice");
allPriceDecimal += (aiPrice * aiDecimalAccuracy);
}
});
allPrice = allPriceDecimal.toDouble();
}
} }
@override @override
@ -103,8 +83,8 @@ class _ShopCar extends State<ShopCar> {
onTap: () { onTap: () {
allPrice = 0; allPrice = 0;
allCount = 0; allCount = 0;
widget.productLists.clear();
state((){}); state(() {});
widget.clearShopCar(); widget.clearShopCar();
}, },
child: Image.asset( child: Image.asset(
@ -117,152 +97,144 @@ class _ShopCar extends State<ShopCar> {
), ),
), ),
Expanded( Expanded(
child: Container( child: Stack(
padding: EdgeInsets.only( children: [
top: 8, Positioned(
left: 16, top: 0,
right: 16, left: 0,
), right: 0,
child: ListView.builder( bottom: 54,
itemCount: widget.productLists == null child: Container(
? 0 padding: EdgeInsets.only(
: widget.productLists.length, top: 8,
physics: BouncingScrollPhysics(), left: 16,
itemBuilder: (context, position) { right: 16,
return GestureDetector( ),
onTap: () {}, child: ListView.builder(
child: ShopGoods( itemCount: widget.shopingCar == null
widget.productLists[position], ? 0
(int count, String productId) { : widget.shopingCar.length,
int index = shopCarGoods.indexWhere((element) => element["id"] == productId); physics: BouncingScrollPhysics(),
if (count == 0) { itemBuilder: (context, position) {
shopCarGoods.removeAt(index); return GestureDetector(
int index1 = widget.productLists.indexWhere((element) => element.id == productId); onTap: () {},
widget.productLists.removeAt(index1); child: ShopGoods(
} else { widget.shopingCar[position],
Map<String, dynamic> map; (int count, List<Attr> attr, String productId) {
print("productId: $productId");
shopCarGoods.forEach((element) {
if (element["id"] == productId) {
map = element;
}
});
map["count"] = count;
shopCarGoods[index] = map;
}
allCount = 0;
allPrice = 0;
shopCarGoods.forEach((element) {
if (element["price"] != null &&
element["price"] != "") {
double singlePrice =
double.tryParse(element["price"]);
allCount += element["count"];
allPrice += (singlePrice * element["count"]);
}
});
widget.fc(count, productId, allCount, allPrice); widget.fc(
count, productId, allCount, allPrice);
state(() {}); state(() {});
},
count: _shopCarGoods(position).count,
shopCarGoods: _shopCarGoods(position),
queryMiNiDetail: widget.queryMiNiDetail,
),
);
}, },
shopCarGoods: _shopCarGoods(position),
queryMiNiDetail: widget.queryMiNiDetail,
), ),
); ),
},
),
),
),
Stack(
alignment: Alignment.bottomLeft,
children: [
Container(
height: 54.h,
decoration: BoxDecoration(
color: Color(0xFFFAFAFA),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(8),
offset: Offset(0, -1),
blurRadius: 3,
spreadRadius: 0,
),
],
), ),
child: Row( Positioned(
children: [ bottom: 0,
Spacer(), left: 0,
Text( right: 0,
S.of(context).heji, child: Stack(
style: TextStyle( alignment: Alignment.bottomLeft,
fontSize: 12.sp, children: [
fontWeight: MyFontWeight.regular, Container(
color: Colors.black,
),
),
Text(
"" + allPrice.toString(),
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF32A060),
),
),
Spacer(),
GestureDetector(
onTap: () {
widget.toDownOrder();
},
child: RoundButton(
width: 103.w,
height: 54.h, height: 54.h,
text: S.current.jiesuan, decoration: BoxDecoration(
textColor: Colors.white, color: Color(0xFFFAFAFA),
fontWeight: MyFontWeight.regular, boxShadow: [
backgroup: Color(0xFF32A060), BoxShadow(
radius: 0, color: Colors.black.withAlpha(8),
fontSize: 16.sp, offset: Offset(0, -1),
padding: EdgeInsets.symmetric(vertical: 5.h), blurRadius: 3,
spreadRadius: 0,
),
],
),
child: Row(
children: [
Spacer(),
Text(
S.of(context).heji,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.regular,
color: Colors.black,
),
),
Text(
"" + allPrice.toString(),
style: TextStyle(
fontSize: 20.sp,
fontWeight: MyFontWeight.medium,
color: Color(0xFF32A060),
),
),
Spacer(),
GestureDetector(
onTap: () {
widget.toDownOrder();
},
child: RoundButton(
width: 103.w,
height: 54.h,
text: S.current.jiesuan,
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060),
radius: 0,
fontSize: 16.sp,
padding:
EdgeInsets.symmetric(vertical: 5.h),
),
),
],
),
), ),
), Stack(
], children: [
), InkWell(
), onTap: () {
Stack( Navigator.of(context).pop();
children: [ },
InkWell( child: Image.asset(
onTap: () { "assets/image/shopp.png",
Navigator.of(context).pop(); width: 88,
}, height: 88,
child: Image.asset( ),
"assets/image/shopp.png", ),
width: 88, Positioned(
height: 88, right: 15,
), top: 14,
), child: RoundButton(
Positioned( width: 17,
right: 15, height: 17,
top: 14, text: allCount.toString(),
child: RoundButton( textColor: Colors.white,
width: 17, fontWeight: MyFontWeight.regular,
height: 17, backgroup: Color(0xFF32A060),
text: allCount.toString(), fontSize: 12.sp,
textColor: Colors.white, radius: 100,
fontWeight: MyFontWeight.regular, callback: () {
backgroup: Color(0xFF32A060), Navigator.of(context)
fontSize: 12.sp, .pushNamed('/router/test_page');
radius: 100, },
callback: () { ),
Navigator.of(context) ),
.pushNamed('/router/test_page'); ],
}, ),
), ],
), ),
], ),
), ],
], ),
flex: 1,
), ),
], ],
), ),
@ -271,13 +243,14 @@ class _ShopCar extends State<ShopCar> {
); );
} }
Map<String, dynamic> _shopCarGoods(int position) { Sku _shopCarGoods(int position) {
Map<String, dynamic> map; Sku map = widget.shopCarGoods[position];
widget.shopCarGoods.forEach((element) { // widget.shopCarGoods.forEach((element) {
if (widget.productLists[position].id == element["id"]) { // if (widget.productLists[position].id == element.id) {
map = element; // map = element;
} // }
}); // });
// print("shopCarGoods123123: ${map.toJson()}");
return map; return map;
} }
} }

36
lib/store/store_view/shop_goods.dart

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/custom_image.dart';
@ -9,12 +10,14 @@ import 'package:huixiang/view_widget/round_button.dart';
class ShopGoods extends StatefulWidget { class ShopGoods extends StatefulWidget {
final ProductListBean product; final ProductListBean product;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(int count, String productId) fc; final Function(int count, List<Attr> attr, String productId) fc;
final Map<String, dynamic> shopCarGoods; final Sku shopCarGoods;
final int count;
ShopGoods( ShopGoods(
this.product, this.product,
this.fc, { this.fc, {
this.count = 0,
this.queryMiNiDetail, this.queryMiNiDetail,
this.shopCarGoods, this.shopCarGoods,
}); });
@ -23,13 +26,13 @@ class ShopGoods extends StatefulWidget {
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
return _ShopGoods(); return _ShopGoods();
} }
} }
class _ShopGoods extends State<ShopGoods> { class _ShopGoods extends State<ShopGoods> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
int buyNum = _count();
return Container( return Container(
color: Colors.white, color: Colors.white,
padding: EdgeInsets.only( padding: EdgeInsets.only(
@ -145,7 +148,7 @@ class _ShopGoods extends State<ShopGoods> {
], ],
), ),
Spacer(), Spacer(),
if (buyNum == 0) if (widget.count == 0)
RoundButton( RoundButton(
width: 49.w, width: 49.w,
text: S.of(context).xuanguige, text: S.of(context).xuanguige,
@ -159,11 +162,11 @@ class _ShopGoods extends State<ShopGoods> {
widget.queryMiNiDetail(widget.product.id); widget.queryMiNiDetail(widget.product.id);
}, },
), ),
if (buyNum > 0) if (widget.count > 0)
InkWell( InkWell(
onTap: () { onTap: () {
reduceCount(); reduceCount();
widget.fc(widget.shopCarGoods["count"], widget.product.id); widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id);
setState(() {}); setState(() {});
}, },
child: Image.asset( child: Image.asset(
@ -172,12 +175,12 @@ class _ShopGoods extends State<ShopGoods> {
height: 22, height: 22,
), ),
), ),
if (buyNum > 0) if (widget.count > 0)
Container( Container(
width: 30, width: 30,
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
"$buyNum", "${widget.count}",
style: TextStyle( style: TextStyle(
color: Colors.black, color: Colors.black,
fontSize: 14.sp, fontSize: 14.sp,
@ -185,11 +188,11 @@ class _ShopGoods extends State<ShopGoods> {
), ),
), ),
), ),
if (buyNum > 0) if (widget.count > 0)
InkWell( InkWell(
onTap: () { onTap: () {
addCount(); addCount();
widget.fc(widget.shopCarGoods["count"], widget.product.id); widget.fc(widget.shopCarGoods.count, widget.shopCarGoods.attr, widget.product.id);
setState(() {}); setState(() {});
}, },
child: Image.asset( child: Image.asset(
@ -209,21 +212,12 @@ class _ShopGoods extends State<ShopGoods> {
} }
addCount() { addCount() {
widget.shopCarGoods["count"] += 1; widget.shopCarGoods.count += 1;
} }
reduceCount() { reduceCount() {
widget.shopCarGoods["count"] -= 1; widget.shopCarGoods.count -= 1;
} }
int _count() {
if (widget.shopCarGoods == null) return 0;
if (widget.product.id == widget.shopCarGoods["id"]) {
return widget.shopCarGoods["count"];
}
return 0;
}
} }

68
lib/store/store_view/store_order_list.dart

@ -4,9 +4,11 @@ import 'package:flutter/material.dart';
import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/activity.dart';
import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/retrofit/data/store_info.dart'; import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/store/store_view/shop_goods.dart'; import 'package:huixiang/store/store_view/shop_goods.dart';
import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -21,7 +23,7 @@ class StoreOrderListPage extends StatefulWidget {
final Function(int count, String productId, int allCount, double allPrice) fc; final Function(int count, String productId, int allCount, double allPrice) fc;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(List<FindMiNiGroupList> appletProducts) productListResult; final Function(List<FindMiNiGroupList> appletProducts) productListResult;
List<Map<String, dynamic>> shopCarGoods; List<ShoppingCart> shopCarGoods;
StoreOrderListPage( StoreOrderListPage(
this.arguments, this.arguments,
@ -199,8 +201,8 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
int count = 0; int count = 0;
findMiNiGroupList.productList.forEach((element) { findMiNiGroupList.productList.forEach((element) {
widget.shopCarGoods.forEach((element1) { widget.shopCarGoods.forEach((element1) {
if (element.id == element1["id"]) { if (element.id == element1.id) {
count += element1["count"]; count += element1.count;
} }
}); });
}); });
@ -208,35 +210,47 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
} }
Widget goodsItem(position) { Widget goodsItem(position) {
Map<String, dynamic> map; Sku map;
int count = 0;
widget.shopCarGoods.forEach((element) { widget.shopCarGoods.forEach((element) {
if (productListBeans[position].id == element["id"]) { if (productListBeans[position].id == element.id) {
map = element; if (map == null) {
map = element;
count = map.count;
} else {
count += element.count;
}
} }
}); });
return ShopGoods( return InkWell(
productListBeans[position], onTap: () {
(int count, String productId) { widget.queryMiNiDetail(productListBeans[position].id);
int allCount = 0; },
AiDecimalAccuracy allPrice = AiDecimalAccuracy.zero; child: ShopGoods(
widget.shopCarGoods.forEach((element2) { productListBeans[position],
if (element2["price"] != null && element2["price"] != "") { (int count, List<Attr> attr, String productId) {
double singlePrice = double.tryParse(element2["price"]); int allCount = 0;
allCount += element2["count"]; 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 aiDecimalAccuracy =
AiDecimalAccuracy.fromInt(element2["count"]); AiDecimalAccuracy.fromInt(element2.count);
AiDecimalAccuracy aiPrice = AiDecimalAccuracy aiPrice =
AiDecimalAccuracy.tryParse("$singlePrice"); AiDecimalAccuracy.tryParse("$singlePrice");
allPrice += (aiPrice * aiDecimalAccuracy); allPrice += (aiPrice * aiDecimalAccuracy);
} }
}); });
widget.fc(count, productId, allCount, allPrice.toDouble()); widget.fc(count, productId, allCount, allPrice.toDouble());
setState(() {}); setState(() {});
}, },
queryMiNiDetail: widget.queryMiNiDetail, count: count,
shopCarGoods: map, queryMiNiDetail: widget.queryMiNiDetail,
shopCarGoods: map,
),
); );
} }
} }

Loading…
Cancel
Save