import 'dart:convert'; import 'package:bbyyy/beans/my_shop_bean_entity.dart'; import 'package:bbyyy/beans/store_bean_entity.dart'; import 'package:bbyyy/https/MyDio.dart'; import 'package:bbyyy/https/url.dart'; import 'package:bbyyy/my_tools/const.dart'; import 'package:bbyyy/my_tools/dims.dart'; import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart'; import 'package:bbyyy/my_tools/event_bus.dart'; import 'package:bbyyy/my_tools/my_colors.dart'; import 'package:bbyyy/my_tools/my_cookie.dart'; import 'package:bbyyy/my_tools/my_tools.dart'; import 'package:bbyyy/my_tools/my_views.dart'; import 'package:bbyyy/paegs/gang_page/create_a_gang_page/create_a_gang_page.dart'; import 'package:bbyyy/paegs/gang_page/gang_in_page/gang_in_page.dart'; import 'package:bbyyy/paegs/gang_page/join_the_gang_page/join_the_gang_page.dart'; import 'package:bbyyy/paegs/gang_page/query_gang_page/query_gang_page.dart'; import 'package:bbyyy/paegs/mine_page/order_page/order_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:lpinyin/lpinyin.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'application_page/application_page.dart'; class GangPage extends StatefulWidget { @override _GangPageState createState() => _GangPageState(); } class _GangPageState extends State with AutomaticKeepAliveClientMixin { List popItems = []; List data = []; List applications = []; int page = 1; RefreshController controller = RefreshController(initialRefresh: true); bool needRE = false; int sIndex = 0; @override void initState() { // TODO: implement initState super.initState(); EventBus().on('needRE', (arg) { print(arg); needRE = arg; }); if (!MyCookie().underReview) popItems.add(PopupMenuItem( child: Text( '创建货帮', style: TextStyle(color: MyColors.c666666, fontSize: 14), ), value: '创建货帮', )); popItems.add(PopupMenuItem( child: Text( '加入货帮', style: TextStyle(color: MyColors.c666666, fontSize: 14), ), value: '加入货帮', )); } @override void dispose() { // TODO: implement dispose super.dispose(); EventBus().off('needRE'); } @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ appBar(context), Container( margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 50), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(16), topRight: Radius.circular(16))), child: SmartRefresher( controller: controller, onRefresh: onRefresh, onLoading: onLoading, enablePullDown: true, enablePullUp: false, child: ListView.builder( padding: EdgeInsets.only(right: 20), itemBuilder: (c, index) { return getGangItem(data[index]); }, itemCount: data.length, ), ), ) ], ), ); } Container appBar(BuildContext context) { return Container( decoration: BoxDecoration( gradient: LinearGradient( colors: MyColors.lg, ), ), height: 152, child: SafeArea( bottom: false, child: Stack( children: [ Container( height: 50, child: Row( children: [ GestureDetector( onTap: () { setState(() { sIndex = 0; controller.requestRefresh(); }); }, child: Text( '货帮', style: TextStyle( color: Colors.white, fontSize: sIndex == 0 ? 16 : 15, fontWeight: sIndex == 0 ? FontWeight.bold : FontWeight.normal), ), ), Container( width: 56, ), GestureDetector( onTap: () { setState(() { sIndex = 1; controller.requestRefresh(); }); }, child: Text( '关注', style: TextStyle( color: Colors.white, fontSize: sIndex == 1 ? 16 : 15, fontWeight: sIndex == 1 ? FontWeight.bold : FontWeight.normal), ), ), ], mainAxisAlignment: MainAxisAlignment.center, ), alignment: Alignment.center, ), Row( children: [ GestureDetector( onTap: () { MyTools().toPage(context, QueryGangPage(), (then) {}); }, behavior: HitTestBehavior.translucent, child: Container( child: SvgPicture.asset( 'images/svg/搜索.svg', color: Colors.white, ), width: 50, height: 50, padding: EdgeInsets.all(15), ), ), Container( height: 50, child: PopupMenuButton( itemBuilder: (BuildContext context) { return popItems; }, onSelected: (v) { if (v == '加入货帮') { MyTools().toPage(context, JoinTheGangPage(), (then) { controller.requestRefresh(); }); } else if (v == '创建货帮') { MyTools().toPage(context, CreateAGangPage(), (then) { controller.requestRefresh(); }); } }, child: Container( padding: EdgeInsets.all(8), margin: EdgeInsets.only(right: 6), child: SvgPicture.asset('images/svg/添加.svg'), ), ), alignment: Alignment.centerRight, ), ], mainAxisAlignment: MainAxisAlignment.end, ) ], alignment: Alignment.topCenter, ), ), alignment: Alignment.topCenter, ); } Widget getGangItem(MyShopBeanDataData data) { if (data.shopPic == null) { return GestureDetector( onTap: () { MyTools().toPage(context, ApplicationPage(), (then) { controller.requestRefresh(); }); }, behavior: HitTestBehavior.translucent, child: Container( height: 73, child: Column( children: [ Expanded( child: Row( children: [ Container( margin: EdgeInsets.only(left: 14, right: 14), child: SvgPicture.asset( 'images/svg/入帮申请.svg', height: 45, width: 45, ), ), Expanded( child: Container( height: 45, child: Column( children: [ Row( children: [ Expanded( child: Text( '入帮申请', style: TextStyle( color: MyColors.c333333, fontSize: 15), )), Text( '', style: TextStyle( color: MyColors.c888888, fontSize: 12), ), ], ), Row( children: [ Expanded( child: Text( applications.length == 0 ? '暂无申请' : '你有新的申请消息', style: TextStyle( color: MyColors.c888888, fontSize: 12), ), ), Visibility( visible: applications.length != 0, child: Container( decoration: BoxDecoration( color: MyColors.cFF4233, borderRadius: BorderRadius.all( Radius.circular(8))), constraints: BoxConstraints(minWidth: 16), height: 16, padding: EdgeInsets.only(left: 5, right: 5), child: Text( '${applications.length}', style: TextStyle( color: Colors.white, fontSize: 8), ), alignment: Alignment.center, ), ) ], ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ) ], ), ), Container( margin: EdgeInsets.only(left: 73), height: 0.5, color: MyColors.cE7E7E7, ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ); } else { return GestureDetector( onTap: () { if (data.shopState == shopStateNormal) { MyTools().toPage(context, GangInPage(data, null), (then) { if (then == '删除货帮') { controller.requestRefresh(); } else if (needRE) { needRE = false; controller.requestRefresh(); } }); } else { String s = ''; if (data.shopState == shopStateArrearage) { s = '欠费'; } else if (data.shopState == shopStateBanned) { s = '被禁'; } else if (data.shopState == shopStateClosed) { s = '关闭'; } showDialog( context: context, builder: (BuildContext context) { return Material( color: Colors.black12, child: Center( child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: Colors.white, ), height: 180, margin: EdgeInsets.symmetric(horizontal: 18), padding: EdgeInsets.symmetric(horizontal: 12, vertical: 12), child: Column( children: [ Row( children: [ GestureDetector( child: Icon(Icons.clear), onTap: () { Navigator.pop(context); }, ), ], mainAxisAlignment: MainAxisAlignment.end, ), Expanded( child: Center( child: Container( child: MyViews().myText( '该店铺已$s,请尽快处理', MyColors.c333333, 14), margin: EdgeInsets.symmetric(horizontal: 20), ), ), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.only(bottom: 12), ), Container( margin: EdgeInsets.symmetric(horizontal: 10), child: Row( children: [ Expanded( child: GestureDetector( onTap: () { Navigator.pop(context); dismissTheBulletFrame(data); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.circular(20), bottomLeft: Radius.circular(20), ), border: Border.all( color: MyColors.cFF4233, width: 1.1), color: Colors.white), child: MyViews() .myText('解散货帮', MyColors.cFF4233, 14), height: 40, alignment: Alignment.center, ), ), ), Expanded( child: GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { if (data.shopState == shopStateArrearage) { MyTools().toPage( context, OrderPage( index: 2, ), (then) { onRefresh(); }); } else if (data.shopState == shopStateBanned) { Navigator.pop(context); } else if (data.shopState == shopStateClosed) { Navigator.pop(context); } }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topRight: Radius.circular(20), bottomRight: Radius.circular(20), ), color: MyColors.cFF4233), height: 40, child: MyViews() .myText('去缴费', Colors.white, 14), alignment: Alignment.center, ), ), ) ], ), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ), ); }, ); } }, behavior: HitTestBehavior.translucent, child: Container( height: 73, child: Column( children: [ Expanded( child: Row( children: [ Container( margin: EdgeInsets.only(left: 14, right: 14), child: ClipRRect( child: MyViews().netImg(imgURL(data.shopPic), 45, 45, placeholder: 'images/svg/占位图.svg'), borderRadius: BorderRadius.all(Radius.circular(4)), ), decoration: BoxDecoration( border: Border.all(color: MyColors.cE7E7E7), borderRadius: BorderRadius.circular(4) ), ), Expanded( child: Container( height: 45, child: Column( children: [ Row( children: [ Expanded( child: Text( data.shopName, style: TextStyle( color: MyColors.c333333, fontSize: 15), )), Visibility( child: Container( decoration: BoxDecoration( color: MyColors.cFFCD00, borderRadius: BorderRadius.only( topLeft: Radius.circular(6), bottomRight: Radius.circular(6))), height: 18, width: 30, child: Text( '自建', style: TextStyle( color: Colors.white, fontSize: 10), ), alignment: Alignment.center, padding: EdgeInsets.only(bottom: 2), ), visible: data.ownerUid == MyCookie().getUID(), ), ], ), Row( children: [ Visibility( visible: !data.privateShop, child: Container( decoration: BoxDecoration( border: Border.all( color: MyColors.cFF4233, width: 1), borderRadius: BorderRadius.circular(8), ), height: 16, width: 28, child: Text( '公开', style: TextStyle( color: MyColors.cFF4233, fontSize: 10), ), alignment: Alignment.center, margin: EdgeInsets.only(right: 5), ), ), Expanded( child: Text( 'ID:${data.shopUid}', style: TextStyle( color: MyColors.c888888, fontSize: 12), ), ), Visibility( child: Container( decoration: BoxDecoration( color: MyColors.cFF4233, borderRadius: BorderRadius.only( topLeft: Radius.circular(6), bottomRight: Radius.circular(6))), height: 18, width: 30, child: Text( '欠费', style: TextStyle( color: Colors.white, fontSize: 10), ), alignment: Alignment.center, padding: EdgeInsets.only(bottom: 2), ), visible: data.shopState == shopStateArrearage, ), ], ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ) ], ), ), Container( margin: EdgeInsets.only(left: 73), height: 0.5, color: MyColors.cE7E7E7, ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ); } } dismissTheBulletFrame(MyShopBeanDataData data) { TextEditingController controller = TextEditingController(); showDialog( context: context, builder: (BuildContext context) { return Material( color: Colors.black12, child: Center( child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: Colors.white, ), height: 180, margin: EdgeInsets.symmetric(horizontal: 18), padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12), child: Column( children: [ Expanded( child: Center( child: Column( children: [ Container( child: MyViews().myText( '确认解散${data.shopName}(${data.shopUid})?', MyColors.c333333, 14), margin: EdgeInsets.symmetric(horizontal: 20), ), TextField( controller: controller, decoration: InputDecoration( border: InputBorder.none, disabledBorder: InputBorder.none, enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, hintText: '输入“解散货帮”确认解散', hintStyle: TextStyle( color: MyColors.c999999, fontSize: 16), isDense: true, contentPadding: const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5)), textAlign: TextAlign.center, ) ], mainAxisAlignment: MainAxisAlignment.spaceAround, ), ), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.only(bottom: 12), ), Container( margin: EdgeInsets.symmetric(horizontal: 10), child: Row( children: [ Expanded( child: GestureDetector( onTap: () { Navigator.pop(context); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.circular(20), bottomLeft: Radius.circular(20), ), border: Border.all( color: MyColors.cFF4233, width: 1.1), color: Colors.white), child: MyViews().myText('取消', MyColors.cFF4233, 14), height: 40, alignment: Alignment.center, ), ), ), Expanded( child: GestureDetector( behavior: HitTestBehavior.translucent, onTap: () { if (controller.text.toString() == '解散货帮') { Navigator.pop(context); EasyLoading.instance ..contentPadding = EdgeInsets.symmetric( horizontal: 20, vertical: 12) ..alignment = Alignment.center ..loadingStyle = EasyLoadingStyle.light ..contentMargin = EdgeInsets.all(20); EasyLoading.show(); delShop(data); } else { showToast('请输入“解散货帮”'); } }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topRight: Radius.circular(20), bottomRight: Radius.circular(20), ), color: MyColors.cFF4233), height: 40, child: MyViews().myText('确认', Colors.white, 14), alignment: Alignment.center, ), ), ) ], ), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ), ); }, ); } @override // TODO: implement wantKeepAlive bool get wantKeepAlive => true; queryGang() { var dJson; var conditions1 = [ "role!=$shopUserOwner", "user_uid==${MyCookie().getUID()}", "review_state==1" ]; var conditions2 = [ "role==$shopUserOwner", "user_uid==${MyCookie().getUID()}" ]; if (sIndex == 0) { conditions1.add('private_shop==true'); dJson = { "key": "shop_user", "filters": { "or": true, "conditions": conditions1, "filters": [ {"conditions": conditions2} ] }, "dims": shopUserDims, "paging": [page, 5000], "order_by": ["shop_name,DESC"] }; } else { conditions1.add('private_shop==false'); dJson = { "key": "shop_user", "filters": {"conditions": conditions1}, "dims": shopUserDims, "paging": [page, 5000], "order_by": ["shop_name,DESC"] }; } // if (sIndex == 1) { // conditions1.add('collected == true'); // conditions2.add('collected == true'); // } MyDio().query(dJson, (response, hasError) { if (!hasError) { MyShopBeanEntity entity = MyShopBeanEntity().fromJson(json.decode(response.data.toString())); if (page == 1) { data.clear(); } data.addAll(entity.data.data); // data.sort((a, b) { // String aT = PinyinHelper.getShortPinyin(a.shopName); // String bT = PinyinHelper.getShortPinyin(b.shopName); // return aT.compareTo(bT); // }); data.forEach((element) { element.tagIndex = PinyinHelper.getPinyinE(element.shopName).toLowerCase(); }); data.sort((left, right) => left.tagIndex.compareTo(right.tagIndex)); if (applications.isNotEmpty && page == 1 && sIndex == 0) { MyShopBeanDataData shopB = MyShopBeanDataData(); shopB.shopName = '0'; // add hotCityList. data.insert(0, shopB); } // _handleList(data); setState(() { endRe(controller); }); } }, (error) {}); } /*void _handleList(List list) { List selfBuilt = []; list.forEach((element) { if (element.ownerUid == MyCookie().getUID()) { selfBuilt.add(element); } }); selfBuilt.forEach((element) { list.removeWhere((data) => data.id == element.id); }); if (list.isEmpty && selfBuilt.isEmpty) return; for (int i = 0, length = list.length; i < length; i++) { String pinyin = PinyinHelper.getPinyinE(list[i].shopName); String tag = pinyin.substring(0, 1).toUpperCase(); if (RegExp('[A-Z]').hasMatch(tag)) { list[i].tagIndex = tag; } else { list[i].tagIndex = '#'; } } // A-Z sort. SuspensionUtil.sortListBySuspensionTag(list); data.insertAll(0, selfBuilt); if (applications.isNotEmpty) { MyShopBeanDataData shopB = MyShopBeanDataData(); shopB.shopName = '★'; // add hotCityList. data.insert(0, shopB); } // show sus tag. SuspensionUtil.setShowSuspensionStatus(data); setState(() {}); }*/ enquiryApplication() { MyDio().query({ "key": "shop_user", "filters": { "conditions": ["owner_uid==${MyCookie().getUID()}", "review_state==0"] }, "dims": shopUserDims, "paging": [1, 2000] }, (response, hasError) { if (!hasError) { MyShopBeanEntity entity = MyShopBeanEntity().fromJson(json.decode(response.data.toString())); applications.clear(); applications.addAll(entity.data.data); } setState(() { endRe(controller); }); }, (error) {}); } void onRefresh() { page = 1; queryGang(); enquiryApplication(); } void onLoading() { page++; queryGang(); enquiryApplication(); } void delShop(MyShopBeanDataData data) { MyDio().query({ "key": "shop", "filters": { "conditions": ["uid == ${data.shopUid}"] }, "dims": shopDims, "paging": [1, 5] }, (response, hasError) { if (!hasError) { StoreBeanEntity entity = StoreBeanEntity().fromJson(json.decode(response.data.toString())); MyDio().del({ 'key': 'shop', 'ids': [entity.data.data[0].id] }, (response, hasError) { if (!hasError) { showToast('删除成功'); onRefresh(); } }, (error) {}); } }, (error) {}); } }