| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:url_launcher/url_launcher.dart';
- import '../util/api.dart';
- import '../util/models.dart';
- import '../showDialog.dart';
- import '../util/session.dart';
- import '../util/util.dart';
- import '../showAlert.dart';
- class OrderTakingPage extends StatefulWidget {
- OrderTakingPage({
- Key key
- }): super(key: key);
- _OrderTakingPageState createState() => _OrderTakingPageState();
- }
- class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeepAliveClientMixin {
- ScrollController _scrollController = ScrollController(); //初始化滚动轴监控对象
- List < OrderList > orderList = []; //订单列表
- bool hasNextPage = true;
- List lineList = []; //线路列表
- String stationId;
- List < bool > checkStatusList = [];
- bool showLineStatus = true;
- String lineIdStr = '';
- String oldLineIdStr = '';
- int page = 1;
- bool loadMoreOrder = true;
- @override
- void initState() {
- super.initState();
- getKey('stationId').then((value) {
- stationId = value;
- getLine().then((childValue) {
- getKey('lineIdStr').then((value) {
- if (value != null) {
- getOrderList(stationId,value, page).then((resp) {
- if (isNotError(context, resp) && this.mounted) {
- setState(() {
- orderList = OrderListObj.fromJson(resp.data).data.items;
-
- hasNextPage = OrderListObj.fromJson(resp.data).data.hasNextPage;
- });
- lineIdStr = value;
- }
- });
- } else {
- getOrderList(stationId,lineIdStr, page).then((resp) {
- if (isNotError(context, resp) && this.mounted) {
- setState(() {
- orderList = OrderListObj.fromJson(resp.data).data.items;
- hasNextPage = OrderListObj.fromJson(resp.data).data.hasNextPage;
- });
- }
- });
- }
- });
- });
- });
- _scrollController.addListener(() {
- if (!showLineStatus) {
- setState(() {
- showLineStatus = true;
- });
- switchLine(context);
- }
- if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
- if (hasNextPage && loadMoreOrder) {
- loadMoreOrder = false;
- page = ++page;
- getOrderList(stationId,lineIdStr, page).then((resp) {
- if (isNotError(context, resp) && this.mounted) {
- OrderListObj tempObj = OrderListObj.fromJson(resp.data);
- setState(() {
- orderList.addAll(tempObj.data.items);
- hasNextPage = tempObj.data.hasNextPage;
- });
- loadMoreOrder = true;
- } else {
- loadMoreOrder = true;
- }
- });
- }
- }
- });
- }
- Future getLine() async {
- setState(() {
- lineList.clear();
- });
- await getAllLine().then((resp) {
- if (isNotError(context, resp) && this.mounted) {
- setState(() {
- checkStatusList = [];
- lineList = StationLine.fromJson(resp.data).data;
- LineObj tempLine =LineObj(code:'xxxx',id:-1,name:'未知线路');//创建未知线路
- lineList.add(tempLine);//添加未知线路
- getKey('lineIdStr').then((value) {
- if (value != null) {
- for (int i = 0; i < lineList.length; i++) {
- if (value.indexOf(lineList[i].id.toString()) != -1) {
- checkStatusList.add(true);
- } else {
- checkStatusList.add(false);
- }
- if (i < lineList.length - 1) {
- lineIdStr += lineList[i].id.toString() + ',';
- } else {
- lineIdStr += lineList[i].id.toString();
- }
- }
- } else {
- for (int i = 0; i < lineList.length; i++) {
- checkStatusList.add(true);
- if (i < lineList.length - 1) {
- lineIdStr += lineList[i].id.toString() + ',';
- } else {
- lineIdStr += lineList[i].id.toString();
- }
- }
- }
- });
- });
- return lineIdStr;
- }
- });
- }
- @override
- bool get wantKeepAlive => true;
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Scaffold(
- appBar: AppBar(
- title: Text('接单', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
- centerTitle: true,
- backgroundColor: Color.fromRGBO(64, 98, 254, 1),
- actions: < Widget > [
- IconButton(icon: Icon(Icons.add_circle_outline),
- onPressed: () {
- setState(() {
- showLineStatus = !showLineStatus;
- });
- if (!showLineStatus) {
- getLine();
- } else {
- switchLine(context);
- }
- }, )
- ]
- ),
- body: Stack(
- children: < Widget > [
- RefreshIndicator(
- onRefresh: _onRefresh, //回调方法
- child: InkWell(
- child: Container(
- padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), 0),
- decoration: BoxDecoration(
- color: Color.fromRGBO(246, 246, 254, 1)
- ),
- child: ListView.builder(
- controller: _scrollController,
- physics: AlwaysScrollableScrollPhysics(),
- itemCount: orderList.length + 1,
- itemBuilder: (BuildContext context, int index) { //itemBuilder实际上就是一个map的循环
- if (index < orderList.length) {
- return OrderCardContainer(order: orderList[index], index: index, callback: (val) => deleteOrder(val));
- }
- if (hasNextPage) {
- return _getMoreWidget();
- } else {
- return _noMoreWidegt();
- }
- },
- )
- ),
- onTap: () {
- setState(() {
- showLineStatus = true;
- });
- switchLine(context);
- },
- ),
- ),
- Positioned(
- top: 0,
- right: 0,
- child:
- Offstage(
- offstage: showLineStatus,
- child: Container(
- width: ScreenUtil.getInstance().setWidth(350),
- height: ScreenUtil.getInstance().setHeight(500),
- margin: EdgeInsets.fromLTRB(0, 2, 8, 0),
- padding: EdgeInsets.fromLTRB(15, 0, 0, 0),
- decoration: BoxDecoration(
- color: Color.fromRGBO(76,76,76,1),
- borderRadius: BorderRadius.all(Radius.circular(4.0)),
- boxShadow: [ //阴影
- BoxShadow(
- color: Colors.black54,
- offset: Offset(2.0, 2.0),
- blurRadius: 4.0
- )
- ]
- ),
- child: lineList.length == 0 ? Center(
- child: Container(
- width: ScreenUtil.getInstance().setWidth(50),
- height: ScreenUtil.getInstance().setHeight(50),
- child: CircularProgressIndicator(
- )
- ),
- ) :
- ListView.builder(
- itemCount: lineList.length,
- itemBuilder: (BuildContext context, int index) { //itemBuilder实际上就是一个map的循环
- if (index < lineList.length) {
- return _lineWidget(lineList[index], index, checkStatusList[index]);
- }
- },
- ),
- ),
- )
- )
- ],
- )
- ),
- );
- }
- Widget _lineWidget(LineObj lineObj, int index, bool checked) {
- return InkWell(
- child: Container(
- height: ScreenUtil.getInstance().setHeight(80),
- decoration: BoxDecoration(
- border: BorderDirectional(bottom: BorderSide(color: Colors.white, width: 0.1))
- ),
- child: Row(
- children: < Widget > [
- Padding(
- padding: EdgeInsets.fromLTRB(0, 0, 15, 0),
- child: checked ? Image.asset('lib/images/icon_checked.png',
- width: ScreenUtil.getInstance().setWidth(30),
- height:ScreenUtil.getInstance().setWidth(30),
- ) : Icon(Icons.check, color: Color.fromRGBO(255, 255, 255, 0.0, )),
- ),
- Expanded(
- flex: 1,
- child: Container(
- padding: EdgeInsets.only(right: 15),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- Text(lineObj.name,overflow: TextOverflow.ellipsis, style: TextStyle(color: Colors.white,fontSize:ScreenUtil.getInstance().setSp(30)))
- ],
- ),
-
- )
- )
- ],
- ),
- ),
- onTap: () {
- setState(() {
- checkStatusList[index] = !checked;
- });
- },
- );
- }
- Widget _getMoreWidget() {
- return Center(
- child: Padding(
- padding: EdgeInsets.all(10.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: < Widget > [
- Text(
- '加载中...',
- style: TextStyle(fontSize: 16.0),
- ),
- Container(
- width: ScreenUtil.getInstance().setWidth(50),
- height: ScreenUtil.getInstance().setHeight(50),
- child: CircularProgressIndicator()
- )
- ],
- ),
- ),
- );
- }
- Widget _noMoreWidegt() {
- return Center(
- child: Padding(
- padding: EdgeInsets.all(10.0),
- child: Text(
- '没有更多数据了...',
- style: TextStyle(fontSize: 16.0),
- ),
- ),
- );
- }
- Future _onRefresh() async {
- page = 1;
- print(lineIdStr);
- await getOrderList(stationId,lineIdStr, page).then((resp) {
- if (isNotError(context, resp) && this.mounted) {
- setState(() {
- orderList = OrderListObj.fromJson(resp.data).data.items;
- });
- }
- });
- }
- void deleteOrder(val) { //确认接单后的操作
- setState(() {
- orderList.removeAt(val);
- if (orderList.length < 4) {
- if (hasNextPage) {
- setState(() {
- page = ++page;
- });
- getOrderList(stationId,lineIdStr, page).then((resp) {
- if (resp.success && resp.code == 1) {
- setState(() {
- orderList.addAll(resp.data.items);
- hasNextPage = resp.data.hasNextPage;
- });
- }
- });
- }
- }
- });
- }
- void switchLine(BuildContext context) { //切换线路
- lineIdStr = '';
- for (int i = 0; i < checkStatusList.length; i++) {
- if (checkStatusList[i]) {
- lineIdStr += lineList[i].id.toString() + ',';
- }
- }
- if (lineIdStr == '') {
- setState(() {
- orderList = [];
- hasNextPage = false;
- });
- return;
- }
- lineIdStr = lineIdStr.substring(0, lineIdStr.length - 1);
- getKey('oldLineIdStr').then((oldLineIdStr){
- if(oldLineIdStr == lineIdStr) return;
- setKey('oldLineIdStr', lineIdStr);
- setState(() {
- orderList = [];
- hasNextPage = true;
- });
- getOrderList(stationId,lineIdStr, page).then((resp) {
- if (isNotError(context, resp) && this.mounted) {
- OrderListObj tempObj = OrderListObj.fromJson(resp.data);
- setState(() {
- orderList = tempObj.data.items;
- hasNextPage = tempObj.data.hasNextPage;
- });
- oldLineIdStr = lineIdStr;
- setKey('lineIdStr', lineIdStr);
- }
- });
- });
- }
- }
- class OrderCardContainer extends StatefulWidget {
- final OrderList order;
- final int index;
- final callback;
- OrderCardContainer({
- Key key,
- @required this.order,
- @required this.index,
- @required this.callback
- }): super(key: key);
- _OrderCardContainerState createState() => _OrderCardContainerState();
- }
- class _OrderCardContainerState extends State < OrderCardContainer > with SingleTickerProviderStateMixin {
- Animation < dynamic > animation;
- AnimationController controller;
- String str = "联系方式";
- bool animationStatus = true;
- @override
- initState() {
- super.initState();
- controller = new AnimationController(duration: const Duration(milliseconds: 200), vsync: this);
- animation = Tween(begin: 0, end: 230).animate(controller);
- animation.addStatusListener((status) {
- if (status == AnimationStatus.completed) {
- //动画执行结束时反向执行动画
- setState(() {
- animationStatus = false;
- str = "收起";
- });
- } else if (status == AnimationStatus.dismissed) {
- //动画恢复到初始状态时执行动画(正向)
- setState(() {
- animationStatus = true;
- str = "联系方式";
- });
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- margin: EdgeInsets.all(4),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(8)),
- boxShadow: [
- BoxShadow(color: Color.fromRGBO(217, 226, 233, 0.5),offset: Offset(0, 2),blurRadius: 3.0),
- ]
- ),
- child: Container(
- padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), 0),
- child: Column(
- children: < Widget > [
- orderNoRow(widget.order.orderNo, widget.order.createTime),
- orderAddress(widget.order.sendCompanyName,widget.order.receiptCompanyName),
- orderItem('货物名称', widget.order.goods, 15),
- orderItem('货物件数', '${widget.order.goodsQuantity}件', 30),
- orderCutLine(),
- orderBtn(context, animationStatus, controller, str, widget.order.orderNo),
- AnimatedOpen(animation: animation, openInfo: widget.order, )
- ],
- ),
- )
- );
- }
- dispose() {
- //路由销毁时需要释放动画资源
- controller.dispose();
- super.dispose();
- }
- Widget orderBtn(BuildContext context, bool animationStatus, AnimationController controller, String str, String orderNo) {
- return Container(
- margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: < Widget > [
- InkWell(
- child: Container(
- width: ScreenUtil.getInstance().setWidth(100),
- height: ScreenUtil.getInstance().setHeight(48),
- color: Colors.white,
- child: Center(
- child: Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1)), ),
- )
- ),
- onTap: () {
- if (animationStatus) {
- //动画恢复到初始状态时执行动画(正向)
- controller.forward();
- } else {
- //动画执行结束时反向执行动画
- controller.reverse();
- }
- },
- ),
- InkWell(
- child: Container(
- width: ScreenUtil.getInstance().setWidth(94),
- height: ScreenUtil.getInstance().setWidth(48),
- decoration: BoxDecoration(
- color: Color.fromRGBO(252, 97, 128, 1),
- borderRadius: BorderRadius.all(Radius.circular(4.0))
- ),
- child: Center(
- child: Text("接单", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Colors.white), ),
- ),
- ),
- onTap: () {
- showDialog < Null > (
- context: context, //BuildContext对象
- barrierDismissible: false,
- builder: (BuildContext context) {
- return new LoadingDialog( //调用对话框
- text: '是否确认接单', childCallback: (val) {
- if (val) {
- orderReception(orderNo).then((resp) {
- if (isNotError(context, resp) && this.mounted) {
- OrderReception obj = OrderReception.fromJson(resp.data);
- if(obj.success){
- widget.callback(widget.index);
- }else{
- showError(obj.msg);
- }
- }
- });
- } else {
- return;
- }
- },
- );
- });
- },
- )
- ],
- )
- );
- }
-
- showError(String str) {
- showDialog < Null > (
- context: context, //BuildContext对象
- barrierDismissible: false,
- builder: (BuildContext context) {
- return MyAlertDialog( //调用对话框
- text: str, childCallback: (val) {},
- );
- });
- }
- }
- class AnimatedOpen extends AnimatedWidget {
- final OrderList openInfo;
- AnimatedOpen({
- Key key,
- Animation < dynamic > animation,
- @required this.openInfo
- }): super(key: key, listenable: animation);
- Widget build(BuildContext context) {
- final Animation < dynamic > animation = listenable;
- return Container(
- height: ScreenUtil.getInstance().setHeight(animation.value),
- child: orderDetailInfo(openInfo),
- );
- }
- }
- Widget orderNoRow(String orderNo, int createTime) { //订单号及时间
- String date = fromatDate(createTime);
- return Container(
- margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: < Widget > [
- Text("订单号:${orderNo}", style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
- Text('${date}', style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
- ],
- ),
- );
- }
- Widget orderAddress(String startAddress, String endAddress) { //运送路线
- return Container(
- margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
- child: Row(children: < Widget > [
- Text('${startAddress} ---> ${endAddress}',
- overflow: TextOverflow.ellipsis, style: TextStyle(color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(30)), ),
- ], )
- );
- }
- Widget orderCutLine() { //分割线
- return Container(
- margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
- height: ScreenUtil.getInstance().setHeight(1),
- color: Color.fromRGBO(223, 223, 223, 1),
- );
- }
- Widget orderDetailInfo(OrderList obj) { //卡片展开信息
- String sendAddress = obj.sendCompanyProvinceName +' '+ (obj.sendCompanyCityName=='市辖区'?'':obj.sendCompanyCityName) +' '+ obj.sendCompanyAreaName+' '+ obj.sendCompanyAddress;
- String receiptAddress = obj.receiptCompanyProvinceName + ' '+(obj.receiptCompanyCityName=='市辖区'?'':obj.receiptCompanyCityName) +' '+ obj.receiptCompanyAreaName+' '+ obj.receiptCompanyAddress;
- return Container(
- child: Wrap(
- children: < Widget > [
- orderCutLine(),
- orderPhone('发件电话', obj.sendCompanyPhone, 15),
- orderItem('发件地址', sendAddress, 30),
- orderPhone('收件电话', obj.receiptCompanyPhone, 15),
- orderItem('收件地址', receiptAddress, 30),
- ],
- )
- );
- }
- Widget orderItem(String key, String value, int marginBottom) { //货物名称,件数
- return Container(
- margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(marginBottom)),
- child: Row(children: < Widget > [
- Text('${key}:${value}',
- overflow: TextOverflow.ellipsis,
- style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
- ], )
- );
- }
- Widget orderPhone(String key, String value, int marginBottom) {
- return InkWell(
- child: Container(
- margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(marginBottom)),
- child: Row(children: < Widget > [
- Text('${key}:', style: TextStyle(color: Color.fromRGBO(153, 153, 153, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
- Text('${value}', style: TextStyle(color: Color.fromRGBO(64, 98, 254, 1), fontSize: ScreenUtil.getInstance().setSp(24)), ),
- ], )
- ),
- onTap: () async {
- String phone = 'tel:${value}';
- print(phone);
- if (await canLaunch(phone)) {
- await (launch(phone));
- } else {
- throw 'Could not launch $value';
- }
- },
- );
- }
|