$(function () {
  // 各班满分、最高分、最低分、平均分对比分析
  function initClassScoreEcharts(classnameArr, classScoreInfo, s_index) {
    var xAxis_data = classnameArr;
    var series_full_data = classScoreInfo.full;
    var series_max_data = classScoreInfo.max;
    var series_min_data = classScoreInfo.min;
    var series_avg_data = classScoreInfo.avg;
    var option = {
      animation: false,
      title: {
        text: "分",
        x: "left",
        y: "top",
        textStyle: {
          color: "#5F6E82",
          fontSize: $.UnitUtil.mm2px(3),
          fontWeight: 500,
        },
      },
      color: ["#5C99FF", "#FF5F56", "#5EC5C8", "#F1982B"],
      legend: {
        itemWidth: $.UnitUtil.mm2px(2),
        itemHeight: $.UnitUtil.mm2px(2),
        top: "bottom",
        data: ["满分", "最高分", "最低分", "平均分"],
      },
      grid: {
        top: $.UnitUtil.mm2px(10),
        left: 0,
        right: 0,
        bottom: $.UnitUtil.mm2px(8),
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: xAxis_data,
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
            interval: 0,
          },
          axisTick: {
            alignWithLabel: true,
          },
          boundaryGap: true,
          triggerEvent: true,
          axisLine: {
            show: true, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
        },
      ],
      yAxis: [
        {
          type: "value",
          axisTick: {
            show: false, //刻度
          },
          axisLine: {
            show: false, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
          splitLine: {
            //网格线
            lineStyle: {
              type: "dotted", //设置网格线类型 dotted：虚线   solid:实线
            },
            show: true, //隐藏或显示
          },
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
          },
        },
      ],
      series: [
        {
          name: "满分",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_full_data,
        },
        {
          name: "最高分",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_max_data,
        },
        {
          name: "最低分",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_min_data,
        },
        {
          name: "平均分",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_avg_data,
        },
      ],
    };
    var myEcharts = echarts.init(
      $(
        ".section_2_class_single_" + s_index + " #classScoreEcharts"
      )[0]
    );
    myEcharts.clear();
    myEcharts.setOption(option);
  }
  // 各班优秀率、良好率、及格率、低分率对比分析
  function initClassRateEcharts(classnameArr, classRateInfo, s_index) {
    var xAxis_data = classnameArr;
    var series_yx_data = classRateInfo.yx;
    var series_lh_data = classRateInfo.lh;
    var series_jg_data = classRateInfo.jg;
    var series_df_data = classRateInfo.df;
    var option = {
      animation: false,
      title: {
        text: "%",
        x: "left",
        y: "top",
        textStyle: {
          color: "#5F6E82",
          fontSize: $.UnitUtil.mm2px(3),
          fontWeight: 500,
        },
      },
      color: ["#5C99FF", "#FF5F56", "#5EC5C8", "#F1982B"],
      legend: {
        itemWidth: $.UnitUtil.mm2px(2),
        itemHeight: $.UnitUtil.mm2px(2),
        top: "bottom",
        data: ["优秀率", "良好率", "及格率", "低分率"],
      },
      grid: {
        top: $.UnitUtil.mm2px(10),
        left: 0,
        right: 0,
        bottom: $.UnitUtil.mm2px(8),
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: xAxis_data,
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
            interval: 0,
          },
          axisTick: {
            alignWithLabel: true,
          },
          boundaryGap: true,
          triggerEvent: true,
          axisLine: {
            show: true, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
        },
      ],
      yAxis: [
        {
          type: "value",
          axisTick: {
            show: false, //刻度
          },
          axisLine: {
            show: false, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
          splitLine: {
            //网格线
            lineStyle: {
              type: "dotted", //设置网格线类型 dotted：虚线   solid:实线
            },
            show: true, //隐藏或显示
          },
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
          },
        },
      ],
      series: [
        {
          name: "优秀率",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_yx_data,
        },
        {
          name: "良好率",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_lh_data,
        },
        {
          name: "及格率",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_jg_data,
        },
        {
          name: "低分率",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_df_data,
        },
      ],
    };
    var myEcharts = echarts.init(
      $(
        ".section_2_class_single_" + s_index + " #classRateEcharts"
      )[0]
    );
    myEcharts.clear();
    myEcharts.setOption(option);
  }
  // 各班实考人数、缺考人数对比
  function initClassExamEcharts(classnameArr, classExamInfo, s_index) {
    var xAxis_data = classnameArr;
    var series_sk_data = classExamInfo.sk;
    var series_qk_data = classExamInfo.qk;
    var option = {
      animation: false,
      title: {
        text: "人",
        x: "left",
        y: "top",
        textStyle: {
          color: "#5F6E82",
          fontSize: $.UnitUtil.mm2px(3),
          fontWeight: 500,
        },
      },
      color: ["#5C99FF", "#FF5F56"],
      legend: {
        itemWidth: $.UnitUtil.mm2px(2),
        itemHeight: $.UnitUtil.mm2px(2),
        top: "bottom",
        data: ["实考人数", "缺考人数"],
      },
      grid: {
        top: $.UnitUtil.mm2px(10),
        left: 0,
        right: 0,
        bottom: $.UnitUtil.mm2px(8),
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: xAxis_data,
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
            interval: 0,
          },
          axisTick: {
            alignWithLabel: true,
          },
          boundaryGap: true,
          triggerEvent: true,
          axisLine: {
            show: true, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
        },
      ],
      yAxis: [
        {
          type: "value",
          axisTick: {
            show: false, //刻度
          },
          axisLine: {
            show: false, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
          splitLine: {
            //网格线
            lineStyle: {
              type: "dotted", //设置网格线类型 dotted：虚线   solid:实线
            },
            show: true, //隐藏或显示
          },
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
          },
        },
      ],
      series: [
        {
          name: "实考人数",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_sk_data,
        },
        {
          name: "缺考人数",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_qk_data,
        },
      ],
    };
    var myEcharts = echarts.init(
      $(
        ".section_2_class_single_" + s_index + " #classExamEcharts"
      )[0]
    );
    myEcharts.clear();
    myEcharts.setOption(option);
  }
  // 各班标准差对比分析
  function initClassStdEcharts(classnameArr, classStd, s_index) {
    var xAxis_data = classnameArr;
    var series_data = classStd;
    var option = {
      animation: false,
      color: ["#5C99FF"],
      legend: {
        itemWidth: $.UnitUtil.mm2px(2),
        itemHeight: $.UnitUtil.mm2px(2),
        top: "bottom",
        data: ["标准差"],
      },
      grid: {
        top: $.UnitUtil.mm2px(10),
        left: 0,
        right: 0,
        bottom: $.UnitUtil.mm2px(8),
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: xAxis_data,
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
            interval: 0,
          },
          axisTick: {
            alignWithLabel: true,
          },
          boundaryGap: true,
          triggerEvent: true,
          axisLine: {
            show: true, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
        },
      ],
      yAxis: [
        {
          type: "value",
          axisTick: {
            show: false, //刻度
          },
          axisLine: {
            show: false, //是否显示轴线
            lineStyle: {
              color: "#DADADA", //刻度线的颜色
            },
          },
          splitLine: {
            //网格线
            lineStyle: {
              type: "dotted", //设置网格线类型 dotted：虚线   solid:实线
            },
            show: true, //隐藏或显示
          },
          axisLabel: {
            color: "#5F6E82", //更改坐标轴文字颜色
          },
        },
      ],
      series: [
        {
          name: "标准差",
          type: "bar",
          barWidth: $.UnitUtil.mm2px(5),
          // 柱状图最小高度
          barMinHeight: $.UnitUtil.mm2px(2),
          barGap: 0,
          label: {
            normal: {
              show: true,
              align: "center",
              verticalAlign: "bottom",
              position: "top",
              distance: 0,
              formatter: "{c}",
            },
          },
          data: series_data,
        },
      ],
    };
    var myEcharts = echarts.init(
      $(
        ".section_2_class_single_" + s_index + " #classStdEcharts"
      )[0]
    );
    myEcharts.clear();
    myEcharts.setOption(option);
  }
  var parameter = $(
    ".section_2_html_root .section_2_class_single_html_root"
  ).data("page-params");
  parameter = JSON.parse(parameter);
  var singleRootHtml = "";
  for (var s_data_i = 0; s_data_i < parameter.length; s_data_i++) {
    singleRootHtml +=
      '<div class="page_root section_2_class_single section_2_class_single_' +
      parameter[s_data_i].s_index +
      '"><h3 class="section_title_3">1.' +
      parameter[s_data_i].s_index +
      ' <span class="subjectname"></span>对比</h3><h4 class="section_title_4">1.' +
      parameter[s_data_i].s_index +
      '.1 各班满分、最高分、最低分、平均分对比分析</h4><div id="classScoreEcharts" style="margin: 0 4mm 4mm;height: 68mm;"></div><div class="echarts_result"><div>上图统计结果表示：</div><div class="echarts_result_content"><div><span class="dot bg_5699FF"></span>高于年级平均分的班级：<span class="gt_avg_classes"></span></div><div><span class="dot bg_FF5F56"></span>低于年级平均分的班级：<span class="lt_avg_classes"></span></div></div></div><h4 class="section_title_4">1.' +
      parameter[s_data_i].s_index +
      '.2 各班优秀率、良好率、及格率、低分率对比分析</h4><div id="classRateEcharts" style="margin: 0 4mm 4mm;height: 78mm;"></div><div class="echarts_result"><div>上图统计结果表示：</div><div class="echarts_result_content"><div><span class="dot bg_5699FF"></span>优秀率最高的班级：<span class="yx_max_class"></span></div><div><span class="dot bg_FF5F56"></span>良好率最高的班级：<span class="lh_max_class"></span></div><div><span class="dot bg_5EC5C8"></span>及格率最高的班级：<span class="jg_max_class"></span></div><div><span class="dot bg_F1982B"></span>低分率最高的班级：<span class="df_max_class"></span></div></div></div></div><div class="page_root section_2_class_single section_2_class_single_' +
      parameter[s_data_i].s_index +
      '"><h4 class="section_title_4">1.' +
      parameter[s_data_i].s_index +
      '.3 各班实考人数、缺考人数对比</h4><div id="classExamEcharts" style="margin: 0 4mm 4mm;height: 78mm;"></div><div class="echarts_result"><div>上图统计结果表示：</div><div class="echarts_result_content"><div><span class="dot bg_5699FF"></span>实考人数最多的班级：<span class="sk_max_class"></span></div><div><span class="dot bg_FF5F56"></span>缺考人数最多的班级：<span class="qk_max_class"></span></div></div></div><h4 class="section_title_4">1.' +
      parameter[s_data_i].s_index +
      '.4 各班标准差对比分析</h4><div id="classStdEcharts" style="margin: 0 4mm 4mm;height: 63mm;"></div></div><div class="page_root section_2_class_single section_2_class_single_' +
      parameter[s_data_i].s_index +
      '"><h4 class="section_title_4">1.' +
      parameter[s_data_i].s_index +
      '.5 班级<span class="subjectname"></span>整体分析</h4><table border="1" class="my_table"><thead><tr><th>班级</th><th class="w16mm">实考人数</th><th class="w16mm">缺考人数</th><th class="w10mm">满分</th><th class="w12mm">最高分</th><th class="w12mm">最低分</th><th class="w12mm">平均分</th><th class="w14mm">优秀率</th><th class="w14mm">良好率</th><th class="w14mm">及格率</th><th class="w14mm">低分率</th><th class="w12mm">标准差</th></tr></thead><tbody class="classTbody"></tbody></table></div>';
  }
  $(".section_2_class_single_root").html(singleRootHtml);
  for (
    var subject_index = 0;
    subject_index < parameter.length;
    subject_index++
  ) {
    (function (subjectItem) {
      var s_index = subjectItem.s_index;
      var subjectname = subjectItem.subjectname;
      var class_arr = subjectItem.arr;
      $(".section_2_class_single_" + s_index + " .subjectname").text(
        subjectname
      );
      var classnameArr = [];
      // 各班满分、最高分、最低分、平均分对比分析
      var classScoreInfo = {
        full: [],
        max: [],
        min: [],
        avg: [],
        gt_avg_classes: [],
        lt_avg_classes: [],
      };
      // 各班优秀率、良好率、及格率、低分率对比分析
      var classRateInfo = {
        yx: [],
        lh: [],
        jg: [],
        df: [],
        yx_max: {
          rate: 0,
          classname: "",
        },
        lh_max: {
          rate: 0,
          classname: "",
        },
        jg_max: {
          rate: 0,
          classname: "",
        },
        df_max: {
          rate: 0,
          classname: "",
        },
      };
      // 各班实考人数、缺考人数对比
      var classExamInfo = {
        sk: [],
        qk: [],
        sk_max: {
          num: 0,
          classname: "",
        },
        qk_max: {
          num: 0,
          classname: "",
        },
      };
      // 各班标准差对比分析
      var classStd = [];
      // 班级整体分析
      var classTbodyHtml = "";
      for (var i = 0; i < class_arr.length; i++) {
        var c_item = class_arr[i];
        classnameArr.push(c_item.classname);
        // 各班满分、最高分、最低分、平均分对比分析
        classScoreInfo.full.push(c_item.allscore);
        classScoreInfo.max.push(c_item.classmaxscore);
        classScoreInfo.min.push(c_item.classminscore);
        classScoreInfo.avg.push(c_item.classavgscore);
        if (c_item.schoolavgscore < c_item.classavgscore) {
          classScoreInfo.gt_avg_classes.push(c_item.classname);
        }
        if (c_item.schoolavgscore > c_item.classavgscore) {
          classScoreInfo.lt_avg_classes.push(c_item.classname);
        }
        // 各班优秀率、良好率、及格率、低分率对比分析
        classRateInfo.yx.push(c_item.yxrate);
        classRateInfo.lh.push(c_item.lhrate);
        classRateInfo.jg.push(c_item.jgrate);
        classRateInfo.df.push(c_item.dfrate);
        if (classRateInfo.yx_max.rate < c_item.yxrate) {
          classRateInfo.yx_max = {
            rate: c_item.yxrate,
            classname: c_item.classname,
          };
        }
        if (classRateInfo.lh_max.rate < c_item.lhrate) {
          classRateInfo.lh_max = {
            rate: c_item.lhrate,
            classname: c_item.classname,
          };
        }
        if (classRateInfo.jg_max.rate < c_item.jgrate) {
          classRateInfo.jg_max = {
            rate: c_item.jgrate,
            classname: c_item.classname,
          };
        }
        if (classRateInfo.df_max.rate < c_item.dfrate) {
          classRateInfo.df_max = {
            rate: c_item.dfrate,
            classname: c_item.classname,
          };
        }
        // 各班实考人数、缺考人数对比
        classExamInfo.sk.push(c_item.stunum);
        classExamInfo.qk.push(c_item.missnum);
        if (classExamInfo.sk_max.num < c_item.stunum) {
          classExamInfo.sk_max = {
            num: c_item.stunum,
            classname: c_item.classname,
          };
        }
        if (classExamInfo.qk_max.num < c_item.missnum) {
          classExamInfo.qk_max = {
            num: c_item.missnum,
            classname: c_item.classname,
          };
        }
        // 各班标准差对比分析
        classStd.push(c_item.bzc);
        // 班级整体分析
        classTbodyHtml +=
          '<tr><td><div class="my_cell">' +
          c_item.classname +
          '</div></td><td><div class="my_cell">' +
          c_item.stunum +
          '</div></td><td><div class="my_cell">' +
          c_item.missnum +
          '</div></td><td><div class="my_cell">' +
          c_item.allscore +
          '</div></td><td><div class="my_cell">' +
          c_item.classmaxscore +
          '</div></td><td><div class="my_cell">' +
          c_item.classminscore +
          '</div></td><td><div class="my_cell">' +
          c_item.classavgscore +
          '</div></td><td><div class="my_cell">' +
          c_item.yxrate +
          '%</div></td><td><div class="my_cell">' +
          c_item.lhrate +
          '%</div></td><td><div class="my_cell">' +
          c_item.jgrate +
          '%</div></td><td><div class="my_cell">' +
          c_item.dfrate +
          '%</div></td><td><div class="my_cell">' +
          c_item.bzc +
          "</div></td></tr>";
      }
      // 各班满分、最高分、最低分、平均分对比分析
      initClassScoreEcharts(classnameArr, classScoreInfo, s_index);
      $(".section_2_class_single_" + s_index + " .gt_avg_classes").text(
        classScoreInfo.gt_avg_classes.join("、")
      );
      $(".section_2_class_single_" + s_index + " .lt_avg_classes").text(
        classScoreInfo.lt_avg_classes.join("、")
      );
      // 各班优秀率、良好率、及格率、低分率对比分析
      initClassRateEcharts(classnameArr, classRateInfo, s_index);
      $(".section_2_class_single_" + s_index + " .yx_max_class").text(
        classRateInfo.yx_max.classname
      );
      $(".section_2_class_single_" + s_index + " .lh_max_class").text(
        classRateInfo.lh_max.classname
      );
      $(".section_2_class_single_" + s_index + " .jg_max_class").text(
        classRateInfo.jg_max.classname
      );
      $(".section_2_class_single_" + s_index + " .df_max_class").text(
        classRateInfo.df_max.classname
      );
      // 各班实考人数、缺考人数对比
      initClassExamEcharts(classnameArr, classExamInfo, s_index);
      $(".section_2_class_single_" + s_index + " .sk_max_class").text(
        classExamInfo.sk_max.classname
      );
      $(".section_2_class_single_" + s_index + " .qk_max_class").text(
        classExamInfo.qk_max.classname
      );
      // 各班标准差对比分析
      initClassStdEcharts(classnameArr, classStd, s_index);
      // 班级整体分析
      $(".section_2_class_single_" + s_index + " .classTbody").html(
        classTbodyHtml
      );
    })(parameter[subject_index]);
  }
});
