|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
|
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
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/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';
|
|
|
|
import 'package:huixiang/retrofit/min_api.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/store/store_view/people_num.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/store_info.dart';
|
|
|
|
import 'package:huixiang/store/store_view/store_order_list.dart';
|
|
|
|
import 'package:huixiang/utils/constant.dart';
|
|
|
|
import 'package:huixiang/utils/flutter_utils.dart';
|
|
|
|
import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
import 'package:huixiang/view_widget/custom_image.dart';
|
|
|
|
import 'package:huixiang/view_widget/receive_success.dart';
|
|
|
|
import 'package:huixiang/view_widget/round_button.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class StoreOrderPage extends StatefulWidget {
|
|
|
|
final Map<String, dynamic>? arguments;
|
|
|
|
|
|
|
|
StoreOrderPage({this.arguments});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _StoreOrderPage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _StoreOrderPage extends State<StoreOrderPage>
|
|
|
|
with TickerProviderStateMixin {
|
|
|
|
TabController? tabcontroller;
|
|
|
|
ApiService? apiService;
|
|
|
|
MinApiService? minService;
|
|
|
|
StoreInfo? storeInfo;
|
|
|
|
List<Activity>? activitys;
|
|
|
|
StoreOrderListPage? storeOrderListPage;
|
|
|
|
ScrollPhysics scrollPhysics = NeverScrollableScrollPhysics();
|
|
|
|
|
|
|
|
ScrollController controller = ScrollController();
|
|
|
|
ShoppingCart? shopCarGoods;
|
|
|
|
int tableId = 0;
|
|
|
|
String parentId = "";
|
|
|
|
String parentCode = "";
|
|
|
|
String tenant = "";
|
|
|
|
String storeId = "";
|
|
|
|
int numberOfPeople = 0;
|
|
|
|
String? vipLevelName;
|
|
|
|
MemberVo? memberVo;
|
|
|
|
MiniDetail? miniDetail;
|
|
|
|
|
|
|
|
GlobalKey<ExtendedNestedScrollViewState> nestedScrollViewKey =
|
|
|
|
GlobalKey<ExtendedNestedScrollViewState>();
|
|
|
|
|
|
|
|
///小程序token
|
|
|
|
String? minToken;
|
|
|
|
String? pName;
|
|
|
|
String? pid;
|
|
|
|
String? cName;
|
|
|
|
String? cid;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
tableId = widget.arguments?["tableId"] ?? 0;
|
|
|
|
tenant = widget.arguments?["tenant"];
|
|
|
|
storeId = widget.arguments?["id"];
|
|
|
|
|
|
|
|
tabcontroller = TabController(length: 1, vsync: this);
|
|
|
|
|
|
|
|
debugPrint(
|
|
|
|
"store_param tableId:$tableId tenant:$tenant storeId:$storeId");
|
|
|
|
|
|
|
|
SharedPreferences.getInstance().then((value) {
|
|
|
|
apiService = ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: value.getString('token') ?? "",
|
|
|
|
);
|
|
|
|
minLogin(value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 小程序登录
|
|
|
|
minLogin(SharedPreferences shared) async {
|
|
|
|
SmartDialog.showLoading(
|
|
|
|
msg: S.of(context).zhengzaijiazai,
|
|
|
|
);
|
|
|
|
minToken = widget.arguments?["miniToken"];
|
|
|
|
await queryStoreInfo();
|
|
|
|
SharedPreferences.getInstance().then(
|
|
|
|
(value) => {
|
|
|
|
value.setString('minToken', minToken ?? ""),
|
|
|
|
value.setString('tenant', tenant),
|
|
|
|
value.setString('storeId', storeId),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
minService = MinApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: minToken ?? "",
|
|
|
|
tenant: tenant,
|
|
|
|
storeId: storeId,
|
|
|
|
);
|
|
|
|
|
|
|
|
queryMemberInfo();
|
|
|
|
|
|
|
|
queryShopCar().then((value) {
|
|
|
|
this.shopCarGoods = value;
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
if (tableId > 0) {
|
|
|
|
getParentInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///会员信息
|
|
|
|
queryMemberInfo() async {
|
|
|
|
BaseData? baseData = await minService?.memberInfo().catchError((error) {
|
|
|
|
debugPrint("${error}");
|
|
|
|
return Future.value(null);
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
SharedPreferences.getInstance().then(
|
|
|
|
(value) => {
|
|
|
|
value.setString('minMember', jsonEncode(baseData!.data)),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
memberVo = MemberVo.fromJson(baseData!.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///获取父订单(火锅订单加菜前调用)
|
|
|
|
getParentInfo() async {
|
|
|
|
BaseData? baseData =
|
|
|
|
await minService?.getParentInfo("$tableId").catchError((error) {
|
|
|
|
debugPrint("${error}");
|
|
|
|
return Future.value(null);
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
if (baseData?.data != null) {
|
|
|
|
parentId = baseData!.data["id"];
|
|
|
|
parentCode = baseData.data["parentCode"];
|
|
|
|
} else {
|
|
|
|
///TODO: 没有父订单,
|
|
|
|
queryStoreInfo1();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///获取桌子信息
|
|
|
|
queryStoreInfo1() async {
|
|
|
|
BaseData? baseData = await minService?.queryStoreInfo1({
|
|
|
|
"getCoupon": true,
|
|
|
|
"storeId": storeId,
|
|
|
|
"tableId": tableId,
|
|
|
|
}).catchError((error) {
|
|
|
|
debugPrint("${error}");
|
|
|
|
return Future.value(null);
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
StoreInfo storeInfo = StoreInfo.fromJson(baseData!.data);
|
|
|
|
showPeopleNum(storeInfo.storeTable?.tableName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 查询店铺信息
|
|
|
|
queryStoreInfo() async {
|
|
|
|
BaseData<StoreInfo>? baseData =
|
|
|
|
await apiService?.queryStoreInfo(storeId).catchError((error) {
|
|
|
|
debugPrint("${error}");
|
|
|
|
return BaseData<StoreInfo>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if ((baseData?.isSuccess ?? false) && baseData?.data != null) {
|
|
|
|
storeInfo = baseData!.data;
|
|
|
|
activitys = storeInfo?.informationVOPageVO?.list
|
|
|
|
?.map((e) => Activity.fromJson(e))
|
|
|
|
.toList();
|
|
|
|
if (mounted) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshController? refreshController;
|
|
|
|
bool dialogShowing = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return PopScope(
|
|
|
|
onPopInvoked: (isPop) {
|
|
|
|
if (dialogShowing) {
|
|
|
|
SmartDialog.dismiss();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
canPop: false,
|
|
|
|
child: Container(
|
|
|
|
color: Colors.white,
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Positioned(
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
bottom: 54.h,
|
|
|
|
child: ExtendedNestedScrollView(
|
|
|
|
controller: controller,
|
|
|
|
key: nestedScrollViewKey,
|
|
|
|
dragStartBehavior: DragStartBehavior.start,
|
|
|
|
scrollBehavior: ScrollBehavior(),
|
|
|
|
floatHeaderSlivers: true,
|
|
|
|
physics: ClampingScrollPhysics(),
|
|
|
|
headerSliverBuilder: (BuildContext context, bool innerScrolled) {
|
|
|
|
return [
|
|
|
|
SliverAppBar(
|
|
|
|
expandedHeight:
|
|
|
|
(storeInfo?.couponVOList?.isNotEmpty ?? true)
|
|
|
|
? 440.h
|
|
|
|
: 395.h,
|
|
|
|
pinned: true,
|
|
|
|
systemOverlayStyle: SystemUiOverlayStyle.dark,
|
|
|
|
flexibleSpace: FlexibleSpaceBar(
|
|
|
|
title: Title(
|
|
|
|
controller,
|
|
|
|
storeInfo?.storeName ?? '',
|
|
|
|
(alpha) {
|
|
|
|
// setState(() {
|
|
|
|
// if (alpha == 1)
|
|
|
|
// scrollPhysics = BouncingScrollPhysics();
|
|
|
|
// else
|
|
|
|
// scrollPhysics =
|
|
|
|
// NeverScrollableScrollPhysics();
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
),
|
|
|
|
centerTitle: false,
|
|
|
|
titlePadding: EdgeInsets.symmetric(
|
|
|
|
vertical: 16,
|
|
|
|
),
|
|
|
|
collapseMode: CollapseMode.pin,
|
|
|
|
stretchModes: [
|
|
|
|
StretchMode.zoomBackground,
|
|
|
|
// StretchMode.fadeTitle,
|
|
|
|
StretchMode.blurBackground,
|
|
|
|
],
|
|
|
|
background: Container(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Positioned.fill(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
buildSwiper(),
|
|
|
|
Spacer(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
),
|
|
|
|
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: 233.h,
|
|
|
|
bottom: 38.h,
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
centerTitle: false,
|
|
|
|
elevation: 0,
|
|
|
|
leadingWidth: 0,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
bottom: PreferredSize(
|
|
|
|
preferredSize: Size(
|
|
|
|
Get.width,
|
|
|
|
38.h,
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
width: Get.width,
|
|
|
|
child: Theme(
|
|
|
|
data: ThemeData(
|
|
|
|
splashColor: Colors.transparent,
|
|
|
|
// 点击时的水波纹颜色设置为透明
|
|
|
|
highlightColor:
|
|
|
|
Colors.transparent, // 点击时的背景高亮颜色设置为透明
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
20.vd,
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
// Color(0xFF32A060),
|
|
|
|
S.of(context).diandan,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
fontSize: 18.sp,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
5.d,
|
|
|
|
Container(
|
|
|
|
width: 20,
|
|
|
|
height: 3,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(2),
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
10.d,
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Spacer(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
pinnedHeaderSliverHeightBuilder: () {
|
|
|
|
final double statusBarHeight =
|
|
|
|
MediaQuery.of(context).padding.top;
|
|
|
|
return statusBarHeight + kToolbarHeight + 38.h;
|
|
|
|
},
|
|
|
|
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: Stack(
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
children: [
|
|
|
|
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: 45.w,
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Stack(
|
|
|
|
children: [
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
if (count() != 0) showShoppingCart();
|
|
|
|
},
|
|
|
|
child: Image.asset(
|
|
|
|
"assets/image/shopping_bag.webp",
|
|
|
|
width: 66,
|
|
|
|
height: 66,
|
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (count() != 0)
|
|
|
|
Positioned(
|
|
|
|
right: 5,
|
|
|
|
// top: 14,
|
|
|
|
child: RoundButton(
|
|
|
|
width: 17.w,
|
|
|
|
height: 17.h,
|
|
|
|
text: "${count()}",
|
|
|
|
textColor: Colors.white,
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
backgroup: Color(0xFFF65720),
|
|
|
|
fontSize: 12.sp,
|
|
|
|
radius: 100,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
///领取优惠券
|
|
|
|
_receiveCoupon(couponId) async {
|
|
|
|
BaseData? baseData = await apiService?.receiveCoupon(couponId);
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
queryStoreInfo();
|
|
|
|
showAlertDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 领取成功弹窗
|
|
|
|
showAlertDialog() {
|
|
|
|
//显示对话框
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ReceiveSuccess();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
///显示选择人数的弹窗
|
|
|
|
showPeopleNum(String? tableName) async {
|
|
|
|
var people = await showDialog(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: false,
|
|
|
|
builder: (context) {
|
|
|
|
return PeopleNumView(tableName ?? "");
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (people != null && people > 0) {
|
|
|
|
setState(() {
|
|
|
|
this.numberOfPeople = people;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///计算个数
|
|
|
|
int count() {
|
|
|
|
if (shopCarGoods?.shoppingCartSkuItemList?.isEmpty ?? true) return 0;
|
|
|
|
int count = 0;
|
|
|
|
shopCarGoods?.shoppingCartSkuItemList?.forEach((element) {
|
|
|
|
count += (element.buyNum ?? 0);
|
|
|
|
});
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
///去下单结算页面
|
|
|
|
toDownOrder() async {
|
|
|
|
int num = count();
|
|
|
|
|
|
|
|
if (parentId == "") {
|
|
|
|
if (num == 0) {
|
|
|
|
SmartDialog.showToast("请先选择您要购买的商品!~", alignment: Alignment.center);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await Navigator.of(context).pushNamed(
|
|
|
|
'/router/settlement',
|
|
|
|
arguments: {
|
|
|
|
"storeInfo": storeInfo,
|
|
|
|
"tableId": tableId,
|
|
|
|
"parentCode": parentCode,
|
|
|
|
"parentId": parentId,
|
|
|
|
// "pName": pName,
|
|
|
|
"pid": pid,
|
|
|
|
// "cName": cName,
|
|
|
|
"cid": cid,
|
|
|
|
"shoppingCart": shopCarGoods,
|
|
|
|
"numberOfPeople": numberOfPeople,
|
|
|
|
"distance": widget.arguments?["distance"],
|
|
|
|
"vipLevelName": memberVo?.memberRankVo?.rankName ?? "",
|
|
|
|
"isVips": memberVo?.isVip ?? false,
|
|
|
|
"subscribeParam": miniDetail?.subscribeParam,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (miniDetail?.subscribeParam?.isEnableSubscribe ?? false) {
|
|
|
|
clearShopCar();
|
|
|
|
this.shopCarGoods = await queryShopCar();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tableId > 0) {
|
|
|
|
getParentInfo();
|
|
|
|
}
|
|
|
|
queryShopCar().then((value) {
|
|
|
|
this.shopCarGoods = value;
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildSwiper() {
|
|
|
|
return Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: 240.h,
|
|
|
|
child: Swiper(
|
|
|
|
pagination: SwiperPagination(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
builder: DotSwiperPaginationBuilder(
|
|
|
|
size: 8.w,
|
|
|
|
activeSize: 8.w,
|
|
|
|
space: 5.w,
|
|
|
|
activeColor: Colors.white,
|
|
|
|
color: Colors.white.withAlpha(76),
|
|
|
|
),
|
|
|
|
margin: EdgeInsets.only(bottom: 13.h),
|
|
|
|
),
|
|
|
|
autoplay: storeInfo?.bannerList?.isNotEmpty ?? false,
|
|
|
|
duration: 1000,
|
|
|
|
autoplayDelay: 2000,
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return Container(
|
|
|
|
child: MImage(
|
|
|
|
(position < (storeInfo?.bannerList?.length ?? 0))
|
|
|
|
? (storeInfo?.bannerList![position].imgUrl ?? "")
|
|
|
|
: "",
|
|
|
|
height: 230.h,
|
|
|
|
width: double.infinity,
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
radius: BorderRadius.zero,
|
|
|
|
errorSrc: "assets/image/default_2_1.webp",
|
|
|
|
fadeSrc: "assets/image/default_2_1.webp",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: storeInfo?.bannerList?.length ?? 1,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 购物车的key,用于刷新UI
|
|
|
|
GlobalKey shopCartKey = GlobalKey();
|
|
|
|
|
|
|
|
///购物车弹窗
|
|
|
|
showShoppingCart() {
|
|
|
|
queryShopCar().then((value) {
|
|
|
|
this.shopCarGoods = value;
|
|
|
|
dialogShowing = true;
|
|
|
|
SmartDialog.show(
|
|
|
|
builder: (ctx) {
|
|
|
|
return ShopCar(
|
|
|
|
shopCartKey,
|
|
|
|
this.shopCarGoods,
|
|
|
|
clearShopCar,
|
|
|
|
toDownOrder,
|
|
|
|
shopCartAdd,
|
|
|
|
shopCartReduce,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onDismiss: () {
|
|
|
|
dialogShowing = false;
|
|
|
|
},
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
///清空购物车
|
|
|
|
clearShopCar() async {
|
|
|
|
BaseData<bool>? baseData =
|
|
|
|
await minService?.clearShoppingCart(num.parse(storeId));
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
shopCarGoods = null;
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///选规格
|
|
|
|
_queryMiNiDetail(String id, int count) async {
|
|
|
|
SmartDialog.showLoading(
|
|
|
|
msg: S.current.zhengzaijiazai,
|
|
|
|
);
|
|
|
|
if (count < 0) {
|
|
|
|
shopCarGoods?.shoppingCartSkuItemList?.forEach((element) async {
|
|
|
|
if (element.productId == id) {
|
|
|
|
await shopCartReduce(element);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BaseData<MiniDetail>? baseData = await minService?.miNiDetail(id);
|
|
|
|
SmartDialog.dismiss();
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
miniDetail = baseData!.data;
|
|
|
|
if (baseData.data != null) {
|
|
|
|
showStoreSelector(baseData.data!, id, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///选规格弹窗
|
|
|
|
showStoreSelector(MiniDetail miniDetail, String? id, int count) async {
|
|
|
|
if (miniDetail.attrStyle == 0) {
|
|
|
|
_addShopCar(miniDetail, [], count);
|
|
|
|
} else {
|
|
|
|
SmartDialog.dismiss();
|
|
|
|
dialogShowing = true;
|
|
|
|
showModalBottomSheet(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
context: context,
|
|
|
|
isDismissible: false,
|
|
|
|
builder: (_) {
|
|
|
|
return ProductSku(
|
|
|
|
miniDetail,
|
|
|
|
shopCarGoods,
|
|
|
|
id,
|
|
|
|
_addShopCar,
|
|
|
|
add,
|
|
|
|
reduce,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///添加购物车
|
|
|
|
Future _addShopCar(MiniDetail? miniDetail, selectSkus, int count) async {
|
|
|
|
ProductSkuVOList? productSku;
|
|
|
|
if (selectSkus != null && selectSkus.length == 0) {
|
|
|
|
productSku = miniDetail?.productSkuVOList?.first;
|
|
|
|
} else {
|
|
|
|
productSku = miniDetail?.productSkuVOList?.firstWhere((element) {
|
|
|
|
bool gg = true;
|
|
|
|
selectSkus.forEach((element1) {
|
|
|
|
if ((element.skuNameStr?.indexOf(element1) ?? 0) < 0) {
|
|
|
|
gg = false;
|
|
|
|
return gg;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return gg;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
String? skuId = productSku?.id;
|
|
|
|
String skuValue = selectSkus
|
|
|
|
.toString()
|
|
|
|
.replaceAll("[", "")
|
|
|
|
.replaceAll("]", "")
|
|
|
|
.replaceAll(",", "");
|
|
|
|
|
|
|
|
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 {
|
|
|
|
SmartDialog.showToast("${baseDate?.msg}", alignment: Alignment.center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///查询购物车
|
|
|
|
Future<ShoppingCart?> queryShopCar() async {
|
|
|
|
pName = ""; //活动
|
|
|
|
pid = ""; //活动
|
|
|
|
cName = ""; //优惠券
|
|
|
|
cid = ""; //优惠券
|
|
|
|
if (storeInfo?.posType?.code == "NORMALSTORE" && tableId == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
BaseListData<ShoppingCart>? baseDate =
|
|
|
|
await minService?.getShoppingCart(tableId);
|
|
|
|
if ((baseDate?.isSuccess ?? false) && (baseDate!.data?.length ?? 0) > 0) {
|
|
|
|
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];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///购物车➕1
|
|
|
|
Future<ShoppingCart?> shopCartAdd(SkuItemList cartSkuItem) async {
|
|
|
|
Map<String, dynamic> shopCarTemp = shopCarGoods?.toJson() ?? {};
|
|
|
|
cartSkuItem.buyNum = (cartSkuItem.buyNum ?? 0) + 1;
|
|
|
|
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
|
|
|
|
BaseListData<ShoppingCart>? baseDate =
|
|
|
|
await minService?.shoppingCartSingle(shopCarTemp);
|
|
|
|
if (baseDate?.isSuccess ?? false) {
|
|
|
|
this.shopCarGoods = await queryShopCar();
|
|
|
|
if (shopCartKey != null) {
|
|
|
|
shopCartKey.currentState?.setState(() {});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.shopCarGoods = await queryShopCar();
|
|
|
|
if (shopCartKey != null) {
|
|
|
|
shopCartKey.currentState?.setState(() {});
|
|
|
|
}
|
|
|
|
if (baseDate != null && baseDate.msg != null && baseDate.msg != "") {
|
|
|
|
SmartDialog.showToast(
|
|
|
|
"${baseDate.msg}",
|
|
|
|
alignment: Alignment.center,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
return this.shopCarGoods;
|
|
|
|
}
|
|
|
|
|
|
|
|
///购物车➖1
|
|
|
|
Future<ShoppingCart?> shopCartReduce(SkuItemList cartSkuItem) async {
|
|
|
|
Map<String, dynamic> shopCarTemp = shopCarGoods?.toJson() ?? {};
|
|
|
|
cartSkuItem.buyNum = (cartSkuItem.buyNum ?? 0) - 1;
|
|
|
|
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
|
|
|
|
BaseListData<ShoppingCart>? baseDate =
|
|
|
|
await minService?.shoppingCartSingle(shopCarTemp);
|
|
|
|
if (baseDate?.isSuccess ?? false) {
|
|
|
|
SmartDialog.dismiss();
|
|
|
|
this.shopCarGoods = await queryShopCar();
|
|
|
|
if (shopCartKey.currentState != null) {
|
|
|
|
shopCartKey.currentState!.setState(() {});
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
return this.shopCarGoods;
|
|
|
|
}
|
|
|
|
|
|
|
|
///商品➕1
|
|
|
|
add(MiniDetail miniDetail, selectSkus) async {
|
|
|
|
ProductSkuVOList? productSku =
|
|
|
|
miniDetail.productSkuVOList?.firstWhere((element) {
|
|
|
|
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";
|
|
|
|
|
|
|
|
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()];
|
|
|
|
} else {
|
|
|
|
await _addShopCar(miniDetail, selectSkus, 1);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///商品➖1
|
|
|
|
reduce(MiniDetail miNiDetail, selectSkus) async {
|
|
|
|
ProductSkuVOList? productSku =
|
|
|
|
miNiDetail.productSkuVOList?.firstWhere((element) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
shopCarGoods?.tableId = "$tableId";
|
|
|
|
|
|
|
|
Map<String, dynamic>? shopCarTemp = shopCarGoods?.toJson();
|
|
|
|
SkuItemList? cartSkuItem = shopCarGoods?.shoppingCartSkuItemList
|
|
|
|
?.firstWhere((element) => skuId == element.id);
|
|
|
|
shopCarTemp?["shoppingCartSkuItemList"] = [cartSkuItem?.toJson()];
|
|
|
|
|
|
|
|
BaseListData<ShoppingCart>? baseDate =
|
|
|
|
await minService?.shoppingCartSingle(shopCarTemp ?? {});
|
|
|
|
if (baseDate?.isSuccess ?? false) {
|
|
|
|
queryShopCar().then((value) {
|
|
|
|
this.shopCarGoods = value;
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
SmartDialog.showToast(baseDate?.msg ?? "", alignment: Alignment.center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool skuY(ProductSkuVOList productSku, selectSkus) {
|
|
|
|
bool gg = true;
|
|
|
|
selectSkus.forEach((element1) {
|
|
|
|
if ((productSku.skuNameStr?.indexOf(element1) ?? 0) < 0) {
|
|
|
|
gg = false;
|
|
|
|
return gg;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return gg;
|
|
|
|
}
|
|
|
|
|
|
|
|
final ScrollController controller1 = ScrollController();
|
|
|
|
final ScrollController controller2 = ScrollController();
|
|
|
|
Drag? _drag;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Title extends StatefulWidget {
|
|
|
|
final ScrollController controller;
|
|
|
|
final String title;
|
|
|
|
final Function scrollChange;
|
|
|
|
|
|
|
|
Title(this.controller, this.title, this.scrollChange);
|
|
|
|
|
|
|
|
@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;
|
|
|
|
double alphaHeight = kToolbarHeight + 38.h;
|
|
|
|
double alphaProgress = maxScrollExtent - widget.controller.offset;
|
|
|
|
// debugPrint("controller.offset: ${widget.controller.offset}");
|
|
|
|
double alphaTemp = 0;
|
|
|
|
if (alphaProgress <= 1) {
|
|
|
|
alphaTemp = 1;
|
|
|
|
} else if (alphaProgress <= alphaHeight) {
|
|
|
|
alphaTemp =
|
|
|
|
(((alphaHeight - alphaProgress) / alphaHeight) > 0.5) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
alphaTemp = 0;
|
|
|
|
}
|
|
|
|
// debugPrint("alpha: $alpha");
|
|
|
|
if (alpha != alphaTemp && mounted) {
|
|
|
|
alpha = alphaTemp;
|
|
|
|
widget.scrollChange(alpha);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: alpha == 0
|
|
|
|
? null
|
|
|
|
: 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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
widget.title ?? "",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 18.sp,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|