|
|
|
@ -9,6 +9,8 @@ import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
|
import 'package:huixiang/view_widget/custom_image.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
|
|
|
|
|
|
|
|
import '../../view_widget/settlement_tips_dialog.dart'; |
|
|
|
|
|
|
|
|
|
class ProductSku extends StatefulWidget { |
|
|
|
|
final MiNiDetail miNiDetail; |
|
|
|
|
final String productId; |
|
|
|
@ -31,43 +33,56 @@ class ProductSku extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
class _ProductSku extends State<ProductSku> { |
|
|
|
|
List<String> selectSkus = []; |
|
|
|
|
int count = 1, realCount = 0; |
|
|
|
|
String selectedPrice = ""; |
|
|
|
|
bool _isTapEd = false; |
|
|
|
|
int _currentSkuIndex; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
|
super.initState(); |
|
|
|
|
if (widget.shopCarGoods != null && widget.shopCarGoods.shoppingCartSkuItemList != null) { |
|
|
|
|
widget.shopCarGoods.shoppingCartSkuItemList.forEach((e1) { |
|
|
|
|
if (widget.miNiDetail != null && widget.miNiDetail.productSkuVOList != null && widget.miNiDetail.productSkuVOList.isNotEmpty) { |
|
|
|
|
try { |
|
|
|
|
widget.miNiDetail.productSkuVOList.firstWhere((e2) => e1.id == e2.id).count = e1.buyNum; |
|
|
|
|
} catch (e) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
widget.miNiDetail.attrList.forEach((element) { |
|
|
|
|
selectSkus.add(element.attrValueList[0].attrValue); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
buildCount(); |
|
|
|
|
_currentSkuIndex = widget.miNiDetail.productSkuVOList.indexWhere((element) { |
|
|
|
|
return skuY(element, selectSkus); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
buildCount() { |
|
|
|
|
count = 1; |
|
|
|
|
ProductSkuVOListBean productSku; |
|
|
|
|
try { |
|
|
|
|
productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) { |
|
|
|
|
return skuY(element, selectSkus); |
|
|
|
|
}); |
|
|
|
|
} catch (ex) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (productSku == null) return; |
|
|
|
|
selectedPrice = productSku.vipPrice ?? productSku.skuPrice ?? ""; |
|
|
|
|
String skuId = productSku.id; |
|
|
|
|
if (widget.shopCarGoods == null || |
|
|
|
|
widget.shopCarGoods.shoppingCartSkuItemList == null) return; |
|
|
|
|
int shopSkuIndex = widget.shopCarGoods.shoppingCartSkuItemList |
|
|
|
|
.indexWhere((element) => skuId == element.id); |
|
|
|
|
if (shopSkuIndex >= 0) { |
|
|
|
|
count = widget.shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum; |
|
|
|
|
realCount = count; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// buildCount() { |
|
|
|
|
// count = 1; |
|
|
|
|
// ProductSkuVOListBean productSku; |
|
|
|
|
// try { |
|
|
|
|
// productSku = widget.miNiDetail.productSkuVOList.firstWhere((element) { |
|
|
|
|
// return skuY(element, selectSkus); |
|
|
|
|
// }); |
|
|
|
|
// } catch (ex) { |
|
|
|
|
// return; |
|
|
|
|
// } |
|
|
|
|
// if (productSku == null) return; |
|
|
|
|
// selectedPrice = productSku.vipPrice ?? productSku.skuPrice ?? ""; |
|
|
|
|
// String skuId = productSku.id; |
|
|
|
|
// widget.miNiDetail.productSkuVOList[_currentSkuIndex].minQty = productSku.minQty; |
|
|
|
|
// if (widget.shopCarGoods == null || |
|
|
|
|
// widget.shopCarGoods.shoppingCartSkuItemList == null) return; |
|
|
|
|
// int shopSkuIndex = widget.shopCarGoods.shoppingCartSkuItemList |
|
|
|
|
// .indexWhere((element) => skuId == element.id); |
|
|
|
|
// if (shopSkuIndex >= 0) { |
|
|
|
|
// count = widget.shopCarGoods.shoppingCartSkuItemList[shopSkuIndex].buyNum; |
|
|
|
|
// realCount = count; |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
bool skuY(ProductSkuVOListBean productSku, selectSkus) { |
|
|
|
|
bool gg = true; |
|
|
|
@ -140,11 +155,7 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(top: 4, bottom: 7), |
|
|
|
|
child: Text( |
|
|
|
|
"已选: " + |
|
|
|
|
(selectSkus |
|
|
|
|
.map((e) => "$e") |
|
|
|
|
.toList() |
|
|
|
|
.toString()), |
|
|
|
|
"已选: " + selectSkus.join(" "), |
|
|
|
|
maxLines: 1, |
|
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
|
style: TextStyle( |
|
|
|
@ -154,6 +165,7 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
|
|
|
|
|
///业务需求暂时隐藏 |
|
|
|
|
// Row( |
|
|
|
|
// children: [ |
|
|
|
@ -175,6 +187,34 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
// ), |
|
|
|
|
// ], |
|
|
|
|
// ), |
|
|
|
|
Row( |
|
|
|
|
children: [ |
|
|
|
|
if (widget.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex].minQty > |
|
|
|
|
1) |
|
|
|
|
Container( |
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 4.w), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
borderRadius: BorderRadius.circular(2), |
|
|
|
|
border: Border.all( |
|
|
|
|
width: 1, |
|
|
|
|
color: Color(0xFFF65720), |
|
|
|
|
style: BorderStyle.solid, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
alignment: Alignment.center, |
|
|
|
|
child: Text( |
|
|
|
|
"${widget.miNiDetail.productSkuVOList[_currentSkuIndex].minQty}份起购", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFFF65720), |
|
|
|
|
fontSize: 10.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Spacer() |
|
|
|
|
], |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
)), |
|
|
|
|
InkWell( |
|
|
|
@ -210,7 +250,11 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
(attrValue) { |
|
|
|
|
state(() { |
|
|
|
|
selectSkus[position] = attrValue; |
|
|
|
|
buildCount(); |
|
|
|
|
_currentSkuIndex = widget |
|
|
|
|
.miNiDetail.productSkuVOList |
|
|
|
|
.indexWhere((element) { |
|
|
|
|
return skuY(element, selectSkus); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
widget.miNiDetail.attrList[position], |
|
|
|
@ -237,71 +281,197 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () async { |
|
|
|
|
if (count == 1) return; |
|
|
|
|
if ((widget?.miNiDetail?.subscribeParam |
|
|
|
|
?.isEnableSubscribe ?? |
|
|
|
|
false) == |
|
|
|
|
false) { |
|
|
|
|
_isTapEd = true; |
|
|
|
|
EasyLoading.show(status: S.current.zhengzaijiazai,maskType: EasyLoadingMaskType.black); |
|
|
|
|
await widget.reduce(widget.miNiDetail, selectSkus); |
|
|
|
|
} |
|
|
|
|
count -= 1; |
|
|
|
|
setState(() {}); |
|
|
|
|
EasyLoading.dismiss(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/reduce.webp", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22, |
|
|
|
|
if (widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty > |
|
|
|
|
1 && |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count == |
|
|
|
|
1) |
|
|
|
|
GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap: () async { |
|
|
|
|
if ((widget?.miNiDetail?.subscribeParam |
|
|
|
|
?.isEnableSubscribe ?? |
|
|
|
|
false) == |
|
|
|
|
false) { |
|
|
|
|
_isTapEd = true; |
|
|
|
|
EasyLoading.show( |
|
|
|
|
status: S.current.zhengzaijiazai, |
|
|
|
|
maskType: EasyLoadingMaskType.black); |
|
|
|
|
if (widget |
|
|
|
|
.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count == |
|
|
|
|
1) |
|
|
|
|
await widget.addShopCar( |
|
|
|
|
widget.miNiDetail, |
|
|
|
|
selectSkus, |
|
|
|
|
widget.miNiDetail.productSkuVOList[ _currentSkuIndex].minQty > 1 |
|
|
|
|
? widget |
|
|
|
|
.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty |
|
|
|
|
: 2); |
|
|
|
|
else |
|
|
|
|
await widget.add(widget.miNiDetail, selectSkus); |
|
|
|
|
} |
|
|
|
|
if ((widget?.miNiDetail?.oversold ?? 0) == 0 && |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] .count >= |
|
|
|
|
(widget?.miNiDetail?.productSkuVOList[0]?.skuStock ?? 0)) { |
|
|
|
|
SmartDialog.showToast("库存不足", |
|
|
|
|
alignment: Alignment.center); |
|
|
|
|
} else { |
|
|
|
|
if (widget.miNiDetail.productSkuVOList[_currentSkuIndex].minQty > 1) { |
|
|
|
|
widget |
|
|
|
|
.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count += widget |
|
|
|
|
.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty - 1; |
|
|
|
|
} else { |
|
|
|
|
widget |
|
|
|
|
.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count += 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
setState(() {}); |
|
|
|
|
EasyLoading.dismiss(); |
|
|
|
|
}, |
|
|
|
|
child: Container( |
|
|
|
|
margin: EdgeInsets.only(right: 8.w, top: 4.h), |
|
|
|
|
child: RoundButton( |
|
|
|
|
text: |
|
|
|
|
"${widget.miNiDetail.productSkuVOList[_currentSkuIndex].minQty}份起购", |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
radius: 3, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
|
fontSize: 11.sp, |
|
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
|
vertical: 5.h, horizontal: 3.w), |
|
|
|
|
), |
|
|
|
|
)), |
|
|
|
|
if ((widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty > |
|
|
|
|
1 && |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count != |
|
|
|
|
1) || |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty == |
|
|
|
|
0 || |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty == |
|
|
|
|
1) |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () async { |
|
|
|
|
if (widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count == |
|
|
|
|
1) return; |
|
|
|
|
if ((widget?.miNiDetail?.subscribeParam |
|
|
|
|
?.isEnableSubscribe ?? |
|
|
|
|
false) == |
|
|
|
|
false) { |
|
|
|
|
_isTapEd = true; |
|
|
|
|
EasyLoading.show( |
|
|
|
|
status: S.current.zhengzaijiazai, |
|
|
|
|
maskType: EasyLoadingMaskType.black); |
|
|
|
|
await widget.reduce(widget.miNiDetail, selectSkus); |
|
|
|
|
} |
|
|
|
|
if (widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty == |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count) { |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count -= (widget.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex].minQty); |
|
|
|
|
} else { |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count -= 1; |
|
|
|
|
} |
|
|
|
|
setState(() {}); |
|
|
|
|
EasyLoading.dismiss(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/reduce.webp", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 8, right: 8), |
|
|
|
|
child: Text( |
|
|
|
|
"$count", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Colors.black, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
if ((widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty > |
|
|
|
|
1 && |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count != |
|
|
|
|
1) || |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty == |
|
|
|
|
0 || |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty == |
|
|
|
|
1) |
|
|
|
|
Padding( |
|
|
|
|
padding: EdgeInsets.only(left: 8, right: 8), |
|
|
|
|
child: Text( |
|
|
|
|
"${widget.miNiDetail.productSkuVOList[_currentSkuIndex].count}", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Colors.black, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () async { |
|
|
|
|
if ((widget?.miNiDetail?.subscribeParam |
|
|
|
|
?.isEnableSubscribe ?? |
|
|
|
|
false) == |
|
|
|
|
false) { |
|
|
|
|
_isTapEd = true; |
|
|
|
|
EasyLoading.show(status: S.current.zhengzaijiazai,maskType: EasyLoadingMaskType.black); |
|
|
|
|
if (count == 1 && realCount == 0) |
|
|
|
|
await widget.addShopCar( |
|
|
|
|
widget.miNiDetail, selectSkus, 2); |
|
|
|
|
else |
|
|
|
|
await widget.add(widget.miNiDetail, selectSkus); |
|
|
|
|
} |
|
|
|
|
if ((widget?.miNiDetail?.oversold ?? 0) == 0 && |
|
|
|
|
count >= |
|
|
|
|
(widget?.miNiDetail?.productSkuVOList[0] |
|
|
|
|
?.skuStock ?? |
|
|
|
|
0)) { |
|
|
|
|
SmartDialog.showToast("库存不足", |
|
|
|
|
alignment: Alignment.center); |
|
|
|
|
} else { |
|
|
|
|
count += 1; |
|
|
|
|
} |
|
|
|
|
setState(() {}); |
|
|
|
|
EasyLoading.dismiss(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/add.webp", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22, |
|
|
|
|
if ((widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty > |
|
|
|
|
1 && |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count != |
|
|
|
|
1) || |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty == |
|
|
|
|
0 || |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.minQty == |
|
|
|
|
1) |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () async { |
|
|
|
|
if ((widget?.miNiDetail?.subscribeParam |
|
|
|
|
?.isEnableSubscribe ?? |
|
|
|
|
false) == |
|
|
|
|
false) { |
|
|
|
|
_isTapEd = true; |
|
|
|
|
EasyLoading.show( |
|
|
|
|
status: S.current.zhengzaijiazai, |
|
|
|
|
maskType: EasyLoadingMaskType.black); |
|
|
|
|
if (widget.miNiDetail.productSkuVOList[_currentSkuIndex].count == 1) |
|
|
|
|
await widget.addShopCar( |
|
|
|
|
widget.miNiDetail, selectSkus,2); |
|
|
|
|
else |
|
|
|
|
await widget.add(widget.miNiDetail, selectSkus); |
|
|
|
|
} |
|
|
|
|
if ((widget?.miNiDetail?.oversold ?? 0) == 0 && |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count >= |
|
|
|
|
(widget?.miNiDetail?.productSkuVOList[0] |
|
|
|
|
?.skuStock ?? |
|
|
|
|
0)) { |
|
|
|
|
SmartDialog.showToast("库存不足", |
|
|
|
|
alignment: Alignment.center); |
|
|
|
|
} else { |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count += 1; |
|
|
|
|
} |
|
|
|
|
setState(() {}); |
|
|
|
|
EasyLoading.dismiss(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/add.webp", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
SizedBox( |
|
|
|
@ -320,9 +490,19 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.semi_bold, |
|
|
|
|
radius: 27, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
|
backgroup:Color(0xFF32A060), |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
callback: () { |
|
|
|
|
if(widget.miNiDetail.productSkuVOList[_currentSkuIndex].minQty > 1 && widget.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex].count ==1){ |
|
|
|
|
SmartDialog.show( |
|
|
|
|
widget: SettlementTips( |
|
|
|
|
() {}, |
|
|
|
|
text: "请选择购买数量", |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
// SmartDialog.dismiss(); |
|
|
|
|
if (!_isTapEd) |
|
|
|
@ -334,7 +514,8 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
false) == |
|
|
|
|
false) |
|
|
|
|
? 1 |
|
|
|
|
: count); |
|
|
|
|
: widget.miNiDetail |
|
|
|
|
.productSkuVOList[_currentSkuIndex].count); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
if (widget.buttonType == 1) |
|
|
|
@ -350,7 +531,11 @@ class _ProductSku extends State<ProductSku> {
|
|
|
|
|
callback: () { |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
// SmartDialog.dismiss(); |
|
|
|
|
widget.addShopCar(widget.miNiDetail, selectSkus, count); |
|
|
|
|
widget.addShopCar( |
|
|
|
|
widget.miNiDetail, |
|
|
|
|
selectSkus, |
|
|
|
|
widget.miNiDetail.productSkuVOList[_currentSkuIndex] |
|
|
|
|
.count); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
|
|
|
|
|