Browse Source

safety

master
fmk 3 years ago
parent
commit
f2bc610020
  1. 3
      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. 106
      lib/retrofit/min_api.g.dart
  6. 8
      lib/retrofit/retrofit_api.dart
  7. 71
      lib/store/sku.dart
  8. 182
      lib/store/store_order.dart
  9. 75
      lib/store/store_view/product_sku.dart
  10. 27
      lib/store/store_view/settlement.dart
  11. 11
      lib/store/store_view/settlement_order_commodity.dart
  12. 109
      lib/store/store_view/shop_car.dart
  13. 36
      lib/store/store_view/shop_goods.dart
  14. 36
      lib/store/store_view/store_order_list.dart

3
lib/community/community_child_page.dart

@ -107,7 +107,8 @@ class _CommunityChildPage extends State<CommunityChildPage> {
);
},
itemCount: comments.length,
));
),
);
},
);
}

8
lib/retrofit/data/settlement_bean.dart

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

14
lib/retrofit/data/shoppingCart.dart

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

33
lib/retrofit/min_api.dart

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

106
lib/retrofit/min_api.g.dart

@ -64,9 +64,8 @@ class _MinApiService implements MinApiService {
}
@override
Future<BaseData<ShoppingCart>> shoppingCart(param, header) async {
Future<BaseData<List<ShoppingCart>>> addShoppingCart(param) async {
ArgumentError.checkNotNull(param, 'param');
ArgumentError.checkNotNull(header, 'header');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
@ -79,13 +78,108 @@ class _MinApiService implements MinApiService {
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<ShoppingCart>.fromJson(
final value = BaseData<List<ShoppingCart>>.fromJson(
_result.data,
(json) => ShoppingCart.fromJson(json),
(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,
(json) => json as bool,
);
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
Future<BaseData<SettleOrderInfo>> getOrderInfo(param) async {
ArgumentError.checkNotNull(param, 'param');
@ -139,8 +233,7 @@ class _MinApiService implements MinApiService {
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(param ?? <String, dynamic>{});
final _result = await _dio.request<Map<String, dynamic>>(
'order/settlement',
final _result = await _dio.request<Map<String, dynamic>>('order/settlement',
queryParameters: queryParameters,
options: RequestOptions(
method: 'POST',
@ -154,5 +247,4 @@ class _MinApiService implements MinApiService {
);
return value;
}
}

8
lib/retrofit/retrofit_api.dart

@ -90,9 +90,9 @@ abstract class ApiService {
EasyLoading.dismiss();
}
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;
if (map["code"] != 0) {
@ -131,11 +131,11 @@ abstract class ApiService {
int maxStrLength = 900;
//1000
while (msg.length > maxStrLength) {
debugPrint(msg.substring(0, maxStrLength));
debugPrint(msg.substring(0, maxStrLength), wrapWidth: 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,
);
}
}

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

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

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

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

109
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:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart';
import 'package:huixiang/retrofit/data/shoppingCart.dart';
import 'package:huixiang/store/sku.dart';
import 'package:huixiang/store/store_view/shop_goods.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class ShopCar extends StatefulWidget {
final List<ProductListBean> productLists;
final Function(String id) queryMiNiDetail;
final Function() clearShopCar;
final Function() toDownOrder;
final List<Map<String, dynamic>> shopCarGoods;
final List<ShoppingCart> shopingCar;
final Function(int count, String productId, int allCount, double allPrice) fc;
ShopCar(
this.productLists,
this.shopCarGoods,
this.shopingCar,
this.clearShopCar,
this.toDownOrder,
this.fc, {
@ -27,7 +28,7 @@ class ShopCar extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ShopCar(this.shopCarGoods);
return _ShopCar();
}
}
@ -35,30 +36,9 @@ class _ShopCar extends State<ShopCar> {
int allCount = 0;
double allPrice = 0.0;
final List<Map<String, dynamic>> shopCarGoods;
_ShopCar(this.shopCarGoods);
@override
void 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
@ -103,7 +83,7 @@ class _ShopCar extends State<ShopCar> {
onTap: () {
allPrice = 0;
allCount = 0;
widget.productLists.clear();
state(() {});
widget.clearShopCar();
},
@ -117,6 +97,13 @@ class _ShopCar extends State<ShopCar> {
),
),
Expanded(
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
right: 0,
bottom: 54,
child: Container(
padding: EdgeInsets.only(
top: 8,
@ -124,49 +111,24 @@ class _ShopCar extends State<ShopCar> {
right: 16,
),
child: ListView.builder(
itemCount: widget.productLists == null
itemCount: widget.shopingCar == null
? 0
: widget.productLists.length,
: widget.shopingCar.length,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {},
child: ShopGoods(
widget.productLists[position],
(int count, String productId) {
int index = shopCarGoods.indexWhere((element) => element["id"] == productId);
if (count == 0) {
shopCarGoods.removeAt(index);
int index1 = widget.productLists.indexWhere((element) => element.id == productId);
widget.productLists.removeAt(index1);
} else {
Map<String, dynamic> map;
print("productId: $productId");
shopCarGoods.forEach((element) {
if (element["id"] == productId) {
map = element;
}
});
map["count"] = count;
shopCarGoods[index] = map;
}
widget.shopingCar[position],
(int count, List<Attr> attr, String productId) {
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(() {});
},
count: _shopCarGoods(position).count,
shopCarGoods: _shopCarGoods(position),
queryMiNiDetail: widget.queryMiNiDetail,
),
@ -175,7 +137,11 @@ class _ShopCar extends State<ShopCar> {
),
),
),
Stack(
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Stack(
alignment: Alignment.bottomLeft,
children: [
Container(
@ -224,7 +190,8 @@ class _ShopCar extends State<ShopCar> {
backgroup: Color(0xFF32A060),
radius: 0,
fontSize: 16.sp,
padding: EdgeInsets.symmetric(vertical: 5.h),
padding:
EdgeInsets.symmetric(vertical: 5.h),
),
),
],
@ -264,6 +231,11 @@ class _ShopCar extends State<ShopCar> {
),
],
),
),
],
),
flex: 1,
),
],
),
);
@ -271,13 +243,14 @@ class _ShopCar extends State<ShopCar> {
);
}
Map<String, dynamic> _shopCarGoods(int position) {
Map<String, dynamic> map;
widget.shopCarGoods.forEach((element) {
if (widget.productLists[position].id == element["id"]) {
map = element;
}
});
Sku _shopCarGoods(int position) {
Sku map = widget.shopCarGoods[position];
// widget.shopCarGoods.forEach((element) {
// if (widget.productLists[position].id == element.id) {
// map = element;
// }
// });
// print("shopCarGoods123123: ${map.toJson()}");
return map;
}
}

36
lib/store/store_view/shop_goods.dart

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

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

Loading…
Cancel
Save