import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
import 'package:liftmanager/internal/wode/model/piao_order_model.dart';
import 'package:liftmanager/internal/wode/presenter/piao_order_list_presenter.dart';
import 'package:liftmanager/mvp/base_page_state.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/utils/time_format.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/widgets/my_refresh_list.dart';
import 'package:liftmanager/widgets/state_layout.dart';
import 'package:provider/provider.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(0xFFF6F6F6),
            // 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(15),
                                left: ScreenUtil().setWidth(10),
                                right: ScreenUtil().setWidth(10),
                                top: ScreenUtil().setWidth(15)),
                            // : EdgeInsets.only(
                            //     left: ScreenUtil().setWidth(10),
                            //     right: ScreenUtil().setWidth(10),
                            //     top: ScreenUtil().setWidth(15)),
                            margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
                            decoration: new BoxDecoration(
                              //背景
                              color: Colors.white,
                              //设置四周圆角 角度
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.0)),
                            ),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                Expanded(
                                  child: GestureDetector(
                                    onTap: () {
                                      // NavigatorUtils.push(
                                      //     context, "${WodeRouter.orderDetail}?id=${lists[i].id}");
                                      // NavigatorUtils.push(context,
                                      //     "${BbsRouter.recommendAsk}?id=${detailObj.id}&type=3");
                                    },
                                    child: Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: <Widget>[
                                        SizedBox(
                                          width: 10,
                                        ),
                                        ClipRRect(
                                          borderRadius:
                                              BorderRadius.circular(20),
                                          child: LoadNetworkImage(
                                            provider.list[index].avatarUrl,
                                            width: ScreenUtil().setWidth(43),
                                            height: ScreenUtil().setWidth(43),
                                            // alignment: Alignment.centerLeft,
                                          ),
                                        ),
                                        SizedBox(
                                          width: 10,
                                        ),
                                        Expanded(
                                          child: Container(
                                            padding: EdgeInsets.only(right: 10),
                                            child: Column(
                                              children: <Widget>[
                                                Container(
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment.start,
                                                    children: <Widget>[
                                                      Row(
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .center,
                                                        children: <Widget>[
                                                          Text(
                                                            provider.list[index]
                                                                    .name ??
                                                                '',
                                                            style: TextStyle(
                                                              fontSize:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          17),
                                                            ),
                                                            textAlign:
                                                                TextAlign.start,
                                                          ),
                                                          Container(
                                                            decoration:
                                                                BoxDecoration(
                                                              //背景
                                                              color: provider
                                                                          .list[
                                                                              index]
                                                                          .dataTable ==
                                                                      1
                                                                  ? Colours
                                                                      .blue_app_main
                                                                  : Color(
                                                                      0xffFDAF2C),
                                                              //设置四周圆角 角度
                                                              borderRadius: BorderRadius
                                                                  .all(Radius
                                                                      .circular(
                                                                          4.0)),
                                                            ),
                                                            margin:
                                                                EdgeInsets.only(
                                                                    left: 5),
                                                            padding:
                                                                EdgeInsets.only(
                                                                    left: 5,
                                                                    right: 5,
                                                                    top: 2,
                                                                    bottom: 2),
                                                            child: Text(
                                                              provider.list[index]
                                                                          .dataTable ==
                                                                      1
                                                                  ? '问诊服务'
                                                                  : '出诊服务',
                                                              style: TextStyle(
                                                                color: Colors
                                                                    .white,
                                                                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:
                                                                            "MM月dd日")
                                                                : '',
                                                            style: TextStyle(
                                                              color: Color(
                                                                  0xff999999),
                                                              fontSize:
                                                                  ScreenUtil()
                                                                      .setSp(
                                                                          13),
                                                            ),
                                                            textAlign:
                                                                TextAlign.start,
                                                          ),
                                                          Container(
                                                            padding:
                                                                EdgeInsets.only(
                                                                    left: 5),
                                                            child: Text(
                                                              provider
                                                                      .list[
                                                                          index]
                                                                      .brandName ??
                                                                  '',
                                                              style: TextStyle(
                                                                color: Colours
                                                                    .blue_app_main,
                                                                fontSize:
                                                                    ScreenUtil()
                                                                        .setSp(
                                                                            13),
                                                              ),
                                                              textAlign:
                                                                  TextAlign
                                                                      .start,
                                                            ),
                                                          )
                                                        ],
                                                      ),
                                                    ],
                                                  ),
                                                ),
                                                provider.list[index]
                                                            .dataTable !=
                                                        1
                                                    ? Container(
                                                        child: Row(
                                                          mainAxisAlignment:
                                                              MainAxisAlignment
                                                                  .spaceBetween,
                                                          children: <Widget>[
                                                            Row(
                                                              crossAxisAlignment:
                                                                  CrossAxisAlignment
                                                                      .start,
                                                              children: <
                                                                  Widget>[
                                                                Container(
                                                                  // padding: EdgeInsets.only(left: 5),
                                                                  child: Text(
                                                                    '出诊时间：',
                                                                    style:
                                                                        TextStyle(
                                                                      color: Color(
                                                                          0xff999999),
                                                                      fontSize:
                                                                          ScreenUtil()
                                                                              .setSp(13),
                                                                    ),
                                                                    textAlign:
                                                                        TextAlign
                                                                            .start,
                                                                  ),
                                                                ),
                                                                Text(
                                                                  provider.list[index].createTime !=
                                                                          null
                                                                      ? DateUtils.instance.getFormartData(
                                                                          timeSamp: provider
                                                                              .list[
                                                                                  index]
                                                                              .createTime,
                                                                          format:
                                                                              "MM月dd日 HH:mm")
                                                                      : '',
                                                                  style:
                                                                      TextStyle(
                                                                    color: Color(
                                                                        0xff666666),
                                                                    fontSize: ScreenUtil()
                                                                        .setSp(
                                                                            13),
                                                                  ),
                                                                  textAlign:
                                                                      TextAlign
                                                                          .start,
                                                                ),
                                                              ],
                                                            ),
                                                          ],
                                                        ),
                                                      )
                                                    : Container(),
                                                provider.list[index]
                                                            .dataTable !=
                                                        1
                                                    ? Container(
                                                        // margin: EdgeInsets.only(top: 6),
                                                        child: Row(
                                                          children: <Widget>[
                                                            Container(
                                                              // padding: EdgeInsets.only(left: 5),
                                                              child: Text(
                                                                '出诊地点：',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xff999999),
                                                                  fontSize:
                                                                      ScreenUtil()
                                                                          .setSp(
                                                                              13),
                                                                ),
                                                                textAlign:
                                                                    TextAlign
                                                                        .start,
                                                              ),
                                                            ),
                                                            Container(
                                                              width:
                                                                  ScreenUtil()
                                                                      .setWidth(
                                                                          200),
                                                              child: Text(
                                                                '${provider.list[index].address ?? ''}',
                                                                style:
                                                                    TextStyle(
                                                                  color: Color(
                                                                      0xff666666),
                                                                  fontSize:
                                                                      ScreenUtil()
                                                                          .setSp(
                                                                              13),
                                                                  // color: Color(0xff666666),
                                                                  // fontSize: ScreenUtil().setSp(15),
                                                                ),
                                                                textAlign:
                                                                    TextAlign
                                                                        .start,
                                                                maxLines: 1,
                                                                overflow:
                                                                    TextOverflow
                                                                        .ellipsis,
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                      )
                                                    : Container(),
                                                Container(
                                                  // margin: EdgeInsets.only(top: 6),
                                                  child: Row(
                                                    children: <Widget>[
                                                      Container(
                                                        // padding: EdgeInsets.only(left: 5),
                                                        child: Text(
                                                          '问题描述：',
                                                          style: TextStyle(
                                                            color: Color(
                                                                0xff999999),
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(13),
                                                          ),
                                                          textAlign:
                                                              TextAlign.start,
                                                        ),
                                                      ),
                                                      Container(
                                                        width: ScreenUtil()
                                                            .setWidth(200),
                                                        child: Text(
                                                          '${provider.list[index].expression ?? ''}',
                                                          style: TextStyle(
                                                            color: Color(
                                                                0xff666666),
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(13),
                                                            // color: Color(0xff666666),
                                                            // fontSize: ScreenUtil().setSp(15),
                                                          ),
                                                          textAlign:
                                                              TextAlign.start,
                                                          maxLines: 1,
                                                          overflow: TextOverflow
                                                              .ellipsis,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                ),
                                                Container(
                                                  margin:
                                                      EdgeInsets.only(top: 6),
                                                  child: Row(
                                                    children: <Widget>[
                                                      Container(
                                                        padding:
                                                            EdgeInsets.only(
                                                                right: 5),
                                                        child: Text(
                                                          provider.list[index]
                                                                      .payCost !=
                                                                  null
                                                              ? "￥${provider.list[index].payCost.toString()}"
                                                              : '',
                                                          style: TextStyle(
                                                            color: Color(
                                                                0xffFD0808),
                                                            fontSize:
                                                                ScreenUtil()
                                                                    .setSp(15),
                                                          ),
                                                          textAlign:
                                                              TextAlign.start,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                )
                                                // Container(
                                                //   child: Row(
                                                //     mainAxisAlignment:
                                                //         MainAxisAlignment.start,
                                                //     children: <Widget>[
                                                //       Row(
                                                //         crossAxisAlignment:
                                                //             CrossAxisAlignment
                                                //                 .center,
                                                //         children: <Widget>[
                                                //           Text(
                                                //             detailObj.createTime !=
                                                //                     null
                                                //                 ? DateUtils
                                                //                     .instance
                                                //                     .getFormartData(
                                                //                     timeSamp:
                                                //                         detailObj
                                                //                             .createTime,
                                                //                     format:
                                                //                         "MM月dd日",
                                                //                   )
                                                //                 : '',
                                                //             style: TextStyle(
                                                //               color: Color(
                                                //                   0xff999999),
                                                //               fontSize:
                                                //                   ScreenUtil()
                                                //                       .setSp(
                                                //                           13),
                                                //             ),
                                                //             textAlign:
                                                //                 TextAlign.left,
                                                //           ),
                                                //           Container(
                                                //             padding:
                                                //                 EdgeInsets.only(
                                                //                     left: 5),
                                                //             child: Text(
                                                //               detailObj
                                                //                       .brandName ??
                                                //                   '',
                                                //               style: TextStyle(
                                                //                 color: Color(
                                                //                     0xff999999),
                                                //                 fontSize:
                                                //                     ScreenUtil()
                                                //                         .setSp(
                                                //                             13),
                                                //               ),
                                                //               textAlign:
                                                //                   TextAlign
                                                //                       .left,
                                                //             ),
                                                //           )
                                                //         ],
                                                //       ),
                                                //     ],
                                                //   ),
                                                // ),
                                                // Row(
                                                //   mainAxisAlignment:
                                                //       MainAxisAlignment.start,
                                                //   children: <Widget>[
                                                //     Container(
                                                //       width: 260,
                                                //       child: Text(
                                                //         detailObj.expression ??
                                                //             '',
                                                //         style: TextStyle(
                                                //           color:
                                                //               Color(0xff0288FF),
                                                //           fontSize: ScreenUtil()
                                                //               .setSp(15),
                                                //         ),
                                                //         textAlign:
                                                //             TextAlign.left,
                                                //         maxLines: 1,
                                                //         overflow: TextOverflow
                                                //             .ellipsis,
                                                //       ),
                                                //     ),
                                                //   ],
                                                // ),
                                              ],
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          );
                        },
                      );
                    }))
              ],
            ),
          ),
        ));
  }

  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();
  }
}
