import 'package:flutter/material.dart';
import 'package:liftmanager/res/gaps.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/utils/toast.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/internal/search/search_router.dart';
import 'package:liftmanager/widgets/app_search_bar.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/internal/bbs/bbs_router.dart';
import 'package:liftmanager/widgets/my_card.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_list_presenter.dart';
import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
import 'package:liftmanager/internal/wode/model/piao_model.dart';
import 'package:liftmanager/widgets/state_layout.dart';
import 'package:provider/provider.dart';
import 'package:liftmanager/utils/time_format.dart';
import 'package:liftmanager/utils/log_util.dart';
import 'package:liftmanager/widgets/my_refresh_list.dart';

class PiaoList extends StatefulWidget {
  // QuestionList(this.index);

  // final String index;
  

  @override
  PiaoListState createState() => PiaoListState();
}

class PiaoListState extends BasePageState<PiaoList,PiaoListPresenter> {
  BaseListProvider<Records> provider =
      BaseListProvider<Records>();
   int _page = 1;

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

  getCheckFlag(int type) {
    String str;
    if (type == 1) {
      str = "已开发票";
    } else if (type == 2) {
      str = "已提交申请";
    } else if (type == 0) {
      str = "驳回";
    }
    return str;
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {

    double width = MediaQuery.of(context).size.width;

    return 

    ChangeNotifierProvider<BaseListProvider<Records>>(
        create: (_) => provider,
        child: 
        Scaffold(
          // resizeToAvoidBottomPadding: true,
          appBar: MyAppBar(
          centerTitle: "我的发票",
          // actions:<Widget>[
          //   FlatButton(
          //     child: Text("发票抬头"),
          //     textColor: Colours.dark_text,
          //     highlightColor: Colors.transparent,
          //     onPressed: () {
          //       NavigatorUtils.push(context, WodeRouter.piaotou);
                
          //     },
          //   )
          // ],
        ),
          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_list'),
                        itemCount: provider.list.length,
                        stateType: provider.stateType,
                        onRefresh: _onRefresh,
                        loadMore: _loadMore,
                        pageSize: 6,
                        hasMore: provider.hasMore,
                        itemBuilder: (_, index) {
                          return 
                          Container(
      padding: index==provider.list.length-1?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)),
      child: MyCard(
      child:InkWell(
      child:Container(
              padding: EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children:<Widget>[
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        "服务",
                        textAlign: TextAlign.left,
                        style: TextStyle(
                          fontSize:ScreenUtil().setSp(16),
                          color:Color(0xff000000),
                        ),
                      ),
                      Text(
                        getCheckFlag(provider.list[index].checkFlag),
                        textAlign: TextAlign.left,
                        style: TextStyle(
                          fontSize:ScreenUtil().setSp(14),
                          color:Color(0xff999999),
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    height:10
                  ),
                  Container(
                    child: Text(
                        provider.list[index].createTime!=null?DateUtils.instance
                                                      .getFormartData(
                                                          timeSamp: provider
                                                              .list[index]
                                                              .createTime,
                                                          format: "yyyy-MM-dd"):"",
                        textAlign: TextAlign.left,
                        style: TextStyle(
                          fontSize:ScreenUtil().setSp(14),
                          color:Color(0xff999999),
                        ),
                      ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        provider.list[index].invoiceType == "1"?'电子发票':"专用发票",
                        textAlign: TextAlign.left,
                        style: TextStyle(
                          fontSize:ScreenUtil().setSp(14),
                          color:Color(0xff999999),
                        ),
                      ),
                      Text(
                        '￥${provider.list[index].hjje??"0"}',
                        textAlign: TextAlign.left,
                        style: TextStyle(
                          fontSize:ScreenUtil().setSp(16),
                          color:Color(0xff333333),
                        ),
                      ),
                    ],
                  ),
                  // Container(
                  //   child: Text(
                  //       '开票序号:${provider.list[index].hm??"0"}',
                  //       textAlign: TextAlign.left,
                  //       style: TextStyle(
                  //         fontSize:ScreenUtil().setSp(14),
                  //         color:Color(0xff999999),
                  //       ),
                  //     ),
                  // ),
                ]
              ),
            ),
      onTap: (){
        NavigatorUtils.push(context, "${WodeRouter.piaoDetail}?id=${provider.list[index].id}");
      },  
    )
    ),
    );
                        },
                      );
                    })
                    )
              ],
            ),
          ),
        ));
    
    
  }

  Future _onRefresh() async {
    _page = 1;
    await presenter.getWalletList( _page);
  }

  Future _loadMore() async {
    _page++;
    await presenter.getWalletList(_page);
  }

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

}



