Browse Source

更改

master
w-R 3 years ago
parent
commit
b211ad27fa
  1. 6
      lib/retrofit/min_api.g.dart
  2. 48
      lib/store/store_order.dart
  3. 79
      lib/store/store_view/shop_car.dart
  4. 21
      lib/store/store_view/shop_goods.dart
  5. 31
      lib/store/store_view/store_order_list.dart

6
lib/retrofit/min_api.g.dart

@ -64,7 +64,7 @@ class _MinApiService implements MinApiService {
} }
@override @override
Future<BaseData<FindMiNiGroupList>> shoppingCart(param, header) async { Future<BaseData<ShoppingCart>> shoppingCart(param, header) async {
ArgumentError.checkNotNull(param, 'param'); ArgumentError.checkNotNull(param, 'param');
ArgumentError.checkNotNull(header, 'header'); ArgumentError.checkNotNull(header, 'header');
const _extra = <String, dynamic>{}; const _extra = <String, dynamic>{};
@ -79,9 +79,9 @@ class _MinApiService implements MinApiService {
extra: _extra, extra: _extra,
baseUrl: baseUrl), baseUrl: baseUrl),
data: _data); data: _data);
final value = BaseData<FindMiNiGroupList>.fromJson( final value = BaseData<ShoppingCart>.fromJson(
_result.data, _result.data,
(json) => FindMiNiGroupList.fromJson(json), (json) => ShoppingCart.fromJon(json),
); );
return value; return value;
} }

48
lib/store/store_order.dart

@ -9,13 +9,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/order_info.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/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/shop_goods.dart';
import 'package:huixiang/store/store_view/store_activity.dart'; import 'package:huixiang/store/store_view/store_activity.dart';
import 'package:huixiang/store/store_view/store_info.dart'; import 'package:huixiang/store/store_view/store_info.dart';
import 'package:huixiang/store/store_view/store_order_list.dart'; import 'package:huixiang/store/store_view/store_order_list.dart';
@ -51,6 +49,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
List<Widget> _widgetOptions; List<Widget> _widgetOptions;
int allCount = 0; int allCount = 0;
double allPrice = 0; double allPrice = 0;
StoreOrderListPage storeOrderListPage;
ScrollController controller = ScrollController(); ScrollController controller = ScrollController();
@ -63,16 +62,17 @@ class _StoreOrderPage extends State<StoreOrderPage>
length: 2, length: 2,
vsync: this, vsync: this,
); );
storeOrderListPage = StoreOrderListPage(
_widgetOptions = [
StoreOrderListPage(
widget.arguments, widget.arguments,
activitys, activitys,
storeInfo, storeInfo,
controller, controller,
_queryMiNiDetail, _queryMiNiDetail,
_fc, _fc
), );
_widgetOptions = [
storeOrderListPage,
///, ///,
StoreActivity( StoreActivity(
@ -84,10 +84,28 @@ class _StoreOrderPage extends State<StoreOrderPage>
queryStoreInfo(); queryStoreInfo();
} }
_fc(ac, ap) { _fc(ProductListBean plb) {
setState(() { setState(() {
allCount = ac; allCount = 0;
allPrice = ap; allPrice = 0;
bool flag = false;
for(var i = 0;i < productLists.length;i++){
if(productLists[i].id == plb.id){
flag = true;
if(plb.buyNum == 0)
productLists.removeAt(i);
else productLists[i] = plb;
break;
}
}
storeOrderListPage.notifyList(productLists);
if(!flag && plb.buyNum != 0)
productLists.add(plb);
productLists.forEach((element) {
allCount += element.buyNum;
allPrice += double.parse(element.price) *
element.buyNum;
});
}); });
} }
@ -108,7 +126,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
String minToken = minStoreInfo["token"]; String minToken = minStoreInfo["token"];
String tenant = widget.arguments["tenant"]; String tenant = widget.arguments["tenant"];
SharedPreferences.getInstance().then( SharedPreferences.getInstance().then(
(value) => { (value) => {
value.setString('minToken', minToken), value.setString('minToken', minToken),
value.setString('tenant', tenant), value.setString('tenant', tenant),
}, },
@ -123,7 +141,6 @@ class _StoreOrderPage extends State<StoreOrderPage>
}); });
} }
/// ///
queryStoreInfo() async { queryStoreInfo() async {
final SharedPreferences value = await SharedPreferences.getInstance(); final SharedPreferences value = await SharedPreferences.getInstance();
@ -451,12 +468,7 @@ class _StoreOrderPage extends State<StoreOrderPage>
context: context, context: context,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
builder: (context) { builder: (context) {
return ShopCar(productLists, _queryMiNiDetail, (ac, ap) { return ShopCar(productLists, _queryMiNiDetail, _fc);
setState(() {
allCount = ac;
allPrice = ap;
});
});
}, },
); );
} }

79
lib/store/store_view/shop_car.dart

@ -1,7 +1,6 @@
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/order_info.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';
@ -11,7 +10,7 @@ class ShopCar extends StatefulWidget {
final List<ProductListBean> productLists; final List<ProductListBean> productLists;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(int allCount, double allPrice) fc; final Function(ProductListBean plb) fc;
ShopCar(this.productLists, this.queryMiNiDetail, this.fc); ShopCar(this.productLists, this.queryMiNiDetail, this.fc);
@ -23,6 +22,41 @@ class ShopCar extends StatefulWidget {
} }
class _ShopCar extends State<ShopCar> { class _ShopCar extends State<ShopCar> {
int allCount = 0;
double allPrice = 0;
@override
void initState() {
super.initState();
_fc(null);
}
_fc(ProductListBean plb) {
setState(() {
if(plb != null){
allCount = 0;
allPrice = 0;
bool flag = false;
for(var i = 0;i < widget.productLists.length;i++){
if(widget.productLists[i].id == plb.id){
flag = true;
if(plb.buyNum == 0)
widget.productLists.removeAt(i);
else widget.productLists[i] = plb;
break;
}
}
if(!flag)
widget.productLists.add(plb);
}
widget.productLists.forEach((element) {
allCount += element.buyNum;
allPrice += double.parse(element.price) *
element.buyNum;
});
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return StatefulBuilder(builder: (context1, state) { return StatefulBuilder(builder: (context1, state) {
@ -61,7 +95,10 @@ class _ShopCar extends State<ShopCar> {
), ),
), ),
InkWell( InkWell(
onTap: () {}, onTap: () {
state(() {
});
},
child: Image.asset( child: Image.asset(
"assets/image/delete.png", "assets/image/delete.png",
width: 22, width: 22,
@ -84,7 +121,10 @@ class _ShopCar extends State<ShopCar> {
itemBuilder: (context, position) { itemBuilder: (context, position) {
return GestureDetector( return GestureDetector(
onTap: () {}, onTap: () {},
child: ShopGoods(widget.productLists, position, widget.queryMiNiDetail, widget.fc), child: ShopGoods(widget.productLists, position, widget.queryMiNiDetail, (plb){setState(() {
_fc(plb);
widget.fc(plb);
});}),
); );
}, },
), ),
@ -118,7 +158,7 @@ class _ShopCar extends State<ShopCar> {
), ),
), ),
Text( Text(
"19.00", ""+allPrice.toString(),
style: TextStyle( style: TextStyle(
fontSize: 20.sp, fontSize: 20.sp,
fontWeight: MyFontWeight.medium, fontWeight: MyFontWeight.medium,
@ -126,16 +166,23 @@ class _ShopCar extends State<ShopCar> {
), ),
), ),
Spacer(), Spacer(),
RoundButton( GestureDetector(
width: 103.w, onTap: () {
height: 54.h, Navigator.of(context).pushNamed(
text: S.current.jiesuan, '/router/settlement',
textColor: Colors.white, );
fontWeight: MyFontWeight.regular, },
backgroup: Color(0xFF32A060), child: RoundButton(
radius: 0, width: 103.w,
fontSize: 16.sp, height: 54.h,
padding: EdgeInsets.symmetric(vertical: 5.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),
),
), ),
], ],
), ),
@ -158,7 +205,7 @@ class _ShopCar extends State<ShopCar> {
child: RoundButton( child: RoundButton(
width: 17, width: 17,
height: 17, height: 17,
text: "1", text: allCount.toString(),
textColor: Colors.white, textColor: Colors.white,
fontWeight: MyFontWeight.regular, fontWeight: MyFontWeight.regular,
backgroup: Color(0xFF32A060), backgroup: Color(0xFF32A060),

21
lib/store/store_view/shop_goods.dart

@ -1,7 +1,6 @@
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/order_info.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';
@ -11,7 +10,7 @@ class ShopGoods extends StatefulWidget {
final List<ProductListBean> productListBeans; final List<ProductListBean> productListBeans;
final int position; final int position;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
final Function(int allCount, double allPrice) fc; final Function(ProductListBean plb) fc;
ShopGoods( ShopGoods(
this.productListBeans, this.productListBeans,
@ -165,14 +164,7 @@ class _ShopGoods extends State<ShopGoods> {
0) 0)
widget.productListBeans[widget.position] widget.productListBeans[widget.position]
.buyNum--; .buyNum--;
int allCount = 0; widget.fc(widget.productListBeans[widget.position]);
double allPrice = 0;
widget.productListBeans.forEach((element) {
allCount += element.buyNum;
allPrice += double.parse(element.price) *
element.buyNum;
});
widget.fc(allCount, allPrice);
} }
}); });
}, },
@ -201,14 +193,7 @@ class _ShopGoods extends State<ShopGoods> {
setState(() { setState(() {
{ {
widget.productListBeans[widget.position].buyNum++; widget.productListBeans[widget.position].buyNum++;
int allCount = 0; widget.fc(widget.productListBeans[widget.position]);
double allPrice = 0;
widget.productListBeans.forEach((element) {
allCount += element.buyNum;
allPrice += double.parse(element.price) *
element.buyNum;
});
widget.fc(allCount, allPrice);
} }
}); });
}, },

31
lib/store/store_view/store_order_list.dart

@ -18,8 +18,9 @@ class StoreOrderListPage extends StatefulWidget {
final List<Activity> activitys; final List<Activity> activitys;
final StoreInfo storeInfo; final StoreInfo storeInfo;
final ScrollController controller; final ScrollController controller;
final Function(int allCount, double allPrice) fc; final Function(ProductListBean plb) fc;
final Function(String id) queryMiNiDetail; final Function(String id) queryMiNiDetail;
_StoreOrderListPage _storeOrderListPage;
StoreOrderListPage( StoreOrderListPage(
this.arguments, this.arguments,
@ -27,12 +28,17 @@ class StoreOrderListPage extends StatefulWidget {
this.storeInfo, this.storeInfo,
this.controller, this.controller,
this.queryMiNiDetail, this.queryMiNiDetail,
this.fc, this.fc
); );
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {
return _StoreOrderListPage(); _storeOrderListPage = _StoreOrderListPage();
return _storeOrderListPage;
}
void notifyList(List<ProductListBean> product){
_storeOrderListPage.notifyList(product);
} }
} }
@ -42,7 +48,18 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
ApiService apiService; ApiService apiService;
MinApiService minService; MinApiService minService;
List<FindMiNiGroupList> appletProducts; List<FindMiNiGroupList> appletProducts;
List<ProductListBean> productListBeans; List<ProductListBean> productListBeans = [];
void notifyList(List<ProductListBean> product){
setState(() {
product.forEach((e0) {
productListBeans.forEach((e1) {
if(e0.id == e1.id)
e1.buyNum = e0.buyNum;
});
});
});
}
@override @override
void initState() { void initState() {
@ -74,8 +91,9 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
setState(() { setState(() {
appletProducts = baseData.data; appletProducts = baseData.data;
productListBeans.clear();
if (appletProducts.length > 0) if (appletProducts.length > 0)
productListBeans = appletProducts[0].productList; productListBeans.addAll(appletProducts[0].productList);
}); });
} }
} }
@ -133,7 +151,8 @@ class _StoreOrderListPage extends State<StoreOrderListPage> {
onTap: () { onTap: () {
setState(() { setState(() {
isSelected = index; isSelected = index;
productListBeans = findMiNiGroupList.productList; productListBeans.clear();
productListBeans.addAll(findMiNiGroupList.productList);
}); });
}, },
child: Container( child: Container(

Loading…
Cancel
Save