|
|
|
@ -1,10 +1,11 @@
|
|
|
|
|
import 'dart:convert'; |
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
|
import 'package:flutter_swiper/flutter_swiper.dart'; |
|
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/miNiDetail.dart' as MiNi; |
|
|
|
|
import 'package:huixiang/retrofit/data/shoppingCart.dart'; |
|
|
|
@ -17,6 +18,7 @@ import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
|
|
|
|
|
import '../../generated/l10n.dart'; |
|
|
|
|
import '../../view_widget/classic_header.dart'; |
|
|
|
|
import '../../view_widget/my_footer.dart'; |
|
|
|
|
|
|
|
|
@ -54,18 +56,7 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
tableId = widget.arguments["tableId"]; |
|
|
|
|
id = widget.arguments["id"]; |
|
|
|
|
storeId = widget.arguments["storeId"]; |
|
|
|
|
SharedPreferences.getInstance().then((value) { |
|
|
|
|
String minToken = value.getString("minToken"); |
|
|
|
|
String tenant = value.getString("tenant"); |
|
|
|
|
String storeId = value.getString("storeId"); |
|
|
|
|
minService = MinApiService(Dio(), |
|
|
|
|
context: context, |
|
|
|
|
token: minToken, |
|
|
|
|
tenant: tenant, |
|
|
|
|
storeId: storeId, |
|
|
|
|
showLoading: true); |
|
|
|
|
queryMiNiDetail(id); |
|
|
|
|
}); |
|
|
|
|
_onRefresh(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///商品详情 |
|
|
|
@ -78,6 +69,11 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
setState(() { |
|
|
|
|
miNiDetail = baseData.data; |
|
|
|
|
productSetMeals = miNiDetail.productSkuVOList[0].productSetMeals; |
|
|
|
|
SharedPreferences.getInstance().then( |
|
|
|
|
(value) => { |
|
|
|
|
value.setString('miNiDetail${id}', jsonEncode(baseData.data)), |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
refreshController.refreshCompleted(); |
|
|
|
|
} else { |
|
|
|
@ -85,7 +81,21 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_onRefresh() { |
|
|
|
|
_onRefresh() async{ |
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
|
String minToken = value.getString("minToken"); |
|
|
|
|
String tenant = value.getString("tenant"); |
|
|
|
|
String storeId = value.getString("storeId"); |
|
|
|
|
minService = MinApiService(Dio(), |
|
|
|
|
context: context, |
|
|
|
|
token: minToken, |
|
|
|
|
tenant: tenant, |
|
|
|
|
storeId: storeId, |
|
|
|
|
showLoading: true); |
|
|
|
|
if (value.getString("miNiDetail${id}") != null) { |
|
|
|
|
miNiDetail = MiNi.MiNiDetail.fromJson(jsonDecode(value.getString('miNiDetail${id}'))); |
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
queryMiNiDetail(id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -168,7 +178,7 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
swiper(), |
|
|
|
|
Padding(padding:EdgeInsets.only(left:14.w,top:10.h,bottom:18.h), |
|
|
|
|
Padding(padding:EdgeInsets.only(left:14.w,top:10.h,bottom:6.h), |
|
|
|
|
child:Text( |
|
|
|
|
miNiDetail?.productName ?? "", |
|
|
|
|
style: TextStyle( |
|
|
|
@ -466,25 +476,28 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
|
|
|
|
|
Widget productMealsList(MiNi.ProductSetMeals productSetMeals) { |
|
|
|
|
return Container( |
|
|
|
|
padding:EdgeInsets.symmetric(horizontal:14.w), |
|
|
|
|
// padding:EdgeInsets.symmetric(horizontal:14.w), |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
Padding(padding:EdgeInsets.only(top: 12.h,left:14.w,right:14.w), |
|
|
|
|
child:Text( |
|
|
|
|
"${productSetMeals.groupName}(${productSetMeals.totalNumber}选${productSetMeals.optionalNumber})", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
color: Colors.black, |
|
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
),), |
|
|
|
|
SizedBox( |
|
|
|
|
height: 8.h, |
|
|
|
|
), |
|
|
|
|
///商品选择 |
|
|
|
|
Container( |
|
|
|
|
height: 205.h, |
|
|
|
|
margin:EdgeInsets.only(bottom:18.h), |
|
|
|
|
margin:EdgeInsets.only(bottom:4.h), |
|
|
|
|
padding:EdgeInsets.symmetric(horizontal:14.w), |
|
|
|
|
child: ListView.builder( |
|
|
|
|
itemCount: productSetMeals?.productInfoList?.length??0, |
|
|
|
|
scrollDirection: Axis.horizontal, |
|
|
|
@ -503,24 +516,183 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
// if (productSetMeals |
|
|
|
|
// .productInfoList[productSetMeals.checkIndex] |
|
|
|
|
// .productAttrInfoList[0] |
|
|
|
|
// .attrName != |
|
|
|
|
// "") |
|
|
|
|
ListView.builder( |
|
|
|
|
///商品规格选择 |
|
|
|
|
if (productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.productAttrInfoList[0] |
|
|
|
|
.attrName != |
|
|
|
|
"") |
|
|
|
|
Container( |
|
|
|
|
padding:EdgeInsets.symmetric(horizontal:14.w), |
|
|
|
|
child: ListView.builder( |
|
|
|
|
itemCount: productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.productAttrInfoList |
|
|
|
|
.length, |
|
|
|
|
scrollDirection: Axis.vertical, |
|
|
|
|
shrinkWrap: true, |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
|
padding: EdgeInsets.zero, |
|
|
|
|
itemBuilder: (context, pos) { |
|
|
|
|
return porAttrItem(productSetMeals |
|
|
|
|
return |
|
|
|
|
porAttrItem(productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.productAttrInfoList[pos]); |
|
|
|
|
}, |
|
|
|
|
)), |
|
|
|
|
///规格数量增加按钮 |
|
|
|
|
Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end, |
|
|
|
|
children: [ |
|
|
|
|
GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
if (productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count >= |
|
|
|
|
1) |
|
|
|
|
productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count -= 1; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
padding:EdgeInsets.only(left:8.w,right:14.w,bottom:14.h), |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/reduce.webp", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22.h, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Container( |
|
|
|
|
padding:EdgeInsets.only(bottom:14.h), |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
child: Text( |
|
|
|
|
(productSetMeals.totalNumber > 1 && |
|
|
|
|
productSetMeals.totalNumber != |
|
|
|
|
productSetMeals.optionalNumber) |
|
|
|
|
? productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count |
|
|
|
|
.toString() |
|
|
|
|
: (productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count = 1) |
|
|
|
|
.toString(), |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Colors.black, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
int total = 0; |
|
|
|
|
if(productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.productAttrInfoList[0] |
|
|
|
|
.attrName != |
|
|
|
|
""){ |
|
|
|
|
productSetMeals |
|
|
|
|
.productInfoList |
|
|
|
|
.forEach((element) { |
|
|
|
|
total += element.count; |
|
|
|
|
}); |
|
|
|
|
if (productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.productAttrInfoList |
|
|
|
|
.where((element) => element.selectSku == null) |
|
|
|
|
.isNotEmpty) { |
|
|
|
|
SmartDialog.showToast(S.of(context).qingxianxuanguige, |
|
|
|
|
alignment: Alignment.center); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (total >= productSetMeals.optionalNumber && |
|
|
|
|
productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count != |
|
|
|
|
1) { |
|
|
|
|
SmartDialog.showToast("抱歉,无法加购更多", |
|
|
|
|
alignment: Alignment.center); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
productSetMeals.productInfoList[productSetMeals.checkIndex].count = |
|
|
|
|
1; |
|
|
|
|
productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.skuInfoList |
|
|
|
|
.forEach((element) { |
|
|
|
|
bool flag = true; |
|
|
|
|
productSetMeals |
|
|
|
|
.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.productAttrInfoList |
|
|
|
|
.forEach((e1) { |
|
|
|
|
if (!element.skuName.contains(e1.selectSku)) |
|
|
|
|
flag = false; |
|
|
|
|
}); |
|
|
|
|
element.isSelected = flag; |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
}else{ |
|
|
|
|
productSetMeals.productInfoList |
|
|
|
|
.forEach((element) { |
|
|
|
|
total += element.count; |
|
|
|
|
}); |
|
|
|
|
if (total >= |
|
|
|
|
productSetMeals.optionalNumber || |
|
|
|
|
productSetMeals.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count >= |
|
|
|
|
1) { |
|
|
|
|
SmartDialog.showToast("抱歉,无法加购更多", |
|
|
|
|
alignment: Alignment.center); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (productSetMeals.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count == |
|
|
|
|
0) |
|
|
|
|
productSetMeals.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
.count += 1; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// setState(() { |
|
|
|
|
// int total = 0; |
|
|
|
|
// productSetMeals.productInfoList |
|
|
|
|
// .forEach((element) { |
|
|
|
|
// total += element.count; |
|
|
|
|
// }); |
|
|
|
|
// if (total >= |
|
|
|
|
// productSetMeals.optionalNumber || |
|
|
|
|
// productSetMeals.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
// .count >= |
|
|
|
|
// 1) { |
|
|
|
|
// SmartDialog.showToast("抱歉,无法加购更多", |
|
|
|
|
// alignment: Alignment.center); |
|
|
|
|
// return; |
|
|
|
|
// } |
|
|
|
|
// if (productSetMeals.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
// .count == |
|
|
|
|
// 0) |
|
|
|
|
// productSetMeals.productInfoList[productSetMeals.checkIndex] |
|
|
|
|
// .count += 1; |
|
|
|
|
// }); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
padding:EdgeInsets.only(left:8.w,right:14.w,bottom:14.h), |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/add.webp", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22.h, |
|
|
|
|
),), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
Container( |
|
|
|
|
color: Color(0xFFF9FAF7), |
|
|
|
|
height: 12.h, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
)); |
|
|
|
@ -562,6 +734,8 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
Padding(padding:EdgeInsets.only(left:8.w,right:8.w,top:8.h,bottom: 6.h), |
|
|
|
|
child:Text( |
|
|
|
|
productInfoList.productName ?? "", |
|
|
|
|
maxLines: 1, |
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
color: Colors.black, |
|
|
|
@ -616,6 +790,11 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget porAttrItem(MiNi.ProductAttrInfoList productAttrInfoList) { |
|
|
|
|
if (productAttrInfoList.attrValueList != null && productAttrInfoList.attrValueList.length > 0) |
|
|
|
|
// 默认选中第一个值 |
|
|
|
|
if (productAttrInfoList.selectSku == null) { |
|
|
|
|
productAttrInfoList.selectSku = productAttrInfoList.attrValueList.first.attrName; |
|
|
|
|
} |
|
|
|
|
if (productAttrInfoList.attrValueList != |
|
|
|
|
null && productAttrInfoList.attrValueList |
|
|
|
|
.length > |
|
|
|
@ -624,12 +803,12 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(top: 16, bottom: 16), |
|
|
|
|
padding: EdgeInsets.only(bottom:16.h,top: 14.h), |
|
|
|
|
child: Text( |
|
|
|
|
productAttrInfoList.attrName, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFB3B3B3), |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
color: Color(0xFF191919), |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
@ -646,8 +825,7 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
return GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
setState(() { |
|
|
|
|
productAttrInfoList |
|
|
|
|
.selectSku = tag.attrName; |
|
|
|
|
productAttrInfoList.selectSku = tag.attrName; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: sweetnessItem( |
|
|
|
@ -664,40 +842,6 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget sweetnessStore(int position, int index, int pos, state) { |
|
|
|
|
return Wrap( |
|
|
|
|
runSpacing: 10.0, |
|
|
|
|
spacing: 10.0, |
|
|
|
|
children: productSetMeals[position] |
|
|
|
|
.productInfoList[index] |
|
|
|
|
.productAttrInfoList[pos] |
|
|
|
|
.attrValueList |
|
|
|
|
.take(productSetMeals[position] |
|
|
|
|
.productInfoList[index] |
|
|
|
|
.productAttrInfoList[pos] |
|
|
|
|
.attrValueList |
|
|
|
|
.length) |
|
|
|
|
.map<Widget>((MiNi.AttrValueList tag) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
state(() { |
|
|
|
|
productSetMeals[position] |
|
|
|
|
.productInfoList[index] |
|
|
|
|
.productAttrInfoList[pos] |
|
|
|
|
.selectSku = tag.attrName; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: sweetnessItem( |
|
|
|
|
tag.attrName, |
|
|
|
|
(productSetMeals[position] |
|
|
|
|
.productInfoList[index] |
|
|
|
|
.productAttrInfoList[pos] |
|
|
|
|
.selectSku == |
|
|
|
|
tag.attrName), |
|
|
|
|
)); |
|
|
|
|
}).toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Widget sweetnessItem(String name, bool isCheck) { |
|
|
|
|
return Container( |
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 12.0), |
|
|
|
@ -717,12 +861,13 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: !isCheck ? Color(0xFF4D4D4D) : Color(0xFF32A060), |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontSize: 13.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
), |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
// |
|
|
|
|
|
|
|
|
|
//原ui,流程 |
|
|
|
|
// Widget productMealsItems(int position, int index) { |
|
|
|
|
// return Container( |
|
|
|
|
// margin: EdgeInsets.symmetric(vertical: 16.h), |
|
|
|
@ -984,7 +1129,7 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// ), |
|
|
|
|
// sweetnessStore(position, index, pos, state), |
|
|
|
|
// sweetnessStores(position, index, pos, state), |
|
|
|
|
// ], |
|
|
|
|
// ); |
|
|
|
|
// else { |
|
|
|
@ -1050,8 +1195,8 @@ class _ProductMealsSku extends State<ProductMealsSku> {
|
|
|
|
|
// ), |
|
|
|
|
// )); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
///选择規格弹窗 |
|
|
|
|
// |
|
|
|
|
// ///选择規格弹窗 |
|
|
|
|
// showSkuDialog(int position, int index) async { |
|
|
|
|
// showDialog( |
|
|
|
|
// context: context, |
|
|
|
|