import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_echart/flutter_echart.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:functional_widget_annotation/functional_widget_annotation.dart';
import 'package:marking_app/common/mixin/common.dart';
import 'package:marking_app/common/model/common/base_structure_result.dart';
import 'package:marking_app/common/model/job/job_report_join_class.dart';
import 'package:marking_app/common/model/job/job_report_knowledge_model.dart';
import 'package:marking_app/common/model/job/job_report_model.dart';
import 'package:marking_app/components/ReturnToHomepage.dart';
import 'package:marking_app/pages/homework_correction/widget/report_table.dart';
import 'package:marking_app/pages/homework_correction/widget/top_count.dart';
import 'package:marking_app/pages/mainPage.dart';
import 'package:marking_app/routes/RouterManager.dart';
import 'package:marking_app/utils/index.dart';
import 'package:marking_app/utils/my_text.dart';
import 'package:marking_app/utils/request/rest_client.dart';
import 'package:marking_app/utils/right_home_icon.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';
import 'package:photo_view/photo_view.dart';

import '../../utils/flutter_wave_loading.dart';

part 'job_report.g.dart';

/// 作业报告
class JobReport extends StatefulWidget {
  final int id;
  final int? schoolId;
  final int? gradeId;
  final String? className;
  final String title;

  const JobReport({required this.id, required this.title, this.schoolId, this.gradeId, this.className, super.key});

  @override
  State<JobReport> createState() => _JobReportState();
}

class _JobReportState extends State<JobReport> with CommonMixin {
  late Future<JobReportModel?> _future; // 考试试卷

  List<JobReportJoinClass>? involveClasses = [];
  JobReportJoinClass? classData;
  JobReportModel? jobReportModel;

  @override
  void initState() {
    getInvolveClasses();
    _future = getReport();
    super.initState();
  }

  Future<void> getInvolveClasses() async {
    try {
      RestClient _client = await getClient();
      BaseStructureResult<List<JobReportJoinClass>> result = await _client.getJobReportJoinClasses(widget.id);
      if (result.success) {
        toUpState(setState, () {
          involveClasses = [JobReportJoinClass(-1, '全部', -1, '全部', '全部', '全部', -1, -1, '-1'), ...(result.data ?? [])];
          involveClasses?.forEach((element) {
            if (element.className == widget.className &&
                element.gradeId == widget.gradeId &&
                element.schoolId == widget.schoolId) {
              classData = element;
            }
          });
        }, mounted);
      }
      _future = getReport();
    } catch (e) {
      print(e);
    }
  }

  Future<JobReportModel?> getReport() async {
    try {
      RestClient _client = await getClient();
      Map<String, dynamic> param = classData?.toJson() ?? {};
      param['jobid'] = widget.id;
      BaseStructureResult<JobReportModel?> data = await _client.getJobReport(param);
      if (!data.success) {
        throw Exception(data.message ?? '获取报告失败');
      }
      return data.data;
    } catch (e) {
      print(e);
    }
    return null;
  }

  Future<void> detailKnowledgeCall(KnowledgeInfos knowledge) async {
    ToastUtils.showLoading();
    try {
      if (knowledge.details == null) {
        RestClient _client = await getClient();
        BaseStructureResult<List<JobReportKnowledgeModel>> datas =
            await _client.getDetailKnowledge(widget.id, knowledge.knowledgeId);
        if (!datas.success) return ToastUtils.showInfo(datas.message ?? '获取知识点失败');
        knowledge.details = datas.data;
      }

      showDialog(
        context: context,
        builder: (BuildContext context1) {
          return Container(
            margin: EdgeInsets.symmetric(vertical: 150.h, horizontal: 24.w),
            padding: EdgeInsets.symmetric(vertical: 15.h),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(18.sp),
            ),
            child: Column(
              children: [
                Container(
                    alignment: Alignment.center,
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: [
                        quickText(knowledge.knowledgeName, color: Theme.of(context1).primaryColor, size: 16.sp),
                        quickText(
                          '的掌握情况',
                          color: Color.fromRGBO(60, 60, 60, 1),
                          size: 15.sp,
                          maxLines: 2,
                        ),
                      ],
                    )),
                Expanded(
                  child: ListView(padding: EdgeInsets.symmetric(horizontal: 12.w), children: [
                    DataTable(
                      sortAscending: false,
                      columns: [
                        DataColumn(
                          label: quickText('班级',
                              color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                        ),
                        DataColumn(
                          label: quickText('掌握度',
                              color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                        ),
                        DataColumn(
                          label: quickText('人数',
                              color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                        ),
                        DataColumn(
                          label: quickText('操作',
                              color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                        ),
                      ],
                      rows: [
                        ...knowledge.details?.map((e) {
                              return DataRow(cells: [
                                DataCell(quickText(e.className, color: Color.fromRGBO(61, 61, 61, 1))),
                                DataCell(quickText(e.rate > 0 ? doubleToStringAsFixed(e.rate) + '%' : 0,
                                    color: Color.fromRGBO(61, 61, 61, 1))),
                                DataCell(quickText(e.ratio, color: Color.fromRGBO(61, 61, 61, 1))),
                                DataCell(quickText('详情', color: Color.fromRGBO(239, 135, 20, 1)), onTap: () {
                                  showDialog(
                                    context: context1,
                                    builder: (BuildContext context2) {
                                      return Container(
                                        margin: EdgeInsets.symmetric(vertical: 150.h, horizontal: 24.w),
                                        padding: EdgeInsets.symmetric(vertical: 15.h),
                                        decoration: BoxDecoration(
                                          color: Colors.white,
                                          borderRadius: BorderRadius.circular(18.sp),
                                        ),
                                        child: Column(
                                          children: [
                                            Container(
                                                child: quickText(
                                              '${e.className}的掌握情况',
                                              color: Color.fromRGBO(239, 135, 20, 1),
                                              size: 16.sp,
                                              maxLines: 2,
                                              fontWeight: FontWeight.bold,
                                            )),
                                            SizedBox(height: 20.h),
                                            Expanded(
                                              child:
                                                  ListView(padding: EdgeInsets.symmetric(horizontal: 12.w), children: [
                                                DataTable(
                                                  sortAscending: false,
                                                  columns: [
                                                    DataColumn(
                                                      label: quickText('学生名字',
                                                          color: Color.fromRGBO(114, 114, 114, 1),
                                                          size: 14.sp,
                                                          fontWeight: FontWeight.bold),
                                                    ),
                                                    DataColumn(
                                                      label: quickText('掌握度',
                                                          color: Color.fromRGBO(114, 114, 114, 1),
                                                          size: 14.sp,
                                                          fontWeight: FontWeight.bold),
                                                    ),
                                                  ],
                                                  rows: [
                                                    ...e.studentReports.map((e) {
                                                      return DataRow(
                                                        cells: [
                                                          DataCell(quickText(e.studentName)),
                                                          DataCell(e.pass
                                                              ? Icon(Icons.check_outlined, color: Colors.green)
                                                              : Icon(Icons.close_outlined, color: Colors.red)),
                                                        ],
                                                      );
                                                    }).toList()
                                                  ],
                                                ),
                                              ]),
                                            )
                                          ],
                                        ),
                                      );
                                    },
                                  );
                                }),
                              ]);
                            }).toList() ??
                            [],
                      ],
                    ),
                  ]),
                )
              ],
            ),
          );
        },
      );
    } catch (e) {
    } finally {
      ToastUtils.dismiss();
    }
  }

  @override
  Widget build(BuildContext context) {
    bool isPadFlag = isPad();
    return Scaffold(
      backgroundColor: Color.fromRGBO(245, 245, 245, 1),
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Center(
            child: quickText(
          widget.title + '作业报告',
          size: 14.sp,
          color: Color.fromRGBO(51, 51, 51, 1),
        )),
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        actions: [
          ReturnToHomepage(),
        ],
        /*actions: [
          // 下拉框
          $DropdownSelection(involveClasses, classData, call: (JobReportJoinClass _classData) {
            classData = _classData;
            if (_classData.gradeId == -1) classData = null;
            _future = getReport();
            toUpState(setState, () {}, mounted);
          }),
        ],*/
      ),
      body: MyFutureBuilder.buildFutureBuilderOfSingleInstance<JobReportModel>(context, _future, (data) {
        if (data == null)
          return Container(
            alignment: Alignment.center,
            child: ElevatedButton(
              child: quickText('点击再次发起请求', color: Colors.white),
              onPressed: () {
                toUpState(setState, () => _future = getReport(), mounted);
              },
            ),
          );

        return ListView(
          padding: EdgeInsets.symmetric(horizontal: 0.w),
          children: [
            // 下拉框
            Container(
              padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 10.w),
              decoration: BoxDecoration(
                color: Colors.white,
              ),
              child: Row(
                children: [
                  $DropdownSelection(involveClasses, classData, call: (JobReportJoinClass _classData) {
                    classData = _classData;
                    if (_classData.gradeId == -1) classData = null;
                    _future = getReport();
                    toUpState(setState, () {}, mounted);
                  }),
                  // Expanded(child: Text('')),
                ],
              ),
            ),
            //完成率、正确率
            TopCount(data,classData == null?'':classData!.className,widget.id),
            /*  InkWell(
              onTap: (){
                RouterManager.router.navigateTo(
                  context,
                  RouterManager.quickDataCheckPath +
                      '?jobId=${1}&className=',
                  transition: getTransition(),
                );
              },
              child: Text('数据快查'),
            ),*/
            //客观题
            Container(
              padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 14.r),
              margin: EdgeInsets.symmetric(vertical: 10.r, horizontal: 10.r),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(6.r)),
              ),
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                        '客观题',
                        style: TextStyle(fontSize: 14.sp, color: Color(0xFF5C5C5C), fontWeight: FontWeight.w600),
                      ),
                      SizedBox(
                        width: 10.r,
                      ),
                      Text(
                        '${data.kgReport.correctRate}%',
                        style: TextStyle(fontSize: 14.sp, color: Color(0xFF6888FD), fontWeight: FontWeight.w600),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 6.r,
                  ),
                  SizedBox(
                    height: data.kgReport.details.length > 10 ? 300.r : data.kgReport.details.length * 40.r + (isPadFlag == true ?40.r:65.r),
                    child: ReportTable(
                      headList: ['题', '作答率', '作答人数', '正确率', '标准答案', '优先批阅概况'],
                      bodyList: data.kgReport.details,
                      fixedCols: 1,
                      fixedRows: 1,
                      jobId: widget.id,
                    ),
                  )
                ],
              ),
            ),
            //主观题
            Container(
              padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 14.r),
              margin: EdgeInsets.symmetric(vertical: 10.r, horizontal: 10.r),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(6.r)),
              ),
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                        '主观题',
                        style: TextStyle(fontSize: 14.sp, color: Color(0xFF5C5C5C), fontWeight: FontWeight.w600),
                      ),
                      SizedBox(
                        width: 6.r,
                      ),
                      Text(
                        '${data.zgReport.correctRate}%',
                        style: TextStyle(fontSize: 14.sp, color: Color(0xFF6888FD), fontWeight: FontWeight.w600),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  SizedBox(
                    height: data.zgReport.details.length > 10 ? 300.r : data.zgReport.details.length * 40.r +(isPad() == true ?40.r:65.r),
                    child: ReportTable(
                      headList: ['题', '作答率', '作答人数', '正确率', '查看原题', '优先批阅概况'],
                      bodyList: data.zgReport.details,
                      fixedCols: 1,
                      fixedRows: 1,
                      isKG: true,
                      jobId: widget.id,
                    ),
                  )
                ],
              ),
            ),
            // 顶部图形数据
            /*  $TopGraphic(data),*/
            // 掌握知识点的情况
            Container(
                margin: EdgeInsets.symmetric(horizontal: 10.r),
                child: $MasterKnowledgePoint(data.knowledgeInfos, detailKnowledgeCall)),
            // 掌握知识点的情况
           /* Container(
                margin: EdgeInsets.symmetric(horizontal: 10.r),
                child: $OverallPerformance(data.studentCount, data.overallTitles)),
            // 单位时间答题情况
            Container(
                margin: EdgeInsets.symmetric(horizontal: 10.r),
                child: $UnitTimeAnsweringSituation(widget.id, data.questionAnswerInfos)),*/
            // 人员数据概况
            Container(
                margin: EdgeInsets.symmetric(horizontal: 10.r), child: $PersonnelDataOverview(data.studentAnswerInfos)),
          ],
        );
      }),
    );
  }
}

/// 下拉选择框
@swidget
Widget $dropdownSelection(List<JobReportJoinClass>? involveClasses, JobReportJoinClass? classData,
    {required Function(JobReportJoinClass) call}) {
  if (involveClasses == null) return Container(child: quickText('点击重试')); // 点击重试
  return Container(
    // width: 200.r,
    padding: EdgeInsets.symmetric(horizontal: 10.r),
    decoration: BoxDecoration(
        color: Color(0xFFF5F5F5),
        borderRadius: BorderRadius.vertical(
          top: Radius.elliptical(10, 10),
          bottom: Radius.elliptical(10, 10),
        )),
    child: DropdownButton(
      value: classData?.uniqueId ?? '-1',
      style: TextStyle(color: Color.fromRGBO(89, 89, 89, 1), fontSize: 12.sp),
      underline: Container(),
      // isExpanded:true,
      items: involveClasses.map((e) {
        return DropdownMenuItem(
          value: e.uniqueId!,
          child: quickText(
              e.uniqueId == '-1'
                  ? e.graduationYear
                  :
              e.gradeName + e.className, size: 12.sp, color: Colors.black),
        );
      }).toList(),
      onChanged: (String? value) {
        if (value == null) return;
        call(involveClasses.firstWhere((element) => element.uniqueId == value));
      },
    ),
  );
}

/// 顶部图形数据
@swidget
Widget $topGraphic(BuildContext context, JobReportModel data) {
  void showDetail(String showType) async {
    // 全对 及格 不及格 未做
    List<StudentAnswerInfos> students = [];
    List<Widget> dataColumns = [];
    String title = '';
    switch (showType) {
      case '全对':
        title = '全对';
        students = data.allpairsStudents!;
        break;
      case '及格':
        title = '及格';
        students = data.passStudents!;
        break;
      case '不及格':
        title = '不及格';
        students = data.disqualifiedStudents!;
        break;
      case '未做':
        title = '未做';
        students = data.notdoneStudents!;
        break;
    }

    if (students.isEmpty) return ToastUtils.showInfo('没有$title学生');
    // 弹出框展示学生信息
    showDialog(
      context: context,
      builder: (BuildContext context1) {
        return Container(
          margin: EdgeInsets.symmetric(vertical: 150.h, horizontal: 24.w),
          padding: EdgeInsets.symmetric(vertical: 15.h),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(18.sp),
          ),
          child: Column(
            children: [
              Container(child: quickText('$title学生', color: Color.fromRGBO(60, 60, 60, 1), size: 15.sp)),
              Expanded(
                child: ListView(padding: EdgeInsets.symmetric(horizontal: 12.w), children: [
                  DataTable(
                    sortAscending: false,
                    columns: [
                      DataColumn(
                        label: quickText('姓名',
                            color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                      ),
                      DataColumn(
                        label: quickText('正确率',
                            color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                      ),
                      DataColumn(
                        label: quickText('未答题数',
                            color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                      ),
                      DataColumn(
                        label: quickText('用时(秒)',
                            color: Color.fromRGBO(114, 114, 114, 1), size: 14.sp, fontWeight: FontWeight.bold),
                      ),
                    ],
                    rows: [
                      ...students.map((e) {
                        return DataRow(cells: [
                          DataCell(quickText(e.studentName, color: Color.fromRGBO(61, 61, 61, 1))),
                          DataCell(quickText(doubleToStringAsFixed(e.correctRate) + '%',
                              color: Color.fromRGBO(61, 61, 61, 1))),
                          DataCell(quickText(e.noAnswerCount, color: Color.fromRGBO(61, 61, 61, 1))),
                          DataCell(quickText(e.useTime, color: Color.fromRGBO(61, 61, 61, 1))),
                        ]);
                      }).toList(),
                    ],
                  ),
                ]),
              )
            ],
          ),
        );
      },
    );
  }

  return Container(
    margin: EdgeInsets.only(top: 16.h, bottom: 10.h),
    padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 14.h),
    decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16.r)),
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        // 整体评价
        Stack(
          alignment: const FractionalOffset(0.5, 0.05),
          children: [
            Padding(
              padding: EdgeInsetsDirectional.all(30.r),
              child: Container(
                width: 188.r,
                height: 188.r,
                alignment: Alignment.center,
                padding: EdgeInsets.all(20.r),
                decoration: BoxDecoration(
                  color: Colors.white,
                  shape: BoxShape.circle, // 设置为圆形
                  boxShadow: [
                    BoxShadow(
                      color: const Color.fromRGBO(104, 136, 253, 1),
                      spreadRadius: 1.r, // 阴影扩散半径
                      blurRadius: 8.r, // 阴影模糊半径
                      offset: Offset(0.0, 0), // 阴影偏移量
                    )
                  ],
                ),
                child: Container(
                  alignment: Alignment.center,
                  padding: EdgeInsets.all(13.r),
                  decoration: BoxDecoration(
                    shape: BoxShape.circle, // 设置为圆形
                    color: Color.fromRGBO(215, 223, 255, 1),
                  ),
                  child: Container(
                    decoration: BoxDecoration(
                      // color: Color.fromRGBO(104, 136, 253, 1),
                      shape: BoxShape.circle, // 设置为圆形
                      border: Border.all(color: Color.fromRGBO(0, 179, 134, 0)),
                      gradient: RadialGradient(
                        center: Alignment.center, // 渐变中心点
                        colors: [
                          Color.fromRGBO(104, 136, 253, 0.7),
                          Color.fromRGBO(104, 136, 253, 0.8),
                          Color.fromRGBO(104, 136, 253, 0.9),
                          Color.fromRGBO(104, 136, 253, 1),
                        ],
                      ),
                    ),
                    alignment: Alignment.center,
                    child: quickText(data.scoreTitle, color: Colors.white, size: 32.sp, fontWeight: FontWeight.bold),
                  ),
                ),
              ),
            ),
            Image.asset("assets/images/job_report_scale.png", width: 230.r, fit: BoxFit.fill),
          ],
        ),

        // 完成率、正确率、作业数量
        Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            Container(
              width: 188.r,
              height: 188.r,
              padding: EdgeInsets.all(9.r),
              decoration: BoxDecoration(
                shape: BoxShape.circle, // 设置为圆形
                color: Color.fromRGBO(104, 136, 253, 1),
              ),
              child: Row(
                children: [
                  Expanded(
                    flex: 2,
                    child:
                        quickText('${data.validCount}份', color: Colors.white, size: 10.sp, fontWeight: FontWeight.bold),
                  ),
                  SizedBox(width: 1.2.w),
                  Expanded(
                    flex: 7,
                    child: Container(
                      padding: EdgeInsets.all(12.r),
                      decoration: BoxDecoration(
                          shape: BoxShape.circle, // 设置为圆形
                          color: Color.fromRGBO(76, 199, 147, 1)),
                      child: Row(
                        children: [
                          Expanded(
                              flex: 2,
                              child: quickText('${doubleToStringAsFixed(data.correctRate)}%',
                                  color: Colors.white, size: 10.sp, fontWeight: FontWeight.bold)),
                          Expanded(
                            flex: 5,
                            child: Container(
                              width: double.infinity,
                              height: double.infinity,
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                shape: BoxShape.circle, // 设置为圆形
                                color: Color.fromRGBO(254, 151, 40, 1),
                              ),
                              child: quickText('${doubleToStringAsFixed(data.finishRate)}%',
                                  color: Colors.white, size: 14.sp, fontWeight: FontWeight.bold),
                            ),
                          ),
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
            SizedBox(width: 20.w),
            Container(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        width: 10.r,
                        height: 10.r,
                        decoration: BoxDecoration(
                          shape: BoxShape.circle, // 设置为圆形
                          color: Color.fromRGBO(254, 151, 40, 1),
                        ),
                      ),
                      SizedBox(width: 5.w),
                      quickText('作业完成率', color: Color.fromRGBO(114, 114, 114, 1), size: 12.sp),
                      SizedBox(width: 4.w),
                      quickText('${doubleToStringAsFixed(data.finishRate)}%',
                          color: Color.fromRGBO(72, 72, 72, 1), size: 13.sp, fontWeight: FontWeight.bold),
                    ],
                  ),
                  SizedBox(height: 14.h),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        width: 10.r,
                        height: 10.r,
                        decoration: BoxDecoration(
                          shape: BoxShape.circle, // 设置为圆形
                          color: Color.fromRGBO(76, 199, 147, 1),
                        ),
                      ),
                      SizedBox(width: 5.w),
                      quickText('作业正确率', color: Color.fromRGBO(114, 114, 114, 1), size: 12.sp),
                      SizedBox(width: 4.w),
                      quickText('${doubleToStringAsFixed(data.correctRate)}%',
                          color: Color.fromRGBO(72, 72, 72, 1), size: 13.sp, fontWeight: FontWeight.bold),
                    ],
                  ),
                  SizedBox(height: 14.h),
                  Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        width: 10.r,
                        height: 10.r,
                        decoration: BoxDecoration(
                          shape: BoxShape.circle, // 设置为圆形
                          color: Color.fromRGBO(104, 136, 253, 1),
                        ),
                      ),
                      SizedBox(width: 5.w),
                      quickText('作业有效份数', color: Color.fromRGBO(114, 114, 114, 1), size: 12.sp),
                      SizedBox(width: 4.w),
                      quickText('${data.validCount}份',
                          color: Color.fromRGBO(72, 72, 72, 1), size: 13.sp, fontWeight: FontWeight.bold),
                    ],
                  ),
                ],
              ),
            )
          ],
        ),
        SizedBox(height: 50.h),
        // 全对、及格、不及格、未做
        Wrap(
          spacing: 30.r,
          runSpacing: 26.r,
          children: [
            // 全对
            Container(
              child: Column(
                children: [
                  Stack(
                    alignment: const FractionalOffset(0.5, 0.94),
                    children: [
                      Container(
                        width: 140.w, //宽
                        height: 170.h, //高
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10.r),
                          color: Color.fromRGBO(241, 241, 241, 1),
                        ),
                        child: FlutterWaveLoading(
                          width: 140.w,
                          //宽
                          height: 170.h,
                          //高
                          isOval: false,
                          // 是否椭圆裁切
                          progress: data.allCorrect / data.studentCount,
                          // 进度
                          waveHeight: 8,
                          //波浪高
                          milliseconds: 5000,
                          color: Color.fromRGBO(0, 179, 134, 1), //颜色
                        ),
                      ),
                      Positioned(
                          left: 16.h,
                          top: 10.h,
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              Row(
                                mainAxisSize: MainAxisSize.min,
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: [
                                  quickText(
                                    data.allCorrect,
                                    size: 32.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Color.fromRGBO(122, 122, 122, 1),
                                  ),
                                  Column(
                                    mainAxisSize: MainAxisSize.min,
                                    children: [
                                      quickText('人', size: 18.sp, color: Color.fromRGBO(122, 122, 122, 1)),
                                      SizedBox(height: 4.h)
                                    ],
                                  )
                                ],
                              ),
                              quickText('全对', color: Color.fromRGBO(164, 164, 164, 1), size: 16.sp),
                            ],
                          )),
                      Row(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          quickText(doubleToStringAsFixed(data.allCorrect / data.studentCount * 100),
                              size: 34.sp, color: Colors.white, fontWeight: FontWeight.bold),
                          SizedBox(width: 1.5.w),
                          quickText('%', size: 22.sp, color: Colors.white)
                        ],
                      ),
                    ],
                  ),
                  SizedBox(height: 8.h),
                  InkWell(
                    onTap: () => showDetail('全对'),
                    child: Container(
                      width: 77.w,
                      alignment: Alignment.center,
                      padding: EdgeInsets.symmetric(vertical: 4.h),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(77.r),
                        border: Border.all(color: Color.fromRGBO(188, 188, 188, 1)),
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          quickText('查看', size: 11.sp, color: Color.fromRGBO(118, 118, 118, 1)),
                          Icon(Icons.arrow_forward_ios, size: 11.sp, color: Color.fromRGBO(95, 95, 95, 1))
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
            // 及格
            Container(
              child: Column(
                children: [
                  Stack(
                    alignment: const FractionalOffset(0.5, 0.94),
                    children: [
                      Container(
                        width: 140.w, //宽
                        height: 170.h, //高
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10.r),
                          color: Color.fromRGBO(241, 241, 241, 1),
                        ),
                        child: FlutterWaveLoading(
                          width: 140.w,
                          //宽
                          height: 170.h,
                          //高
                          isOval: false,
                          // 是否椭圆裁切
                          progress: data.passCount / data.studentCount,
                          // 进度
                          waveHeight: 8,
                          //波浪高
                          milliseconds: 8000,
                          color: Color.fromRGBO(255, 134, 0, 0.84), //颜色
                        ),
                      ),
                      Positioned(
                          left: 16.h,
                          top: 10.h,
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              Row(
                                mainAxisSize: MainAxisSize.min,
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: [
                                  quickText(
                                    data.passCount,
                                    size: 32.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Color.fromRGBO(122, 122, 122, 1),
                                  ),
                                  Column(
                                    mainAxisSize: MainAxisSize.min,
                                    children: [
                                      quickText('人', size: 18.sp, color: Color.fromRGBO(122, 122, 122, 1)),
                                      SizedBox(height: 4.h)
                                    ],
                                  )
                                ],
                              ),
                              quickText('及格', color: Color.fromRGBO(164, 164, 164, 1), size: 16.sp),
                            ],
                          )),
                      Row(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          quickText(doubleToStringAsFixed(data.passCount / data.studentCount * 100),
                              size: 34.sp, color: Colors.white, fontWeight: FontWeight.bold),
                          SizedBox(width: 1.5.w),
                          quickText('%', size: 22.sp, color: Colors.white)
                        ],
                      ),
                    ],
                  ),
                  SizedBox(height: 8.h),
                  InkWell(
                    onTap: () => showDetail('及格'),
                    child: Container(
                      width: 77.w,
                      alignment: Alignment.center,
                      padding: EdgeInsets.symmetric(vertical: 4.h),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(77.r),
                        border: Border.all(color: Color.fromRGBO(188, 188, 188, 1)),
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          quickText('查看', size: 11.sp, color: Color.fromRGBO(118, 118, 118, 1)),
                          Icon(Icons.arrow_forward_ios, size: 11.sp, color: Color.fromRGBO(95, 95, 95, 1))
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
            // 不及格
            Container(
              child: Column(
                children: [
                  Stack(
                    alignment: const FractionalOffset(0.5, 0.94),
                    children: [
                      Container(
                        width: 140.w, //宽
                        height: 170.h, //高
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10.r),
                          color: Color.fromRGBO(241, 241, 241, 1),
                        ),
                        child: FlutterWaveLoading(
                          width: 140.w,
                          //宽
                          height: 170.h,
                          //高
                          isOval: false,
                          // 是否椭圆裁切
                          progress: data.failCount / data.studentCount,
                          // 进度
                          waveHeight: 8,
                          //波浪高
                          milliseconds: 7000,
                          color: Color.fromRGBO(255, 106, 106, 1), //颜色
                        ),
                      ),
                      Positioned(
                          left: 16.h,
                          top: 10.h,
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              Row(
                                mainAxisSize: MainAxisSize.min,
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: [
                                  quickText(
                                    data.failCount,
                                    size: 32.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Color.fromRGBO(122, 122, 122, 1),
                                  ),
                                  Column(
                                    mainAxisSize: MainAxisSize.min,
                                    children: [
                                      quickText('人', size: 18.sp, color: Color.fromRGBO(122, 122, 122, 1)),
                                      SizedBox(height: 4.h)
                                    ],
                                  )
                                ],
                              ),
                              quickText('不及格', color: Color.fromRGBO(164, 164, 164, 1), size: 16.sp),
                            ],
                          )),
                      Row(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          quickText(doubleToStringAsFixed(data.failCount / data.studentCount * 100),
                              size: 34.sp, color: Colors.white, fontWeight: FontWeight.bold),
                          SizedBox(width: 1.5.w),
                          quickText('%', size: 22.sp, color: Colors.white)
                        ],
                      ),
                    ],
                  ),
                  SizedBox(height: 8.h),
                  InkWell(
                    onTap: () => showDetail('不及格'),
                    child: Container(
                      width: 77.w,
                      alignment: Alignment.center,
                      padding: EdgeInsets.symmetric(vertical: 4.h),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(77.r),
                        border: Border.all(color: Color.fromRGBO(188, 188, 188, 1)),
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          quickText('查看', size: 11.sp, color: Color.fromRGBO(118, 118, 118, 1)),
                          Icon(Icons.arrow_forward_ios, size: 11.sp, color: Color.fromRGBO(95, 95, 95, 1))
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
            // 未做
            Container(
              child: Column(
                children: [
                  Stack(
                    alignment: const FractionalOffset(0.5, 0.94),
                    children: [
                      Container(
                        width: 140.w, //宽
                        height: 170.h, //高
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10.r),
                          color: Color.fromRGBO(241, 241, 241, 1),
                        ),
                        child: FlutterWaveLoading(
                          width: 140.w,
                          //宽
                          height: 170.h,
                          //高
                          isOval: false,
                          // 是否椭圆裁切
                          progress: data.noAnswerCount / data.studentCount,
                          // 进度
                          waveHeight: 8,
                          //波浪高
                          milliseconds: 6000,
                          color: Color.fromRGBO(96, 96, 96, 1), //颜色
                        ),
                      ),
                      Positioned(
                        left: 16.h,
                        top: 10.h,
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Row(
                              mainAxisSize: MainAxisSize.min,
                              crossAxisAlignment: CrossAxisAlignment.end,
                              children: [
                                quickText(
                                  data.noAnswerCount,
                                  size: 32.sp,
                                  fontWeight: FontWeight.bold,
                                  color: Color.fromRGBO(122, 122, 122, 1),
                                ),
                                Column(
                                  mainAxisSize: MainAxisSize.min,
                                  children: [
                                    quickText('人', size: 18.sp, color: Color.fromRGBO(122, 122, 122, 1)),
                                    SizedBox(height: 4.h)
                                  ],
                                )
                              ],
                            ),
                            quickText('未做', color: Color.fromRGBO(164, 164, 164, 1), size: 16.sp),
                          ],
                        ),
                      ),
                      Row(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          quickText(doubleToStringAsFixed(data.noAnswerCount / data.studentCount * 100),
                              size: 34.sp, color: Colors.white, fontWeight: FontWeight.bold),
                          SizedBox(width: 1.5.w),
                          quickText('%', size: 22.sp, color: Colors.white)
                        ],
                      ),
                    ],
                  ),
                  SizedBox(height: 8.h),
                  InkWell(
                    onTap: () => showDetail('未做'),
                    child: Container(
                      width: 77.w,
                      alignment: Alignment.center,
                      padding: EdgeInsets.symmetric(vertical: 4.h),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(77.r),
                        border: Border.all(color: Color.fromRGBO(188, 188, 188, 1)),
                      ),
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          quickText('查看', size: 11.sp, color: Color.fromRGBO(118, 118, 118, 1)),
                          Icon(Icons.arrow_forward_ios, size: 11.sp, color: Color.fromRGBO(95, 95, 95, 1))
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
        SizedBox(height: 30.h)
      ],
    ),
  );
}

/// 掌握知识点的情况
@swidget
Widget $masterKnowledgePoint(BuildContext context, List<KnowledgeInfos> knowledgeInfos,
    Future<void> Function(KnowledgeInfos knowledge) detailCall) {
  Widget childItem(int serialNumber, KnowledgeInfos knowItem) => Container(
        margin: EdgeInsets.only(bottom: 15.h, left: 15.r, right: 15.r),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Expanded(
                  flex: 10,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      quickText('${(serialNumber + 1).toString() + '.' + knowItem.knowledgeName}',
                          size: 12.sp, color: Color.fromRGBO(152, 152, 152, 1)),
                      quickText('${doubleToStringAsFixed(knowItem.rate)}%',
                          size: 12.sp, color: Color.fromRGBO(64, 64, 64, 1)),
                    ],
                  ),
                ),
                SizedBox(width: 10.w),
                Expanded(flex: 1, child: SizedBox()),
              ],
            ),
            SizedBox(height: 3.h),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                    flex: 10,
                    child: LinearPercentIndicator(
                      padding: EdgeInsets.zero,
                      animation: true,
                      lineHeight: 10.h,
                      animationDuration: 2500,
                      percent: 0.1,
                      /* center:
                      Text(
                        '${doubleToStringAsFixed(knowItem.rate)}%',
                        style: TextStyle(color: Colors.white, fontSize: 10.sp),
                      ),*/
                      progressColor: Theme.of(context).primaryColor,
                      backgroundColor: const Color.fromRGBO(219, 224, 243, 1),
                      barRadius: Radius.circular(10.r),
                    )),
                SizedBox(width: 10.w),
                InkWell(
                  onTap: () => detailCall(knowItem),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      quickText('查看', size: 12.sp, color: Color.fromRGBO(239, 135, 20, 1)),
                      Icon(Icons.arrow_forward_ios, size: 11.sp, color: Color.fromRGBO(239, 135, 20, 1)),
                    ],
                  ),
                ),
              ],
            )
          ],
        ),
      );
  return Container(
      margin: EdgeInsets.only(top: 10.h),
      padding: EdgeInsets.symmetric(vertical: 16.h, horizontal: 12.w),
      constraints: BoxConstraints(maxHeight: 320.h),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.r)),
      child: Column(
        children: [
          Container(
            child: quickText('知识点掌握情况', color: Color.fromRGBO(92, 92, 92, 1), size: 14.sp, fontWeight: FontWeight.bold),
            margin: EdgeInsets.only(bottom: 24.h),
          ),
          // ...knowledgeInfos.asMap().keys.map((e) => childItem(e, knowledgeInfos[e])).toList()
          Expanded(
            child: ListView(children: knowledgeInfos.asMap().keys.map((e) => childItem(e, knowledgeInfos[e])).toList()),
          ),
        ],
      ));
}

/// 整体表现
@swidget
Widget $overallPerformance(int totalNumber, List<OverallTitles> overallTitles) {
  List colorMap = [
    Color.fromRGBO(104, 136, 253, 1),
    Color.fromRGBO(255, 186, 33, 1),
    Color.fromRGBO(243, 163, 44, 1),
    Color.fromRGBO(201, 201, 201, 1),
    Color.fromRGBO(211, 211, 211, 1),
  ];
  return Container(
    margin: EdgeInsets.only(top: 20.h),
    padding: EdgeInsets.symmetric(vertical: 16.h, horizontal: 16.w),
    decoration: BoxDecoration(
      color: Colors.white,
      borderRadius: BorderRadius.circular(10.r),
    ),
    height: 310.h,
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          alignment: Alignment.center,
          child: quickText('整体表现', color: Color.fromRGBO(92, 92, 92, 1), size: 14.sp, fontWeight: FontWeight.bold),
          margin: EdgeInsets.only(bottom: 20.h),
        ),
        Expanded(
          child: PieChatWidget(
            dataList:  overallTitles.asMap().keys.map((index) {
              var e = overallTitles[index];
              return EChartPieBean(
                 title: e.title,

                  number: e.count,
                  color: colorMap[index]);
            }).toList(),
            //是否需要背景
            isBackground: true,
            //是否画直线
            isLineText: true,
            //背景
            bgColor: Colors.white,
            //是否显示最前面的内容
            isFrontgText: false,
            //默认选择放大的块
            initSelect: 1,
            //初次显示以动画方式展开
            openType: OpenType.ANI,
            //旋转类型
            loopType: LoopType.DOWN_LOOP,
            //点击回调
            clickCallBack: (int value) {
              print("当前点击显示 $value");
            },
          ),

         /* PieChart(
            PieChartData(
              borderData: FlBorderData(show: false),
              sectionsSpace: 0,
              centerSpaceRadius: 0,
              sections: overallTitles.asMap().keys.map((index) {
                var e = overallTitles[index];
                return PieChartSectionData(
                  color: colorMap[index],
                  value: e.count / totalNumber * 100,
                  radius: 110,
                  title: e.title + (doubleToStringAsFixed(e.count / totalNumber * 100) + '%'),
                  titleStyle: TextStyle(fontSize: 12.sp, color: Color(0xFF999999)),
                );
              }).toList(),
            ),
          ),*/
        )
      ],
    ),
  );
}

/// 单位时间答题情况
@swidget
Widget $unitTimeAnsweringSituation(BuildContext context, int jobid, List<QuestionAnswerInfos> questionAnswerInfos) {
  List<String> questionNos = []; // 题号
  List<String> questionTypes = []; // 题型
  List<String> completionStatusWithinThirtySeconds = []; // 30s内完成情况
  List<String> completionStatusWithinThirtyOneSixtySeconds = []; // 31s-60s内完成情况
  List<String> completionStatusWithinSixtyOneOneHundredAndTwenty = []; // 61s-120s内完成情况
  List<String> accuracys = []; // 正确率
  List<String> errorRate = []; // 错误率
  List<String> notDone = []; // 未做
  List<QuestionPictureModel> viewOriginalQuestion = []; // 查看原题
  List<QuestionPictureModel> operate = [];
  Map<String, List<dynamic>> mapData = {
    '题号': questionNos,
    '题型': questionTypes,
    '30s内完成情况': completionStatusWithinThirtySeconds,
    '31s-60s内完成情况': completionStatusWithinThirtyOneSixtySeconds,
    '61s-120s内完成情况': completionStatusWithinSixtyOneOneHundredAndTwenty,
    '正确率': accuracys,
    '错误率': errorRate,
    '未做': notDone,
    '查看原题': viewOriginalQuestion,
    // '操作': operate
  };

  questionAnswerInfos.forEach((e) {
    QuestionPictureModel _quinfoModel = QuestionPictureModel(
      questionNo: e.questionNo,
      jobid: jobid,
      questionid: e.questionId,
      questionPicture: e.questionPicture,
    );
    questionNos.add(e.questionNo); // 题号
    questionTypes.add(e.questionType == 2 ? '主观题' : '客观题'); // 题型

    accuracys.add(doubleToStringAsFixed(e.correctRate) + '%');
    errorRate.add(doubleToStringAsFixed(e.errorRate) + '%');
    notDone.add(doubleToStringAsFixed(e.noAnswerRate) + '%');
    viewOriginalQuestion.add(_quinfoModel);
    operate.add(_quinfoModel);

    e.finishInfos.forEach((element) {
      if ('30s内完成情况' == element.title) {
        completionStatusWithinThirtySeconds
            .add('${element.finishCount}人完成，正确率${doubleToStringAsFixed(element.correctRate)}%');
      } else if ('31-60s内完成情况' == element.title) {
        completionStatusWithinThirtyOneSixtySeconds
            .add('${element.finishCount}人完成，正确率${doubleToStringAsFixed(element.correctRate)}%');
      } else {
        // 61-120s内完成情况
        completionStatusWithinSixtyOneOneHundredAndTwenty
            .add('${element.finishCount}人完成，正确率${doubleToStringAsFixed(element.correctRate)}%');
      }
    });
  });
  bool containsChinese(String text) {
    // 汉字、扩展A、扩展B、兼容汉字等Unicode范围
    const int startRange = 0x4E00; // 汉字范围的起始Unicode码
    const int endRange = 0x9FFF; // 汉字范围的结束Unicode码

    for (int i = 0; i < text.length; i++) {
      int charCode = text.codeUnitAt(i);
      if (charCode >= startRange && charCode <= endRange) {
        return true; // 找到了中文字符
      }
    }

    return false; // 没有找到中文字符
  }
  return Container(
    width: double.infinity,
    // height: isPad() ? 520.h : 460.h,
    margin: EdgeInsets.only(top: 20.h),
    padding: EdgeInsets.symmetric(vertical: 16.h, horizontal: 12.w),
    decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.r)),
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          child: quickText('整体表现', color: Color.fromRGBO(92, 92, 92, 1), size: 14.sp, fontWeight: FontWeight.bold),
          margin: EdgeInsets.only(bottom: 20.h),
        ),
        Scrollbar(
          thickness: 8.w,
          thumbVisibility: true,
          trackVisibility: true,
          radius: Radius.circular(10.r),
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                ...mapData.entries.map((entrie) {
                  bool isViewButton = ['查看原题', '操作'].contains(entrie.key); // 查看按钮
                  bool isRatio = ['正确率', '错误率', '未做'].contains(entrie.key);
                  bool isQuestionNo = entrie.key == '题号';
                  return Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        width: 94.r,
                        alignment: Alignment.center,
                        margin: EdgeInsets.only(bottom: 1.h, right: 1.w),
                        padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 8.w),
                        color: Color.fromRGBO(230, 230, 230, 1),
                        child: quickText(entrie.key, color: Color.fromRGBO(24, 35, 77, 1), size: 12.sp, maxLines: 2),
                      ),
                      ...entrie.value.map((e) {
                        bool noHasChineseCharacter = isQuestionNo && !containsChinese(e);
                        return Container(
                          width: 96.r,
                          alignment: Alignment.center,
                          margin: EdgeInsets.only(bottom: 1.h, right: 1.w),
                          padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 8.w),
                          color: Color.fromRGBO(245, 245, 245, 1),
                          child: isViewButton
                              ? InkWell(
                                  onTap: () {
                                    // e
                                    var _qpm = e as QuestionPictureModel;
                                    // if (entrie.key == '操作') {
                                    //   showDialog(
                                    //     context: context,
                                    //     builder: (BuildContext context1) {
                                    //       return Container(
                                    //         margin: EdgeInsets.symmetric(vertical: 150.h, horizontal: 24.w),
                                    //         padding: EdgeInsets.symmetric(vertical: 15.h),
                                    //         decoration: BoxDecoration(
                                    //           color: Colors.white,
                                    //           borderRadius: BorderRadius.circular(18.sp),
                                    //         ),
                                    //         child: Column(
                                    //           children: [
                                    //             Container(
                                    //                 child: quickText('${_qpm.questionNo}题',
                                    //                     color: Color.fromRGBO(60, 60, 60, 1), size: 15.sp)),
                                    //             Expanded(
                                    //               child: ListView(
                                    //                   padding: EdgeInsets.symmetric(horizontal: 12.w),
                                    //                   children: [
                                    //                     DataTable(
                                    //                       sortAscending: false,
                                    //                       columns: [
                                    //                         DataColumn(
                                    //                           label: quickText('姓名',
                                    //                               color: Color.fromRGBO(114, 114, 114, 1),
                                    //                               size: 14.sp,
                                    //                               fontWeight: FontWeight.bold),
                                    //                         ),
                                    //                       ],
                                    //                       rows: [],
                                    //                     ),
                                    //                   ]),
                                    //             )
                                    //           ],
                                    //         ),
                                    //       );
                                    //     },
                                    //   );
                                    //   return;
                                    // }
                                    if (_qpm.questionPicture == null) return ToastUtils.showInfo('当前试题没有原题');
                                    Navigator.push(
                                      context,
                                      MaterialPageRoute(builder: (_) {
                                        return Scaffold(
                                          appBar: AppBar(),
                                          body: PhotoView(imageProvider: NetworkImage(_qpm.questionPicture!)),
                                        );
                                      }),
                                    );
                                  },
                                  child: Row(
                                    mainAxisSize: MainAxisSize.min,
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: [
                                      quickText('查看', color: Color.fromRGBO(239, 135, 20, 1), size: 12.sp),
                                      Container(
                                        padding: EdgeInsets.only(top: 1.h),
                                        child: Icon(
                                          Icons.arrow_forward_ios,
                                          size: 10.sp,
                                          color: Color.fromRGBO(239, 135, 20, 1),
                                        ),
                                      ),
                                    ],
                                  ),
                                )
                              : RegExp(r'^\d+$').hasMatch(e) || (e.contains('%') && e.length < 4)
                                  ? Row(
                                      mainAxisSize: MainAxisSize.min,
                                      children: [
                                        quickText(e,
                                            color: isRatio
                                                ? Theme.of(context).primaryColor
                                                : Color.fromRGBO(82, 82, 82, 1),
                                            size: isRatio || noHasChineseCharacter ? 12.sp : 12.sp,
                                            maxLines: 2),
                                        quickText('透', color: Colors.transparent, size: 12.sp),
                                      ],
                                    )
                                  : quickText(e,
                                      color: isRatio ? Theme.of(context).primaryColor : Color.fromRGBO(82, 82, 82, 1),
                                      size: isRatio || noHasChineseCharacter ? 12.sp : 12.sp,
                                      maxLines: 2),
                        );
                      }).toList(),
                    ],
                  );
                }).toList(),
              ],
            ),
          ),
        ),
      ],
    ),
  );
}

/// 人员数据概况
@swidget
Widget $personnelDataOverview(BuildContext context, List<StudentAnswerInfos> studentAnswerInfos) {
  List<String> names = [];
  List<String> useTimes = [];
  List<String> correctRates = [];
  List<String> noAnswerCounts = [];
  List<String> rankings = [];
  Map<String, List<dynamic>> mapData = {
    '姓名': names,
    '答题时长': useTimes,
    '正确率': correctRates,
    '未答题数': noAnswerCounts,
    '班级排名': rankings,
  };

  studentAnswerInfos.forEach((student) {
    TimeUnits timeUnits = convertMilliseconds(student.useTime);
    String timeerStr = '';
    if (timeUnits.hours > 0) timeerStr = timeUnits.hours.toString() + ':';
    if (timeUnits.minutes > 0) timeerStr += timeUnits.minutes.toString() + ':';
    if (timeUnits.seconds > 0) timeerStr += timeUnits.seconds.toString();

    names.add(student.studentName);
    useTimes.add(timeerStr);
    correctRates.add(doubleToStringAsFixed(student.correctRate) + '%');
    noAnswerCounts.add(student.noAnswerCount.toString());
    rankings.add(student.ranking.toString() + '名');
  });

  return Container(
    width: double.infinity,
    // height: isPad() ? 290.h : 264.h,
    margin: EdgeInsets.only(top: 20.h),
    padding: EdgeInsets.symmetric(vertical: 16.h, horizontal: 12.w),
    decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10.r)),
    child: Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          child: quickText('人员数据概况', color: Color.fromRGBO(92, 92, 92, 1), size: 14.sp, fontWeight: FontWeight.bold),
          margin: EdgeInsets.only(bottom: 20.h),
        ),
        Scrollbar(
          thickness: 8.w,
          thumbVisibility: true,
          trackVisibility: true,
          radius: Radius.circular(10.r),
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                ...mapData.entries.map((entrie) {
                  bool isTransparentChinese = ['答题时长', '正确率', '未答题数'].contains(entrie.key); // 透明中文

                  return Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        width: 94.r,
                        alignment: Alignment.center,
                        color: Color.fromRGBO(230, 230, 230, 1),
                        margin: EdgeInsets.only(bottom: 1.h, right: 1.w),
                        padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 8.w),
                        child: quickText(entrie.key, color: Color.fromRGBO(24, 35, 77, 1), size: 12.sp, maxLines: 2),
                      ),
                      ...entrie.value.map((e) {
                        bool isTransparentChineseNew = isTransparentChinese && (e?.length ?? 0) == 0;
                        return Container(
                          width: 100.r,
                          alignment: Alignment.center,
                          margin: EdgeInsets.only(bottom: 1.h, right: 1.w),
                          padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 8.w),
                          color: Color.fromRGBO(245, 245, 245, 1),
                          child: isTransparentChineseNew
                              ? quickText('透明', color: Colors.transparent, size: 12.sp)
                              : RegExp(r'^\d+$').hasMatch(e) || e.contains('%')
                                  ? Row(
                                      mainAxisSize: MainAxisSize.min,
                                      children: [
                                        quickText(e, color: Color.fromRGBO(82, 82, 82, 1), size: 12.sp, maxLines: 2),
                                        quickText('透', color: Colors.transparent, size: 12.sp),
                                      ],
                                    )
                                  : quickText(e, color: Color.fromRGBO(82, 82, 82, 1), size: 12.sp, maxLines: 2),
                        );
                      }).toList(),
                    ],
                  );
                }).toList(),
              ],
            ),
          ),
        ),
      ],
    ),
  );
}

// 定义一个类来保存转换后的时间单位
class TimeUnits {
  int hours;
  int minutes;
  int seconds;

  TimeUnits(this.hours, this.minutes, this.seconds);
}

// 毫秒转小时、分钟、秒的函数
TimeUnits convertMilliseconds(int totalSeconds) {
  int hours = totalSeconds ~/ 3600; // 整除得到小时数
  int remainingSeconds = totalSeconds % 3600; // 求余得到剩余的秒数
  int minutes = remainingSeconds ~/ 60; // 整除得到分钟数
  int seconds = remainingSeconds % 60; // 求余得到秒数

  return TimeUnits(hours, minutes, seconds);
}

class QuestionPictureModel extends Object {
  String? questionPicture;
  String questionNo;
  int questionid;
  int jobid;

  QuestionPictureModel({required this.jobid, required this.questionid, required this.questionNo, this.questionPicture});
}
