| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- import 'dart:convert';
- import 'package:azlistview/azlistview.dart';
- import 'package:bbyyy/beans/my_shop_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/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: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);
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- 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
- Widget build(BuildContext context) {
- return Scaffold(
- body: Stack(
- children: [
- Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- colors: MyColors.lg,
- ),
- ),
- height: 152,
- child: SafeArea(
- bottom: false,
- child: Stack(
- children: [
- Container(
- height: 50,
- child: Text(
- '货帮',
- style: TextStyle(color: Colors.white, fontSize: 16),
- ),
- alignment: Alignment.center,
- ),
- 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,
- )
- ],
- alignment: Alignment.topCenter,
- ),
- ),
- alignment: Alignment.topCenter,
- ),
- 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: true,
- child: AzListView(
- padding: EdgeInsets.only(right: 20),
- itemBuilder: (c, index) {
- return getGangItem(data[index]);
- },
- itemCount: data.length,
- data: data,
- ),
- ),
- )
- ],
- ),
- );
- }
- 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,
- padding: EdgeInsets.only(right: 14),
- 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, right: 14),
- height: 0.5,
- color: MyColors.cE7E7E7,
- )
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ),
- ),
- );
- } else {
- return GestureDetector(
- onTap: () {
- MyTools().toPage(context, GangInPage(data, null), (then) {
- if(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: ClipRRect(
- child: MyViews().netImg(imgURL(data.shopPic), 45, 45,
- placeholder: 'images/svg/占位图.svg'),
- borderRadius: BorderRadius.all(Radius.circular(4)),
- ),
- ),
- Expanded(
- child: Container(
- height: 45,
- padding: EdgeInsets.only(right: 14),
- 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.role == shopUserOwner,
- ),
- ],
- ),
- Row(
- children: [
- 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, right: 14),
- height: 0.5,
- color: MyColors.cE7E7E7,
- )
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ),
- ),
- );
- }
- }
- @override
- // TODO: implement wantKeepAlive
- bool get wantKeepAlive => true;
- queryGang() {
- MyDio().query({
- "key": "shop_user",
- "filters": {
- "or": true,
- "conditions": [
- "role!=$shopUserOwner",
- "user_uid==${MyCookie().getUID()}",
- "review_state==1"
- ],
- "filters": [
- {
- "conditions": ["role==$shopUserOwner", "user_uid==${MyCookie().getUID()}"]
- }
- ]
- },
- "dims": shopUserDims,
- "paging": [page, 1000],
- "order_by": ["shop_name,DESC"]
- }, (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);
- // });
- _handleList(data);
- setState(() {
- endRe(controller);
- });
- }
- }, (error) {});
- }
- void _handleList(List<MyShopBeanDataData> list) {
- if (list.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);
- 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();
- }
- }
|