|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:math' as mm;
|
|
|
|
|
|
|
|
import 'package:dio/dio.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/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';
|
|
|
|
import 'package:huixiang/retrofit/min_api.dart';
|
|
|
|
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';
|
|
|
|
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/utils/shared_preference.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';
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
ShoppingCart? shopCarGoods;
|
|
|
|
int tableId = 0;
|
|
|
|
String parentId = "";
|
|
|
|
String parentCode = "";
|
|
|
|
String tenant = "";
|
|
|
|
String storeId = "";
|
|
|
|
int numberOfPeople = 0;
|
|
|
|
String? vipLevelName;
|
|
|
|
MemberVo? memberVo;
|
|
|
|
MiniDetail? miniDetail;
|
|
|
|
|
|
|
|
///小程序token
|
|
|
|
String? minToken;
|
|
|
|
String? pName;
|
|
|
|
String? pid;
|
|
|
|
String? cName;
|
|
|
|
String? cid;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_shopCoordinator = ShopScrollCoordinator();
|
|
|
|
|
|
|
|
tableId = widget.arguments?["tableId"] ?? 0;
|
|
|
|
tenant = widget.arguments?["tenant"];
|
|
|
|
storeId = widget.arguments?["id"];
|
|
|
|
|
|
|
|
tabcontroller = TabController(length: 1, vsync: this);
|
|
|
|
|
|
|
|
_pageScrollController = _shopCoordinator.pageScrollController(0);
|
|
|
|
|
|
|
|
apiService = ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: SharedInstance.instance.token,
|
|
|
|
);
|
|
|
|
minLogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 小程序登录
|
|
|
|
minLogin() async {
|
|
|
|
S.current.zhengzaijiazai.loading;
|
|
|
|
minToken = widget.arguments?["miniToken"];
|
|
|
|
await queryStoreInfo();
|
|
|
|
SharedInstance.instance.saveMini(minToken, tenant, 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 BaseData()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
SharedInstance.instance.saveMiniMember(jsonEncode(baseData!.data));
|
|
|
|
memberVo = MemberVo.fromJson(baseData.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///获取父订单(火锅订单加菜前调用)
|
|
|
|
getParentInfo() async {
|
|
|
|
BaseData? baseData =
|
|
|
|
await minService?.getParentInfo("$tableId").catchError((error) {
|
|
|
|
debugPrint("${error}");
|
|
|
|
return BaseData()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
if (baseData?.data != null) {
|
|
|
|
parentId = baseData!.data["id"];
|
|
|
|
parentCode = baseData.data["parentCode"];
|
|
|
|
} else {
|
|
|
|
queryStoreInfo1();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///获取桌子信息
|
|
|
|
queryStoreInfo1() async {
|
|
|
|
BaseData<StoreInfo>? baseData = await minService?.queryStoreInfo1({
|
|
|
|
"getCoupon": true,
|
|
|
|
"storeId": storeId,
|
|
|
|
"tableId": tableId,
|
|
|
|
}).catchError((error) {
|
|
|
|
debugPrint("${error}");
|
|
|
|
return BaseData<StoreInfo>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if ((baseData?.isSuccess ?? false) && baseData?.data != null) {
|
|
|
|
StoreInfo storeInfo = 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;
|
|
|
|
|
|
|
|
final ScrollController controller1 = ScrollController();
|
|
|
|
final ScrollController controller2 = ScrollController();
|
|
|
|
|
|
|
|
late ShopScrollCoordinator _shopCoordinator;
|
|
|
|
ShopScrollController? _pageScrollController;
|
|
|
|
|
|
|
|
@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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
///领取优惠券
|
|
|
|
_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 {
|
|
|
|
S.current.zhengzaijiazai.loading;
|
|
|
|
if (count < 0) {
|
|
|
|
shopCarGoods?.shoppingCartSkuItemList?.forEach((element) async {
|
|
|
|
if (element.productId == id) {
|
|
|
|
await shopCartReduce(element);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///选规格弹窗
|
|
|
|
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 {
|
|
|
|
if (baseDate?.msg?.isNotEmpty ?? false) {
|
|
|
|
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).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];
|
|
|
|
} 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();
|
|
|
|
shopCartKey.currentState?.setState(() {});
|
|
|
|
} else {
|
|
|
|
this.shopCarGoods = await queryShopCar();
|
|
|
|
shopCartKey.currentState?.setState(() {});
|
|
|
|
if (baseDate?.msg?.isNotEmpty ?? false) {
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Title extends StatefulWidget {
|
|
|
|
final ShopScrollController 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;
|
|
|
|
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;
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|