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] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=A2=E5=8D=95=E6=A0=B7?= =?UTF-8?q?=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)), ), ); }