import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class OrderDetailPage extends StatefulWidget {
  final int orderId;

  OrderDetailPage({
    Key key,
    @required this.orderId
  }): super(key: key);

  _OrderDetailPageState createState() => _OrderDetailPageState();
}

class _OrderDetailPageState extends State < OrderDetailPage > {

  final Map < Object,
  String > sendInfo = {
    "icon": 'lib/images/icon_send.png',
    "title": "发件信息",
    "phone": "010-8788 6890",
    "code": "345678",
    "name": "朝阳门大阳汽贸",
    "address": "北京市朝阳区",
    "addressDetail": "朝阳门外大街28号"
  };

  final Map < Object,
  String > getInfo = {
    "icon": 'lib/images/icon_shoujian.png',
    "title": "收件信息",
    "name": "香河汽修厂",
    "phone": "010-6734 3426",
    "address": "河北省廊坊市",
    "addressDetail": "香河县东大街29号院18栋3单元206"
  };

  @override
  void initState() {
    super.initState();
    //print(sendInfo.title);
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("订单详情", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36)), ),
        centerTitle: true,
        backgroundColor: Color.fromRGBO(64, 98, 254, 1),
      ),
      body: Container(
        padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(20), 0, ScreenUtil.getInstance().setHeight(20)),
        color: Color.fromRGBO(246, 246, 254, 1),
        child: ListView(
          children: < Widget > [
            _sendInfo(sendInfo),
            _getInfo(getInfo),
            ItemInfoWidget(),
            submitBtn()
          ],
        )
      ),
      //resizeToAvoidBottomPadding: false //键盘弹出，页面不跟随向上滑动,防止出现溢出错误
    );
  }

  Widget _sendInfo(Map str) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
      child: Column(
        children: < Widget > [
          titleWidget(str['icon'], str['title']),
          underLine(),
          contentWiget('电话', str['phone']),
          contentWiget('企业编码', str['code']),
          contentWiget('企业名称', str['name']),
          contentWiget('城市/区域', str['address']),
          lastContentWiget('详细地址', str['addressDetail'])
        ],
      )
    );
  }

  Widget _getInfo(Map str) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(20)),
      child: Column(
        children: < Widget > [
          titleWidget(str['icon'], str['title']),
          underLine(),
          contentWiget('企业名称', str['name']),
          contentWiget('电话', str['phone']),
          contentWiget('城市/区域', str['address']),
          lastContentWiget('详细地址', str['addressDetail'])
        ],
      )
    );
  }
}


class ItemInfoWidget extends StatefulWidget {

  ItemInfoWidget({
    Key key
  }): super(key: key);

  _ItemInfoWidgetState createState() => _ItemInfoWidgetState();
}

class _ItemInfoWidgetState extends State < ItemInfoWidget > {

  Map < String,
  String > _itemInfo = {
    "icon": "lib/images/icon_huowu.png",
    "title": "货物信息",
    "itemName": "汽车轮胎",
    "itemNo": "4",
    "expressPrice": "15",
    "collectionPrice": "15800",
    "supportPrice": "5000",
    "weight": "600",
    "itemDesc": "轮胎请核对数量轮胎请"
  };

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Container(
        color: Colors.white,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: < Widget > [
            titleWidget(_itemInfo['icon'], "货物信息"),
            underLine(),
            contentWiget("货物名称", _itemInfo["itemName"]),
            _inputWidget("数量", _itemInfo["itemNo"]),
            _inputWidget("运费", _itemInfo["expressPrice"]),
            _inputWidget("代收", _itemInfo["collectionPrice"]),
            contentWiget("保价", _itemInfo["supportPrice"]),
            contentWiget("重量", _itemInfo["weight"]),
            _descWidget(_itemInfo['itemDesc'])
          ],
        ),
      )
    );
  }

  Widget _inputWidget(String key, String value) {
    return Padding(
      padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
      child: Column(
        children: < Widget > [
           SizedBox(
              height: ScreenUtil.getInstance().setHeight(89),
              child: Center(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: < Widget > [
                    Text(key, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
                    Container(
                      width: ScreenUtil.getInstance().setWidth(300),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: < Widget > [
                          Expanded(
                            //padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(20)),
                            //child: Text(value,style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
                            child: Center(
                              child: TextField(
                                keyboardType: TextInputType.number,
                                textAlign: TextAlign.end,
                                style: TextStyle(
                                  fontSize: ScreenUtil.getInstance().setSp(30),
                                  color: Color.fromRGBO(136, 136, 136, 1)
                                ),
                                decoration: InputDecoration(
                                  border: InputBorder.none,
                                  hintText: value,
                                  hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)),
                                  contentPadding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(20), 0, 0, 0),
                                ),
                              ),
                            )
                          ),
                          Icon(Icons.keyboard_arrow_right, color: Color.fromRGBO(199, 199, 204, 1), )
                        ],
                      )
                    )
                  ],
                ),
              )
          ),
          Expanded(
            flex: 0,
            child: underLine()
          )
        ],
      )
    );
  }

  Widget _descWidget(String str) {
    return
    Container(
      padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(30)),
      child: Text(str, maxLines: 100, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
    );
  }
}

Widget titleWidget(String iconUrl, String str) {
  return Container(
    height: ScreenUtil.getInstance().setHeight(90),
    padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
    child: Center(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: < Widget > [
          Padding(
            padding: EdgeInsets.only(right: ScreenUtil.getInstance().setHeight(20)),
            child: Image.asset(
              iconUrl,
              width: ScreenUtil.getInstance().setWidth(40),
              height: ScreenUtil.getInstance().setHeight(40),
            )
          ),
          Text(str, style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32)), )
        ],
      ),
    ),
  );
}

Widget underLine() {
  return Container(
    color: Color.fromRGBO(223, 223, 223, 1),
    height: ScreenUtil.getInstance().setHeight(1),
  );
}

Widget contentWiget(String key, String value) {
  return Padding(
    padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
    child: Column(
      children: < Widget > [
        Padding(
          padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
          child: SizedBox(
            height: ScreenUtil.getInstance().setHeight(89),
            child: Center(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: < Widget > [
                  Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
                  Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
                ],
              ),
            )
          )
        ),
        Expanded(
          flex: 0,
          child: underLine()
        )
      ],
    )
  );
}

Widget lastContentWiget(String key, String value) {
  return Padding(
    padding: EdgeInsets.only(left: ScreenUtil.getInstance().setWidth(30)),
    child:
    Padding(
      padding: EdgeInsets.only(right: ScreenUtil.getInstance().setWidth(30)),
      child: SizedBox(
        height: ScreenUtil.getInstance().setHeight(89),
        child: Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: < Widget > [
              Text('${key}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(74, 74, 74, 1)), ),
              Text('${value}', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(30), color: Color.fromRGBO(136, 136, 136, 1)), ),
            ],
          ),
        )
      )
    ),
  );
}


Widget submitBtn() {
  return GestureDetector(
    child: Container(
      margin: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(50), ScreenUtil.getInstance().setWidth(30), ScreenUtil.getInstance().setWidth(40)),
      height: ScreenUtil.getInstance().setHeight(88),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(4)),
        color: Color.fromRGBO(37, 102, 242, 1),
      ),
      child: Center(
        child: Text("提交", style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Colors.white), ),
      ),
    ),
    onTap: () {
      print('提交');
    },
  );
}