Browse Source

Merge remote-tracking branch 'origin/master'

tags/0.0.1
PH2 4 years ago
parent
commit
7004b535b4
9 changed files with 276 additions and 69 deletions
  1. +23
    -4
      lib/pages/home_page/home_page.dart
  2. +52
    -0
      lib/pages/orders_page/bloc/order_content_bloc.dart
  3. +36
    -12
      lib/pages/orders_page/models/order_filter_model.dart
  4. +36
    -0
      lib/pages/orders_page/models/order_model.dart
  5. +49
    -11
      lib/pages/orders_page/order_content_page.dart
  6. +13
    -9
      lib/pages/orders_page/orders_page.dart
  7. +34
    -23
      lib/pages/orders_page/views/order_filter.dart
  8. +17
    -5
      lib/pages/orders_page/views/order_item_widget.dart
  9. +16
    -5
      lib/pages/orders_page/views/order_tabbar_widget.dart

+ 23
- 4
lib/pages/home_page/home_page.dart View File

@@ -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<HomePage> {
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<bool> _checkLimit(BaseTabModel model) async {
if (model.requiredLogin == '1') {
UserInfoModel user =
await Provider.of<UserInfoNotifier>(context, listen: false)
.getUserInfoModel();
print(user.toString());
if (user?.token == null || user.token == '') {
print('need login...');
RouterUtil.goLogin(context);
return false;
}
}
return true;
}
}

+ 52
- 0
lib/pages/orders_page/bloc/order_content_bloc.dart View File

@@ -0,0 +1,52 @@
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<OrderModel> _orders = List();

StreamController<List<OrderModel>> _ordersController =
StreamController<List<OrderModel>>();

Stream<List<OrderModel>> get outData => _ordersController.stream;

@override
void dispose() {
_ordersController.close();
_ordersController = null;
}

void loadData(OrderFilterModel filter) {
Map<String, dynamic> 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 ?? [];

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.addAll(list.map((item) {
return OrderModel.fromJson(Map<String, dynamic>.from(item));
}).toList());

_ordersController.add(_orders);
}
}

+ 36
- 12
lib/pages/orders_page/models/order_filter_model.dart View File

@@ -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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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;
}
}

+ 36
- 0
lib/pages/orders_page/models/order_model.dart View File

@@ -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<String, dynamic> json) {
itemId = json['item_id'];
title = json['title'];
price = json['price'];
commission = json['commission'];
commissionRate = json['commission_rate'];
imgUrl = json['img_url'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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;
}
}

+ 49
- 11
lib/pages/orders_page/order_content_page.dart View File

@@ -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<OrderContentPage> {
@override
Widget build(BuildContext context) {
return BlocProvider<OrderContentBloc>(
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<OrderContentContainer> {
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<List<OrderModel>>(
stream: _bloc.outData,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container();
}
List<OrderModel> orders = snapshot.data;
if (orders.length == 0) {
return Container(
child: Center(
child: EmptyWidget(tips: '暂无订单,快去下一单吧'),
),
);
}
return ListView.builder(
itemCount: orders.length,
itemBuilder: (context, index) {
return OrderItemWidget(orders[index]);
});
});
}
}

+ 13
- 9
lib/pages/orders_page/orders_page.dart View File

@@ -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;
});
},
),
)
],
),


+ 34
- 23
lib/pages/orders_page/views/order_filter.dart View File

@@ -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<OrderFilterWidget> {
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: double.infinity,
color: Color(0x55555555),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
_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: <Widget>[
_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<OrderFilterWidget> {
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(),


+ 17
- 5
lib/pages/orders_page/views/order_item_widget.dart View File

@@ -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),


+ 16
- 5
lib/pages/orders_page/views/order_tabbar_widget.dart View File

@@ -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)),
),
);
}


Loading…
Cancel
Save