import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/widgets/click_item.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/widgets/my_button.dart';
import 'package:provider/provider.dart';
import 'package:liftmanager/widgets/bbs_content.dart';
import 'package:liftmanager/internal/bbs/bbs_router.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/internal/wode/wode_router.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:liftmanager/mvp/base_page_state.dart';
import 'package:liftmanager/internal/wode/presenter/piao_order_list_presenter.dart';
import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
import 'package:liftmanager/internal/wode/model/piao_order_model.dart';
import 'package:liftmanager/widgets/state_layout.dart';
import 'package:liftmanager/utils/time_format.dart';
import 'package:liftmanager/utils/log_util.dart';
import 'package:liftmanager/widgets/my_refresh_list.dart';
import 'package:liftmanager/utils/url.dart';

class PiaoOrder extends StatefulWidget {
  PiaoOrder(this.id);

  final String id;
  @override
  PiaoOrderState createState() => PiaoOrderState();
}

class PiaoOrderState extends BasePageState<PiaoOrder,PiaoOrderListPresenter> {
  BaseListProvider<Records> provider =
      BaseListProvider<Records>();
  List<dynamic> paramsList = [
    {
      "pic":"temporary/avator1",
      "name":"张涛",
      "serviceType":"出诊服务",
      "time":"01月05日",
      "brand":"奥的斯",
      "desc":"电梯故障紧急维修、电梯保养、电梯短路处理、电梯闸门故障维修",
      "price":"20",
    },
    {
      "pic":"temporary/avator2",
      "name":"张涛",
      "serviceType":"出诊服务",
      "time":"01月05日",
      "brand":"奥的斯",
      "desc":"电梯故障紧急维修、电梯保养、电梯短路处理、电梯闸门故障维修",
      "price":"20",
    },
    {
      "pic":"temporary/avator2",
      "name":"张涛",
      "serviceType":"出诊服务",
      "time":"01月05日",
      "brand":"奥的斯",
      "desc":"电梯故障紧急维修、电梯保养、电梯短路处理、电梯闸门故障维修",
      "price":"20",
    },
  ];

  int _page = 1;

   @override
  void initState() {
    provider.setStateTypeNotNotify(StateType.loading);
    super.initState();
    _onRefresh();
    print(66666);
    
  }

  
  
  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    double height = MediaQuery.of(context).size.height;
    return ChangeNotifierProvider<BaseListProvider<Records>>(
        create: (_) => provider,
        child:Scaffold(
              appBar: MyAppBar(
                centerTitle: "发票订单",
              ),
              body: Container(
            // color: Color(0xFFF1F4FC),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                
                Expanded(
                  flex: 1,
                    child: Consumer<BaseListProvider<Records>>(
                        builder: (_, provider, __) {
                      return MyListView(
                        key: Key('piao_order_list'),
                        itemCount: provider.list.length,
                        stateType: provider.stateType,
                        onRefresh: _onRefresh,
                        loadMore: _loadMore,
                        pageSize: 6,
                        hasMore: provider.hasMore,
                        itemBuilder: (_, index) {
                          return Container(
      // height: 20,
      padding:EdgeInsets.only(bottom:ScreenUtil().setWidth(20),top:ScreenUtil().setWidth(10)),
      decoration: BoxDecoration(
        border: Border(
                  bottom: BorderSide(width: 0.5, color: Colours.line),
                ),
      ),
      child:  Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Expanded(
              child: GestureDetector(
                onTap: (){
                  // NavigatorUtils.push(context, "${WodeRouter.orderDetail}?type=${list[i]["type"]}");
                },
                child:Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children:<Widget>[
                  Container(
                    margin: EdgeInsets.only(left:ScreenUtil().setWidth(10),right:ScreenUtil().setWidth(10),top:ScreenUtil().setWidth(5)),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(ScreenUtil().setWidth(20)),
                    ),
                    child: LoadNetworkImage(
                      // image: AssetImage(i['img']),
                      provider.list[index].avatarUrl,
                      width: ScreenUtil().setWidth(40),
                      height:ScreenUtil().setWidth(40),
                      // alignment: Alignment.centerLeft,
                    ),
                  ),
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.only(right:ScreenUtil().setWidth(15)),
                      child:Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        Container(
                          child:Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children:<Widget>[
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.start,
                                children:<Widget>[
                                  Text(
                                    provider.list[index].name??"",
                                    style: TextStyle(
                                      color:Color(0xff333333),
                                      fontSize:ScreenUtil().setSp(16)
                                    ),
                                    textAlign:TextAlign.start,
                                  ),
                                  Container(
                                    padding: EdgeInsets.only(left:5),
                                    child:Text(
                                      provider.list[index].dataTable==1?"问诊服务":"出诊服务",
                                      style: TextStyle(
                                        color:Color(0xff1B87F6),
                                        fontSize:ScreenUtil().setSp(14)
                                      ),
                                      textAlign:TextAlign.start,
                                    ),
                                  )
                                ]
                              ),
                            ]
                          )
                        ),
                        Container(
                          child:Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children:<Widget>[
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children:<Widget>[
                                  Text(
                                    provider.list[index].createTime!=null?DateUtils.instance.getFormartData(timeSamp: provider.list[index].createTime,format: "yyyy-MM-dd"):'',
                                    style: TextStyle(
                                      color:Color(0xff999999),
                                      fontSize:ScreenUtil().setSp(12)
                                    ),
                                    textAlign:TextAlign.start,
                                  ),
                                  Container(
                                    padding: EdgeInsets.only(left:5),
                                    child:Text(
                                      provider.list[index].brandName??"",
                                      style: TextStyle(
                                        color:Color(0xff999999),
                                        fontSize:ScreenUtil().setSp(12)
                                      ),
                                      textAlign:TextAlign.start,
                                    ),
                                  )
                                ]
                              ),
                            ]
                          )
                        ),
                        Container(
                                child:Text(
                                    provider.list[index].expression??"",
                                    style: TextStyle(
                                      color:Color(0xff999999),
                                      fontSize:ScreenUtil().setSp(14)
                                    ),
                                    textAlign:TextAlign.start,
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                  ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top:6),
                          // decoration: BoxDecoration(
                          //         border: Border(
                          //           top: BorderSide(width: 0.5, color: Colours.line),
                          //         ), 
                          //       ),
                          child:Row(
                            children:<Widget>[
                              Container(
                                padding: EdgeInsets.only(right:5),
                                child:Text(
                                    "￥${provider.list[index].payCost.toString()??""}",
                                    style: TextStyle(
                                      color:Colors.red,
                                      fontSize:ScreenUtil().setSp(14)
                                    ),
                                    textAlign:TextAlign.start,
                                  ),
                              ),
                            ]
                          )
                        )
                      ],
                    )
                    )
                  )
                ]
              ),
              )
            ),
            
          ],
        ),
    );
                        },
                      );
                    })
                    )
              ],
            ),
          ),
        )
        );
    
    
  }
    Future _onRefresh() async {
    _page = 1;
    await presenter.getOrderList( _page,int.parse(widget.id));
  }

  Future _loadMore() async {
    _page++;
    await presenter.getOrderList(_page,int.parse(widget.id));
  }

  @override
  PiaoOrderListPresenter createPresenter() {
    return PiaoOrderListPresenter();
  }
    
  }

  








