| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871 |
- 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<GangPage>
- with AutomaticKeepAliveClientMixin {
- List<PopupMenuItem> popItems = [];
- List<MyShopBeanDataData> data = [];
- List<MyShopBeanDataData> 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)),
- ),
- ),
- 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<MyShopBeanDataData> list) {
- List<MyShopBeanDataData> 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) {});
- }
- }
|