import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import '../../generated/l10n.dart'; import '../../retrofit/business_api.dart'; import '../../retrofit/data/base_data.dart'; import '../../retrofit/data/business_login_info.dart'; import '../../retrofit/data/business_store_list.dart'; import '../../utils/business_instance.dart'; import '../../view_widget/classic_header.dart'; import '../../view_widget/my_footer.dart'; class SelectShop extends StatefulWidget { final arguments; SelectShop({this.arguments}); @override State createState() { return _SelectShop(); } } class _SelectShop extends State { final RefreshController refreshController = RefreshController(); BusinessLoginInfo businessLoginInfo; BusinessApiService businessService; List records = []; int selectIndex = 0; @override void initState() { super.initState(); businessLoginInfo = widget.arguments["businessLoginInfo"]; records = widget.arguments["records"]; } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color(0xFFF8F8FA), appBar: MyAppBar( title: "选择门店", titleColor: Colors.black, leading: (widget.arguments["routeSource"] == "门店设置")?true:false, leadingColor: Colors.black, brightness: Brightness.dark, ), body: SmartRefresher( controller: refreshController, enablePullDown: true, enablePullUp: false, header: MyHeader( color: Colors.white, ), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), onRefresh: () {}, physics: BouncingScrollPhysics(), scrollController: ScrollController(), child: Container( height: double.infinity, padding: EdgeInsets.only(top: 13.h, left: 16.w, right: 16.w), child: Column( children: [ Row( children: [ Image.asset( "assets/image/bs_switch_shop.webp", width: 24, height: 24, ), SizedBox( width: 4.w, ), Text( (widget.arguments["routeSource"] == "门店设置")?"请选择门店":"请选择登录门店", style: TextStyle( fontSize: 15.sp, fontWeight: MyFontWeight.semi_bold, color: Color(0xFF1A1A1A)), ), ], ), SizedBox( height: 20.h, ), Expanded( child: ListView.builder( padding: EdgeInsets.zero, itemCount: (widget.arguments["routeSource"] == "门店设置") ? (records?.length ?? 0):(businessLoginInfo?.storeList?.length ?? 0), scrollDirection: Axis.vertical, shrinkWrap: true, physics: BouncingScrollPhysics(), itemBuilder: (context, position) { return GestureDetector( onTap: () { setState(() { selectIndex = position; }); }, child: (widget.arguments["routeSource"] == "门店设置") ? merchantItem(records[position], position): shopsItem(businessLoginInfo?.storeList[position], position), ); }, )), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { if(widget.arguments["routeSource"] == "门店设置"){ Navigator.of(context) .popAndPushNamed('/router/merchant_info',arguments: { "storeId": records[selectIndex]?.id ?? "", "storeName": records[selectIndex]?.storeName ?? "", "records": records[selectIndex], }); }else{ Navigator.of(context).pushReplacementNamed( '/router/business_page', arguments: { "selectStoreIndex": selectIndex, "businessLoginInfo": businessLoginInfo, }); } }, child: Container( width: double.infinity, padding: EdgeInsets.symmetric(vertical: 16.h), margin: EdgeInsets.only(bottom: 34.h, top: 10.h), alignment: Alignment.center, decoration: BoxDecoration( color: Color(0xFF30415B), borderRadius: BorderRadius.circular(27.w), ), child: Text( S.of(context).queding, style: TextStyle( fontWeight: MyFontWeight.bold, fontSize: 16.sp, color: Colors.white, ), ), ), ), ], ), ), ), ); } Widget shopsItem(StoreList storeList, index) { return Container( height: 52.h, margin: EdgeInsets.only(bottom: 12), child: Stack( alignment: Alignment.bottomRight, children: [ Container( height: 52.h, width: double.infinity, decoration: BoxDecoration( color: selectIndex == index ? Color(0xFFEFF5FF) : Colors.white, borderRadius: BorderRadius.circular(4.w), border: Border.all( color: selectIndex == index ? Color(0xFF30415B) : Colors.white, width: selectIndex == index ? 1.w : 0, ), ), padding: EdgeInsets.only( top: 16.h, bottom: 16.h, left: 16.w, right: 17.w), child: Text( storeList?.name ?? "", style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.medium, color: selectIndex == index ? Color(0xFF30415B) : Color(0xFF0D0D0D)), ), ), if (selectIndex == index) Image.asset( "assets/image/bs_shop.webp", width: 20, height: 20, fit: BoxFit.fill, ), ], ), ); } Widget merchantItem(Records records, index) { return Container( height: 52.h, margin: EdgeInsets.only(bottom: 12), child: Stack( alignment: Alignment.bottomRight, children: [ Container( height: 52.h, width: double.infinity, decoration: BoxDecoration( color: selectIndex == index ? Color(0xFFEFF5FF) : Colors.white, borderRadius: BorderRadius.circular(4.w), border: Border.all( color: selectIndex == index ? Color(0xFF30415B) : Colors.white, width: selectIndex == index ? 1.w : 0, ), ), padding: EdgeInsets.only( top: 16.h, bottom: 16.h, left: 16.w, right: 17.w), child: Text( records?.storeName ?? "", style: TextStyle( fontSize: 14.sp, fontWeight: MyFontWeight.medium, color: selectIndex == index ? Color(0xFF30415B) : Color(0xFF0D0D0D)), ), ), if (selectIndex == index) Image.asset( "assets/image/bs_shop.webp", width: 20, height: 20, fit: BoxFit.fill, ), ], ), ); } }