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/punishments_model.dart';

import 'package:liftmanager/internal/wode/presenter/reward_record_list_presenter.dart';
import 'package:liftmanager/internal/wode/wode_router.dart';
import 'package:liftmanager/mvp/base_page_state.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/routers/fluro_navigator.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 RewardRecordList extends StatefulWidget {
  // QuestionList(this.index);

  // final String index;

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

class RewardRecordListState
    extends BasePageState<RewardRecordList, RewardRecordListPresenter> {
  BaseListProvider<ExpertsRewardRecordModel> provider =
      BaseListProvider<ExpertsRewardRecordModel>();
  ScrollController _scrollController = new ScrollController();
  int _page = 1;
  String searchWord;
  @override
  void initState() {
    provider.setStateTypeNotNotify(StateType.loading);
    super.initState();
    _onRefresh();
    print(66666);
  }

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

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;

    return ChangeNotifierProvider<BaseListProvider<ExpertsRewardRecordModel>>(
        create: (_) => provider,
        child: Scaffold(
            appBar: MyAppBar(
              centerTitle: "打赏记录",
              // backgroundColor:Colors.transparent,
            ),
            body: Container(
                child: Column(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: Consumer<BaseListProvider<ExpertsRewardRecordModel>>(
                        builder: (_, provider, __) {
                      return MyListView(
                        key: Key('expertsPunishments_list'),
                        itemCount: provider.list.length,
                        stateType: provider.stateType,
                        onRefresh: _onRefresh,
                        pageSize: 10,
                        loadMore: _loadMore,
                        hasMore: provider.hasMore,
                        itemBuilder: (_, index) {
                          return InkWell(
                            onTap: () {
                              // print(index);
                              // NavigatorUtils.push(context,
                              //     "${WodeRouter.errorRecordDetail}?id=${provider.list[index].id.toString()}");
                            },
                            child: Container(
                              padding: EdgeInsets.only(
                                  left: ScreenUtil().setWidth(15),
                                  right: ScreenUtil().setWidth(15),
                                  top: ScreenUtil().setHeight(10),
                                  bottom: ScreenUtil().setHeight(10)),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  ClipRRect(
                                    borderRadius: BorderRadius.circular(18),
                                    child: Container(
                                      // padding: EdgeInsets.only(
                                      //     right: ScreenUtil().setWidth(10)),
                                      child: LoadNetworkImage(
                                        provider.list[index].targetAvatarUrl,
                                        // fit: BoxFit.cover,
                                        width: ScreenUtil().setWidth(36),
                                        height: ScreenUtil().setWidth(36),
                                      ),
                                    ),
                                  ),
                                  SizedBox(
                                    width: 5,
                                  ),
                                  Expanded(
                                      child: Column(
                                    // mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Row(
                                        // mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        children: [
                                          Text(
                                              '${provider.list[index].targetUserName ?? ""}',
                                              style: TextStyle(
                                                  color: Colours.text,
                                                  fontSize: 14)),
                                          Expanded(child: Container()),
                                          Text(
                                              '${provider.list[index].amount ?? '0'}',
                                              style: TextStyle(
                                                  color: Color(0xff333333),
                                                  fontSize: 14)),
                                        ],
                                      ),
                                      // Text(
                                      //     '处罚原因：${provider.list[index].des ?? ""}',
                                      //     style: TextStyle(
                                      //         color: Colours.text_gray,
                                      //         fontSize: 12)),
                                      Text(
                                          '${DateUtils.instance.getFormartData(timeSamp: provider.list[index].createTime, format: "yyyy-MM-dd HH:mm")}',
                                          style: TextStyle(
                                              color: Colours.text_gray,
                                              fontSize: 12)),
                                    ],
                                  ))
                                ],
                              ),
                            ),
                          );
                        },
                      );
                    }))
              ],
            ))));
  }

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

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

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