From cdf3c59716de52283e92bddee2212083d282c674 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Fri, 16 Oct 2020 17:12:59 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orders_page/bloc/order_content_bloc.dart | 42 +++++++++++++ .../models/order_filter_model.dart | 48 +++++++++++---- lib/pages/orders_page/models/order_model.dart | 36 +++++++++++ lib/pages/orders_page/order_content_page.dart | 60 +++++++++++++++---- lib/pages/orders_page/orders_page.dart | 22 ++++--- lib/pages/orders_page/views/order_filter.dart | 57 +++++++++++------- .../views/order_tabbar_widget.dart | 21 +++++-- 7 files changed, 226 insertions(+), 60 deletions(-) create mode 100644 lib/pages/orders_page/bloc/order_content_bloc.dart create mode 100644 lib/pages/orders_page/models/order_model.dart diff --git a/lib/pages/orders_page/bloc/order_content_bloc.dart b/lib/pages/orders_page/bloc/order_content_bloc.dart new file mode 100644 index 0000000..95a183b --- /dev/null +++ b/lib/pages/orders_page/bloc/order_content_bloc.dart @@ -0,0 +1,42 @@ +import 'dart:async'; + +import 'package:zhiying_base_widget/pages/orders_page/models/order_filter_model.dart'; +import 'package:zhiying_base_widget/pages/orders_page/models/order_model.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +class OrderContentBloc extends BlocBase { + List _orders = List(); + + StreamController> _ordersController = + StreamController>(); + + Stream> get outData => _ordersController.stream; + + @override + void dispose() { + _ordersController.close(); + _ordersController = null; + } + + void loadData(OrderFilterModel filter) { + Map params = filter.toJson(); + params.removeWhere((key, value) => value == null || value == ''); + NetUtil.request('/api/v1/order', method: NetMethod.POST, params: params, + onCache: (data) { + _loadData(data); + }, onSuccess: (data) { + _loadData(data); + }); + } + + void _loadData(dynamic data) { + List list = data ?? []; + + _orders = list.map((item) { + return OrderModel.fromJson(Map.from(item)); + }).toList(); + + _ordersController.add(_orders); + } +} diff --git a/lib/pages/orders_page/models/order_filter_model.dart b/lib/pages/orders_page/models/order_filter_model.dart index 1508809..b846e13 100644 --- a/lib/pages/orders_page/models/order_filter_model.dart +++ b/lib/pages/orders_page/models/order_filter_model.dart @@ -1,21 +1,45 @@ // 订单筛选条件 class OrderFilterModel { - final String state; // 否 string 订单状态0已付款,1已收货,2成功,3失效 - final String keyword; // 否 string 关键字 - final String start_time; // 否 string 开始时间 - final String end_time; // 否 string 结束时间 - final String type; // 否 string 订单类型self自购, share分享, fans粉丝 - final String provider; // 否 string 供应商taobao, jd, pdd, vip, kaola,suning,own自营 - final String page_no; // 否 string 页码 - final String page_size; + String state; + String keyword; + String startTime; + String endTime; + String type; + String provider; + String pageNo; + String pageSize; OrderFilterModel( {this.state, this.keyword, - this.start_time, - this.end_time, + this.startTime, + this.endTime, this.type, this.provider, - this.page_no, - this.page_size}); // 否 string 页数 + this.pageNo, + this.pageSize}); + + OrderFilterModel.fromJson(Map json) { + state = json['state']; + keyword = json['keyword']; + startTime = json['start_time']; + endTime = json['end_time']; + type = json['type']; + provider = json['provider']; + pageNo = json['page_no']; + pageSize = json['page_size']; + } + + Map toJson() { + final Map data = new Map(); + data['state'] = this.state; + data['keyword'] = this.keyword; + data['start_time'] = this.startTime; + data['end_time'] = this.endTime; + data['type'] = this.type; + data['provider'] = this.provider; + data['page_no'] = this.pageNo; + data['page_size'] = this.pageSize; + return data; + } } diff --git a/lib/pages/orders_page/models/order_model.dart b/lib/pages/orders_page/models/order_model.dart new file mode 100644 index 0000000..7e52ef0 --- /dev/null +++ b/lib/pages/orders_page/models/order_model.dart @@ -0,0 +1,36 @@ +class OrderModel { + String itemId; + String title; + String price; + String commission; + String commissionRate; + String imgUrl; + + OrderModel( + {this.itemId, + this.title, + this.price, + this.commission, + this.commissionRate, + this.imgUrl}); + + OrderModel.fromJson(Map json) { + itemId = json['item_id']; + title = json['title']; + price = json['price']; + commission = json['commission']; + commissionRate = json['commission_rate']; + imgUrl = json['img_url']; + } + + Map toJson() { + final Map data = new Map(); + data['item_id'] = this.itemId; + data['title'] = this.title; + data['price'] = this.price; + data['commission'] = this.commission; + data['commission_rate'] = this.commissionRate; + data['img_url'] = this.imgUrl; + return data; + } +} diff --git a/lib/pages/orders_page/order_content_page.dart b/lib/pages/orders_page/order_content_page.dart index 0e061ac..8bd38aa 100644 --- a/lib/pages/orders_page/order_content_page.dart +++ b/lib/pages/orders_page/order_content_page.dart @@ -1,10 +1,13 @@ -import 'package:event_bus/event_bus.dart'; import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/pages/orders_page/bloc/order_content_bloc.dart'; +import 'package:zhiying_base_widget/pages/orders_page/models/order_filter_model.dart'; +import 'package:zhiying_base_widget/pages/orders_page/models/order_model.dart'; import 'package:zhiying_base_widget/pages/orders_page/views/order_item_widget.dart'; -import 'package:zhiying_comm/zhiying_comm.dart'; +import 'package:zhiying_base_widget/widgets/empty/empty_widget.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; class OrderContentPage extends StatefulWidget { - final EventBus filter; + final OrderFilterModel filter; const OrderContentPage({Key key, this.filter}) : super(key: key); @@ -13,22 +16,57 @@ class OrderContentPage extends StatefulWidget { } class _OrderContentPageState extends State { + @override + Widget build(BuildContext context) { + return BlocProvider( + bloc: OrderContentBloc(), + child: OrderContentContainer(widget.filter), + ); + } +} + +class OrderContentContainer extends StatefulWidget { + final OrderFilterModel filter; + + const OrderContentContainer(this.filter, {Key key}) : super(key: key); + + @override + _OrderContentContainerState createState() => _OrderContentContainerState(); +} + +class _OrderContentContainerState extends State { + OrderContentBloc _bloc; + @override void initState() { - // 每次滑动刷新数据 - widget.filter?.streamController?.add((filter) { - Logger.debug(filter.toString()); - }); + _bloc = BlocProvider.of(context); + _bloc.loadData(widget.filter); + super.initState(); } @override Widget build(BuildContext context) { print(context.toString()); - return ListView.builder( - itemCount: 20, - itemBuilder: (context, index) { - return OrderItemWidget(); + return StreamBuilder>( + stream: _bloc.outData, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.data == null) { + return Container(); + } + List orders = snapshot.data; + if (orders.length == 0) { + return Container( + child: Center( + child: EmptyWidget(tips: '暂无订单,快去下一单吧'), + ), + ); + } + return ListView.builder( + itemCount: 20, + itemBuilder: (context, index) { + return OrderItemWidget(); + }); }); } } diff --git a/lib/pages/orders_page/orders_page.dart b/lib/pages/orders_page/orders_page.dart index ca6df4a..2c365b6 100644 --- a/lib/pages/orders_page/orders_page.dart +++ b/lib/pages/orders_page/orders_page.dart @@ -1,4 +1,3 @@ -import 'package:event_bus/event_bus.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:zhiying_base_widget/pages/orders_page/models/order_filter_model.dart'; @@ -80,7 +79,6 @@ class _OrdersContainerState extends State<_OrdersContainer> TabController _tabController; GlobalKey _tabKey = GlobalKey(); - final EventBus _eventBus = EventBus(); final OrderFilterModel _filter = OrderFilterModel(); bool _isFilterShow = false; @@ -99,22 +97,22 @@ class _OrdersContainerState extends State<_OrdersContainer> _tabController = TabController(length: 6, vsync: this); _contents = [ OrderContentPage( - filter: _eventBus, + filter: _filter, ), OrderContentPage( - filter: _eventBus, + filter: _filter, ), OrderContentPage( - filter: _eventBus, + filter: _filter, ), OrderContentPage( - filter: _eventBus, + filter: _filter, ), OrderContentPage( - filter: _eventBus, + filter: _filter, ), OrderContentPage( - filter: _eventBus, + filter: _filter, ), ]; super.initState(); @@ -152,7 +150,13 @@ class _OrdersContainerState extends State<_OrdersContainer> ), Visibility( visible: _isFilterShow, - child: OrderFilterWidget(), + child: OrderFilterWidget( + onDismiss: () { + setState(() { + _isFilterShow = false; + }); + }, + ), ) ], ), diff --git a/lib/pages/orders_page/views/order_filter.dart b/lib/pages/orders_page/views/order_filter.dart index 281141e..9157cfd 100644 --- a/lib/pages/orders_page/views/order_filter.dart +++ b/lib/pages/orders_page/views/order_filter.dart @@ -2,6 +2,10 @@ import 'package:flutter/material.dart'; import 'package:zhiying_base_widget/widgets/others/action_date_alert/action_date_alert.dart'; class OrderFilterWidget extends StatefulWidget { + final VoidCallback onDismiss; + + const OrderFilterWidget({Key key, this.onDismiss}) : super(key: key); + @override _OrderFilterWidgetState createState() => _OrderFilterWidgetState(); } @@ -9,26 +13,32 @@ class OrderFilterWidget extends StatefulWidget { class _OrderFilterWidgetState extends State { @override Widget build(BuildContext context) { - return Container( - width: double.infinity, - height: double.infinity, - color: Color(0x55555555), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - _creteTitle('订单来源'), - _createTags(), - _creteTitle('订单类型'), - _createTags(), - _creteTitle('订单时间'), - _creteTime(), - Container( - width: double.infinity, - height: 0.5, - color: Color(0xffe3e3e3), + return GestureDetector( + onTap: widget.onDismiss, + child: Container( + width: double.infinity, + height: double.infinity, + color: Color(0x55555555), + child: GestureDetector( + onTap: () {}, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + _creteTitle('订单来源'), + _createTags(), + _creteTitle('订单类型'), + _createTags(), + _creteTitle('订单时间'), + _creteTime(), + Container( + width: double.infinity, + height: 0.5, + color: Color(0xffe3e3e3), + ), + _createButtons(), + ], ), - _createButtons(), - ], + ), ), ); } @@ -60,12 +70,13 @@ class _OrderFilterWidgetState extends State { runSpacing: 10, children: List.generate(10, (index) { return Container( - padding: EdgeInsets.only(left: 8, right: 8, top: 4, bottom: 4), + padding: EdgeInsets.only(left: 12, right: 12, top: 6, bottom: 6), decoration: BoxDecoration( - color: Colors.blue, borderRadius: BorderRadius.circular(5)), + color: Color(0xfff1f1f1), + borderRadius: BorderRadius.circular(5)), child: Text( - 'aaaa', - style: TextStyle(fontSize: 12), + '全部', + style: TextStyle(fontSize: 12, color: Color(0xff999999)), ), ); }).toList(), diff --git a/lib/pages/orders_page/views/order_tabbar_widget.dart b/lib/pages/orders_page/views/order_tabbar_widget.dart index 158687e..882b66f 100644 --- a/lib/pages/orders_page/views/order_tabbar_widget.dart +++ b/lib/pages/orders_page/views/order_tabbar_widget.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/widgets/search/widget/my_tab.dart'; class OrderTabbarWidget extends StatelessWidget { final TabController controller; @@ -25,9 +26,16 @@ class OrderTabbarWidget extends StatelessWidget { controller: controller, isScrollable: true, indicatorSize: TabBarIndicatorSize.label, - tabs: titles - .map((title) => OrderTabbarItemWidget(title: title)) - .toList(), + // tabs: widgets, + indicatorColor: Color(0xffff4242), + labelColor: Color(0xffff4242), + unselectedLabelColor: Color(0xff999999), + tabs: titles.map((item) { + return MyTab( + // icon: CachedNetworkImage(imageUrl: item?.with_icon_color ?? '', width: 14,), + text: item, + ); + }).toList(), ), ), GestureDetector( @@ -52,8 +60,10 @@ class OrderTabbarWidget extends StatelessWidget { class OrderTabbarItemWidget extends StatelessWidget { final String title; + final bool isSelected; - const OrderTabbarItemWidget({Key key, this.title}) : super(key: key); + const OrderTabbarItemWidget({Key key, this.title, this.isSelected = false}) + : super(key: key); @override Widget build(BuildContext context) { @@ -61,7 +71,8 @@ class OrderTabbarItemWidget extends StatelessWidget { height: 26, child: Text( title, - style: TextStyle(color: Color(0xFFFF4242)), + style: TextStyle( + color: isSelected ? Color(0xFFFF4242) : Color(0xff999999)), ), ); } From e81a3506a7847aee01219c95e9052095978c0406 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Fri, 16 Oct 2020 17:25:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../orders_page/bloc/order_content_bloc.dart | 10 +++++++++ lib/pages/orders_page/order_content_page.dart | 4 ++-- .../orders_page/views/order_item_widget.dart | 22 ++++++++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/pages/orders_page/bloc/order_content_bloc.dart b/lib/pages/orders_page/bloc/order_content_bloc.dart index 95a183b..4ebb1a7 100644 --- a/lib/pages/orders_page/bloc/order_content_bloc.dart +++ b/lib/pages/orders_page/bloc/order_content_bloc.dart @@ -33,6 +33,16 @@ class OrderContentBloc extends BlocBase { void _loadData(dynamic data) { List list = data ?? []; + OrderModel model = OrderModel(); + model.itemId = '6918577752399759376'; + model.imgUrl = + 'https://t7.baidu.com/it/u=3616242789,1098670747&fm=79&app=86&size=h300&n=0&g=4n&f=jpeg?sec=1603444938&t=04aeb23595ac79d419be19ab92bea668'; + model.title = '乐町百褶半身裙秋冬女2019新款复古麻花半身裙甜美百褶半身裙'; + model.price = '108'; + model.commission = '0'; + model.commissionRate = '9.2'; + _orders.add(model); + _orders = list.map((item) { return OrderModel.fromJson(Map.from(item)); }).toList(); diff --git a/lib/pages/orders_page/order_content_page.dart b/lib/pages/orders_page/order_content_page.dart index 8bd38aa..de1671f 100644 --- a/lib/pages/orders_page/order_content_page.dart +++ b/lib/pages/orders_page/order_content_page.dart @@ -63,9 +63,9 @@ class _OrderContentContainerState extends State { ); } return ListView.builder( - itemCount: 20, + itemCount: orders.length, itemBuilder: (context, index) { - return OrderItemWidget(); + return OrderItemWidget(orders[index]); }); }); } diff --git a/lib/pages/orders_page/views/order_item_widget.dart b/lib/pages/orders_page/views/order_item_widget.dart index c134fa3..0221a8c 100644 --- a/lib/pages/orders_page/views/order_item_widget.dart +++ b/lib/pages/orders_page/views/order_item_widget.dart @@ -1,6 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:zhiying_base_widget/pages/orders_page/models/order_model.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; class OrderItemWidget extends StatelessWidget { + final OrderModel model; + + const OrderItemWidget(this.model, {Key key}) : super(key: key); + @override Widget build(BuildContext context) { return Container( @@ -56,7 +62,13 @@ class OrderItemWidget extends StatelessWidget { margin: EdgeInsets.only(right: 10), width: 96, height: 96, - color: Colors.black12, + child: ClipRRect( + borderRadius: BorderRadius.circular(8), + child: CachedNetworkImage( + imageUrl: model.imgUrl ?? '', + fit: BoxFit.cover, + ), + ), ), Expanded( child: Column( @@ -80,20 +92,20 @@ class OrderItemWidget extends StatelessWidget { padding: EdgeInsets.only(left: 2, right: 2, top: 3, bottom: 3), margin: EdgeInsets.only(right: 4), child: Text( - '类型', + '淘宝', style: TextStyle( fontSize: 9, height: 1, - color: Colors.purpleAccent, + color: Colors.white, ), ), decoration: BoxDecoration( - color: Colors.amber, borderRadius: BorderRadius.circular(2.5)), + color: Colors.redAccent, borderRadius: BorderRadius.circular(2.5)), ), )); list.add( TextSpan( - text: '桶装水抽水器饮水机泵器动桶装水抽水器饮水机泵器动', + text: model.title, style: TextStyle( fontSize: 15, color: Color(0xff333333), From 41ccf420cf0b391be0522b69f7f6ed4e8124cabf Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Fri, 16 Oct 2020 17:26:03 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/orders_page/bloc/order_content_bloc.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pages/orders_page/bloc/order_content_bloc.dart b/lib/pages/orders_page/bloc/order_content_bloc.dart index 4ebb1a7..ac769bb 100644 --- a/lib/pages/orders_page/bloc/order_content_bloc.dart +++ b/lib/pages/orders_page/bloc/order_content_bloc.dart @@ -43,9 +43,9 @@ class OrderContentBloc extends BlocBase { model.commissionRate = '9.2'; _orders.add(model); - _orders = list.map((item) { + _orders.addAll(list.map((item) { return OrderModel.fromJson(Map.from(item)); - }).toList(); + }).toList()); _ordersController.add(_orders); } From 116c2fbe028e6603d7172fb10f0782e447f82779 Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Fri, 16 Oct 2020 18:11:12 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BA=95=E9=83=A8?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/home_page/home_page.dart | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/pages/home_page/home_page.dart b/lib/pages/home_page/home_page.dart index 7205df4..d4355a0 100644 --- a/lib/pages/home_page/home_page.dart +++ b/lib/pages/home_page/home_page.dart @@ -3,6 +3,7 @@ import 'dart:convert' as convert; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'package:zhiying_base_widget/utils/contants.dart'; import 'package:zhiying_comm/models/base/base_tab_model.dart'; import 'package:zhiying_comm/util/image_util.dart'; @@ -105,12 +106,30 @@ class _HomePageState extends State { unselectedFontSize: 11, currentIndex: _currentIndex, elevation: 0, - onTap: ((index) { - setState(() { - _currentIndex = index; - }); + onTap: ((index) async { + BaseTabModel model = BaseTabModel.fromJson(tabs[index]); + if (await _checkLimit(model)) { + setState(() { + _currentIndex = index; + }); + } }), //底部导航栏 items: items); } + + Future _checkLimit(BaseTabModel model) async { + if (model.requiredLogin == '1') { + UserInfoModel user = + await Provider.of(context, listen: false) + .getUserInfoModel(); + print(user.toString()); + if (user?.token == null || user.token == '') { + print('need login...'); + RouterUtil.goLogin(context); + return false; + } + } + return true; + } }