import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:liftmanager/common/common.dart';
import 'package:liftmanager/internal/account/account_router.dart';
import 'package:liftmanager/internal/account/model/user_info_entity.dart';
import 'package:liftmanager/internal/account/provider/user_provider.dart';
import 'package:liftmanager/internal/wode/wode_router.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';
import 'package:liftmanager/utils/image_utils.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/mvp/base_page_state.dart';
import 'package:liftmanager/internal/wode/presenter/piao_tou_list_presenter.dart';
import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
import 'package:liftmanager/internal/wode/model/piao_tou_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/fast_notification.dart';
import 'package:flustars/flustars.dart' as FlutterStars;
import 'package:liftmanager/utils/theme_utils.dart';

class Piaotou extends StatefulWidget {
  Piaotou(this.checkTou,this.type);

  final String checkTou;
  final String type;
  @override
  PiaotouState createState() => PiaotouState();
}

class PiaotouState extends BasePageState<Piaotou,PiaotouListPresenter> {
  BaseListProvider<Records> provider =
      BaseListProvider<Records>();
   int _page = 1;

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

    FastNotification.addListener("initThis",(initThisString){
      setState(() {
        
        
      });
      _onRefresh();
    });
    
  }

  
  @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(
          // resizeToAvoidBottomPadding: true,
          appBar: MyAppBar(
                centerTitle: "发票抬头",
              ),
          body: Container(
            // color: Color(0xFFF1F4FC),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                widget.checkTou!="checkTou"?GestureDetector(
                      onTap: (){
                        NavigatorUtils.push(context, "${WodeRouter.piaotouEdit}?type=add&id=");
                      },
                      child:Container(
                        color: ThemeUtils.getDialogTextFieldColor(context),
                        width: width,
                        padding: EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children:<Widget>[
                          Text(
                            "添加发票抬头",
                            textAlign: TextAlign.left,
                            style: TextStyle(
                              fontSize:ScreenUtil().setSp(15),
                            ),
                          ),
                          Icon(
                                    Icons.keyboard_arrow_right,
                                    color: Color(0xffcccccc),
                                  ),
                        ]
                      ),
                    ),
                    ):Container(child: null,),
                Expanded(
                  flex: 1,
                    child: Consumer<BaseListProvider<Records>>(
                        builder: (_, provider, __) {
                      return MyListView(
                        key: Key('piao_tou_list'),
                        itemCount: provider.list.length,
                        stateType: provider.stateType,
                        onRefresh: _onRefresh,
                        loadMore: _loadMore,
                        pageSize: 10,
                        hasMore: provider.hasMore,
                        itemBuilder: (_, index) {
                          return Container(
      // height: 20,
      padding:EdgeInsets.only(bottom:20,top:10),
      decoration: BoxDecoration(
        border: Border(
                  bottom: BorderSide(width: 0.5, color: Colours.line),
                ),
      ),
      child:  Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Expanded(
              child: GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: (){
                  print(456);
                  if(widget.checkTou=="checkTou"){
                    Navigator.pop(context);
                    dynamic piaoTouObj = provider.list[index];
                    FastNotification.push("piaoTou",piaoTouObj);
                  }else {
                    NavigatorUtils.push(context, "${WodeRouter.piaotouEdit}?type=edit&id=${provider.list[index].id.toString()}");
                  }
                },
                child:Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children:<Widget>[
                  
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.only(right:15,left:15),
                      child:Column(
                      children: <Widget>[
                        Container(
                          child:Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children:<Widget>[
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children:<Widget>[
                                  Text(
                                    provider.list[index].name??"",
                                    style: TextStyle(
                                      color:Color(0xff333333),
                                      fontSize:ScreenUtil().setSp(15)
                                    ),
                                    textAlign:TextAlign.start,
                                  ),
                                  provider.list[index].isDefault==1?Container(
                                    padding: EdgeInsets.only(left:5),
                                    child:Text(
                                      "(默认)",
                                      style: TextStyle(
                                        color:Color(0xffff0000),
                                        fontSize:ScreenUtil().setSp(15)
                                      ),
                                      textAlign:TextAlign.start,
                                    ),
                                  ):Container(child:null)
                                ]
                              ),
                              widget.checkTou!="checkTou"?Icon(
                                IconData(
                                  0xe626,
                                  fontFamily:"myfont"
                                ),
                                size: 18.0,
                                color:Color(0xff666666),
                              ):Container(child: null,),
                              // Text("123")
                            ]
                          )
                        ),
                        Container(
                          child:Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children:<Widget>[
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children:<Widget>[
                                  Text(
                                    "发票类型:",
                                    style: TextStyle(
                                      color:Color(0xff999999),
                                      fontSize:ScreenUtil().setSp(14)
                                    ),
                                    textAlign:TextAlign.start,
                                  ),
                                  Container(
                                    padding: EdgeInsets.only(left:5),
                                    child:Text(
                                      provider.list[index].type==1?"个人":"公司",
                                      style: TextStyle(
                                        color:Color(0xff999999),
                                        fontSize:ScreenUtil().setSp(14)
                                      ),
                                      textAlign:TextAlign.start,
                                    ),
                                  )
                                ]
                              ),
                            ]
                          )
                        ),
                        provider.list[index].type==2?Container(
                          child:Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children:<Widget>[
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children:<Widget>[
                                  Text(
                                    "税号:",
                                    style: TextStyle(
                                      color:Color(0xff999999),
                                      fontSize:ScreenUtil().setSp(14)
                                    ),
                                    textAlign:TextAlign.start,
                                  ),
                                  Container(
                                    padding: EdgeInsets.only(left:5),
                                    child:Text(
                                      provider.list[index].enterpriseNumber??"",
                                      style: TextStyle(
                                        color:Color(0xff999999),
                                        fontSize:ScreenUtil().setSp(14)
                                      ),
                                      textAlign:TextAlign.start,
                                    ),
                                  )
                                ]
                              ),
                            ]
                          )
                        ):Container(child:null),

                      ],
                    )
                    )
                  )
                ]
              ),
              )
            ),
            
          ],
        ),
    );
                        },
                      );
                    })
                    )
              ],
            ),
          ),
        ));
    

  }

  Future _onRefresh() async {
    _page = 1;
    await presenter.getList( _page,widget.type!=null&&widget.type!=""?int.parse(widget.type):null);
  }

  Future _loadMore() async {
    _page++;
    await presenter.getList(_page,widget.type!=null&&widget.type!=""?int.parse(widget.type):null);
  }

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

}






