import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'order_management_page/order_detail_page.dart';
import '../showDialog.dart';
class OrderManagementPage extends StatefulWidget {
  final Widget child;

  OrderManagementPage({
    Key key,
    this.child
  }): super(key: key);

  _OrderManagementPageState createState() => _OrderManagementPageState();
}

class _OrderManagementPageState extends State < OrderManagementPage > with AutomaticKeepAliveClientMixin {
  @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: () {},
          //   )
          // ],
        ),
        body: Container(
          decoration: BoxDecoration(
            color: Color.fromRGBO(246, 246, 254, 1)
          ),
          child: QueryWidget()

        ),
        resizeToAvoidBottomPadding: false //键盘弹出，页面不跟随向上滑动,防止出现溢出错误
      )
    );
  }
  @override
  bool get wantKeepAlive => true;
}

class QueryWidget extends StatefulWidget { //搜索栏
  final Widget child;

  QueryWidget({
    Key key,
    this.child
  }): super(key: key);

  _QueryWidgetState createState() => _QueryWidgetState();
}

class _QueryWidgetState extends State < QueryWidget > {
  //单号的输入框控制器
  TextEditingController _orderController = TextEditingController();
  ScrollController _scrollController =ScrollController();

  GlobalKey _globalKey = GlobalKey(); //搜索栏key
  List < bool > statusList = [true, false, false];
  double inputPostX = 0;
  double inputPostY = 0;
  double inputWidth = 0;
  double inputHeight = 0;
  bool showStatus = true; //提示层显示状态
  String _orderNo = "";

  @override
  void initState() {
    super.initState();
    _scrollController.addListener((){
      if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
        print("滑到底部了");
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: < Widget > [
        Container(
          child: Column(
            children: < Widget > [
              Container(
                color: Colors.white,
                height: ScreenUtil.getInstance().setHeight(222),
                padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), 0),
                child: Column(
                  children: < Widget > [
                    Container(
                      key: _globalKey,
                      height: ScreenUtil.getInstance().setHeight(100),
                      decoration: BoxDecoration(
                        border: Border.all(color: Color.fromRGBO(204, 204, 204, 1), width: 1),
                        borderRadius: BorderRadius.all(Radius.circular(5))
                      ),
                      child: Row(
                        children: < Widget > [
                          Expanded(
                            child: TextField(
                              controller: _orderController,
                              keyboardType: TextInputType.number,
                              autocorrect: true,
                              decoration: InputDecoration(
                                border: InputBorder.none,
                                hintText: "输入运单号后6位查询物流",
                                hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(26), color: Color.fromRGBO(155, 155, 155, 1)),
                                contentPadding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), 0, ScreenUtil.getInstance().setWidth(30), 0)
                              ),
                              onTap: () {
                                RenderObject inputObj = _globalKey.currentContext.findRenderObject();
                                setState(() {
                                  inputWidth = inputObj.paintBounds.size.width;
                                  inputHeight = inputObj.paintBounds.size.height;
                                  inputPostX = inputObj.getTransformTo(null).getTranslation().x;
                                  inputPostY = ScreenUtil.getInstance().setWidth(20) + inputHeight;
                                });
                              },
                              onChanged: ((value) {
                                print(value);
                                setState(() {
                                  _orderNo = value;
                                });
                                if (_orderNo.length >= 6) {
                                  setState(() {
                                    showStatus = false;
                                  });
                                } else {
                                  setState(() {
                                    showStatus = true;
                                  });
                                }
                              }),
                              onEditingComplete: () {
                                FocusScope.of(context).requestFocus(FocusNode());
                                setState(() {
                                  showStatus = true;
                                });
                              },
                            ),
                          ),
                          IconButton(
                            icon: Image.asset('lib/images/icon_saoyisao.png',
                              width: ScreenUtil.getInstance().setWidth(38),
                              height: ScreenUtil.getInstance().setHeight(36),
                            ),
                            onPressed: () {},
                          ),
                          GestureDetector(
                            child: Container(
                              width: ScreenUtil.getInstance().setWidth(120),
                              decoration: BoxDecoration(
                                border: Border(left: BorderSide.merge(BorderSide(color: Color.fromRGBO(204, 204, 204, 1), width: 1), BorderSide(color: Color.fromRGBO(204, 204, 204, 1), width: 0)), )
                              ),
                              child: Center(
                                child: Text("查询", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(26), color: Color.fromRGBO(64, 98, 254, 1)), ),
                              ),
                            ),
                            onTap: () {
                              print("查询");
                            }
                          ),
                        ],
                      ),
                    ),
                    Container(
                      height: ScreenUtil.getInstance().setHeight(100),
                      child: Container(
                        padding: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(25)),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: < Widget > [
                            GestureDetector(
                              child: Container(
                                height: ScreenUtil.getInstance().setHeight(80),
                                decoration: BoxDecoration(
                                  border: statusList[0] ? Border(bottom: BorderSide.merge(BorderSide(color: Colors.black, width: 1), BorderSide(color: Colors.black, width: 0)), ) : Border()
                                ),
                                child: Center(
                                  child: Text("待取件", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: statusList[0] ? Colors.black : Color.fromRGBO(155, 155, 155, 1)), ),
                                )
                              ),
                              onTap: () {
                                if (statusList[0]) {
                                  return;
                                } else {
                                  setState(() {
                                    statusList = [true, false, false];
                                  });
                                }
                              },
                            ),
                            GestureDetector(
                              child: Container(
                                height: ScreenUtil.getInstance().setHeight(80),
                                decoration: BoxDecoration(
                                  border: statusList[1] ? Border(bottom: BorderSide.merge(BorderSide(color: Colors.black, width: 1), BorderSide(color: Colors.black, width: 0)), ) : Border()
                                ),
                                child: Center(
                                  child: Text("运途中", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: statusList[1] ? Colors.black : Color.fromRGBO(155, 155, 155, 1)), ),
                                )
                              ),
                              onTap: () {
                                if (statusList[1]) {
                                  return;
                                } else {
                                  setState(() {
                                    statusList = [false, true, false];
                                  });
                                }
                              },
                            ),
                            GestureDetector(
                              child: Container(
                                height: ScreenUtil.getInstance().setHeight(80),
                                decoration: BoxDecoration(
                                  border: statusList[2] ? Border(bottom: BorderSide.merge(BorderSide(color: Colors.black, width: 1), BorderSide(color: Colors.black, width: 0)), ) : Border()
                                ),
                                child: Center(
                                  child: Text("已完成", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: statusList[2] ? Colors.black : Color.fromRGBO(155, 155, 155, 1)), ),
                                )
                              ),
                              onTap: () {
                                if (statusList[2]) {
                                  return;
                                } else {
                                  setState(() {
                                    statusList = [false, false, true];
                                  });
                                }
                              },
                            ),
                          ],
                        )
                      )
                    ),
                  ],
                )
              ),
              Expanded(
                child: Container(
                  padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), ScreenUtil.getInstance().setWidth(20), 0),
                  child: ListView(
                    controller: _scrollController,
                    children: < Widget > [
                      _cardWiget(),
                      _cardWiget(),
                      _cardWiget(),
                    ],
                  ),
                ),
              )
            ],
          )
        ),
        Positioned(
          left: inputPostX,
          top: inputPostY,
          child: Offstage(
            offstage: showStatus,
            child:
            Container(
              width: inputWidth,
              height: ScreenUtil.getInstance().setHeight(320),
              margin: EdgeInsets.only(top: ScreenUtil.getInstance().setHeight(1)),
              decoration: BoxDecoration(
                color: Color.fromRGBO(244, 248, 251, 1),
                border: Border.all(color: Color.fromRGBO(204, 204, 204, 1), width: 1),
                borderRadius: BorderRadius.all(Radius.circular(5))
              ),
              child: ListView(
                children: < Widget > [
                  InkWell(
                    child: Padding(
                      padding: EdgeInsets.all(10),
                      child: Text("11012312312312312313123131"),
                    ),
                    onTap: () {
                      setState(() {
                        _orderController.text = ('11122223333333');
                        showStatus = true;
                        FocusScope.of(context).requestFocus(FocusNode());
                      });
                    },
                  )

                ],
              ),
            ),
          )
        )
      ],
    );
  }
  Widget _cardWiget() {
    return GestureDetector(
      child: Card(
        color: Colors.white,
        child: Container(
          padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(20)),
          child: Column(
            children: < Widget > [
              Padding(
                padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: < Widget > [
                    Text('订单号：10893477897899', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(102, 102, 102, 1)), ),
                    Text("待取货", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(126, 211, 33, 1)), ),
                  ],
                )
              ),
              Padding(
                padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
                child: Row(
                  children: < Widget > [
                    Text('朝阳门大阳汽贸 --> 香河汽修厂', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30)), ),
                  ],
                )
              ),
              Padding(
                padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(15)),
                child: Row(
                  children: < Widget > [
                    SizedBox(
                      width: ScreenUtil.getInstance().setWidth(355),
                      child: Text('货物名称：汽车轮胎', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
                    ),
                    Text('代收款：2800元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
                  ],
                ),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(30)),
                child: Row(
                  children: < Widget > [
                    SizedBox(
                      width: ScreenUtil.getInstance().setWidth(355),
                      child: Text('货物件数：4件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
                    ),
                    Text('运费：280元', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(155, 155, 155, 1)), ),
                  ],
                ),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
                child: Container(
                  height: ScreenUtil.getInstance().setHeight(1),
                  color: Color.fromRGBO(223, 223, 223, 1),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: < Widget > [
                  GestureDetector(
                    child: Offstage(
                      offstage: false,
                      child: Container(
                        width: ScreenUtil.getInstance().setWidth(94),
                        height: ScreenUtil.getInstance().setHeight(48),
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(239, 243, 249, 1),
                          borderRadius: BorderRadius.all(Radius.circular(4.0))
                        ),
                        child: Center(
                          child: Text('作废', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
                        ),
                      ),
                    ),
                    onTap: () {
                      showDialog < Null > (
                      context: context, //BuildContext对象
                      barrierDismissible: false,
                      builder: (BuildContext context) {
                        return new LoadingDialog( //调用对话框
                          text:'是否确认作废',childCallback: (val){
                            if(val){
                              //widget.callback(widget.index);
                            }else{
                              return;
                            }
                          },
                        );
                      });
                      print("作废");
                    },
                  ),
                  GestureDetector(
                    child: Offstage(
                      offstage: false,
                      child: Container(
                        width: ScreenUtil.getInstance().setWidth(94),
                        height: ScreenUtil.getInstance().setHeight(48),
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(239, 243, 249, 1),
                          borderRadius: BorderRadius.all(Radius.circular(4.0))
                        ),
                        child: Center(
                          child: Text('寄件', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
                        ),
                      ),
                    ),
                    onTap: () {
                      showDialog < Null > (
                      context: context, //BuildContext对象
                      barrierDismissible: false,
                      builder: (BuildContext context) {
                        return new LoadingDialog( //调用对话框
                          text:'是否确认寄件',childCallback: (val){
                            if(val){
                              //widget.callback(widget.index);
                            }else{
                              return;
                            }
                          },
                        );
                      });
                      print("寄件");
                    },
                  ),
                  GestureDetector(
                    child: Offstage(
                      offstage: false,
                      child: Container(
                        width: ScreenUtil.getInstance().setWidth(94),
                        height: ScreenUtil.getInstance().setHeight(48),
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(239, 243, 249, 1),
                          borderRadius: BorderRadius.all(Radius.circular(4.0))
                        ),
                        child: Center(
                          child: Text('拒收', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
                        ),
                      ),
                    ),
                    onTap: () {
                      showDialog < Null > (
                      context: context, //BuildContext对象
                      barrierDismissible: false,
                      builder: (BuildContext context) {
                        return new LoadingDialog( //调用对话框
                          text:'是否确认拒收',childCallback: (val){
                            if(val){
                              //widget.callback(widget.index);
                            }else{
                              return;
                            }
                          },
                        );
                      });
                      print("拒收");
                    },
                  ),
                  GestureDetector(
                    child: Offstage(
                      offstage: false,
                      child: Container(
                        width: ScreenUtil.getInstance().setWidth(94),
                        height: ScreenUtil.getInstance().setHeight(48),
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(239, 243, 249, 1),
                          borderRadius: BorderRadius.all(Radius.circular(4.0))
                        ),
                        child: Center(
                          child: Text('签收', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
                        ),
                      ),
                    ),
                    onTap: () {
                      showDialog < Null > (
                      context: context, //BuildContext对象
                      barrierDismissible: false,
                      builder: (BuildContext context) {
                        return new LoadingDialog( //调用对话框
                          text:'是否确认签收',childCallback: (val){
                            if(val){
                              //widget.callback(widget.index);
                            }else{
                              return;
                            }
                          },
                        );
                      });
                      print("签收");
                    },
                  ),
                  GestureDetector(
                    child: Offstage(
                      offstage: false,
                      child: Container(
                        width: ScreenUtil.getInstance().setWidth(94),
                        height: ScreenUtil.getInstance().setHeight(48),
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(239, 243, 249, 1),
                          borderRadius: BorderRadius.all(Radius.circular(4.0))
                        ),
                        child: Center(
                          child: Text('改单', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
                        ),
                      ),
                    ),
                    onTap: () {
                      showDialog < Null > (
                      context: context, //BuildContext对象
                      barrierDismissible: false,
                      builder: (BuildContext context) {
                        return new LoadingDialog( //调用对话框
                          text:'是否确认改单',childCallback: (val){
                            if(val){
                              print(val);
                               Navigator.push(context, MaterialPageRoute(builder: (context) {
                                  return OrderDetailPage(orderId: 123456, );
                                }));
                            }else{
                              return;
                            }
                          },
                        );
                      });
                      print("改单");
                    },
                  ),
                  GestureDetector(
                    child: Offstage(
                      offstage: false,
                      child: Container(
                        width: ScreenUtil.getInstance().setWidth(94),
                        height: ScreenUtil.getInstance().setHeight(48),
                        decoration: BoxDecoration(
                          color: Color.fromRGBO(239, 243, 249, 1),
                          borderRadius: BorderRadius.all(Radius.circular(4.0))
                        ),
                        child: Center(
                          child: Text('打印', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(24), color: Color.fromRGBO(64, 98, 254, 1))),
                        ),
                      ),
                    ),
                    onTap: () {
                      showDialog < Null > (
                      context: context, //BuildContext对象
                      barrierDismissible: false,
                      builder: (BuildContext context) {
                        return new LoadingDialog( //调用对话框
                          text:'是否确认打印',childCallback: (val){
                            if(val){
                              //widget.callback(widget.index);
                            }else{
                              return;
                            }
                          },
                        );
                      });
                      print("打印");
                    },
                  ),
                ],
              )
            ],
          ),
        )
      ),
      onTap: () {
       
      },
    );
  }
}