diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 1b512ee..16bf5b7 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -297,7 +297,7 @@ }, { "name": "path_provider", - "rootUri": "file:///Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/path_provider-1.6.21", + "rootUri": "file:///Users/fnuser/.pub-cache/hosted/pub.flutter-io.cn/path_provider-1.6.22", "packageUri": "lib/", "languageVersion": "2.1" }, @@ -620,7 +620,7 @@ "languageVersion": "2.8" } ], - "generated": "2020-10-23T06:24:35.938865Z", + "generated": "2020-10-27T02:24:43.007495Z", "generator": "pub", "generatorVersion": "2.8.2" } diff --git a/example/lib/main.dart b/example/lib/main.dart index 704282d..6e7cb23 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -39,7 +39,7 @@ class _MyAppState extends State { BaseWidgetRegister.init(); print('初始化百川'); FlutterAlibc.initAlibc(version: "", appName: "").then((result) { - print("白川"+'${result.errorCode} ${result.errorMessage}'); + print("白川" + '${result.errorCode} ${result.errorMessage}'); }); } @@ -53,8 +53,17 @@ class _MyAppState extends State { ChangeNotifierProvider.value(value: UserInfoNotifier()), ], child: MaterialApp( - home: LaunchPage( - builder: (context) => HomePage(), + home: GestureDetector( + onTap: () { + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus && + currentFocus.focusedChild != null) { + FocusManager.instance.primaryFocus.unfocus(); + } + }, + child: LaunchPage( + builder: (context) => HomePage(), + ), ), ), ); diff --git a/lib/pages/orders_page/bloc/order_content_bloc.dart b/lib/pages/orders_page/bloc/order_content_bloc.dart index 633ffee..ec1fb89 100644 --- a/lib/pages/orders_page/bloc/order_content_bloc.dart +++ b/lib/pages/orders_page/bloc/order_content_bloc.dart @@ -12,6 +12,8 @@ class OrderContentBloc extends BlocBase { StreamController>(); Stream> get outData => _ordersController.stream; + String _state; + OrderFilterModel _filter; @override void dispose() { @@ -19,30 +21,46 @@ class OrderContentBloc extends BlocBase { _ordersController = null; } - void loadData(String state, OrderFilterModel filter) { - Map params = filter.toJson(); + void refresh(String state, OrderFilterModel filter) { + _state = state; + _filter = filter; + + _filter.pageNo = '1'; + _loadData(state, filter); + } + + void _loadData(String state, OrderFilterModel filter) { + Map params = _filter.toJson(); params.removeWhere((key, value) => value == null || value == ''); - params['state'] = state; + params['state'] = _state; NetUtil.request('/api/v1/order', method: NetMethod.POST, params: params, onCache: (data) { - _loadData(data); + _parseData(data); }, onSuccess: (data) { - _loadData(data); + _parseData(data); }); } - void _loadData(dynamic data) { + void loadMore() { + _loadData(_state, _filter); + } + + void _parseData(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); + if (_filter.pageNo == null || + _filter.pageNo == '' || + _filter.pageNo == '1') { + _orders.clear(); + } + + if (list.length > 0) { + if (_filter.pageNo == null || _filter.pageNo == '') { + _filter.pageNo = '2'; + } else { + _filter.pageNo = ((int.tryParse(_filter.pageNo) ?? 1) + 1).toString(); + } + } _orders.addAll(list.map((item) { return OrderModel.fromJson(Map.from(item)); diff --git a/lib/pages/orders_page/bloc/order_search_bloc.dart b/lib/pages/orders_page/bloc/order_search_bloc.dart new file mode 100644 index 0000000..d0ceb84 --- /dev/null +++ b/lib/pages/orders_page/bloc/order_search_bloc.dart @@ -0,0 +1,62 @@ +import 'dart:async'; + +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 OrderSearchBloc extends BlocBase { + List _orders = List(); + + StreamController> _ordersController = + StreamController>(); + + Stream> get outData => _ordersController.stream; + int _page = 1; + String _keyword = ''; + + @override + void dispose() { + _ordersController.close(); + _ordersController = null; + } + + void refresh(String keyword) { + _keyword = keyword; + _page = 1; + _loadData(_keyword); + } + + void _loadData(String keyword) { + Map params = Map(); + params['keyword'] = keyword; + params['page_no'] = _page.toString(); + NetUtil.request('/api/v1/order', method: NetMethod.POST, params: params, + onCache: (data) { + _parseData(data); + }, onSuccess: (data) { + _parseData(data); + }); + } + + void loadMore() { + _loadData(_keyword); + } + + void _parseData(dynamic data) { + List list = data ?? []; + + if (_page <= 1) { + _orders.clear(); + } + + if (list.length > 0) { + _page++; + } + + _orders.addAll(list.map((item) { + return OrderModel.fromJson(Map.from(item)); + }).toList()); + + _ordersController.add(_orders); + } +} diff --git a/lib/pages/orders_page/order_content_page.dart b/lib/pages/orders_page/order_content_page.dart index c7ef74f..91088cb 100644 --- a/lib/pages/orders_page/order_content_page.dart +++ b/lib/pages/orders_page/order_content_page.dart @@ -1,4 +1,6 @@ +import 'package:event_bus/event_bus.dart'; import 'package:flutter/material.dart'; +import 'package:pull_to_refresh/pull_to_refresh.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'; @@ -11,8 +13,11 @@ class OrderContentPage extends StatefulWidget { final String state; // 订单状态 final OrderPageStyleModel style; final OrderFilterModel filter; + final int index; + final EventBus eventBus; - const OrderContentPage(this.state, {Key key, this.filter, this.style}) + const OrderContentPage(this.state, + {Key key, this.filter, this.style, this.index, this.eventBus}) : super(key: key); @override @@ -24,7 +29,13 @@ class _OrderContentPageState extends State { Widget build(BuildContext context) { return BlocProvider( bloc: OrderContentBloc(), - child: OrderContentContainer(widget.state, widget.filter, widget.style), + child: OrderContentContainer( + widget.state, + widget.filter, + widget.style, + index: widget.index, + eventBus: widget.eventBus, + ), ); } } @@ -33,8 +44,11 @@ class OrderContentContainer extends StatefulWidget { final String state; // 订单状态 final OrderFilterModel filter; final OrderPageStyleModel style; + final int index; + final EventBus eventBus; - const OrderContentContainer(this.state, this.filter, this.style, {Key key}) + const OrderContentContainer(this.state, this.filter, this.style, + {Key key, this.index, this.eventBus}) : super(key: key); @override @@ -43,11 +57,19 @@ class OrderContentContainer extends StatefulWidget { class _OrderContentContainerState extends State { OrderContentBloc _bloc; + RefreshController _refreshController = + RefreshController(initialRefresh: false); @override void initState() { _bloc = BlocProvider.of(context); - _bloc.loadData(widget.state, widget.filter); + _bloc.refresh(widget.state, widget.filter); + + widget.eventBus.on().listen((index) { + if (index == widget.index) { + _bloc.refresh(widget.state, widget.filter); + } + }); super.initState(); } @@ -61,6 +83,7 @@ class _OrderContentContainerState extends State { if (snapshot.data == null) { return Container(); } + _refreshController.refreshCompleted(); List orders = snapshot.data; if (orders.length == 0) { return Container( @@ -69,14 +92,26 @@ class _OrderContentContainerState extends State { ), ); } - return ListView.builder( - itemCount: orders.length, - itemBuilder: (context, index) { - return OrderItemWidget( - orders[index], - widget.style, - ); - }); + return SmartRefresher( + enablePullDown: true, + enablePullUp: true, + header: WaterDropHeader(), + controller: _refreshController, + onLoading: () { + _bloc.loadMore(); + }, + onRefresh: () { + _bloc.refresh(widget.state, widget.filter); + }, + child: ListView.builder( + itemCount: orders.length, + itemBuilder: (context, index) { + return OrderItemWidget( + orders[index], + widget.style, + ); + }), + ); }); } } diff --git a/lib/pages/orders_page/order_search_page.dart b/lib/pages/orders_page/order_search_page.dart index 43aee78..1587d5c 100644 --- a/lib/pages/orders_page/order_search_page.dart +++ b/lib/pages/orders_page/order_search_page.dart @@ -1,43 +1,99 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:pull_to_refresh/pull_to_refresh.dart'; +import 'package:zhiying_base_widget/pages/orders_page/bloc/order_search_bloc.dart'; +import 'package:zhiying_base_widget/pages/orders_page/models/order_model.dart'; +import 'package:zhiying_base_widget/pages/orders_page/models/order_page_style_model.dart'; +import 'package:zhiying_base_widget/pages/orders_page/views/order_item_widget.dart'; import 'package:zhiying_base_widget/widgets/empty/empty_widget.dart'; +import 'package:zhiying_comm/util/base_bloc.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; // 订单搜索页面 class OrderSearchPage extends StatefulWidget { + final OrderPageStyleModel style; + + const OrderSearchPage(this.style, {Key key}) : super(key: key); + @override _OrderSearchPageState createState() => _OrderSearchPageState(); } class _OrderSearchPageState extends State { + @override + Widget build(BuildContext context) { + return BlocProvider( + bloc: OrderSearchBloc(), + child: _OrderSearchContainer(widget.style), + ); + } +} + +class _OrderSearchContainer extends StatefulWidget { + final OrderPageStyleModel style; + + const _OrderSearchContainer(this.style, {Key key}) : super(key: key); + + @override + _OrderSearchContainerState createState() => _OrderSearchContainerState(); +} + +class _OrderSearchContainerState extends State<_OrderSearchContainer> { final TextEditingController _keywordController = TextEditingController(); + OrderSearchBloc _bloc; + RefreshController _refreshController = + RefreshController(initialRefresh: false); @override void initState() { - // TODO: implement initState + _bloc = BlocProvider.of(context); super.initState(); } @override void dispose() { - _keywordController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { - return GestureDetector( - onTap: () { - FocusScope.of(context).requestFocus(FocusNode()); - }, - child: Scaffold( - appBar: _createNav(), - body: SafeArea( - child: Container( - width: double.infinity, - height: double.infinity, - child: Center(child: EmptyWidget())), - ), + return Scaffold( + appBar: _createNav(), + body: SafeArea( + child: StreamBuilder>( + stream: _bloc.outData, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.data == null) { + return Container(); + } + _refreshController.refreshCompleted(); + List orders = snapshot.data; + if (orders.length == 0) { + return Container( + child: Center( + child: EmptyWidget(), + ), + ); + } + return SmartRefresher( + enablePullDown: false, + enablePullUp: true, + controller: _refreshController, + onLoading: () { + _bloc.loadMore(); + }, + child: ListView.builder( + itemCount: orders.length, + itemBuilder: (context, index) { + return OrderItemWidget( + orders[index], + widget.style, + ); + }), + ); + }), ), ); } @@ -106,5 +162,10 @@ class _OrderSearchPageState extends State { void _search(String keyword) { FocusScope.of(context).requestFocus(FocusNode()); + if (_keywordController.text == null || _keywordController.text == '') { + Fluttertoast.showToast(msg: '请输入搜索关键词'); + return; + } + _bloc.refresh(_keywordController.text); } } diff --git a/lib/pages/orders_page/orders_page.dart b/lib/pages/orders_page/orders_page.dart index f37157d..5804d33 100644 --- a/lib/pages/orders_page/orders_page.dart +++ b/lib/pages/orders_page/orders_page.dart @@ -1,3 +1,4 @@ +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/bloc/order_page_bloc.dart'; @@ -10,6 +11,7 @@ import 'package:zhiying_base_widget/pages/orders_page/views/order_filter.dart'; import 'package:zhiying_base_widget/pages/orders_page/views/order_serch_widget.dart'; import 'package:zhiying_base_widget/pages/orders_page/views/order_tabbar_widget.dart'; import 'package:zhiying_comm/util/base_bloc.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; // 订单页面 class OrdersPage extends StatefulWidget { @@ -96,6 +98,8 @@ class _OrdersContainerState extends State<_OrdersContainer> List _titles = []; List _contents = []; + EventBus _eventBus = EventBus(); + @override void initState() { _bloc = BlocProvider.of(context); @@ -106,6 +110,12 @@ class _OrdersContainerState extends State<_OrdersContainer> super.initState(); } + @override + void dispose() { + _tabController?.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return StreamBuilder( @@ -116,8 +126,13 @@ class _OrdersContainerState extends State<_OrdersContainer> return Container(); } List type = model.filter.orderState; + + _tabController?.dispose(); _tabController = TabController(length: type?.length ?? 0, vsync: this); + _tabController.addListener(() { + Logger.debug('????? ${_tabController.index.toString()}'); + }); _titles = List.generate(type?.length, (index) => type[index].name); _contents = List.generate( type?.length ?? 0, @@ -125,6 +140,8 @@ class _OrdersContainerState extends State<_OrdersContainer> type[index].type, style: model, filter: _filter, + index: index, + eventBus: _eventBus, ), ); @@ -135,7 +152,7 @@ class _OrdersContainerState extends State<_OrdersContainer> onTap: () { Navigator.of(context) .push(CupertinoPageRoute(builder: (BuildContext context) { - return OrderSearchPage(); + return OrderSearchPage(model); })); }, ), @@ -167,6 +184,18 @@ class _OrdersContainerState extends State<_OrdersContainer> _isFilterShow = false; }); }, + onConfirm: (_) { + _eventBus.fire(_tabController.index); + setState(() { + _isFilterShow = false; + }); + }, + onReset: (_) { + _eventBus.fire(_tabController.index); + setState(() { + _isFilterShow = false; + }); + }, ), ) ], diff --git a/lib/pages/orders_page/views/order_filter.dart b/lib/pages/orders_page/views/order_filter.dart index c6ff8ea..f16c45c 100644 --- a/lib/pages/orders_page/views/order_filter.dart +++ b/lib/pages/orders_page/views/order_filter.dart @@ -9,11 +9,19 @@ import 'package:zhiying_comm/zhiying_comm.dart'; class OrderFilterWidget extends StatefulWidget { final OrderPageStyleModel style; final OrderFilterModel filterModel; + final VoidCallback onDismiss; + final ValueChanged onConfirm; + final ValueChanged onReset; - const OrderFilterWidget(this.style, this.filterModel, - {Key key, this.onDismiss}) - : super(key: key); + const OrderFilterWidget( + this.style, + this.filterModel, { + Key key, + this.onDismiss, + this.onConfirm, + this.onReset, + }) : super(key: key); @override _OrderFilterWidgetState createState() => _OrderFilterWidgetState(); @@ -181,12 +189,18 @@ class _OrderFilterWidgetState extends State { child: Row( children: [ Expanded( - child: Container( - color: Colors.transparent, - child: Center( - child: Text( - '重置', - style: TextStyle(fontSize: 15, color: Color(0xff999999)), + child: GestureDetector( + onTap: () { + Logger.debug('重置'); + _resetFilter(); + }, + child: Container( + color: Colors.transparent, + child: Center( + child: Text( + '重置', + style: TextStyle(fontSize: 15, color: Color(0xff999999)), + ), ), ), ), @@ -198,12 +212,18 @@ class _OrderFilterWidgetState extends State { color: Color(0xffe3e3e3), ), Expanded( - child: Container( - color: Colors.transparent, - child: Center( - child: Text( - '确定', - style: TextStyle(fontSize: 15, color: Colors.redAccent), + child: GestureDetector( + onTap: () { + Logger.debug('确定'); + _confirmFilter(); + }, + child: Container( + color: Colors.transparent, + child: Center( + child: Text( + '确定', + style: TextStyle(fontSize: 15, color: Colors.redAccent), + ), ), ), ), @@ -221,7 +241,8 @@ class _OrderFilterWidgetState extends State { starTime = '不限'; } - String endTime = formatter.format(DateTime(_endTime)); + String endTime = + formatter.format(DateTime.fromMillisecondsSinceEpoch(_endTime)); if (_endTime == 0) { endTime = '不限'; } @@ -318,4 +339,57 @@ class _OrderFilterWidgetState extends State { } setState(() {}); } + + // 确定筛选条件 + void _confirmFilter() { + List list = widget?.style?.filter?.providerType ?? []; + if (_currentProvider < list.length) { + widget?.filterModel?.provider = list[_currentProvider].type; + } + List types = widget?.style?.filter?.orderType ?? []; + if (_currentType < types.length) { + widget?.filterModel?.type = types[_currentType].type; + } + + var formatter = new DateFormat('yyyy-MM-dd'); + if (_startTime == 0) { + widget.filterModel?.startTime = ''; + } else { + String starTime = + formatter.format(DateTime.fromMillisecondsSinceEpoch(_startTime)); + var sTime = DateTime.parse(starTime); + var _intendtime = (sTime.millisecondsSinceEpoch / 1000).ceil(); //方法一 + Logger.debug('${_intendtime.toString()}'); + widget.filterModel?.startTime = _intendtime.toString(); + } + + if (_endTime == 0) { + widget.filterModel?.endTime = ''; + } else { + String endTime = + formatter.format(DateTime.fromMillisecondsSinceEpoch(_endTime)); + var eTime = DateTime.parse('${endTime} 23:59:59'); + var _intendtime = (eTime.millisecondsSinceEpoch / 1000).ceil(); //方法一 + Logger.debug('${_intendtime.toString()}'); + widget.filterModel?.endTime = _intendtime.toString(); + } + if (widget?.onConfirm != null) { + widget.onConfirm(widget.filterModel); + } + } + + void _resetFilter() { + widget.filterModel?.type = ''; + widget.filterModel?.provider = ''; + widget.filterModel?.startTime = ''; + widget.filterModel?.endTime = ''; + _currentProvider = 0; //订单来源 + _currentType = 0; // 订单类型 + _startTime = 0; // 起始时间 + _endTime = 0; // 结束时间 + setState(() {}); + if (widget?.onReset != null) { + widget.onReset(widget.filterModel); + } + } } diff --git a/lib/pages/orders_page/views/order_tabbar_widget.dart b/lib/pages/orders_page/views/order_tabbar_widget.dart index 68c54b3..ce1dd4b 100644 --- a/lib/pages/orders_page/views/order_tabbar_widget.dart +++ b/lib/pages/orders_page/views/order_tabbar_widget.dart @@ -37,6 +37,7 @@ class OrderTabbarWidget extends StatelessWidget { labelColor: HexColor.fromHex(model?.appActivateColor ?? '#ff4242'), unselectedLabelColor: Color(0xff999999), + tabs: titles.map((item) { return MyTab( // icon: CachedNetworkImage(imageUrl: item?.with_icon_color ?? '', width: 14,),