diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index e5d6febb..697588a6 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -8,10 +8,12 @@ import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; +import 'package:huixiang/retrofit/data/miNiDetail.dart'; import 'package:huixiang/retrofit/data/order_info.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/store_view/product_sku.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'; @@ -28,7 +30,7 @@ import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; class StoreOrderPage extends StatefulWidget { - final Map arguments; + final Map arguments; StoreOrderPage({this.arguments}); @@ -63,13 +65,14 @@ class _StoreOrderPage extends State ); _widgetOptions = [ - StoreOrderListPage(widget.arguments, activitys, storeInfo, controller, - (ac, ap) { - setState(() { - allCount = ac; - allPrice = ap; - }); - }), + StoreOrderListPage( + widget.arguments, + activitys, + storeInfo, + controller, + _queryMiNiDetail, + _fc, + ), ///星店活动, StoreActivity( @@ -77,10 +80,50 @@ class _StoreOrderPage extends State activitys, ), ]; - + minLogin(); queryStoreInfo(); } + _fc(ac, ap) { + setState(() { + allCount = ac; + allPrice = ap; + }); + } + + /// 小程序登录 + minLogin() async { + final SharedPreferences value = await SharedPreferences.getInstance(); + apiService = ApiService( + Dio(), + context: context, + token: value.getString('token'), + ); + apiService + .minLogin(widget.arguments["id"]) + .catchError((onError) {}) + .then((baseData) { + if (baseData != null && baseData.isSuccess) { + Map minStoreInfo = baseData.data; + String minToken = minStoreInfo["token"]; + String tenant = widget.arguments["tenant"]; + SharedPreferences.getInstance().then( + (value) => { + value.setString('minToken', minToken), + value.setString('tenant', tenant), + }, + ); + minService = MinApiService( + Dio(), + context: context, + token: minToken, + tenant: tenant, + ); + } + }); + } + + /// 查询店铺信息 queryStoreInfo() async { final SharedPreferences value = await SharedPreferences.getInstance(); @@ -307,7 +350,7 @@ class _StoreOrderPage extends State onTap: () { Navigator.of(context).pushNamed( '/router/settlement', - arguments: {}, + arguments: widget.arguments, ); }, child: RoundButton( @@ -400,7 +443,7 @@ class _StoreOrderPage extends State ); } - List productLists = []; + List productLists = []; ///购物车弹窗 showShoppingCart() { @@ -408,13 +451,47 @@ class _StoreOrderPage extends State context: context, backgroundColor: Colors.transparent, builder: (context) { - return ShopCar(productLists); + return ShopCar(productLists, _queryMiNiDetail, (ac, ap) { + setState(() { + allCount = ac; + allPrice = ap; + }); + }); }, ); } - Widget shoppGoodsItem(ProductList pro, position) { - return ShopGoods(pro, position); + ///选规格 + _queryMiNiDetail(String id) async { + BaseData baseData = await minService.miNiDetail(id); + if (baseData != null && baseData.isSuccess) { + setState(() { + showStoreSelector(baseData.data); + }); + } + } + + ///添加购物车 + addsShoppingCart() async { + BaseData baseDate = await apiService.creditOrder({ + "parentId": widget.arguments["parentId"], + "skuImg": widget.arguments["skuImg"], + "skuNameStr": widget.arguments["skuNameStr"], + "skuPrice": widget.arguments["skuPrice"], + "skuStock": widget.arguments["skuStock"], + }); + if (baseDate != null && baseDate.isSuccess) {} + } + + ///选规格弹窗 + showStoreSelector(MiNiDetail miNiDetail) { + showModalBottomSheet( + context: context, + backgroundColor: Colors.transparent, + builder: (context) { + return ProductSku(miNiDetail); + }, + ); } @override diff --git a/lib/store/store_view/settlement.dart b/lib/store/store_view/settlement.dart index 573262e8..5ab3b2bf 100644 --- a/lib/store/store_view/settlement.dart +++ b/lib/store/store_view/settlement.dart @@ -50,10 +50,8 @@ class _Settlement extends State { int refundStatus = 0; // String storeType = "NORMALSTORE"; //NORMALSTORE FASTSTORE RETAILSTORE - queryDetails() async { - BaseData baseData = - await apiService.orderDetail(widget.arguments["id"]); + BaseData baseData = await apiService.orderDetail(widget.arguments["id"]); if (baseData != null && baseData.isSuccess) { orderInfo = baseData.data; payStatus = orderInfo.payStatus; diff --git a/lib/store/store_view/shop_car.dart b/lib/store/store_view/shop_car.dart index a41ea79a..b09e315f 100644 --- a/lib/store/store_view/shop_car.dart +++ b/lib/store/store_view/shop_car.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.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/utils/font_weight.dart'; @@ -8,9 +9,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; class ShopCar extends StatefulWidget { - final List productLists; + final List productLists; + final Function(String id) queryMiNiDetail; + final Function(int allCount, double allPrice) fc; - ShopCar(this.productLists); + ShopCar(this.productLists, this.queryMiNiDetail, this.fc); @override State createState() { @@ -79,10 +82,9 @@ class _ShopCar extends State { itemCount: widget.productLists == null ? 0 : widget.productLists.length, physics: BouncingScrollPhysics(), itemBuilder: (context, position) { - // return shoppGoodsItem(); return GestureDetector( onTap: () {}, - child: ShopGoods(widget.productLists[position], position), + child: ShopGoods(widget.productLists, position, widget.queryMiNiDetail, widget.fc), ); }, ), diff --git a/lib/store/store_view/shop_goods.dart b/lib/store/store_view/shop_goods.dart index 87c09ed8..b912ffd4 100644 --- a/lib/store/store_view/shop_goods.dart +++ b/lib/store/store_view/shop_goods.dart @@ -1,74 +1,92 @@ - - import 'package:flutter/material.dart'; +import 'package:huixiang/generated/l10n.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:flutter_screenutil/flutter_screenutil.dart'; +import 'package:huixiang/view_widget/custom_image.dart'; +import 'package:huixiang/view_widget/round_button.dart'; class ShopGoods extends StatefulWidget { - - final ProductList pro; + final List productListBeans; final int position; + final Function(String id) queryMiNiDetail; + final Function(int allCount, double allPrice) fc; - ShopGoods(this.pro, this.position); + ShopGoods( + this.productListBeans, + this.position, + this.queryMiNiDetail, + this.fc, + ); @override State createState() { return _ShopGoods(); } - } class _ShopGoods extends State { - @override Widget build(BuildContext context) { return Container( - padding: EdgeInsets.only(bottom: 10), + color: Colors.white, + padding: EdgeInsets.only(right: 16.w, bottom: 10.h, top: 10.h), child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, children: [ - Image.asset( - "assets/image/default_1.png", - width: 60, - height: 60, + SizedBox(width: 12.w), + MImage( + widget.productListBeans[widget.position] != null + ? widget.productListBeans[widget.position].imgPath + : "", + width: 70, + height: 70, fit: BoxFit.cover, + errorSrc: "assets/image/default_1.png", + fadeSrc: "assets/image/default_1.png", + ), + SizedBox( + width: 10, ), - SizedBox(width: 10), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - "手工啵啵奶茶", + widget.productListBeans[widget.position].productName, style: TextStyle( color: Colors.black, - fontSize: 12.sp, + fontSize: 13.sp, fontWeight: MyFontWeight.medium, ), ), - SizedBox(height: 2), + SizedBox( + height: 2, + ), Row( children: [ - Text( - "无香精", - style: TextStyle( - color: Color(0xFF4C4C4C), - fontSize: 11.sp, - fontWeight: MyFontWeight.regular, + Expanded( + child: Text( + widget.productListBeans[widget.position].shortName, + overflow: TextOverflow.ellipsis, + maxLines: 2, + style: TextStyle( + color: Color(0xFF4C4C4C), + fontSize: 10.sp, + fontWeight: MyFontWeight.regular, + ), ), ), - SizedBox(width: 10), - Text( - "无香精", - style: TextStyle( - color: Color(0xFF4C4C4C), - fontSize: 11.sp, - fontWeight: MyFontWeight.regular, - ), - ) + SizedBox( + width: 10, + ), ], ), - SizedBox(height: 6), + SizedBox( + height: 7, + ), Row( children: [ Column( @@ -77,62 +95,136 @@ class _ShopGoods extends State { Row( children: [ Text( - "会员价", + S.of(context).huiyuanjia, style: TextStyle( color: Color(0xFFFF7A1A), - fontSize: 13.sp, + fontSize: 10.sp, fontWeight: MyFontWeight.medium, ), ), + SizedBox( + width: 4, + ), Text( - "¥19.00", + "¥${widget.productListBeans[widget.position].price}", style: TextStyle( color: Color(0xFFFF7A1A), - fontSize: 14.sp, + fontSize: 11.sp, fontWeight: MyFontWeight.medium, ), - ) + ), + ], + ), + Row( + children: [ + Text( + S.of(context).yuanjia, + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 9.sp, + fontWeight: MyFontWeight.regular, + ), + ), + SizedBox( + width: 4, + ), + Text( + "¥${widget.productListBeans[widget.position].applyPrice}", + style: TextStyle( + color: Color(0xFFA29E9E), + fontSize: 10.sp, + fontWeight: MyFontWeight.regular, + ), + ), ], ), ], ), Spacer(), - InkWell( - onTap: () {}, - child: Image.asset( - "assets/image/reduce.png", - width: 22, - height: 22, - ), - ), - Padding( - padding: EdgeInsets.only(left: 8, right: 8), - child: Text( - "1", - style: TextStyle( - color: Colors.black, - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, + widget.productListBeans[widget.position].attrStyle == 1 + ? RoundButton( + width: 49.w, + text: S.of(context).xuanguige, + textColor: Colors.white, + fontWeight: MyFontWeight.medium, + radius: 11, + backgroup: Color(0xFF32A060), + fontSize: 11.sp, + padding: EdgeInsets.symmetric(vertical: 5.h), + callback: () { + widget.queryMiNiDetail( + widget.productListBeans[widget.position].id); + }, + ) + : InkWell( + onTap: () { + setState(() { + { + if (widget.productListBeans[widget.position] + .buyNum > + 0) + widget.productListBeans[widget.position] + .buyNum--; + int allCount = 0; + double allPrice = 0; + widget.productListBeans.forEach((element) { + allCount += element.buyNum; + allPrice += double.parse(element.price) * + element.buyNum; + }); + widget.fc(allCount, allPrice); + } + }); + }, + child: Image.asset( + "assets/image/reduce.png", + width: 22, + height: 22, + ), + ), + if (widget.productListBeans[widget.position].attrStyle == 0) + Padding( + padding: EdgeInsets.only(left: 8, right: 8), + child: Text( + widget.productListBeans[widget.position].buyNum + .toString(), + style: TextStyle( + color: Colors.black, + fontSize: 14.sp, + fontWeight: MyFontWeight.medium, + ), ), ), - ), - InkWell( - onTap: () {}, - child: Image.asset( - "assets/image/add.png", - width: 22, - height: 22, + if (widget.productListBeans[widget.position].attrStyle == 0) + InkWell( + onTap: () { + setState(() { + { + widget.productListBeans[widget.position].buyNum++; + int allCount = 0; + double allPrice = 0; + widget.productListBeans.forEach((element) { + allCount += element.buyNum; + allPrice += double.parse(element.price) * + element.buyNum; + }); + widget.fc(allCount, allPrice); + } + }); + }, + child: Image.asset( + "assets/image/add.png", + width: 22, + height: 22, + ), ), - ), ], ), ], ), - flex: 1, - ), + ) ], ), ); } - -} \ No newline at end of file +} diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index 33e7f813..04e1759a 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -1,7 +1,5 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; -import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; @@ -10,9 +8,8 @@ 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/store_view/product_sku.dart'; +import 'package:huixiang/store/store_view/shop_goods.dart'; import 'package:huixiang/utils/font_weight.dart'; -import 'package:huixiang/view_widget/custom_image.dart'; -import 'package:huixiang/view_widget/round_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -22,9 +19,16 @@ class StoreOrderListPage extends StatefulWidget { final StoreInfo storeInfo; final ScrollController controller; final Function(int allCount, double allPrice) fc; + final Function(String id) queryMiNiDetail; StoreOrderListPage( - this.arguments, this.activitys, this.storeInfo, this.controller, this.fc); + this.arguments, + this.activitys, + this.storeInfo, + this.controller, + this.queryMiNiDetail, + this.fc, + ); @override State createState() { @@ -33,7 +37,6 @@ class StoreOrderListPage extends StatefulWidget { } class _StoreOrderListPage extends State { - int isSelected = 0; int tempClickIndex = 0; ApiService apiService; @@ -45,47 +48,23 @@ class _StoreOrderListPage extends State { void initState() { super.initState(); - minLogin(); + appletGoods(); widget.controller.addListener(() {}); } - /// 小程序登录 - minLogin() async { - final SharedPreferences value = await SharedPreferences.getInstance(); - apiService = ApiService( + ///小程序查询分组及商品列表 + appletGoods() async { + SharedPreferences value = await SharedPreferences.getInstance(); + String minToken = value.getString("minToken"); + String tenant = value.getString("tenant"); + minService = MinApiService( Dio(), context: context, - token: value.getString('token'), + token: minToken, + tenant: tenant, ); - apiService - .minLogin(widget.arguments["id"]) - .catchError((onError) {}) - .then((baseData) { - if (baseData != null && baseData.isSuccess) { - Map minStoreInfo = baseData.data; - String minToken = minStoreInfo["token"]; - String tenant = widget.arguments["tenant"]; - SharedPreferences.getInstance().then( - (value) => { - value.setString('minToken', minToken), - value.setString('tenant', tenant), - }, - ); - minService = MinApiService( - Dio(), - context: context, - token: minToken, - tenant: tenant, - ); - appletGoods(); - // queryMiNiDetail(widget.arguments["id"]); - } - }); - } - ///小程序查询分组及商品列表 - appletGoods() async { BaseData> baseData = await minService.findMiNiGroupList( { @@ -101,28 +80,6 @@ class _StoreOrderListPage extends State { } } - ///选规格 - queryMiNiDetail(String id) async { - BaseData baseData = await minService.miNiDetail(id); - if (baseData != null && baseData.isSuccess) { - setState(() { - showStoreSelector(baseData.data); - }); - } - } - - ///添加购物车 - addsShoppingCart() async { - BaseData baseDate = await apiService.creditOrder({ - "parentId": widget.arguments["parentId"], - "skuImg": widget.arguments["skuImg"], - "skuNameStr": widget.arguments["skuNameStr"], - "skuPrice": widget.arguments["skuPrice"], - "skuStock": widget.arguments["skuStock"], - }); - if (baseDate != null && baseDate.isSuccess) {} - } - @override Widget build(BuildContext context) { return Container( @@ -202,199 +159,11 @@ class _StoreOrderListPage extends State { } Widget goodsItem(position) { - return Container( - color: Colors.white, - padding: EdgeInsets.only(right: 16.w, bottom: 10.h, top: 10.h), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - SizedBox(width: 12.w), - MImage( - productListBeans[position] != null - ? productListBeans[position].imgPath - : "", - width: 70, - height: 70, - fit: BoxFit.cover, - errorSrc: "assets/image/default_1.png", - fadeSrc: "assets/image/default_1.png", - ), - SizedBox( - width: 10, - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - productListBeans[position].productName, - style: TextStyle( - color: Colors.black, - fontSize: 13.sp, - fontWeight: MyFontWeight.medium, - ), - ), - SizedBox( - height: 2, - ), - Row( - children: [ - Expanded( - child: Text( - productListBeans[position].shortName, - overflow: TextOverflow.ellipsis, - maxLines: 2, - style: TextStyle( - color: Color(0xFF4C4C4C), - fontSize: 10.sp, - fontWeight: MyFontWeight.regular, - ), - ), - ), - SizedBox( - width: 10, - ), - ], - ), - SizedBox( - height: 7, - ), - Row( - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Text( - S.of(context).huiyuanjia, - style: TextStyle( - color: Color(0xFFFF7A1A), - fontSize: 10.sp, - fontWeight: MyFontWeight.medium, - ), - ), - SizedBox( - width: 4, - ), - Text( - "¥${productListBeans[position].price}", - style: TextStyle( - color: Color(0xFFFF7A1A), - fontSize: 11.sp, - fontWeight: MyFontWeight.medium, - ), - ), - ], - ), - Row( - children: [ - Text( - S.of(context).yuanjia, - style: TextStyle( - color: Color(0xFFA29E9E), - fontSize: 9.sp, - fontWeight: MyFontWeight.regular, - ), - ), - SizedBox( - width: 4, - ), - Text( - "¥${productListBeans[position].applyPrice}", - style: TextStyle( - color: Color(0xFFA29E9E), - fontSize: 10.sp, - fontWeight: MyFontWeight.regular, - ), - ), - ], - ), - ], - ), - Spacer(), - productListBeans[position].attrStyle == 1 - ? GestureDetector( - onTap: () { - queryMiNiDetail(productListBeans[position].id); - }, - child: RoundButton( - width: 49.w, - text: S.of(context).xuanguige, - textColor: Colors.white, - fontWeight: MyFontWeight.medium, - radius: 11, - backgroup: Color(0xFF32A060), - fontSize: 11.sp, - padding: EdgeInsets.symmetric(vertical: 5.h), - ), - ) - : InkWell( - onTap: () { - setState(() { - { - if (productListBeans[position].buyNum > 0) - productListBeans[position].buyNum--; - int allCount = 0; - double allPrice = 0; - productListBeans.forEach((element) { - allCount += element.buyNum; - allPrice += double.parse(element.price) * - element.buyNum; - }); - widget.fc(allCount, allPrice); - } - }); - }, - child: Image.asset( - "assets/image/reduce.png", - width: 22, - height: 22, - ), - ), - if (productListBeans[position].attrStyle == 0) - Padding( - padding: EdgeInsets.only(left: 8, right: 8), - child: Text( - productListBeans[position].buyNum.toString(), - style: TextStyle( - color: Colors.black, - fontSize: 14.sp, - fontWeight: MyFontWeight.medium, - ), - ), - ), - if (productListBeans[position].attrStyle == 0) - InkWell( - onTap: () { - setState(() { - { - productListBeans[position].buyNum++; - int allCount = 0; - double allPrice = 0; - productListBeans.forEach((element) { - allCount += element.buyNum; - allPrice += double.parse(element.price) * - element.buyNum; - }); - widget.fc(allCount, allPrice); - } - }); - }, - child: Image.asset( - "assets/image/add.png", - width: 22, - height: 22, - ), - ), - ], - ), - ], - ), - ) - ], - ), + return ShopGoods( + productListBeans, + position, + widget.queryMiNiDetail, + widget.fc, ); } @@ -402,15 +171,4 @@ class _StoreOrderListPage extends State { return productListBeans; } - ///选规格弹窗 - showStoreSelector(MiNiDetail miNiDetail) { - showModalBottomSheet( - context: context, - backgroundColor: Colors.transparent, - builder: (context) { - return ProductSku(miNiDetail); - }, - ); - } - }