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:geolocator/geolocator.dart'; import 'package:huixiang/data/base_data.dart'; import 'package:huixiang/data/page.dart'; import 'package:huixiang/data/store.dart'; import 'package:huixiang/data/user_bill.dart'; import 'package:huixiang/data/vip_card.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/store/scan.dart'; import 'package:huixiang/utils/app_util.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/location.dart'; import 'package:huixiang/utils/shared_preference.dart'; import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_footer.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:shimmer/shimmer.dart'; class MineShopDetails extends StatefulWidget { final Map arguments; MineShopDetails({required this.arguments}); @override State createState() { return _MineShopDetails(); } } class _MineShopDetails extends State { ApiService? apiService; int selectType = 0; List userBill = []; @override void dispose() { super.dispose(); refreshController.dispose(); consumeRefreshController.dispose(); LocationInstance.getInstance().stopLocation(); } @override void initState() { super.initState(); apiService = ApiService(Dio(), token: SharedInstance.instance.token, context: context, ); vipDetail("", ""); startLocation(); } VipCard? vipCard; final RefreshController refreshController = RefreshController(); final RefreshController consumeRefreshController = RefreshController(); int current = 1; vipDetail(latitude, longitude) async { BaseData? baseData = await apiService?.vipDetail({ "id": widget.arguments["id"], "latitude": "$latitude", "longitude": "$longitude", }).catchError((onError) { return BaseData()..isSuccess = false; }); if (baseData?.isSuccess ?? false) { vipCard = baseData!.data; if ((vipCard?.storeList?.isNotEmpty ?? false) && (vipCard!.storeList!.first.logo?.isNotEmpty ?? false)) { Color? color = await loadShopColor(vipCard!.storeList!.first.logo!); if (color != null) { vipCard!.color = color; } } refreshController.loadComplete(); } else { refreshController.loadFailed(); } setState(() {}); } startLocation() async { LocationInstance.getInstance().startLocation(context, (Position? result) { if (result?.latitude != null && result?.longitude != null) { vipDetail(result?.latitude, result?.longitude); } else { SmartDialog.dismiss(status: SmartStatus.loading); } }).then((value) { if (!value) { SmartDialog.dismiss(status: SmartStatus.loading); refreshController.refreshFailed(); } }); } billInfo() async { BaseData>? baseData = await apiService?.queryBillInfo({ "current": current, "model": {"category": "", "title": "bill_title_balance", "type": ""}, "order": "descending", "size": 10, "sort": "id" }).catchError((onError) { refreshController.refreshFailed(); refreshController.loadFailed(); consumeRefreshController.refreshFailed(); consumeRefreshController.loadFailed(); return BaseData>()..isSuccess = false; }); if (baseData?.isSuccess ?? false) { if (current == 1) { userBill.clear(); } if (baseData?.data?.records?.isNotEmpty ?? false) { userBill.addAll(baseData!.data!.records!); } refreshController.refreshCompleted(); refreshController.loadComplete(); consumeRefreshController.refreshCompleted(); consumeRefreshController.loadComplete(); if (current * 10 > (int.tryParse("${baseData?.data?.total}") ?? 0)) { refreshController.loadNoData(); consumeRefreshController.loadNoData(); } else { current += 1; } } else { refreshController.refreshFailed(); refreshController.loadFailed(); consumeRefreshController.refreshFailed(); consumeRefreshController.loadFailed(); } if (mounted) setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppBar( title: S.of(context).huiyuankaxiangqing, titleColor: Colors.black, background: Colors.white, systemUiOverlayStyle: SystemUiOverlayStyle.dark, leadingColor: Colors.black, ), body: Column( children: [ buildVipCard(), Container( margin: EdgeInsets.only(left: 14.w), child: Row( children: [ GestureDetector( onTap: () { setState(() { selectType = 0; }); }, child: Column( children: [ Text( "适用门店", style: TextStyle( color: Color(selectType == 0 ? 0xFF000000 : 0xFF868686), fontSize: 15.sp, fontWeight: MyFontWeight.medium, ), ), SizedBox( height: 8.h, ), if (selectType == 0) Container( width: 52.w, height: 2.h, color: Color(0xFF32A060), ) ], ), ), SizedBox( width: 20.w, ), // GestureDetector( // onTap: () { // setState(() { // selectType = 1; // billInfo(); // }); // }, // child: Column( // children: [ // Text( // "余额明细", // style: TextStyle( // color: // Color(selectType == 1 ? 0xFF000000 : 0xFF868686), // fontSize: 15.sp, // fontWeight: MyFontWeight.medium, // ), // ), // SizedBox( // height: 8.h, // ), // if (selectType == 1) // Container( // width: 52.w, // height: 2.h, // color: Color(0xFF32A060), // ) // ], // ), // ), ], ), ), selectType == 0 ? Expanded( child: SmartRefresher( controller: refreshController, enablePullDown: false, enablePullUp: false, footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), physics: BouncingScrollPhysics(), child: ListView.builder( itemBuilder: (context, position) { return GestureDetector( onTap: () {}, child: shopItem(vipCard!.storeList![position]), ); }, padding: EdgeInsets.symmetric(vertical: 1), itemCount: vipCard?.storeList?.length ?? 0, ), ), ) : Expanded( child: SmartRefresher( controller: consumeRefreshController, enablePullDown: true, enablePullUp: true, physics: BouncingScrollPhysics(), header: MyHeader(), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), onRefresh: () { current = 1; billInfo(); }, onLoading: () { billInfo(); }, child: ListView.builder( itemBuilder: (context, position) { return GestureDetector( onTap: () {}, child: consumeItem(userBill[position]), ); }, shrinkWrap: true, padding: EdgeInsets.symmetric(vertical: 1), itemCount: userBill.length ?? 0, ), ), ), ], ), ); } int colorByName(String storeName) { if (storeName.contains("百年川椒") || storeName.contains("百年川椒")) { return 0xFFC30D23; } else if (storeName.contains("海峡姐妹") || storeName.contains("海峽姐妹")) { return 0xFFE4C796; } else if (storeName.contains("前进麦味") || storeName.contains("前進麥味")) { return 0xFF265782; } return 0xFF32A060; } Widget buildVipCard() { return Container( width: double.infinity, // height:140.h, margin: EdgeInsets.only( bottom: 24.h, top: 14.h, left: 14.w, right: 14.w, ), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( decoration: BoxDecoration( borderRadius: new BorderRadius.only( topLeft: Radius.circular(6), topRight: Radius.circular(6), ), color: vipCard?.color ?? Color(colorByName(vipCard?.tenantName ?? "")), boxShadow: [ BoxShadow( color: (vipCard?.color ?? Color(colorByName(vipCard?.tenantName ?? ""))).withAlpha(80), offset: Offset(0, -1), blurRadius: 3, spreadRadius: 1, ), ], ), padding: EdgeInsets.only(left: 12.w), height: 62.h, child: Row( children: [ MImage( vipCard?.storeList?[0].logo ?? "", width: 38, height: 38, radius: BorderRadius.circular(100), fit: BoxFit.cover, errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox( width: 6, ), Text( vipCard?.tenantName ?? "", style: TextStyle( color: Color(0xFFFFFFFF), fontSize: 15.sp, fontWeight: MyFontWeight.medium, ), ), ], ), ), Container( decoration: BoxDecoration( borderRadius: new BorderRadius.only( bottomRight: Radius.circular(6), topRight: Radius.circular(6), ), color: Colors.white, boxShadow: [ BoxShadow( color: (vipCard?.color ?? Color(colorByName(vipCard?.tenantName ?? ""))).withAlpha(10), offset: Offset(0, 2), blurRadius: 5, spreadRadius: 1, ), ], ), padding: EdgeInsets.all(12.h), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "店铺余额(元)", style: TextStyle( color: Color(0xFF262626), fontSize: 12.sp, fontWeight: MyFontWeight.regular, ), ), Text( "No.${vipCard?.id ?? ""}", style: TextStyle( color: Color(0xFF262626), fontSize: 12.sp, fontWeight: MyFontWeight.regular, ), ), ], ), SizedBox( height: 4.h, ), Text( "¥ ${vipCard?.balance ?? ""}", style: TextStyle( color: Color(0xFF262626), fontSize: 24.sp, fontFamily: 'JDZhengHT', fontWeight: MyFontWeight.bold, ), ), ], ), ), ], ), ); } ///整体骨架屏 Widget skeletonScreen() { return Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( margin: EdgeInsets.only( bottom: 24.h, top: 14.h, left: 14.w, right: 14.w, ), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.circular(6), topRight: Radius.circular(6), ), color: Color(0XFFD8D8D8), ), height: 62.h, ), Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( bottomRight: Radius.circular(6), topRight: Radius.circular(6), ), color: Colors.white, ), padding: EdgeInsets.all(12.h), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, children: [ Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 68.w, height: 17.h, ), ), Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 120.w, height: 17.h, ), ), ], ), SizedBox( height: 4.h, ), Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 99.w, height: 34.h, ), ), ], ), ), ], )), Padding( padding: EdgeInsets.only(left: 14.w), child: Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 52.w, height: 17.h, ), )), SizedBox( height: 8.h, ), Container( margin: EdgeInsets.only(left: 14.w), width: 52.w, height: 2.h, color: Color(0XFFD8D8D8), ), ListView.builder( itemCount: 4, physics: BouncingScrollPhysics(), shrinkWrap: true, itemBuilder: (context, position) { return Container( decoration: BoxDecoration( borderRadius: new BorderRadius.circular(6), color: Colors.white, ), padding: EdgeInsets.all(12), margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 178.w, height: 20.h, ), ), Spacer(), Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 24.w, height: 17.h, ), ), Icon( Icons.chevron_right, color: Color(0XFFD8D8D8), size: 16, ), ], ), SizedBox( height: 8.h, ), Row( children: [ Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 28.w, height: 17.h, ), ), SizedBox( width: 4.w, ), Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 213.w, height: 17.h, ), ), ], ), SizedBox( height: 4.h, ), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 52.w, height: 17.h, ), ), Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 69.w, height: 17.h, ), ), Spacer(), Shimmer.fromColors( baseColor: Color(0XFFD8D8D8), highlightColor: Color(0XFFD8D8D8), child: Container( color: Color(0XFFD8D8D8), width: 52.w, height: 17.h, ), ), ], ), ], ), ); }, ), ], ), ); } Widget shopItem(Store store) { return Container( decoration: BoxDecoration( borderRadius: new BorderRadius.circular(6), color: Colors.white, ), padding: EdgeInsets.all(12), margin: EdgeInsets.symmetric( horizontal: 16.w, vertical: 8.h, ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( flex: 1, child: Text( store.storeName ?? "", style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.semi_bold, color: Colors.black, ), ), ), GestureDetector( onTap: () { // Navigator.of(context).pushNamed('/router/union_detail_page', // arguments: {"id": store.id}); if (store.posType?.code == "NORMALSTORE") { Scan.toScan( context, store.id, store.tenantCode, store.storeName, apiService!, ); } else { String storeId = store.id ?? ""; String tenant = store.tenantCode ?? ""; miniLogin(apiService!, tenant, storeId, (token) { Navigator.of(context).pushNamed( '/router/store_order', arguments: { "id": store.id, "tenant": store.tenantCode, "storeName": store.storeName, "miniToken": token, }, ); }); } }, child: Text( S.of(context).chakan, style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.medium, color: Color(0xff32A060), ), ), ), Icon( Icons.chevron_right, color: Color(0xff32A060), size: 16, ), ], ), SizedBox( height: 8.h, ), Row( children: [ Text( "${S.of(context).dizhi}: ", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xff353535), ), ), Expanded( child: Text( store.address ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xff353535), ), ), flex: 1, ) ], ), SizedBox( height: 4.h, ), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 1, child: Text( S.of(context).yingyeshijian((store.openStartTime == null && store.openEndTime == null) ? S.of(context).quantian : "${store.openStartTime?.substring(0, store.openStartTime?.lastIndexOf(":"))} - ${store.openEndTime?.substring(0, store.openEndTime?.lastIndexOf(":"))}"), style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xff353535), ), ), ), if (((store.distance ?? 0) > 1000 ? S.of(context).gongli( ((store.distance ?? 0) / 1000 * 100).toInt() / 100.0) : S .of(context) .mi(((store.distance ?? 0) * 100).toInt() / 100.0)) != "0.0米") Text( (store.distance ?? 0) > 1000 ? S.of(context).gongli( ((store.distance ?? 0) / 1000 * 100).toInt() / 100.0) : S .of(context) .mi(((store.distance ?? 0) * 100).toInt() / 100.0), style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xff868686), ), ), ], ), ], ), ); } Widget consumeItem(UserBill userBill) { return Container( decoration: BoxDecoration( borderRadius: new BorderRadius.circular(6), color: Colors.white, ), padding: EdgeInsets.all(12), margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( userBill.name ?? "", style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.semi_bold, color: Colors.black, ), ), SizedBox( height: 4, ), Text( userBill.updateTime ?? "", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF4D4D4D), ), ), ], ), Text( "-${double.tryParse("${userBill.number}") ?? 0}元", style: TextStyle( fontSize: 18.sp, fontWeight: MyFontWeight.regular, color: Color(0xFF4D4D4D), ), ), ], ), ); } bool isRemake = true; // String totalPrice(orderInfo) { // if (orderInfo == null) return ""; // double totalPrice = (double.tryParse(orderInfo.orderSum) + // double.tryParse(orderInfo.postFee)); // if (orderInfo.orderDetail != null && // orderInfo.orderDetail.couponDTO != null) { // totalPrice -= double.tryParse(orderInfo.orderDetail.couponDTO.money); // } // return "$totalPrice"; // } // List goodsItem(List products) { // if (products.length > 3) { // products = products.sublist(0, 3); // } // return products // .map( // (e) => Container( // margin: EdgeInsets.symmetric(horizontal: 2.w), // child: Column( // mainAxisAlignment: MainAxisAlignment.spaceAround, // crossAxisAlignment: CrossAxisAlignment.center, // children: [ // MImage( // e.skuImg, // width: 75.w, // height: 75.h, // fit: BoxFit.contain, // errorSrc: "assets/image/default_1.webp", // fadeSrc: "assets/image/default_1.webp", // ), // SizedBox( // height: 4.h, // ), // if (isRemake) // Container( // width: 75.w, // child: Text( // e.productName, // maxLines: 1, // textAlign: TextAlign.center, // overflow: TextOverflow.ellipsis, // style: TextStyle( // fontSize: 10.sp, // fontWeight: MyFontWeight.regular, // color: Color(0xFF353535), // ), // ), // ), // ], // ), // ), // ) // .toList(); // } }