import 'package:data_table_2/data_table_2.dart';
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:get/get.dart';
import 'package:get/get_rx/get_rx.dart';
import 'package:making_school_asignment_app/common/job/annotated_class.dart';
import 'package:making_school_asignment_app/common/job/homework_details.dart';
import 'package:making_school_asignment_app/common/utils/toast_utils.dart';
import 'package:making_school_asignment_app/common/utils/utils.dart';
import 'package:making_school_asignment_app/page/global_widget/MyEmptyWidget.dart';
import 'package:making_school_asignment_app/page/global_widget/imgDialog.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
import 'package:making_school_asignment_app/page/home_page/widget/progress_bar.dart';
import 'package:making_school_asignment_app/routes/app_pages.dart';
import 'package:auto_size_text/auto_size_text.dart';

class ReportTable extends StatefulWidget {
  final List headList;
  final List bodyList;
  final int? fixedRows;
  final int? fixedCols;
  final bool? isZG;
  final String jobId;
  final int studentCount;
  final int subject;

  const ReportTable({
    Key? key,
    required this.headList,
    required this.bodyList,
    required this.jobId,
    required this.studentCount,
    required this.subject,
    this.fixedCols = 0,
    this.fixedRows = 0,
    this.isZG = false,
  }) : super(key: key);

  @override
  State<ReportTable> createState() => _ReportTableState();
}

class _ReportTableState extends State<ReportTable> {
  final ScrollController _controller = ScrollController();
  int? _sortColumnIndex;
  final bool _sortAscending = true;
  List colorMap = const [
    Color.fromRGBO(184, 161, 255, 1),
    Color.fromRGBO(79, 199, 147, 1),
    Color.fromRGBO(144, 224, 190, 1),
    Color.fromRGBO(255, 107, 107, 1),
    Color.fromRGBO(211, 211, 211, 1),
  ];

  void showAnswerEfficiency(overallTitles) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            contentPadding: EdgeInsets.all(20.r),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(15.r))),
            content: SizedBox(
              width: MediaQuery.of(context).size.width * 0.5,
              height: MediaQuery.of(context).size.height * 0.4,
              child: Column(
                children: [
                  Text(
                    '作答效率',
                    style: TextStyle(
                        fontSize: 15.sp,
                        color: const Color(0xFF3C3C3C),
                        fontWeight: FontWeight.w500),
                  ),
                  Padding(
                    padding:
                        EdgeInsets.symmetric(vertical: 20.r, horizontal: 10.r),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        mapIcon(const Color(0xFFB8A1FF)),
                        SizedBox(
                          width: 5.r,
                        ),
                        mapTxt('优'),
                        const Spacer(),
                        mapIcon(const Color(0xFF4CC793)),
                        SizedBox(
                          width: 5.r,
                        ),
                        mapTxt('良'),
                        const Spacer(),
                        mapIcon(const Color(0xFF90E0BE)),
                        SizedBox(
                          width: 5.r,
                        ),
                        mapTxt('中'),
                        const Spacer(),
                        mapIcon(const Color(0xFFFF6B6B)),
                        SizedBox(
                          width: 5.r,
                        ),
                        mapTxt('差'),
                      ],
                    ),
                  ),
                  Expanded(
                    child: PieChart(
                      PieChartData(
                        borderData: FlBorderData(show: true),
                        sectionsSpace: 0,
                        centerSpaceRadius: 0,
                        sections: List.generate(overallTitles.length, (index) {
                          var e = overallTitles[index];
                          return PieChartSectionData(
                            color: colorMap[index],
                            value: e.count / widget.studentCount * 100,
                            radius: 110,
                            // borderSide:BorderSide(color: const Color(0xFF273366),width: 0.5.r),
                            // title: e.title + (Utils.doubleToStringAsFixed(e.count / widget.studentCount * 100) + '%'),
                            title: e.count.toString(),
                            titleStyle: TextStyle(
                                fontSize: 12.sp,
                                color: const Color(0xFFFFFFFF)),
                          );
                        }),
                      ),
                    ),

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

  void showPeopleListDialog(
      {required BuildContext context,
      required String title,
      required String questionNo,
      required List arr,
      List? dcList}) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            // insetPadding: EdgeInsets.symmetric(vertical: 20.r,horizontal: 20.r),
            contentPadding: EdgeInsets.all(20.r),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(15.r))),
            content: SizedBox(
              width: MediaQuery.of(context).size.width * 0.7,
              height: MediaQuery.of(context).size.height * 0.7,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Center(
                    child: Text(
                      title,
                      style: TextStyle(
                          fontSize: 15.sp,
                          color: const Color(0xFF3C3C3C),
                          fontWeight: FontWeight.w500),
                    ),
                  ),
                  SizedBox(
                    height: 5.r,
                  ),
                  Row(
                    children: [
                      Text(
                        widget.isZG == true ? '主观题' : '客观题',
                        style: TextStyle(
                            fontSize: 14.sp,
                            color: Theme.of(context).primaryColor),
                      ),
                      Text(
                        '―',
                        style: TextStyle(
                            fontSize: 14.sp,
                            color: Theme.of(context).primaryColor),
                      ),
                      Text(
                        '第$questionNo题',
                        style: TextStyle(
                            fontSize: 14.sp,
                            color: Theme.of(context).primaryColor),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 15.r,
                  ),
                  dcList != null
                      ? Row(
                          children: [
                            Expanded(
                                flex: 1,
                                child: Center(
                                    child: Text(
                                  '未作答人',
                                  style: TextStyle(
                                      fontSize: 12.sp,
                                      color: Color(0xFF6A6A6A)),
                                ))),
                            Expanded(
                                flex: 1,
                                child: Center(
                                    child: Text(
                                  '答对人数',
                                  style: TextStyle(
                                      fontSize: 12.sp,
                                      color: Color(0xFF6A6A6A)),
                                ))),
                            Expanded(
                                flex: 1,
                                child: Center(
                                    child: Text(
                                  '答错人',
                                  style: TextStyle(
                                      fontSize: 12.sp,
                                      color: Color(0xFF6A6A6A)),
                                ))),
                          ],
                        )
                      : Padding(
                          padding: EdgeInsets.only(left: 15.r),
                          child: Text(
                            title,
                            style: TextStyle(
                                fontSize: 12.sp, color: Color(0xFF6A6A6A)),
                          ),
                        ),
                  SizedBox(
                    height: 5.r,
                  ),
                  if (dcList != null)
                    Expanded(
                      child: ListView.builder(
                        shrinkWrap: true,
                        itemBuilder: (context, index) {
                          var item = arr[index];
                          return Container(
                            padding: EdgeInsets.symmetric(vertical: 5.r),
                            color:
                                index.isOdd ? Colors.white : Color(0xFFF0F0F0),
                            child: Row(
                              children: [
                                Expanded(
                                    flex: 1,
                                    child: InkWell(
                                        onTap: () {
                                          goQuickCheckPersonalPath(
                                              item['noAnswerStudents']
                                                  .studentId);
                                        },
                                        child: Center(
                                            child: Text(
                                          item['noAnswerStudents']
                                                  ?.studentName ??
                                              '--',
                                          style: TextStyle(
                                              fontSize: 12.sp,
                                              color: Color(0xFF323232)),
                                        )))),
                                Expanded(
                                    flex: 1,
                                    child: InkWell(
                                        onTap: () {
                                          goQuickCheckPersonalPath(
                                              item['answerOkStudents']
                                                  .studentId);
                                        },
                                        child: Center(
                                            child: Text(
                                          item['answerOkStudents']
                                                  ?.studentName ??
                                              '--',
                                          style: TextStyle(
                                              fontSize: 12.sp,
                                              color: Color(0xFF323232)),
                                        )))),
                                Expanded(
                                    flex: 1,
                                    child: InkWell(
                                        onTap: () {
                                          goQuickCheckPersonalPath(
                                              item['answerNgStudents']
                                                  .studentId);
                                        },
                                        child: Center(
                                            child: Text(
                                          item['answerNgStudents']
                                                  ?.studentName ??
                                              '--',
                                          style: TextStyle(
                                              fontSize: 12.sp,
                                              color: Color(0xFF323232)),
                                        )))),
                              ],
                            ),
                          );
                        },
                        itemCount: arr.length,
                      ),
                    )
                  else
                    arr.isNotEmpty
                        ? Expanded(
                            child: ListView.builder(
                              shrinkWrap: true,
                              itemBuilder: (context, index) {
                                Dtls item = arr[index];
                                return InkWell(
                                  onTap: () {
                                    goQuickCheckPersonalPath(item.studentId);
                                  },
                                  child: Container(
                                    padding: EdgeInsets.symmetric(
                                        vertical: 5.r, horizontal: 15.r),
                                    color: index.isOdd
                                        ? Colors.white
                                        : Color(0xFFF0F0F0),
                                    child: Text(
                                      item.studentName! ?? '--',
                                      style: TextStyle(
                                          fontSize: 12.sp,
                                          color: Color(0xFF323232)),
                                    ),
                                  ),
                                );
                              },
                              itemCount: arr.length,
                            ),
                          )
                        : const MyEmptyWidget()
                ],
              ),
            ),
          );
        });
  }

  void goQuickCheckPersonalPath(id) {
    if (id != null) {
      Get.toNamed(Routes.studentPersonalPage, arguments: {
        'studentId': id,
        'homeworkId': widget.jobId,
        'subject': widget.subject
      });
    }
  }

  void zdHandle(BuildContext context, String title, String questionNo,
      List noAnswerStudents, List answerNgStudents, List answerOkStudents) {
    List list = [];
    // Questions student = Questions('','',-1,-1,'',-1,'','',[],-1,-1,[] as double?);
    if (noAnswerStudents.length > answerNgStudents.length &&
        noAnswerStudents.length > answerOkStudents.length) {
      for (int i = 0; i < noAnswerStudents.length; i++) {
        var obj = {
          'noAnswerStudents': noAnswerStudents[i],
          'answerNgStudents':
              answerNgStudents.length > i ? answerNgStudents[i] : null,
          'answerOkStudents':
              answerOkStudents.length > i ? answerOkStudents[i] : null
        };
        list.add(obj);
      }
    } else if (answerNgStudents.length > noAnswerStudents.length &&
        answerNgStudents.length > answerOkStudents.length) {
      for (int i = 0; i < answerNgStudents.length; i++) {
        var obj = {
          'noAnswerStudents':
              noAnswerStudents.length > i ? noAnswerStudents[i] : null,
          'answerNgStudents': answerNgStudents[i],
          'answerOkStudents':
              answerOkStudents.length > i ? answerOkStudents[i] : null
        };
        list.add(obj);
      }
    } else if (answerOkStudents.length > noAnswerStudents.length &&
        answerOkStudents.length > answerNgStudents.length) {
      for (int i = 0; i < answerOkStudents.length; i++) {
        var obj = {
          'noAnswerStudents':
              noAnswerStudents.length > i ? noAnswerStudents[i] : null,
          'answerNgStudents':
              answerNgStudents.length > i ? answerNgStudents[i] : null,
          'answerOkStudents': answerOkStudents[i]
        };
        list.add(obj);
      }
    } else {
      for (int i = 0; i < answerOkStudents.length; i++) {
        var obj = {
          'noAnswerStudents':
              noAnswerStudents.length > i ? noAnswerStudents[i] : null,
          'answerNgStudents':
              answerNgStudents.length > i ? answerNgStudents[i] : null,
          'answerOkStudents': answerOkStudents[i]
        };
        list.add(obj);
      }
    }

    showPeopleListDialog(
        context: context,
        title: title,
        questionNo: questionNo,
        arr: list,
        dcList: []);
  }

  void dcHandle(
      BuildContext context, String title, String questionNo, List arr) {
    showPeopleListDialog(
        context: context, title: title, questionNo: questionNo, arr: arr);
  }

  DataRow _getRow(int index, [Color? color]) {
    assert(index >= 0);
    var item = widget.bodyList[index];
    return DataRow2.byIndex(
      index: index,
      color: color != null ? WidgetStateProperty.all(color) : null,
      cells: [
        DataCell(Center(
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 5.r),
            child: Text(item.questionNo.toString(),
                style:
                    TextStyle(fontSize: 10.sp, color: const Color(0xFF525252))),
          ),
        )),
        DataCell(InkWell(
          onTap: () {
            if (widget.isZG == false) {
              showSelectRate(
                questionNo: item.questionNo.toString(),
                options: item.options,
                answer: item.answer,
              );
            }
          },
          child: Center(
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 5.r),
              child: Text('${item.answerRate.toStringAsFixed(0)}%',
                  style: TextStyle(
                      fontSize: 10.sp,
                      color: widget.isZG == false
                          ? Theme.of(context).primaryColor
                          : const Color(0xFF525252))),
            ),
          ),
        )),
        DataCell(InkWell(
          onTap: () {
            zdHandle(
                context,
                '作答人数',
                item.questionNo.toString(),
                item.noAnswerStudents,
                item.answerNgStudents,
                item.answerOkStudents);
          },
          child: Center(
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 5.r),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('${item.answerCount}/${widget.studentCount}',
                      style: TextStyle(
                          fontSize: 10.sp,
                          color: Theme.of(context).primaryColor)),
                  Image.asset(
                    'assets/images/green_right_icon.png',
                    width: 12.r,
                    height: 12.r,
                  ),
                ],
              ),
            ),
          ),
        )),
        DataCell(Center(
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 5.r),
            child: Text('${item.correctRate.toStringAsFixed(0)}%',
                style:
                    TextStyle(fontSize: 10.sp, color: const Color(0xFF525252))),
          ),
        )),
        DataCell(Center(
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 5.r),
            child: Text('${item.okRate.toStringAsFixed(0)}%',
                style:
                    TextStyle(fontSize: 10.sp, color: const Color(0xFF525252))),
          ),
        )),
        DataCell(Center(
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 5.r),
            child: widget.isZG == true
                ? InkWell(
                    onTap: () {
                      if (item.questionPicture == null) {
                        ToastUtils.showInfo('当前试题没有原题');
                      } else {
                        ImageDialog.showImgDialog(
                            context, item.questionPicture);
                      }
                    },
                    child: Text('原题',
                        style: TextStyle(
                            fontSize: 10.sp,
                            color: widget.isZG == true
                                ? const Color(0xFFFF8A00)
                                : Theme.of(context).primaryColor)),
                  )
                : Text(item.answer,
                    style: TextStyle(
                        fontSize: 10.sp,
                        color: widget.isZG == true
                            ? const Color(0xFFFF8A00)
                            : Theme.of(context).primaryColor)),
          ),
        )),
        DataCell(InkWell(
          onTap: () {
            // List<String> parts = item.priorityGeneral.split('人');
            dcHandle(context, '优先批阅答错人', item.questionNo.toString(),
                item.priorityInfo);
          },
          child: Center(
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 5.r),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('${item.priorityInfo.length}人答错',
                      style: TextStyle(
                          fontSize: 10.sp,
                          color: Theme.of(context).primaryColor)),
                  Image.asset(
                    'assets/images/green_right_icon.png',
                    width: 12.r,
                    height: 12.r,
                  )
                ],
              ),
            ),
          ),
        )),
        if (widget.isZG == true)
          DataCell(Center(
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 5.r),
              child: widget.isZG == true
                  ? InkWell(
                      onTap: () {
                        showAnswerEfficiency(item.overallTitles);
                      },
                      child: Text('查看',
                          style: TextStyle(
                              fontSize: 10.sp,
                              color: widget.isZG == true
                                  ? const Color(0xFFFF8A00)
                                  : Theme.of(context).primaryColor)),
                    )
                  : Text(item.answer,
                      style: TextStyle(
                          fontSize: 10.sp,
                          color: widget.isZG == true
                              ? const Color(0xFFFF8A00)
                              : Theme.of(context).primaryColor)),
            ),
          )),
      ],
    );
  }

  void showSelectRate(
      {required String questionNo,
      required List<SelectionRate> options,
      required String answer}) {
    RxList<SelectionRate> students = RxList();
    students.value = options;
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            // insetPadding: EdgeInsets.symmetric(vertical: 20.r,horizontal: 20.r),
            contentPadding: EdgeInsets.all(0.r),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(15.r))),
            content: SizedBox(
              width: MediaQuery.of(context).size.width * 0.7,
              height: MediaQuery.of(context).size.height * 0.7,
              child: Column(
                children: [
                  Container(
                    decoration: BoxDecoration(
                        color: Theme.of(context).primaryColor,
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(10.r),
                          topRight: Radius.circular(10.r),
                        )),
                    width: double.infinity,
                    child: Container(
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 8.h),
                        child: Text(
                          '第$questionNo题',
                          style:
                              TextStyle(fontSize: 16.sp, color: Colors.white),
                        )),
                  ),
                  Expanded(
                    child: Padding(
                      padding:
                          EdgeInsets.symmetric(vertical: 5.h, horizontal: 10.w),
                      child: Column(
                        children: [
                          SizedBox(
                            height: 10.h,
                          ),
                          Row(
                            children: [
                              Text(
                                '标准答案：',
                                style: TextStyle(
                                    fontSize: 12.sp,
                                    color: const Color(0xFF000101)),
                              ),
                              SizedBox(
                                width: 5.w,
                              ),
                              Container(
                                  width: 20.r,
                                  height: 20.r,
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                    color: const Color(0xFF4BC793),
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(10.r)),
                                  ),
                                  child: AutoSizeText(
                                    answer,
                                    style: TextStyle(
                                        fontSize: 12.sp, color: Colors.white),
                                    maxLines: 1,
                                    minFontSize: 10,
                                  ))
                            ],
                          ),
                          SizedBox(
                            height: 10.h,
                          ),
                          Row(
                            children: [
                              Text('选项',
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                    color: const Color(0xFF000101),
                                  )),
                              SizedBox(
                                width: 10.w,
                              ),
                              Text('选择率',
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                    color: const Color(0xFF000101),
                                  )),
                            ],
                          ),
                          SizedBox(
                            height: 5.h,
                          ),
                          Obx(() {
                            return Expanded(
                              child: students.isNotEmpty
                                  ? ListView.builder(
                                      // shrinkWrap: true,
                                      // physics: NeverScrollableScrollPhysics(),
                                      itemCount: students.length,
                                      itemBuilder: (context, index) {
                                        SelectionRate item = students[index];

                                        return Container(
                                          margin: EdgeInsets.only(bottom: 5.h),
                                          decoration: BoxDecoration(
                                            color: const Color(0xFFFAFAFA),
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(5.r)),
                                          ),
                                          child: Column(
                                            children: [
                                              SizedBox(
                                                height: 5.h,
                                              ),
                                              Row(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.center,
                                                children: [
                                                  item.optionName == answer
                                                      ? Container(
                                                          width: 20.r,
                                                          height: 20.r,
                                                          margin:
                                                              EdgeInsets.only(
                                                                  left: 4.r),
                                                          alignment:
                                                              Alignment.center,
                                                          decoration:
                                                              BoxDecoration(
                                                            color: const Color(
                                                                0xFF4BC793),
                                                            borderRadius:
                                                                BorderRadius.all(
                                                                    Radius.circular(
                                                                        10.r)),
                                                          ),
                                                          child: AutoSizeText(
                                                            item.optionName,
                                                            style: TextStyle(
                                                                fontSize: 12.sp,
                                                                color: Colors
                                                                    .white),
                                                            maxLines: 1,
                                                            minFontSize: 10,
                                                          ))
                                                      : Padding(
                                                          padding:
                                                              EdgeInsets.only(
                                                                  left: 8.r),
                                                          child: Text(
                                                            item.optionName,
                                                            style: TextStyle(
                                                              fontSize: 12.sp,
                                                              color: const Color(
                                                                  0xFF000101),
                                                            ),
                                                          ),
                                                        ),
                                                  SizedBox(
                                                    width: 10.w,
                                                  ),
                                                  Expanded(
                                                    child: ProgressBar(
                                                      color: Theme.of(context)
                                                          .primaryColor,
                                                      percent: item.rate / 100,
                                                      title: '',
                                                      padingEdg:
                                                          EdgeInsets.only(
                                                              left: 5.w,
                                                              right: 10.w),
                                                      fontSize: 10.sp,
                                                      lineHeight: 6.h,
                                                      marginEdg:
                                                          EdgeInsets.only(
                                                              top: 0.h),
                                                    ),
                                                  ),
                                                  SizedBox(
                                                    width: 15.w,
                                                  ),
                                                  InkWell(
                                                    onTap: () {
                                                      item.isCheck =
                                                          !item.isCheck;
                                                      students[index] = item;
                                                    },
                                                    child: item.isCheck
                                                        ? const Icon(
                                                            Icons
                                                                .arrow_drop_down_rounded,
                                                            size: 30,
                                                            color: Color(
                                                                0xFF000101),
                                                          )
                                                        : const Icon(
                                                            Icons
                                                                .arrow_right_rounded,
                                                            size: 30,
                                                            color: Color(
                                                                0xFF000101),
                                                          ),
                                                  ),
                                                ],
                                              ),
                                              SizedBox(
                                                height: 5.h,
                                              ),
                                              item.isCheck
                                                  ? Container(
                                                      width: double.infinity,
                                                      height: 120.h,
                                                      decoration: BoxDecoration(
                                                          color: const Color(
                                                              0xFFF2F2F2),
                                                          borderRadius:
                                                              BorderRadius.only(
                                                            bottomLeft:
                                                                Radius.circular(
                                                                    5.r),
                                                            bottomRight:
                                                                Radius.circular(
                                                                    5.r),
                                                          )),
                                                      padding:
                                                          EdgeInsets.symmetric(
                                                              vertical: 5.h,
                                                              horizontal: 10.w),
                                                      child: Column(
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .start,
                                                        children: [
                                                          Text(
                                                            '选择的学生（${item.currentOptionStudents.length}）',
                                                            style: TextStyle(
                                                                fontSize: 12.sp,
                                                                color: const Color(
                                                                    0xFF000101)),
                                                          ),
                                                          SizedBox(
                                                            height: 5.h,
                                                          ),
                                                          Expanded(
                                                            child:
                                                                SingleChildScrollView(
                                                              child: Wrap(
                                                                spacing: 6.r,
                                                                // 主轴(水平)方向间距
                                                                runSpacing: 4.r,
                                                                // 纵轴（垂直）方向间距
                                                                alignment:
                                                                    WrapAlignment
                                                                        .start,
                                                                //沿主轴方向居中
                                                                children: item
                                                                    .currentOptionStudents
                                                                    .map((e) {
                                                                  return InkWell(
                                                                    onTap: () {
                                                                      Get.toNamed(
                                                                          Routes
                                                                              .studentPersonalPage,
                                                                          arguments: {
                                                                            'studentId':
                                                                                e.studentId,
                                                                            'homeworkId':
                                                                                widget.jobId,
                                                                            'subject':
                                                                                widget.subject
                                                                          });
                                                                    },
                                                                    child:
                                                                        Container(
                                                                      padding: EdgeInsets.symmetric(
                                                                          vertical: 4
                                                                              .r,
                                                                          horizontal:
                                                                              8.r),
                                                                      color: const Color(
                                                                          0xFFF0ECFF),
                                                                      child: quickText(
                                                                          e
                                                                              .studentName,
                                                                          color: const Color(
                                                                              0xFF505E6E),
                                                                          size:
                                                                              10.sp),
                                                                    ),
                                                                  );
                                                                }).toList(),
                                                              ),
                                                            ),
                                                          ),
                                                        ],
                                                      ),
                                                    )
                                                  : Container()
                                            ],
                                          ),
                                        );
                                      })
                                  : const MyEmptyWidget(),
                            );
                          })
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    bool isPadFlag = Utils.isPad();
    return DataTable2(
        dividerThickness: 0,
        scrollController: _controller,
        columnSpacing: 0,
        horizontalMargin: 0,
        dataRowHeight: 40.h,
        bottomMargin: 0,
        headingRowHeight: 40.h,
        border: const TableBorder(
            horizontalInside: BorderSide(
                width: 1, color: Colors.white, style: BorderStyle.solid),
            bottom: BorderSide(
                width: 1, color: Colors.white, style: BorderStyle.solid),
            verticalInside: BorderSide(
                width: 1, color: Colors.white, style: BorderStyle.solid)),
        headingRowColor: MaterialStateProperty.resolveWith((states) =>
            widget.fixedCols! > 0 ? Colors.white : Colors.transparent),
        headingRowDecoration: const BoxDecoration(color: Color(0xFFE6E6E6)),
        fixedColumnsColor: const Color(0xFFE6E6E6),
        fixedCornerColor: Colors.grey[400],
        minWidth: widget.headList.length > 6
            ? 80.r * widget.headList.length
            : isPadFlag
                ? MediaQuery.of(context).size.width
                : 85.r * widget.headList.length,
        fixedTopRows: widget.fixedRows!,
        fixedLeftColumns: widget.fixedCols!,
        sortColumnIndex: _sortColumnIndex,
        sortAscending: _sortAscending,
        // onSelectAll: (val) => setState(() => selectAll(val)),
        columns: List.generate(widget.headList.length, (index) {
          var item = widget.headList[index];
          return DataColumn2(
            label: index == 3
                ? Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(item,
                          style: TextStyle(
                              fontSize: 10.sp, color: const Color(0xFF505767))),
                      SizedBox(
                        width: 2.r,
                      ),
                      const Tooltip(
                          message: '答对人数/作答人数',
                          triggerMode: TooltipTriggerMode.tap,
                          preferBelow: false,
                          child: Icon(
                            Icons.info_outline_rounded,
                            color: Colors.grey,
                          )),
                    ],
                  )
                : index == 4
                    ? Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(item,
                              style: TextStyle(
                                  fontSize: 10.sp,
                                  color: const Color(0xFF505767))),
                          SizedBox(
                            width: 2.r,
                          ),
                          const Tooltip(
                              message: '答对人数/总人数',
                              triggerMode: TooltipTriggerMode.tap,
                              preferBelow: false,
                              child: Icon(
                                Icons.info_outline_rounded,
                                color: Colors.grey,
                              )),
                        ],
                      )
                    : Center(
                        child: Text(item,
                            style: TextStyle(
                                fontSize: 10.sp,
                                color: const Color(0xFF505767))),
                      ),
            // size: ColumnSize.S,
            fixedWidth: index == 0
                ? 40.r
                : widget.headList.length > 6
                    ? 80.r
                    : isPadFlag
                        ? (MediaQuery.of(context).size.width - 8.r) /
                            widget.headList.length
                        : 85.r,
          );
        }),
        rows: List<DataRow>.generate(widget.bodyList.length,
            (index) => _getRow(index, const Color(0xFFF5F5F5))));
  }
}

Widget mapIcon(Color bgColor) {
  return Container(
    width: 12.r,
    height: 12.r,
    decoration: BoxDecoration(
      color: bgColor,
      borderRadius: BorderRadius.all(Radius.circular(6.r)),
    ),
  );
}

Widget mapTxt(String title) {
  return Text(
    title,
    style: TextStyle(
        fontSize: 12.sp,
        color: const Color(0xFF525252),
        fontWeight: FontWeight.w400),
  );
}
