// /*
//  * @Author: wangyang 1147192855@qq.com
//  * @Date: 2022-07-05 16:42:44
//  * @LastEditors: wangyang 1147192855@qq.com
//  * @LastEditTime: 2022-09-27 16:15:03
//  * @FilePath: \marking_app\lib\pages\marking\index.dart
//  * @Description: 阅卷主页
//  */

// import 'package:flutter/material.dart';
// import 'package:flutter/services.dart';
// import 'package:functional_widget_annotation/functional_widget_annotation.dart';
// import 'package:marking_app/common/mixin/common.dart';
// import 'package:flutter_easyrefresh/easy_refresh.dart';
// import 'package:flutter_screenutil/flutter_screenutil.dart';
// import 'package:hooks_riverpod/hooks_riverpod.dart';
// import 'package:marking_app/common/config/request_config.dart';
// import 'package:marking_app/provider/review_provider.dart';
// import 'package:marking_app/utils/index.dart';
// import 'package:marking_app/utils/request/rest_client.dart';
// import 'package:marking_app/common/model/common/base_page_data.dart';
// import 'package:marking_app/common/model/marking/marking_item.dart';
// import 'package:marking_app/common/model/marking/marking_list_params.dart';
// import 'package:marking_app/components/TestPaperItem.dart';
// import 'package:marking_app/utils/easy_refresh/MyEmptyWidget.dart';
// import 'package:marking_app/utils/easy_refresh/mixin/refresh_data_handle.dart';

// part 'index.g.dart';

// // 作业主页
// class HomeworkCorrection extends StatefulHookConsumerWidget {
//   const HomeworkCorrection({Key? key}) : super(key: key);

//   @override
//   _HomeworkCorrectionState createState() => _HomeworkCorrectionState();
// }

// class _HomeworkCorrectionState extends ConsumerState<HomeworkCorrection>
//     with
//         CommonMixin,
//         SingleTickerProviderStateMixin,
//         RefreshDataHandle<MarkingItem, MarkingListParams>,
//         AutomaticKeepAliveClientMixin {
//   @override
//   bool get wantKeepAlive => true;

//   /* Tab控制器 */
//   late TabController _tabController;
//   int _tabIndex = 0;
//   bool completedToRefresh = true;

//   /* 待阅卷 */
//   late final EasyRefreshController _refreshController1;
//   final MarkingListParams params1 = MarkingListParams(
//     isFinish: false,
//     page: RequestConfig.basePage.page,
//     limit: RequestConfig.basePage.limit,
//     pageType: 0,
//   );
//   List<MarkingItem> markingDatas1 = [];

//   /* 已阅完 */
//   late final EasyRefreshController _refreshController2;
//   RemoveListener? _currentTaskIdListener;
//   final MarkingListParams params2 = MarkingListParams(
//     isFinish: true,
//     page: RequestConfig.basePage.page,
//     limit: RequestConfig.basePage.limit,
//     pageType: 0,
//   );
//   List<MarkingItem> markingDatas2 = [];

//   /* 发起请求 */
//   Future<List<MarkingItem>> getData(
//     EasyRefreshController controller,
//     MarkingListParams params, {
//     bool isReFresh = false,
//   }) async {
//     RestClient client = await getClient();
//     BasePageData<MarkingItem>? results = await toRefreshData(
//       controller,
//       api: client.getJobsByPage,
//       params: params,
//       isReFresh: isReFresh,
//       context: context,
//     );
//     if (results != null) return results.items;
//     return [];
//   }

//   @override
//   void initState() {
//     _tabController = TabController(length: 2, vsync: this);
//     _refreshController1 = EasyRefreshController();
//     _refreshController2 = EasyRefreshController();

//     Future.delayed(Duration.zero, () {
//       //在这里处理页面
//       _currentTaskIdListener = ref.watch(currentTaskIdProvider.notifier).addListener((state) {
//         int? taskId = state.taskId;

//         if (taskId != null && state.refresh) {
//           _refreshController1.callRefresh();
//           _refreshController2.callRefresh();
//         }
//       });
//     });
//     super.initState();
//   }

//   @override
//   void dispose() {
//     if (_currentTaskIdListener != null) {
//       _currentTaskIdListener!();
//     }
//     _tabController.dispose();
//     _refreshController1.dispose();
//     _refreshController2.dispose();
//     super.dispose();
//   }

//   /// 刷新方法
//   Future<void> onMyRefresh(EasyRefreshController controller, MarkingListParams params, int tab) async {
//     params.page = RequestConfig.basePage.page;
//     List<MarkingItem> lists = await getData(controller, params, isReFresh: true);
//     try {
//       tab == 1 ? (markingDatas1 = lists) : (markingDatas2 = lists);
//     } catch (e) {}
//     toUpState(setState, () {}, mounted);
//   }

//   /// 加载方法
//   Future<void> onMyLoad(EasyRefreshController controller, MarkingListParams params, int tab) async {
//     params.page++;
//     List<MarkingItem> lists = await getData(controller, params);
//     if (lists.isNotEmpty) {
//       tab == 1 ? markingDatas1.addAll(lists) : markingDatas2.addAll(lists);
//       toUpState(setState, () {}, mounted);
//     }
//   }

//   @override
//   Widget build(BuildContext context) {
//     super.build(context); //调用super.build(返回值始终返回null，应将其忽略)

//     return AnnotatedRegion(
//       value: const SystemUiOverlayStyle(
//         systemNavigationBarColor: Color(0xFF000000),
//         systemNavigationBarDividerColor: null,
//         statusBarColor: Colors.transparent,
//         systemNavigationBarIconBrightness: Brightness.light,
//         statusBarIconBrightness: Brightness.dark,
//         statusBarBrightness: Brightness.light,
//       ),
//       child: Scaffold(
//         body: Column(
//           children: <Widget>[
//             Padding(
//               padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 4.h),
//               child: TabBar(
//                 controller: _tabController,
//                 unselectedLabelStyle: TextStyle(fontSize: 14.sp),
//                 labelStyle: TextStyle(
//                     fontSize: 16.sp, fontWeight: FontWeight.bold, color: const Color.fromRGBO(148, 163, 182, 1)),
//                 labelColor: const Color.fromRGBO(45, 56, 76, 1),
//                 indicatorSize: TabBarIndicatorSize.label,
//                 onTap: (index) {
//                   setState(() {
//                     _tabIndex = index;
//                     if (index == 1 && completedToRefresh) {
//                       // 已阅卷
//                       _refreshController2.callRefresh();
//                       completedToRefresh = false;
//                     }
//                   });
//                 },
//                 tabs: const <Widget>[Tab(text: '待批阅'), Tab(text: '已阅完')],
//               ),
//             ),
//             Expanded(
//               child: IndexedStack(
//                 index: _tabIndex,
//                 children: <Widget>[
//                   $EasyRefresh(
//                     controller: _refreshController1,
//                     params: params1,
//                     tab: 1,
//                     data: markingDatas1,
//                     onLoad: onMyLoad,
//                     onRefresh: onMyRefresh,
//                   ),
//                   $EasyRefresh(
//                     controller: _refreshController2,
//                     params: params2,
//                     tab: 2,
//                     data: markingDatas2,
//                     onLoad: onMyLoad,
//                     onRefresh: onMyRefresh,
//                   ),
//                 ],
//               ),
//             ),
//           ],
//         ),
//       ),
//     );
//   }
// }

// /// 已阅卷
// /// OnRefreshCallback? onRefresh
// ///
// @swidget
// Widget $easyRefresh({
//   required EasyRefreshController controller,
//   required Future<void> Function(EasyRefreshController controller, MarkingListParams params, int tab) onRefresh,
//   required Future<void> Function(EasyRefreshController controller, MarkingListParams params, int tab) onLoad,
//   required MarkingListParams params,
//   required List<MarkingItem> data,
//   required int tab,
// }) {
//   return EasyRefresh(
//     firstRefresh: true,
//     taskIndependence: true,
//     enableControlFinishLoad: true,
//     enableControlFinishRefresh: true,
//     emptyWidget: data.isEmpty ? const MyEmptyWidget() : null,
//     controller: controller,
//     header: MaterialHeader(),
//     footer: TaurusFooter(),
//     child: ListView.builder(
//       padding: EdgeInsets.only(top: 4.h, bottom: 10.h),
//       itemBuilder: (context, index) => TestPaperItem(
//         markingItem: data[index],
//         isHomeworkCorrection: true,
//         call: () {
//           print('开始批改...................................');
//           controller.callRefresh();
//         },
//       ),
//       itemCount: data.length,
//     ),
//     onRefresh: () => onRefresh(controller, params, tab),
//     onLoad: () => onLoad(controller, params, tab),
//   );
// }
