You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1066 lines
35 KiB

3 years ago
import 'dart:convert';
import 'dart:math' as mm;
3 years ago
3 years ago
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
3 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:get/get.dart';
import 'package:huixiang/constant.dart';
import 'package:huixiang/data/activity.dart';
import 'package:huixiang/data/base_data.dart';
import 'package:huixiang/data/base_list_data.dart';
import 'package:huixiang/data/member_vo.dart';
import 'package:huixiang/data/mini_detail.dart';
import 'package:huixiang/data/shopping_cart.dart';
import 'package:huixiang/data/store_info.dart';
import 'package:huixiang/generated/l10n.dart';
3 years ago
import 'package:huixiang/retrofit/min_api.dart';
3 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/store/shop/shop_scroll_controller.dart';
import 'package:huixiang/store/shop/shop_scroll_coordinator.dart';
3 years ago
import 'package:huixiang/store/store_view/people_num.dart';
3 years ago
import 'package:huixiang/store/store_view/product_sku.dart';
3 years ago
import 'package:huixiang/store/store_view/shop_car.dart';
3 years ago
import 'package:huixiang/store/store_view/store_info.dart';
3 years ago
import 'package:huixiang/store/store_view/store_order_list.dart';
import 'package:huixiang/utils/constant.dart';
import 'package:huixiang/utils/flutter_utils.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/utils/shared_preference.dart';
3 years ago
import 'package:huixiang/view_widget/custom_image.dart';
3 years ago
import 'package:huixiang/view_widget/receive_success.dart';
3 years ago
import 'package:huixiang/view_widget/round_button.dart';
import 'package:intl/intl.dart';
3 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
3 years ago
class StoreOrderPage extends StatefulWidget {
final Map<String, dynamic>? arguments;
3 years ago
3 years ago
StoreOrderPage({this.arguments});
3 years ago
@override
State<StatefulWidget> createState() {
return _StoreOrderPage();
}
}
3 years ago
class _StoreOrderPage extends State<StoreOrderPage>
3 years ago
with TickerProviderStateMixin {
TabController? tabcontroller;
ApiService? apiService;
MinApiService? minService;
StoreInfo? storeInfo;
List<Activity>? activitys;
StoreOrderListPage? storeOrderListPage;
ScrollPhysics scrollPhysics = NeverScrollableScrollPhysics();
3 years ago
ShoppingCart? shopCarGoods;
3 years ago
int tableId = 0;
3 years ago
String parentId = "";
String parentCode = "";
3 years ago
String tenant = "";
String storeId = "";
int numberOfPeople = 0;
String? vipLevelName;
MemberVo? memberVo;
MiniDetail? miniDetail;
3 years ago
3 years ago
///小程序token
String? minToken;
String? pName;
String? pid;
String? cName;
String? cid;
3 years ago
@override
void initState() {
super.initState();
_shopCoordinator = ShopScrollCoordinator();
3 years ago
tableId = widget.arguments?["tableId"] ?? 0;
tenant = widget.arguments?["tenant"];
storeId = widget.arguments?["id"];
3 years ago
tabcontroller = TabController(length: 1, vsync: this);
_pageScrollController = _shopCoordinator.pageScrollController(0);
apiService = ApiService(
Dio(),
context: context,
token: SharedInstance.instance.token,
);
minLogin();
3 years ago
}
3 years ago
/// 小程序登录
minLogin() async {
S.current.zhengzaijiazai.loading;
minToken = widget.arguments?["miniToken"];
await queryStoreInfo();
SharedInstance.instance.saveMini(minToken, tenant, storeId);
minService = MinApiService(
3 years ago
Dio(),
context: context,
token: minToken ?? "",
tenant: tenant,
storeId: storeId,
3 years ago
);
3 years ago
queryMemberInfo();
3 years ago
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
3 years ago
});
if (tableId > 0) {
getParentInfo();
}
3 years ago
}
///会员信息
3 years ago
queryMemberInfo() async {
BaseData? baseData = await minService?.memberInfo().catchError((error) {
debugPrint("${error}");
return BaseData()..isSuccess = false;
3 years ago
});
if (baseData?.isSuccess ?? false) {
SharedInstance.instance.saveMiniMember(jsonEncode(baseData!.data));
memberVo = MemberVo.fromJson(baseData.data);
3 years ago
}
}
3 years ago
///获取父订单(火锅订单加菜前调用)
getParentInfo() async {
BaseData? baseData =
await minService?.getParentInfo("$tableId").catchError((error) {
debugPrint("${error}");
return BaseData()..isSuccess = false;
3 years ago
});
if (baseData?.isSuccess ?? false) {
if (baseData?.data != null) {
parentId = baseData!.data["id"];
3 years ago
parentCode = baseData.data["parentCode"];
} else {
queryStoreInfo1();
}
}
3 years ago
}
///获取桌子信息
queryStoreInfo1() async {
BaseData<StoreInfo>? baseData = await minService?.queryStoreInfo1({
3 years ago
"getCoupon": true,
"storeId": storeId,
"tableId": tableId,
}).catchError((error) {
debugPrint("${error}");
return BaseData<StoreInfo>()..isSuccess = false;
3 years ago
});
if ((baseData?.isSuccess ?? false) && baseData?.data != null) {
StoreInfo storeInfo = baseData!.data!;
showPeopleNum(storeInfo.storeTable?.tableName);
3 years ago
}
}
3 years ago
/// 查询店铺信息
3 years ago
queryStoreInfo() async {
BaseData<StoreInfo>? baseData =
await apiService?.queryStoreInfo(storeId).catchError((error) {
debugPrint("${error}");
return BaseData<StoreInfo>()..isSuccess = false;
3 years ago
});
if ((baseData?.isSuccess ?? false) && baseData?.data != null) {
storeInfo = baseData!.data;
activitys = storeInfo?.informationVOPageVO?.list
?.map((e) => Activity.fromJson(e))
3 years ago
.toList();
3 years ago
if (mounted) {
setState(() {});
}
}
}
RefreshController? refreshController;
3 years ago
bool dialogShowing = false;
3 years ago
final ScrollController controller1 = ScrollController();
final ScrollController controller2 = ScrollController();
late ShopScrollCoordinator _shopCoordinator;
ShopScrollController? _pageScrollController;
3 years ago
@override
Widget build(BuildContext context) {
return PopScope(
onPopInvoked: (isPop) {
if (dialogShowing) {
SmartDialog.dismiss();
}
},
canPop: true,
child: Container(
color: Colors.white,
child: Stack(
children: [
Positioned(
left: 0,
right: 0,
top: 0,
bottom: 54.h,
child: Listener(
onPointerUp: _shopCoordinator.onPointerUp,
child: CustomScrollView(
controller: _pageScrollController,
physics: ClampingScrollPhysics(),
slivers: [
SliverAppBar(
expandedHeight: 360.h,
pinned: true,
collapsedHeight: kToolbarHeight,
systemOverlayStyle: SystemUiOverlayStyle.dark,
surfaceTintColor: Colors.white,
backgroundColor: Colors.white,
flexibleSpace: FlexibleSpaceBar(
title: Title(
_pageScrollController!,
storeInfo?.storeName ?? '',
),
centerTitle: false,
titlePadding: EdgeInsets.symmetric(
vertical: 10,
),
background: Container(
child: Stack(
children: [
Positioned.fill(
child: Column(
children: [
buildSwiper(),
Spacer(),
],
),
),
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
height: kToolbarHeight,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.white.withAlpha(60),
Colors.white.withAlpha(30),
Colors.transparent,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
),
Positioned(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.vertical(
top: Radius.circular(18),
),
),
child: StoreInfoView(
storeInfo,
widget.arguments?["distance"],
),
),
top: 300,
left: 0,
right: 0,
),
Positioned(
top: 40,
left: 10,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pop();
},
child: Container(
padding: EdgeInsets.all(10.h),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
)
],
),
),
),
centerTitle: false,
leadingWidth: 0,
automaticallyImplyLeading: false,
),
SliverPersistentHeader(
pinned: true,
floating: false,
delegate: _SliverAppBarDelegate(
maxHeight: 50,
minHeight: 50,
child: Container(
width: Get.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
),
child: Row(
children: [
20.vd,
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
// Color(0xFF32A060),
S.of(context).diandan,
style: TextStyle(
color: Colors.black,
fontSize: 18.sp,
fontWeight: FontWeight.bold,
2 years ago
),
),
5.d,
Container(
width: 20,
height: 3,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: Color(0xFF32A060),
),
),
10.d,
],
),
Spacer(),
],
),
),
),
),
SliverFillRemaining(
child: StoreOrderListPage(
widget.arguments,
activitys,
storeInfo,
shopCarGoods,
_shopCoordinator,
minToken,
tenant,
tableId,
_queryMiNiDetail,
() {
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
},
scrollPhysics,
),
),
],
// pinnedHeaderSliverHeightBuilder: () {
// final double statusBarHeight = MediaQuery.of(context).padding.top;
// return statusBarHeight + kToolbarHeight + 38;
// },
// body: StoreOrderListPage(
// widget.arguments,
// activitys,
// storeInfo,
// shopCarGoods,
// controller1,
// controller2,
// nestedScrollViewKey,
// minToken,
// tenant,
// tableId,
// _queryMiNiDetail,
// () {
// queryShopCar().then((value) {
// this.shopCarGoods = value;
// setState(() {});
// });
// },
// scrollPhysics,
// ),
),
),
),
Positioned(
bottom: 30,
left: 0,
right: 0,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 14),
height: 45.h,
// color: Color(0xFFFAFAFA),
decoration: BoxDecoration(
color: Color(0xFF383A38),
borderRadius: BorderRadius.circular(100),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 70,
child: InkWell(
onTap: () {
if (count() != 0) showShoppingCart();
},
child: Stack(
alignment: Alignment.bottomLeft,
children: [
Positioned(
left: 5.h,
top: 5.h,
bottom: 5.h,
child:Image.asset(
"assets/image/shopping_bag.png",
width: 35.h,
height: 35.h,
fit: BoxFit.fitWidth,
),
2 years ago
),
if (count() != 0)
Positioned(
right: 5,
top: 5,
child: RoundButton(
width: 17.w,
height: 17.h,
text: "${count()}",
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFF65720),
fontSize: 12.sp,
radius: 100,
),
),
],
),
),
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: "",
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFFFFFFFF),
fontWeight: MyFontWeight.bold,
),
),
TextSpan(
text: "${shopCarGoods?.cartSum ?? 0}",
style: TextStyle(
fontSize: 20.sp,
fontFamily: 'JDZhengHT',
color: Color(0xFFFFFFFF),
fontWeight: MyFontWeight.medium,
3 years ago
),
3 years ago
),
],
),
2 years ago
),
Spacer(),
GestureDetector(
onTap: () {
if (AppUtils.compareTime(
storeInfo?.openStartTime,
DateFormat('HH:mm:ss')
.format(DateTime.now())) &&
(!AppUtils.compareTime(
storeInfo?.openEndTime,
DateFormat('HH:mm:ss')
.format(DateTime.now())))) {
toDownOrder();
} else
SmartDialog.showToast(
"营业时间:${storeInfo?.openStartTime}-${storeInfo?.openEndTime}",
alignment: Alignment.center);
},
child: RoundButton(
width: 103.w,
height: 54.h,
text: S.current.jiesuan,
textColor: Colors.white,
fontWeight: MyFontWeight.bold,
backgroup: Color(0xFF32A060),
radius: 100,
fontSize: 16.sp,
padding: EdgeInsets.symmetric(vertical: 5.h),
),
),
],
),
),
),
],
),
),
);
3 years ago
}
3 years ago
///领取优惠券
_receiveCoupon(couponId) async {
BaseData? baseData = await apiService?.receiveCoupon(couponId);
if (baseData?.isSuccess ?? false) {
3 years ago
queryStoreInfo();
showAlertDialog();
}
}
/// 领取成功弹窗
showAlertDialog() {
//显示对话框
showDialog(
context: context,
builder: (BuildContext context) {
return ReceiveSuccess();
},
);
}
3 years ago
///显示选择人数的弹窗
showPeopleNum(String? tableName) async {
3 years ago
var people = await showDialog(
context: context,
3 years ago
barrierDismissible: false,
3 years ago
builder: (context) {
return PeopleNumView(tableName ?? "");
3 years ago
},
);
if (people != null && people > 0) {
setState(() {
this.numberOfPeople = people;
});
3 years ago
} else {
Navigator.of(context).pop();
3 years ago
}
}
3 years ago
///计算个数
int count() {
if (shopCarGoods?.shoppingCartSkuItemList?.isEmpty ?? true) return 0;
3 years ago
int count = 0;
shopCarGoods?.shoppingCartSkuItemList?.forEach((element) {
count += (element.buyNum ?? 0);
3 years ago
});
return count;
}
///去下单结算页面
3 years ago
toDownOrder() async {
3 years ago
int num = count();
if (parentId == "") {
3 years ago
if (num == 0) {
SmartDialog.showToast("请先选择您要购买的商品!~", alignment: Alignment.center);
3 years ago
return;
}
3 years ago
}
3 years ago
await Navigator.of(context).pushNamed(
3 years ago
'/router/settlement',
arguments: {
"storeInfo": storeInfo,
3 years ago
"tableId": tableId,
"parentCode": parentCode,
"parentId": parentId,
3 years ago
// "pName": pName,
"pid": pid,
3 years ago
// "cName": cName,
"cid": cid,
3 years ago
"shoppingCart": shopCarGoods,
3 years ago
"numberOfPeople": numberOfPeople,
"distance": widget.arguments?["distance"],
"vipLevelName": memberVo?.memberRankVo?.rankName ?? "",
1.动态详情,评论-已显示全部—修改; 2.新增加集换卡详情页面; 3.语言-增加部分文本语言并更改; 4.回乡VIP板块更改;原本的VIP卡逻辑暂时不用,换成用户充值200即成为会员,该页面ui调整;(原来逻辑未删减,暂保留不使用) 5.16进制渐变色值的方法,改变亮度暂定统一为95; 6.首页ui调整;邀请好友图片处,原单一图片现更改为轮播效果,新增集换卡引导也放在此处; 7.积分明细页面更改;共用一个页面根据积分跟集换卡的入口,传对应的值,查看对应的数据; 8.积分明细跳转路径更改,新增一个类型带入路径中跳转传入; 9.更改测试版本服务地址; 10.我的页面跟首页更改一致,单一图片改轮播效果; 11.会员中心,会员卡部分更改;将原有写法去掉,重写了会员卡的使用显示,并优化了该页面数据的显示; 12.我的页面,vip等级显示更改; 13.会员卡列表等级接口,实体类新增部分字段;(原定位分数已不用,更改为originScore,后期若用的原字段,需要修改) 14.订单结算页,支付类型更换时queryOrderInfo()接口中。优惠类型做了调整更改;(改修改需要多测试下,尝试多种情况看下,是否有问题;有可能部分情况没有预判到) 15.点单页结算跳转,vipLevelName,vipLevelName字段做了非空判断; 16.UserInfo实体类新增isVip字段;(主要用于查看用户数据是查询该用户是否已是vip卡状态) 17.福利兑换中心页面,我的信息部分ui做调整,新增集换卡数量的显示;
2 years ago
"isVips": memberVo?.isVip ?? false,
"subscribeParam": miniDetail?.subscribeParam,
3 years ago
},
);
if (miniDetail?.subscribeParam?.isEnableSubscribe ?? false) {
clearShopCar();
this.shopCarGoods = await queryShopCar();
}
if (tableId > 0) {
3 years ago
getParentInfo();
}
3 years ago
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
3 years ago
}
3 years ago
Widget buildSwiper() {
return Container(
width: double.infinity,
height: 240.h,
3 years ago
child: Swiper(
3 years ago
pagination: SwiperPagination(
alignment: Alignment.bottomCenter,
builder: DotSwiperPaginationBuilder(
size: 8.w,
activeSize: 8.w,
space: 5.w,
activeColor: Colors.white,
color: Colors.white.withAlpha(76),
3 years ago
),
margin: EdgeInsets.only(bottom: 13.h),
3 years ago
),
autoplay: storeInfo?.bannerList?.isNotEmpty ?? false,
duration: 1000,
autoplayDelay: 2000,
3 years ago
itemBuilder: (context, position) {
return Container(
child: MImage(
(position < (storeInfo?.bannerList?.length ?? 0))
? (storeInfo?.bannerList![position].imgUrl ?? "")
3 years ago
: "",
3 years ago
height: 230.h,
3 years ago
width: double.infinity,
3 years ago
fit: BoxFit.cover,
radius: BorderRadius.zero,
errorSrc: "assets/image/default_2_1.webp",
fadeSrc: "assets/image/default_2_1.webp",
3 years ago
),
);
},
itemCount: storeInfo?.bannerList?.length ?? 1,
3 years ago
),
3 years ago
);
}
3 years ago
/// 购物车的key,用于刷新UI
3 years ago
GlobalKey shopCartKey = GlobalKey();
3 years ago
///购物车弹窗
showShoppingCart() {
3 years ago
queryShopCar().then((value) {
3 years ago
this.shopCarGoods = value;
3 years ago
dialogShowing = true;
SmartDialog.show(
builder: (ctx) {
return ShopCar(
shopCartKey,
this.shopCarGoods,
clearShopCar,
toDownOrder,
shopCartAdd,
shopCartReduce,
);
},
onDismiss: () {
dialogShowing = false;
},
alignment: Alignment.bottomCenter,
);
3 years ago
});
3 years ago
}
3 years ago
///清空购物车
3 years ago
clearShopCar() async {
BaseData<bool>? baseData =
await minService?.clearShoppingCart(num.parse(storeId));
if (baseData?.isSuccess ?? false) {
3 years ago
shopCarGoods = null;
3 years ago
setState(() {});
}
3 years ago
}
3 years ago
///选规格
_queryMiNiDetail(String id, int count) async {
S.current.zhengzaijiazai.loading;
3 years ago
if (count < 0) {
shopCarGoods?.shoppingCartSkuItemList?.forEach((element) async {
3 years ago
if (element.productId == id) {
await shopCartReduce(element);
3 years ago
setState(() {});
}
});
return;
}
BaseData<MiniDetail>? baseData = await minService?.miNiDetail(id);
if (baseData?.isSuccess ?? false) {
miniDetail = baseData!.data;
if (baseData.data != null) {
showStoreSelector(baseData.data!, id, count);
}
3 years ago
}
}
3 years ago
///选规格弹窗
showStoreSelector(MiniDetail miniDetail, String? id, int count) async {
if (miniDetail.attrStyle == 0) {
_addShopCar(miniDetail, [], count);
3 years ago
} else {
SmartDialog.dismiss();
3 years ago
dialogShowing = true;
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
isDismissible: false,
builder: (_) {
return ProductSku(
miniDetail,
shopCarGoods,
id,
_addShopCar,
add,
reduce,
);
},
);
3 years ago
}
3 years ago
}
3 years ago
///添加购物车
Future _addShopCar(MiniDetail? miniDetail, selectSkus, int count) async {
ProductSkuVOList? productSku;
if (selectSkus != null && selectSkus.length == 0) {
productSku = miniDetail?.productSkuVOList?.first;
3 years ago
} else {
productSku = miniDetail?.productSkuVOList?.firstWhere((element) {
3 years ago
bool gg = true;
selectSkus.forEach((element1) {
if ((element.skuNameStr?.indexOf(element1) ?? 0) < 0) {
3 years ago
gg = false;
return gg;
}
});
return gg;
3 years ago
});
3 years ago
}
String? skuId = productSku?.id;
3 years ago
String skuValue = selectSkus
.toString()
.replaceAll("[", "")
.replaceAll("]", "")
.replaceAll(",", "");
3 years ago
if (miniDetail?.subscribeParam?.isEnableSubscribe ?? false) {
clearShopCar();
}
BaseListData<ShoppingCart>? baseDate = await minService?.addShoppingCart({
"storeId": storeInfo?.id,
"storeName": storeInfo?.storeName ?? "",
"numberOfPeople": numberOfPeople,
"tableId": tableId,
"parentId": parentId,
"parentCode": parentCode,
"shoppingCartSkuItemList": [
{
"buyNum": count,
"id": skuId,
"productId": miniDetail?.id,
"productName": miniDetail?.productName,
"skuName": skuValue,
"storeId": storeInfo?.id,
"skuPrice": productSku?.skuPrice,
"skuStock": productSku?.skuStock,
"tableId": tableId,
},
],
}).catchLEr<ShoppingCart>();
// SmartDialog.dismiss();
if (baseDate?.isSuccess ?? false) {
this.shopCarGoods = await queryShopCar();
if (miniDetail?.subscribeParam?.isEnableSubscribe ?? false) toDownOrder();
setState(() {});
} else {
if (baseDate?.msg?.isNotEmpty ?? false) {
SmartDialog.showToast(
"${baseDate?.msg}",
alignment: Alignment.center,
);
}
3 years ago
}
}
///查询购物车
Future<ShoppingCart?> queryShopCar() async {
pName = ""; //活动
pid = ""; //活动
cName = ""; //优惠券
cid = ""; //优惠券
if (storeInfo?.posType?.code == "NORMALSTORE" && tableId == 0) {
return null;
}
BaseListData<ShoppingCart>? baseDate =
await minService?.getShoppingCart(tableId).catchLEr<ShoppingCart>();
if ((baseDate?.isSuccess ?? false) &&
(baseDate!.data?.isNotEmpty ?? false)) {
if (baseDate.data![0].selectDiscount == 1) {
baseDate.data![0].couponList?.forEach((element) {
if (element.isMaxCoupon ?? false) {
// cName = element.promotionName;
cid = element.id;
}
});
} else if (baseDate.data![0].selectDiscount == 2) {
baseDate.data![0].promotionInfoList?.forEach((element) {
if (element.isMaxPromotion ?? false) {
// pName = element.name;
pid = element.id;
}
});
}
return baseDate.data![0];
3 years ago
} else {
3 years ago
return null;
3 years ago
}
3 years ago
}
3 years ago
///购物车➕1
Future<ShoppingCart?> shopCartAdd(SkuItemList cartSkuItem) async {
Map<String, dynamic> shopCarTemp = shopCarGoods?.toJson() ?? {};
cartSkuItem.buyNum = (cartSkuItem.buyNum ?? 0) + 1;
3 years ago
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
BaseListData<ShoppingCart>? baseDate =
await minService?.shoppingCartSingle(shopCarTemp);
if (baseDate?.isSuccess ?? false) {
3 years ago
this.shopCarGoods = await queryShopCar();
shopCartKey.currentState?.setState(() {});
} else {
7 months ago
this.shopCarGoods = await queryShopCar();
shopCartKey.currentState?.setState(() {});
if (baseDate?.msg?.isNotEmpty ?? false) {
7 months ago
SmartDialog.showToast(
"${baseDate!.msg}",
7 months ago
alignment: Alignment.center,
);
}
3 years ago
}
7 months ago
setState(() {});
3 years ago
return this.shopCarGoods;
3 years ago
}
///购物车➖1
Future<ShoppingCart?> shopCartReduce(SkuItemList cartSkuItem) async {
Map<String, dynamic> shopCarTemp = shopCarGoods?.toJson() ?? {};
cartSkuItem.buyNum = (cartSkuItem.buyNum ?? 0) - 1;
3 years ago
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
BaseListData<ShoppingCart>? baseDate =
await minService?.shoppingCartSingle(shopCarTemp);
if (baseDate?.isSuccess ?? false) {
3 years ago
this.shopCarGoods = await queryShopCar();
if (shopCartKey.currentState != null) {
shopCartKey.currentState!.setState(() {});
3 years ago
}
3 years ago
setState(() {});
3 years ago
}
3 years ago
return this.shopCarGoods;
3 years ago
}
///商品➕1
add(MiniDetail miniDetail, selectSkus) async {
ProductSkuVOList? productSku =
miniDetail.productSkuVOList?.firstWhere((element) {
3 years ago
return skuY(element, selectSkus);
});
String? skuId = productSku?.id;
int shopSkuIndex = shopCarGoods?.shoppingCartSkuItemList
?.indexWhere((element) => skuId == element.id) ??
-1;
Map<String, dynamic>? shopCarTemp = shopCarGoods?.toJson();
shopCarGoods?.tableId = "$tableId";
3 years ago
if (shopSkuIndex >= 0) {
int buy =
shopCarGoods?.shoppingCartSkuItemList?[shopSkuIndex].buyNum ?? 0;
shopCarGoods?.shoppingCartSkuItemList?[shopSkuIndex].buyNum = (buy + 1);
SkuItemList? cartSkuItem = shopCarGoods?.shoppingCartSkuItemList
?.firstWhere((element) => skuId == element.id);
shopCarTemp?["shoppingCartSkuItemList"] = [cartSkuItem?.toJson()];
3 years ago
} else {
await _addShopCar(miniDetail, selectSkus, 1);
3 years ago
return;
}
BaseListData<ShoppingCart>? baseDate =
await minService?.shoppingCartSingle(shopCarTemp ?? {});
if (baseDate?.isSuccess ?? false) {
this.shopCarGoods = await queryShopCar();
debugPrint("count.toString()");
setState(() {});
} else {
SmartDialog.showToast("${baseDate?.msg}", alignment: Alignment.center);
3 years ago
}
}
///商品➖1
reduce(MiniDetail miNiDetail, selectSkus) async {
ProductSkuVOList? productSku =
miNiDetail.productSkuVOList?.firstWhere((element) {
3 years ago
return skuY(element, selectSkus);
});
String? skuId = productSku?.id;
SkuItemList? shopSkuItem = shopCarGoods?.shoppingCartSkuItemList
?.firstWhere((element) => skuId == element.id);
int shopSkuIndex = shopCarGoods?.shoppingCartSkuItemList
?.indexWhere((element) => skuId == element.id) ??
-1;
if ((shopSkuItem?.buyNum ?? 0) > 1) {
int butNum =
shopCarGoods?.shoppingCartSkuItemList?[shopSkuIndex].buyNum ?? 0;
shopCarGoods?.shoppingCartSkuItemList?[shopSkuIndex].buyNum = butNum - 1;
3 years ago
}
shopCarGoods?.tableId = "$tableId";
3 years ago
Map<String, dynamic>? shopCarTemp = shopCarGoods?.toJson();
SkuItemList? cartSkuItem = shopCarGoods?.shoppingCartSkuItemList
?.firstWhere((element) => skuId == element.id);
shopCarTemp?["shoppingCartSkuItemList"] = [cartSkuItem?.toJson()];
3 years ago
BaseListData<ShoppingCart>? baseDate =
await minService?.shoppingCartSingle(shopCarTemp ?? {});
if (baseDate?.isSuccess ?? false) {
3 years ago
queryShopCar().then((value) {
this.shopCarGoods = value;
setState(() {});
});
} else {
SmartDialog.showToast(baseDate?.msg ?? "", alignment: Alignment.center);
3 years ago
}
}
bool skuY(ProductSkuVOList productSku, selectSkus) {
3 years ago
bool gg = true;
selectSkus.forEach((element1) {
if ((productSku.skuNameStr?.indexOf(element1) ?? 0) < 0) {
3 years ago
gg = false;
return gg;
}
});
return gg;
3 years ago
}
3 years ago
}
3 years ago
class Title extends StatefulWidget {
final ShopScrollController controller;
3 years ago
final String title;
// final Function scrollChange;
Title(this.controller, this.title /*, this.scrollChange*/);
3 years ago
@override
State<StatefulWidget> createState() {
return _Title();
}
}
class _Title extends State<Title> {
double alpha = 0;
@override
void initState() {
super.initState();
widget.controller.addListener(() {
double maxScrollExtent = widget.controller.position.maxScrollExtent;
debugPrint(
" maxScrollExtent: $maxScrollExtent offset: ${widget.controller.offset} s/m: ${(widget.controller.offset / maxScrollExtent)}");
double alphaTemp =
(widget.controller.offset / maxScrollExtent) > 0.70 ? 1 : 0;
if (alpha != alphaTemp && mounted) {
alpha = alphaTemp;
3 years ago
setState(() {});
}
});
}
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.bottomLeft,
height: kToolbarHeight,
child: alpha == 0
? null
: Container(
child: Row(
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pop();
},
child: Container(
margin: EdgeInsets.only(left: 10.w),
padding: EdgeInsets.all(10.h),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
Expanded(
child: Text(
widget.title ?? "",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18.sp,
),
),
),
],
),
));
3 years ago
}
}
class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
_SliverAppBarDelegate({
required this.minHeight,
required this.maxHeight,
required this.child,
});
final double minHeight;
final double maxHeight;
final Widget child;
@override
double get minExtent => this.minHeight;
@override
double get maxExtent => mm.max(maxHeight, minHeight);
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return SizedBox.expand(child: child);
}
@override
bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
return maxHeight != oldDelegate.maxHeight ||
minHeight != oldDelegate.minHeight ||
child != oldDelegate.child;
}
}