<template>
  <div class="content-box">
    <div class="pageIndex">
      <div class="left">
        <!-- <el-icon :size="23" class="camera"><VideoCameraFilled /></el-icon> -->
        <span class="cameratxt">学生综合素质评价</span>
      </div>

      <div class="middle">
        <div class="filter">
          <div class="condition">
            <el-input
              :clearable="true"
              @clear="searchBtn"
              v-model.trim="searchInput.keyWord"
              class="sel"
              placeholder="请输入学生姓名或学号"
            /><el-button
              color="rgba(0, 97, 255, 1)"
              type="primary"
              class="search"
              @click="searchBtn"
              >查询</el-button
            >
          </div>
          <div class="condition">
            <span class="title">学期 :</span>
            <el-select
              v-model="searchInput.semester"
              class="sel"
              placeholder="请选择学期"
              style="width: 250px"
              @change="searchBtn"
              :clearable="true"
            >
              <el-option
                :label="i.name"
                :value="i.id"
                v-for="i in semesterData"
              />
            </el-select>
          </div>
          <div class="condition">
            <span class="title">年级 :</span>
            <el-select
              v-model="searchInput.grade"
              placeholder="请选择年级"
              style="width: 160px"
              @change="yearClassChange"
              :clearable="true"
            >
              <el-option
                v-for="i in gradeData"
                :label="i.name"
                :value="`${i.name}-${i.id}`"
              >
              </el-option>
            </el-select>
          </div>
          <div class="condition">
            <span class="title">班级 :</span>
            <el-tooltip
              class="box-item"
              effect="dark"
              content="请先选择年级"
              placement="top"
            >
              <el-select
                v-model="searchInput.class"
                placeholder="请选择班级"
                style="width: 160px"
                @change="searchBtn"
                :clearable="true"
              >
                <el-option
                  v-for="i in classsData"
                  :label="i.name"
                  :value="i.name"
                />
              </el-select>
            </el-tooltip>
          </div>
          <!-- <div class="condition">
            <span class="title">测评等级 :</span>
            <el-select
              v-model="searchInput.appraisal"
              class="sel"
              placeholder="请选择测评等级"
            >
              <el-option label="全部" value="1" />
              <el-option label="优等" value="2" />
              <el-option label="良" value="2" />
            </el-select>
          </div> -->
          <el-button
            type="primary"
            color="rgba(0, 97, 255, 1)"
            plain
            @click="scoreItemClick"
            >评分项管理</el-button
          >
        </div>
      </div>
      <div class="scroll">
        <div class="footer" v-loading="loading">
          <el-table
            :row-class-name="tableRowClassName"
            :data="tableData.list"
            @selection-change="handleSelectionChange"
            style="width: 100%"
            :header-cell-style="{
              background: 'rgba(240, 243, 247, 1)',
              height: '50px',
              border: 0,
            }"
          >
            <!-- <el-table-column align="center" type="selection" width="80" /> -->
            <el-table-column
              width="80"
              align="center"
              type="index"
              label="序号"
            />
            <el-table-column
              align="center"
              prop="term"
              width="200"
              label="学期"
            />
            <el-table-column align="center" prop="gradeName" label="年级" />
            <el-table-column align="center" prop="className" label="班级" />
            <el-table-column align="center" prop="name" label="姓名" />
            <el-table-column
              align="center"
              prop="scoreLevel"
              label="测评等级"
            />
            <el-table-column align="center" label="操作">
              <template #default="scope">
                <div class="edit">
                  <div class="look" @click="teacherInfoClick(scope.row)">
                    教师寄语
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 分页组件 -->
        <div class="pageSize">
          <span></span>
          <el-pagination
            background
            :current-page="currentPage"
            :page-size="pageSize"
            layout="total, prev, pager, next, jumper, slot"
            :total="total"
            @update:current-page="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 教师寄语 -->
    <el-dialog
      class="teacherDialog"
      v-model="teacherVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="教师寄语"
      align-center
      width="600"
      :before-close="cancelTeacher"
    >
      <el-input
        v-model="teacherRemark"
        style="width: 540px"
        :rows="12"
        type="textarea"
        placeholder="请输入评语"
      />
      <div class="options">
        <el-button
          color="rgba(41, 109, 227, 1)"
          class="queding"
          type="primary"
          @click="configTeacher"
        >
          确认
        </el-button>
        <el-button @click="cancelTeacher">取消</el-button>
      </div>
    </el-dialog>

    <!-- 评分项管理 -->
    <el-dialog
      class="scoreItemDialog"
      v-model="scoreItemVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="评分项管理"
      align-center
      width="1000"
      :before-close="cancelScoreItem"
    >
      <div class="selObject">
        <el-button
          type="primary"
          color="rgba(0, 97, 255, 1)"
          plain
          @click="criterionClick"
          >增加</el-button
        >
      </div>
      <el-table
        :row-class-name="tableRowClassName"
        :data="scoreItemData.list"
        :header-cell-style="{
          background: 'rgba(240, 243, 247, 1)',
          height: '50px',
        }"
      >
        <el-table-column width="80" align="center" type="index" label="序号" />
        <el-table-column width="160" align="center" prop="grade" label="年级" />
        <el-table-column width="230" align="center" prop="term" label="学期" />
        <el-table-column
          width="230"
          align="center"
          prop="createTime"
          label="创建时间"
        />
        <el-table-column align="center" prop="status" label="操作">
          <template #default="{ index, row }">
            <div class="option">
              <div class="edit" @click="criterionEditClick(row)">编辑</div>
              <div class="edit" @click="delScoreScope(row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 新增评分项管理按钮 -->
    <el-dialog
      class="criterionDialog"
      v-model="criterionVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :title="criterionTitle"
      align-center
      width="825"
      :before-close="cancelCriterion"
    >
      <div class="criterion">
        <el-form
          ref="assessRef"
          :model="assessRuleForm"
          :rules="assessRules"
          label-width="90px"
          class="demo-ruleForm"
          :size="formSize"
          label-position="right"
          status-icon
        >
          <el-form-item label="考核年级 :" prop="grade">
            <el-select
              v-model="assessRuleForm.grade"
              :reserve-keyword="false"
              placeholder="请选择考核年级"
              style="width: 400px"
              @change="assessgradeChange"
            >
              <el-option
                :label="i.name"
                :value="i.name"
                v-for="i in gradeData"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="学期 :" prop="term">
            <el-select
              v-model="assessRuleForm.term"
              placeholder="请选择学期"
              style="width: 400px"
            >
              <el-option
                :label="i.name"
                :value="i.name"
                v-for="i in semesterData"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="考试类型 :" prop="type">
            <el-select
              v-model="assessRuleForm.type"
              placeholder="请先选择考试类型"
              multiple
              style="width: 400px"
            >
              <el-option
                :label="i.name"
                :value="i.name"
                v-for="i in examTypeData"
              />
            </el-select>
            <span style="margin-left: 10px; font-size: 12px">多选</span>
          </el-form-item>
          <div class="selObject">
            <ul>
              <li class="sel">平均成绩</li>
            </ul>
          </div>
          <el-table
            :row-class-name="tableRowClassName"
            :data="scoreScope.list"
            :header-cell-style="{
              background: 'rgba(240, 243, 247, 1)',
              height: '50px',
            }"
          >
            <el-table-column
              width="160"
              align="center"
              type="index"
              label="序号"
            />
            <el-table-column
              width="208"
              align="center"
              prop="status"
              label="等级"
            >
              <template #default="{ row, index }">
                <el-input
                  :clearable="true"
                  @clear="searchBtn"
                  v-model.trim="row.status"
                  class="grade_right"
                  placeholder="请输入等级"
                  style="width: 180px"
                  v-if="row.flag"
                />
                <span v-else>{{ row.level }}</span>
              </template>
            </el-table-column>
            <el-table-column
              width="230"
              align="center"
              prop="score"
              label="分值区间"
            >
              <template #default="{ row, index }">
                <div class="grade" v-if="row.flag">
                  <el-input
                    :clearable="true"
                    @clear="searchBtn"
                    v-model.trim="row.scoreB"
                    class="grade_left"
                    placeholder="最低区间"
                    style="width: 90px"
                  />
                  <span class="line">-</span>
                  <el-input
                    :clearable="true"
                    @clear="searchBtn"
                    v-model.trim="row.scoreT"
                    class="grade_right"
                    placeholder="最高区间"
                    style="width: 90px"
                  />
                </div>
                <span v-else>{{ row.scoreRange }}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="status" label="操作">
              <template #default="{ index, row }">
                <div class="edit" @click="editScoreScope(index, row)">编辑</div>
              </template>
            </el-table-column>
          </el-table>
          <el-form-item class="options">
            <el-button
              color="rgba(41, 109, 227, 1)"
              class="queding"
              type="primary"
              @click="confirmAssess(assessRef)"
            >
              确认
            </el-button>
            <el-button @click="cancelAssess">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>

    <!-- 编辑评分等级 -->
    <el-dialog
      class="addItemDialog"
      v-model="editCriterionVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="编辑评分等级"
      align-center
      width="550"
      :before-close="cancelEditCriterion"
    >
      <el-form
        ref="editCriterionRef"
        :model="editCriterionRuleForm"
        :rules="editCriterionRules"
        label-width="100px"
        class="demo-ruleForm"
        :size="formSize"
        label-position="right"
        status-icon
      >
        <el-form-item label="等级 :" prop="level">
          <el-input
            v-model.trim="editCriterionRuleForm.level"
            placeholder="请输入等级名称"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item label="最小分 :" prop="scoreMin">
          <el-input
            v-model.trim="editCriterionRuleForm.scoreMin"
            placeholder="请输入最小分"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item label="最大分 :" prop="scoreMax">
          <el-input
            v-model.trim="editCriterionRuleForm.scoreMax"
            placeholder="请输入最大分"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item class="options">
          <el-button
            color="rgba(41, 109, 227, 1)"
            class="queding"
            type="primary"
            @click="confirmEditCriterion(editCriterionRef)"
          >
            确认
          </el-button>
          <el-button @click="cancelEditCriterion">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { markRaw } from "vue";
import {
  ref,
  reactive,
  watch,
  nextTick,
  onBeforeMount,
  onMounted,
  onUnmounted,
} from "vue";
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus";
import { Calendar } from "@element-plus/icons-vue";
import vidiconsApi from "@/api/vidicons.js";
import { dayjs } from "element-plus";
import lodash from "lodash";
import eds from "@/utils/eds.js";
import axios from "axios";
import { useStore } from "vuex";
const store = useStore();
const api = ref("");
const router = useRouter();
// 表格数据
const loading = ref(false);
const tableData = reactive({
  list: [
    {
      type: "2019-2020秋季学期（下学期）",
      name: "消息平台",
      link: "2020152",
      status: 1,
      describe: "消息平台",
    },
  ],
});

const searchInput = reactive({
  keyWord: "",
  semester: "", // 学期
  grade: "", // 年级
  class: "", // 班级
  appraisal: "", // 测评等级
}); // 搜索按钮数据

const currentPage = ref(1); // 当前页
const pageSize = ref(10);
const total = ref(5); // 当前总数
const selectData = reactive({
  list: [
    { a: 1, b: 2, c: 1, d: 1, e: 1, f: 1, g: 1, h: 1, i: 1, j: 1, k: 1, l: 1 },
  ],
}); // 表格勾选的数据
const semesterData = ref(); //学期下拉数据
const gradeData = ref(); //年级下拉数据
const classsData = ref(); //班级下拉数据
const examTypeData = ref(); //考试类型数据

// 教师寄语
const teacherVisible = ref(false);
const teacherRemark = ref();
const teacherId = ref();

// 评分项管理 弹窗 (-------------------------------------------------)
const scoreItemVisible = ref(false);
const scoreItemData = reactive({
  list: [
    {
      grade: "七年级",
      semester: "2023年春季",
      createTime: "2023-04-11 12:20:10",
    },
  ],
});
// 评分项管理中的 新增页面 （------------------------------------------------）
// 考核年级 、考核学期、考核考试类型数据上面已设置
const assessRef = ref();
const criterionTitle = ref("新增评分项");
const criterionVisible = ref(false);
const scoreScope = reactive({
  list: [],
}); // 评分等级数据
const assessRuleForm = reactive({
  grade: "", // 考核年级
  term: "", // 考核学期
  type: "", // 考核考试类型
  id: "",
});
// 表单验证
const assessRules = reactive({
  grade: [{ required: true, message: "考核年级不能为空", trigger: "blur" }],
  term: [{ required: true, message: "学期不能为空", trigger: "blur" }],
  type: [{ required: true, message: "考试类型不能为空", trigger: "blur" }],
});

// 编辑评分等级（---------------------------）
const editCriterionVisible = ref(false); // 编辑评分等级弹窗
const editCriterionRef = ref();
const editCriterionRuleForm = reactive({
  level: "", // 等级
  scoreMax: "",
  scoreMin: "",
  id: "",
});
const validateScoreMin = (rule, value, callback) => {
  if (!/^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/.test(value)) {
    callback("请输入正确的分值");
  } else if (
    Number(editCriterionRuleForm.scoreMax) <
    Number(editCriterionRuleForm.scoreMin)
  ) {
    callback(new Error("最小分应小于最大分"));
  } else {
    callback();
  }
};
const validateScoreMax = (rule, value, callback) => {
  if (!/^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/.test(value)) {
    callback("请输入正确的分值");
  } else if (
    Number(editCriterionRuleForm.scoreMax) <
    Number(editCriterionRuleForm.scoreMin)
  ) {
    callback(new Error("最大分应大于最小分"));
  } else {
    callback();
  }
};
// 表单验证
const editCriterionRules = reactive({
  level: [{ required: true, message: "等级不能为空", trigger: "blur" }],
  scoreMax: [
    { required: true, message: "最大分不能为空", trigger: "blur" },
    { validator: validateScoreMax, trigger: "blur" },
  ],
  scoreMin: [
    { required: true, message: "最小分不能为空", trigger: "blur" },
    // { validator: validateScoreMin, trigger: "blur" },
  ],
});

// 学生列表
const getList = async () => {
  loading.value = true;
  let params = {
    currentPage: currentPage.value,
    pageCount: pageSize.value,
  };
  let data = {
    name: searchInput.keyWord,
    term: searchInput.semester,
    gradeName: searchInput.grade.split("-")[0],
    className: searchInput.class,
    // scoreLevel: searchInput.appraisal,
  };
  let res = await axios({
    method: "post",
    url: api.value + "/wanzai/api/smartEvaluateStudent/queryEvaluateStudent",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    params: params,
    data: data,
  });
  console.log(res, JSON.parse(eds.decryptDes(res.data.data)), "学生信息分页");
  if (res.data.code == 200) {
    loading.value = false;
    tableData.list = JSON.parse(eds.decryptDes(res.data.data)).list;
    total.value = JSON.parse(eds.decryptDes(res.data.data)).totalCount;
    // ElMessage({
    //   type: "success",
    //   showClose: true,
    //   message: res.data.message,
    //   center: true,
    // });
  } else {
    loading.value = false;
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};
// 获取学期下拉
const semesterList = async () => {
  let semester = await axios({
    method: "get",
    url: api.value + "/wanzai/api/smartScore/querySmartSemesters",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    // params: data,
  });
  console.log(
    semester,
    JSON.parse(eds.decryptDes(semester.data.data)),
    "学期下拉数据"
  );
  semesterData.value = JSON.parse(eds.decryptDes(semester.data.data));
};

// 年级数据下拉
const classDataList = async () => {
  semesterList();
  let grade = await axios({
    method: "get",
    url: api.value + "/wanzai/api/smartGrade/querySmartGrades",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    // params: data,
  });
  console.log(
    grade,
    JSON.parse(eds.decryptDes(grade.data.data)),
    "年级下拉数据"
  );
  gradeData.value = JSON.parse(eds.decryptDes(grade.data.data));
};

// 改变年级选择
const yearClassChange = async (value) => {
  console.log(value);
  let arr = value.split("-");
  if (value) {
    classInfoList(arr[1]);
  } else {
    classsData.value = [];
    searchInput.class = "";
  }
  getList();
};

// 班级数据下拉
const classInfoList = async (value) => {
  let data = {
    gradeId: value,
  };
  let classs = await axios({
    method: "get",
    url: api.value + "/wanzai/api/smartClass/querySmartClasss",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    params: data,
  });
  console.log(
    classs,
    JSON.parse(eds.decryptDes(classs.data.data)),
    "班级下拉数据"
  );
  classsData.value = JSON.parse(eds.decryptDes(classs.data.data));
};
// 考试类型下拉
const assessType = async (value) => {
  let data = {
    gradeId: value,
  };
  let examType = await axios({
    method: "get",
    url: api.value + "/wanzai/api/smartScore/queryExamTypes",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    params: data,
  });
  // console.log(
  //   examType,
  //   JSON.parse(eds.decryptDes(examType.data.data)),
  //   "考试类型下拉数据"
  // );
  console.log(examType, "考试类型下拉数据");
  if (examType.data.code == 200) {
    examTypeData.value = JSON.parse(eds.decryptDes(examType.data.data));
    // ElMessage({
    //   type: "success",
    //   showClose: true,
    //   message: examType.data.message,
    //   center: true,
    // });
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: examType.data.message,
      center: true,
    });
  }
 
};

// 搜索功能
const searchBtn = lodash.debounce(async () => {
  getList();
}, 300);

// 教师寄语弹窗
const teacherInfoClick = (row) => {
  teacherVisible.value = true;
  teacherRemark.value = row.scoreComment;
  teacherId.value = row.id;
};
const configTeacher = async () => {
  let data = new FormData();
  data.append("id", teacherId.value);
  data.append("scoreComment", teacherRemark.value);
  let res = await axios({
    method: "post",
    url: api.value + "/wanzai/api/smartEvaluateStudent2/evaluateScore",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    data: data,
  });
  if (res.data.code == 200) {
    teacherVisible.value = false;
    ElMessage({
      type: "success",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};
const cancelTeacher = (row) => {
  teacherVisible.value = false;
};

// 评分项管理（-----------------------------------------------）
const scoreItemClick = () => {
  scoreItemVisible.value = true;
  scoreItemList();
};
// 评分项管理数据
const scoreItemList = async () => {
  let data = new FormData();
  data.append("currentPage", 1);
  data.append("pageCount", 200);
  let res = await axios({
    method: "post",
    url: api.value + "/wanzai/api/smartEvaluateStudent2/queryTemplatePage",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    data: data,
  });
  console.log(res, "评分项管理表格数据");
  if (res.data.code == 200) {
    scoreItemData.list = res.data.data.list;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};
const cancelScoreItem = () => {
  scoreItemVisible.value = false;
};
// 删除评分管理
const delScoreScope = async (row) => {
  let data = new FormData();
  data.append("id", row.id);
  let res = await axios({
    method: "post",
    url:
      api.value + "/wanzai/api/smartEvaluateStudent2/delSmartSubjectTemplate",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    data: data,
  });
  if (res.data.code == 200) {
    scoreItemList();
    ElMessage({
      type: "success",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

//导出功能 (-------------------------------------------------)
const importExcel = async () => {
  // if (searchInput.createTime == null) {
  //   searchInput.createTime = "";
  // }
  // let data = new FormData();
  // data.set("car_number", searchInput.carnumber);
  // data.set("create_time", searchInput.createTime);
  // let res = await axios({
  //   method: "post",
  //   url: api.value + "/carBook/cinfotoExcel.action",
  //  headers: {
  // token: sessionStorage.getItem("token"),
  //   user_head: sessionStorage.getItem("userhead"),
  // },
  //   data: data,
  // });
  // // console.log(res, "导出账号");
  // if (res.data.code == 200) {
  //   // const elt = document.createElement("a");
  //   // elt.setAttribute(
  //   //   "href",
  //   //   "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl
  //   // );
  //   // elt.setAttribute("download", "file.png");
  //   // elt.style.display = "none";
  //   // document.body.appendChild(elt);
  //   // elt.click();
  //   var downloadPath = "https://chtech.ncjti.edu.cn/carstop" + res.data.downurl;
  //   console.log("获得地址数据:", downloadPath);
  //   var downloadLink = document.createElement("a");
  //   downloadLink.style.display = "none"; // 使其隐藏
  //   downloadLink.href = downloadPath;
  //   downloadLink.download = "";
  //   downloadLink.click();
  //   document.body.appendChild(downloadLink);
  //   document.body.removeChild(downloadLink);
  //   ElMessage({
  //     type: "success",
  //     showClose: true,
  //     message: res.data.message,
  //     center: true,
  //   });
  // } else {
  //   ElMessage({
  //     type: "error",
  //     showClose: true,
  //     message: res.data.message,
  //     center: true,
  //   });
  // }
};

//  增加评分项按钮（----------------------------------------------------------------）
const criterionClick = () => {
  criterionVisible.value = true;
  criterionTitle.value = "新增评分项";
  criterionDataList(); // 评分标准数据
  assessRuleForm.grade = "";
  assessRuleForm.term = "";
  assessRuleForm.type = "";
  assessRuleForm.id = "";
};
// 改变年级 改变考试类型
const assessgradeChange = (value) => {
  let id = "";
  gradeData.value.forEach((item) => {
    if (item.name == value) {
      id = item.id;
    }
  });
  assessType(id);
  assessRuleForm.type = [];
};
// 等级标准数据
const criterionDataList = async () => {
  let res = await axios({
    method: "post",
    url: api.value + "/wanzai/api/smartEvaluateStudent/querySubjectRule",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
  });
  console.log(res, JSON.parse(eds.decryptDes(res.data.data)), "评分标准数据");
  if (res.data.code == 200) {
    scoreScope.list = JSON.parse(
      eds.decryptDes(res.data.data)
    ).smartSubjectRuleInLists[6].subjectRuleList;
    console.log(scoreScope.list, "标准评分表格");
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};
const confirmAssess = (formEl) => {
  formEl.validate(async (valid, fields) => {
    if (valid) {
      let arr = [];
      scoreScope.list.forEach((item, index) => {
        arr.push({ level: item.level, scoreRange: item.scoreRange });
      });
      let data = {
        smartSubjectTemplate: {
          grade: assessRuleForm.grade,
          term: assessRuleForm.term,
          examType: assessRuleForm.type.join(","),
        },
        ruleList: arr,
      };
      console.log(data);
      if (assessRuleForm.id) {
        data.smartSubjectTemplate.id = assessRuleForm.id;
        let res = await axios({
          method: "post",
          url:
            api.value +
            "/wanzai/api/smartEvaluateStudent2/updateSmartSubjectTemplate",
          headers: {
            token: sessionStorage.getItem("token"),
            user_head: sessionStorage.getItem("userhead"),
          },
          data: data,
        });
        console.log(res, "评分管理-新增/更新/删除");
        if (res.data.code == 200) {
          scoreItemList();
          criterionVisible.value = false;
          ElMessage({
            type: "success",
            showClose: true,
            message: res.data.message,
            center: true,
          });
        } else {
          ElMessage({
            type: "error",
            showClose: true,
            message: res.data.message,
            center: true,
          });
        }
      } else {
        let res = await axios({
          method: "post",
          url:
            api.value +
            "/wanzai/api/smartEvaluateStudent2/addSmartSubjectTemplate",
          headers: {
            token: sessionStorage.getItem("token"),
            user_head: sessionStorage.getItem("userhead"),
          },
          data: data,
        });
        console.log(res, "评分管理-新增/更新/删除");
        if (res.data.code == 200) {
          scoreItemList();
          criterionVisible.value = false;
          ElMessage({
            type: "success",
            showClose: true,
            message: res.data.message,
            center: true,
          });
        } else {
          ElMessage({
            type: "error",
            showClose: true,
            message: res.data.message,
            center: true,
          });
        }
      }
    }
  });
};
const cancelAssess = () => {
  criterionVisible.value = false;
  assessRef.value.resetFields();
};
//  编辑评分项按钮（----------------------------------------------------------------）
const criterionEditClick = async (row) => {
  criterionVisible.value = true;
  criterionTitle.value = "编辑评分项";
  console.log(row);
  
  let id = "";
  gradeData.value.forEach((item) => {
    if (item.name == row.grade) {
      id = item.id;
    }
  });
  assessType(id);
  assessRuleForm.grade = row.grade;
  assessRuleForm.term = row.term;
  assessRuleForm.id = row.id;
  assessRuleForm.type = row.examType.split(",");
  // 编辑时的等级表格数据
  let formData = new FormData();
  formData.append("id", row.id);
  let res = await axios({
    method: "post",
    url: api.value + "/wanzai/api/smartEvaluateStudent2/queryTemplateRulePage",
    headers: {
      token: sessionStorage.getItem("token"),
      user_head: sessionStorage.getItem("userhead"),
    },
    data: formData,
  });
  // console.log(res, JSON.parse(eds.decryptDes(res.data.data)), "评分标准数据");
  console.log(res, "编辑时的等级表格数据");
  if (res.data.code == 200) {
    scoreScope.list = res.data.data;
  } else {
    ElMessage({
      type: "error",
      showClose: true,
      message: res.data.message,
      center: true,
    });
  }
};

// 编辑评分等级（----------------------------------------）
const editScoreScope = (index, row) => {
  console.log(row, "编辑等级");
  editCriterionVisible.value = true;
  editCriterionRuleForm.level = row.level;
  editCriterionRuleForm.id = row.id;
  let arr = row.scoreRange.split("-");
  editCriterionRuleForm.scoreMin = arr[0];
  editCriterionRuleForm.scoreMax = arr[1];
};
const confirmEditCriterion = (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid, fields) => {
    if (valid) {
      scoreScope.list.forEach((item, index) => {
        if (item.id == editCriterionRuleForm.id) {
          item.level = editCriterionRuleForm.level;
          item.scoreRange =
            editCriterionRuleForm.scoreMin +
            "-" +
            editCriterionRuleForm.scoreMax;
        }
        editCriterionVisible.value = false;
      });
    }
  });
};
const cancelEditCriterion = () => {
  editCriterionVisible.value = false;
};

// 表格斑马纹颜色修改
const tableRowClassName = ({ row, rowIndex }) => {
  if (rowIndex % 2 === 0) {
    return "even";
  } else if (rowIndex % 2 !== 0) {
    return "odd";
  }
  return "";
};
// 分页
const handleCurrentChange = (value) => {
  // console.log(value);
  currentPage.value = value;
  getList();
};

onBeforeMount(async () => {
  api.value = store.state.user.api;
  getList();
  classDataList();
});
onMounted(() => {});
onUnmounted(() => {
  // scoreEcharts.value.dispose();
});
</script>

<style scoped lang="scss">
.content-box {
  min-width: 1000px;
  width: calc(100vw - 260px);
  height: calc(100vh - 105px);
  margin: 20px auto;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: 0px 3px 10px rgba(0, 97, 255, 0.2);
  .pageIndex {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .left {
    // width: calc(100wh - 40px);
    display: flex;
    align-items: center;
    height: 60px;
    margin: 0 30px;
    border-bottom: 1px solid #ccc;
    color: rgb(0, 0, 0);
    font-size: 18px;
    font-weight: 600;

    span {
      display: block;
      height: 60px;
      line-height: 60px;
    }

    .is_active {
      color: rgba(111, 182, 184, 1);
    }
  }
  .scroll {
    // height: calc(100% - 175px);
    flex: 1;
    overflow: auto;
  }
  .middle {
    width: 96%;
    margin: 0 auto;

    color: #000;

    // border-bottom: 1px solid rgb(231, 231, 231);
    .filter {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      margin: 10px 0 0 0;

      .search {
        color: #fff;
      }

      .condition {
        display: flex;
        align-items: center;
        margin: 10px 30px 10px 0;
        .title {
          padding-right: 5px;
        }
        .sel {
          margin-right: 10px;
        }
        :deep(.el-input .el-input__inner) {
          font-size: 14px;
        }
      }
    }

    .gongneng {
      margin: 10px 0 20px 0;

      span {
        color: #fff;
      }
      .el-button {
        margin-right: 10px;
      }
    }

    :deep(.download) {
      display: flex;
      align-items: center;
      margin: 10px;
    }

    :deep(.download span) {
      font-size: 16px;
      margin-left: 20px;
    }
  }
  .footer {
    width: 96%;
    height: calc(100% - 70px);
    margin: 10px auto;

    .el-table--fit {
      height: 100%;

      :deep(.el-table__header-wrapper) {
        background-color: #000;
        font-size: 14px;
      }

      :deep(.el-table__row) {
        height: 50px;
        font-size: 14px;
        // color: #000;

        &:hover {
          td {
            background-color: rgba(223, 236, 254, 1);
          }
        }
      }

      :deep(.el-table__row td) {
        padding: 0;
        .normal {
          cursor: pointer;
          color: rgba(0, 97, 255, 1);
        }
      }

      .el-button--primary {
        margin-left: 5px;
      }

      :deep(.el-table__body .even) {
        background-color: #fff;
      }

      :deep(.el-table__body .odd) {
        background-color: rgba(240, 243, 247, 1);
      }

      :deep(.edit) {
        display: flex;
        align-items: center;
        justify-content: center;
        color: rgba(111, 182, 184, 1);
      }

      :deep(.look) {
        padding: 0 10px;
        cursor: pointer;
        color: rgba(30, 125, 251, 1);
      }

      .del {
        padding: 0 10px;
        color: rgba(212, 48, 48, 1);
        cursor: pointer;
      }

      // :deep(.look):hover {
      //   color: red;
      // }
      // :deep(.del):hover {
      //   color: red;
      // }
    }
  }

  // 评分项管理
  :deep(.scoreItemDialog) {
    border-radius: 11px;
    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(237, 241, 245, 1);
      font-weight: 600;
      margin: 0;
      .el-dialog__headerbtn {
        outline: none;
      }
    }
    .el-dialog__body {
      padding: 0 30px 20px;
      .selObject {
        padding: 10px 0;
      }
      .el-table--fit {
        height: 500px;
        .el-table__header-wrapper {
          font-size: 14px;
          .cell {
            color: #000;
          }
        }

        .el-table__row {
          height: 50px;
          font-size: 14px;
          color: #000;

          td {
            padding: 0;
            border-right: 1px solid rgba(230, 230, 230, 1);
            &:nth-child(1) {
              border-left: 1px solid rgba(230, 230, 230, 1);
            }
          }
          .option {
            display: flex;
            align-items: center;
            justify-content: center;
            .edit {
              color: rgba(0, 97, 255, 1);
              cursor: pointer;
              padding-right: 10px;
            }
          }
        }
      }
      .options {
        margin: 30px 20px 0 0;
        width: 100%;
        display: flex;
        flex-direction: row-reverse;

        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }

  // 去评分按钮
  :deep(.criterionDialog) {
    //   height: 420px;
    border-radius: 11px;
    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(237, 241, 245, 1);
      font-weight: 600;
      margin: 0;
      .el-dialog__headerbtn {
        outline: none;
      }
    }
    .el-dialog__body {
      padding: 15px 30px 30px 30px;
      .criterion {
        .selObject {
          ul {
            display: flex;
            list-style: none;
            padding: 0;
            li {
              width: 70px;
              height: 37px;
              text-align: center;
              line-height: 37px;
              padding: 0;
              margin-right: 10px;
              border-radius: 5px;
              background: rgba(242, 242, 242, 1);
              border: 1px solid rgba(204, 204, 204, 1);
              color: rgba(166, 166, 166, 1);
              cursor: pointer;
            }
            .sel {
              color: rgba(0, 97, 255, 1);
              background: rgba(235, 242, 255, 1);
              border: 1px solid rgba(0, 97, 255, 1);
            }
          }
        }
        .el-table--fit {
          height: calc(100% - 92px);
          .el-table__header-wrapper {
            font-size: 14px;
            .cell {
              color: #000;
            }
          }

          .el-table__row {
            height: 50px;
            font-size: 14px;
            color: #000;

            td {
              padding: 0;
              border-right: 1px solid rgba(230, 230, 230, 1);
              &:nth-child(1) {
                border-left: 1px solid rgba(230, 230, 230, 1);
              }
            }
            .edit {
              color: rgba(0, 97, 255, 1);
              cursor: pointer;
            }
            .grade {
              display: flex;
              justify-content: center;
              .el-input {
                .el-input__wrapper {
                  box-shadow: none;
                }
              }
              .grade_left {
                border-top: 1px solid #dcdfe6;
                border-bottom: 1px solid #dcdfe6;
                border-left: 1px solid #dcdfe6;
                border-top-left-radius: 4px;
                border-bottom-left-radius: 4px;
              }
              .line {
                display: block;
                height: 32px;
                line-height: 32px;
                padding: 0 8px;
                border-top: 1px solid #dcdfe6;
                border-bottom: 1px solid #dcdfe6;
              }
              .grade_right {
                border-top: 1px solid #dcdfe6;
                border-bottom: 1px solid #dcdfe6;
                border-right: 1px solid #dcdfe6;
                border-top-right-radius: 4px;
                border-bottom-right-radius: 4px;
              }
            }
            &:hover {
              td {
                // background-color: rgba(223, 236, 254, 0.6);
                background-color: transparent;
              }
            }
          }
        }
      }
      .options {
        margin: 30px 20px 0 0;
        width: 100%;
        display: flex;
        flex-direction: row-reverse;
        .el-form-item__content {
          flex: none;
        }
        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }
  // 等级评分
  :deep(.addItemDialog) {
    //   height: 420px;
    border-radius: 11px;
    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(237, 241, 245, 1);
      font-weight: 600;
      margin: 0;
      .el-dialog__headerbtn {
        outline: none;
      }
    }
    .el-dialog__body {
      padding: 30px 30px 10px 30px;
      .el-form-item__content {
        width: 200px;
        .el-input-group__append {
          background-color: rgba(222, 234, 252, 1);
          color: rgba(0, 97, 255, 1);
          cursor: pointer;
          user-select: none;
        }
      }
      .el-form {
        .typeTitle {
          display: block;
          color: red;
          margin: 0 0 6px 100px;
        }
        .account {
          display: flex;
          justify-content: space-between;
          .el-form-item {
            .el-form-item__content {
              width: 300px;
            }
            .el-input {
              width: 300px;
            }
          }
        }
      }

      .options {
        margin: 50px 20px 20px 0;
        width: 100%;
        .el-form-item__content {
          display: flex;
          flex-direction: row-reverse;
        }

        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }

  // 教师寄语
  :deep(.teacherDialog) {
    //   height: 420px;
    border-radius: 11px;
    .el-dialog__header {
      border-radius: 11px 11px 0 0;
      background: rgba(237, 241, 245, 1);
      font-weight: 600;
      margin: 0;
      .el-dialog__headerbtn {
        outline: none;
      }
    }
    .el-dialog__body {
      padding: 20px 30px;

      .options {
        margin-top: 15px;
        width: 100%;
        display: flex;
        flex-direction: row-reverse;

        .queding {
          color: #fff;
          margin-left: 15px;
        }
      }
    }
  }

  .pageSize {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 30px;

    span {
      color: #000;
    }

    .el-pagination {
      // width: 1600px;
      :deep(.el-pagination__total) {
        color: #000;
      }

      :deep(.el-pagination__goto) {
        color: #000;
      }

      :deep(.el-pagination__classifier) {
        color: #000;
      }

      :deep(.el-input__wrapper) {
        border: 1px solid rgba(0, 0, 0, 1);
        border-radius: 5px;
        box-shadow: none;
      }

      :deep(.el-pager li) {
        margin: 0 5px;
        border: 1px solid rgba(0, 0, 0, 1);
        border-radius: 5px;
        background-color: transparent;
      }

      :deep(.el-pager li.is-active) {
        // background-color: rgba(0, 97, 255, 0.8);
        border: 1px solid rgba(0, 97, 255, 1);
        color: rgba(0, 97, 255, 1);
      }

      :deep(.btn-prev) {
        margin-right: 5px;
        border: 1px solid rgba(0, 0, 0, 1);
        border-radius: 5px;
        background-color: transparent;
      }

      :deep(.btn-next) {
        margin-left: 5px;
        border: 1px solid rgba(0, 0, 0, 1);
        border-radius: 5px;
        background-color: transparent;
      }
    }
  }
}

.el-input {
  width: 192px;
}
</style>
