<template>
  <div class="home-guide">
    <!-- 命题组卷 -->
    <div class="guide-group">
      <div class="guide-box">
        <h4 class="guide-title">命题组卷</h4>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('createQuestion'),
              'is-link': checkIsLink('createQuestion'),
            }"
            @click="guideLink('createQuestion')"
          >
            试题录入
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('createPaper'),
              'is-link': checkIsLink('createPaper'),
            }"
            @click="guideLink('createPaper')"
          >
            组卷
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('buildPaper'),
              'is-link': checkIsLink('buildPaper'),
            }"
            @click="guideLink('buildPaper')"
          >
            生成试卷
          </li>
        </ul>
      </div>
    </div>
    <!-- 电子交卷 -->
    <div class="guide-group">
      <div class="guide-box">
        <h4 class="guide-title">电子交卷</h4>
        <p class="guide-desc">提交命题任务</p>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('uploadPaper'),
              'is-link': checkIsLink('uploadPaper'),
            }"
            @click="guideLink('uploadPaper')"
          >
            选择/上传试卷
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('createCard'),
              'is-link': checkIsLink('createCard'),
            }"
            @click="guideLink('createCard')"
          >
            选择通卡/设计答题卡
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('selectApproveUser'),
              'is-link': checkIsLink('selectApproveUser'),
            }"
            @click="guideLink('selectApproveUser')"
          >
            选择审核人提交
          </li>
        </ul>
      </div>
    </div>
    <!-- 印刷&扫描 -->
    <div class="guide-group">
      <div class="guide-box">
        <h4 class="guide-title">印刷&扫描</h4>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('print'),
              'is-link': checkIsLink('print'),
            }"
          >
            印刷
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('cardScan'),
              'is-link': checkIsLink('cardScan'),
            }"
          >
            答题卡扫描
          </li>
        </ul>
      </div>
    </div>

    <!-- 评卷管理 -->
    <div class="guide-group">
      <div class="guide-box">
        <h4 class="guide-title">评卷管理</h4>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('markSetting'),
              'is-link': checkIsLink('markSetting'),
            }"
            @click="guideLink('markSetting')"
          >
            评卷参数设置
          </li>
        </ul>
        <p class="guide-desc">评卷过程管理</p>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('markProgress'),
              'is-link': checkIsLink('markProgress'),
            }"
            @click="guideLink('markProgress')"
          >
            评卷进度
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('markTaskDetail'),
              'is-link': checkIsLink('markTaskDetail'),
            }"
            @click="guideLink('markTaskDetail')"
          >
            已评任务查看
          </li>
        </ul>
        <p class="guide-desc">成绩检查</p>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('scoreCheck'),
              'is-link': checkIsLink('scoreCheck'),
            }"
            @click="guideLink('scoreCheck')"
          >
            复核
          </li>
        </ul>
        <p class="guide-desc">结束评卷</p>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('markResultCheck'),
              'is-link': checkIsLink('markResultCheck'),
            }"
          >
            数据检查
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('overMark'),
              'is-link': checkIsLink('overMark'),
            }"
            @click="guideLink('overMark')"
          >
            结束评卷
          </li>
        </ul>
      </div>
    </div>

    <!-- 归档&成绩导出 -->
    <div class="guide-group">
      <div class="guide-box">
        <h4 class="guide-title">归档&成绩导出</h4>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('scoreView'),
              'is-link': checkIsLink('scoreView'),
            }"
            @click="guideLink('scoreView')"
          >
            查看成绩
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('reportView'),
              'is-link': checkIsLink('reportView'),
            }"
            @click="guideLink('reportView')"
          >
            查看成绩报告
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('exportScore'),
              'is-link': checkIsLink('exportScore'),
            }"
            @click="guideLink('exportScore')"
          >
            导出成绩
          </li>
        </ul>
      </div>
    </div>

    <div class="guide-group">
      <div class="guide-line-top"></div>
      <div class="guide-line-bottom"></div>
      <!-- 教研分析 -->
      <div class="guide-box">
        <h4 class="guide-title">教研分析</h4>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('setAnalysisBlue'),
              'is-link': checkIsLink('setAnalysisBlue'),
            }"
            @click="guideLink('setAnalysisBlue')"
          >
            设置试卷蓝图数据
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('analysisReport'),
              'is-link': checkIsLink('analysisReport'),
            }"
            @click="guideLink('analysisReport')"
          >
            查看报告
          </li>
        </ul>
      </div>
      <!-- 达成度分析 -->
      <div class="guide-box">
        <h4 class="guide-title">达成度分析</h4>
        <ul class="guide-menus">
          <li
            :class="{
              'is-disabled': !guideAuthentic('trainingPlan'),
              'is-link': checkIsLink('trainingPlan'),
            }"
            @click="guideLink('trainingPlan')"
          >
            设置培养方案
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('courseTarget'),
              'is-link': checkIsLink('courseTarget'),
            }"
            @click="guideLink('courseTarget')"
          >
            设置课程目标
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('evaluationMode'),
              'is-link': checkIsLink('evaluationMode'),
            }"
            @click="guideLink('evaluationMode')"
          >
            设置课程考核方式权重
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('targetScore'),
              'is-link': checkIsLink('targetScore'),
            }"
            @click="guideLink('targetScore')"
          >
            导入平时成绩 / 期末成绩
          </li>
          <li
            :class="{
              'is-disabled': !guideAuthentic('targetStatistics'),
              'is-link': checkIsLink('targetStatistics'),
            }"
            @click="guideLink('targetStatistics')"
          >
            查看报告
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { objTypeOf } from "@/plugins/utils";
import { mapState } from "vuex";

export default {
  name: "home-guide",
  data() {
    return {
      guidePriviledges: {
        // 命题组卷 -----
        // 试题录入
        createQuestion: {
          // 去题库
        },
        // 组卷
        createPaper: {},
        // 生成试卷
        buildPaper: {},

        // 电子交卷 -----
        // 选择/上传试卷
        uploadPaper: {
          authentic: "TaskApplyManage",
          toLink: "TaskApplyManage",
        },
        // 选择通卡/设计答题卡
        createCard: {
          authentic: "TaskApplyManage",
          toLink: "TaskApplyManage",
        },
        // 选择审核人提交
        selectApproveUser: {
          authentic: "TaskApplyManage",
          toLink: "TaskApplyManage",
        },

        // 印刷&扫描 -----
        // 印刷
        print: {},
        // 答题卡扫描
        cardScan: {},

        // 评卷管理 -----
        // 评卷参数设置
        markSetting: { authentic: "MarkSetting", toLink: "MarkSetting" },
        // 评卷进度
        markProgress: {
          authentic: "MarkManage",
          toLink: "MarkManage",
        },
        // 已评任务查看
        markTaskDetail: { authentic: "MarkManage", toLink: "MarkManage" },
        // 复核
        scoreCheck: { authentic: "ScoreCheck", toLink: "ScoreCheck" },
        // 数据检查
        markResultCheck: {},
        // 结束评卷
        overMark: { authentic: "MarkManage", toLink: "MarkManage" },

        // 归档&成绩导出 ----
        // 查看成绩
        scoreView: { authentic: "ScoreManage", toLink: "ScoreManage" },
        // 查看成绩报告
        reportView: { authentic: "ScoreManage", toLink: "ScoreManage" },
        // 导出成绩
        exportScore: { authentic: "ScoreManage", toLink: "ScoreManage" },

        // 教研分析 ----
        // 设置试卷蓝图数据
        setAnalysisBlue: {
          authentic: "DataInitManage",
          toLink: "DataInitManage",
        },
        // 查看报告
        analysisReport: {
          authentic: "AnalysisReportView",
          toLink: "AnalysisReportView",
        },

        // 达成度分析 ----
        // 设置培养方案
        trainingPlan: { authentic: "CultureProgram", toLink: "CultureProgram" },
        // 设置课程目标
        courseTarget: {
          authentic: "CourseOutlineManager",
          toLink: "CourseOutlineManager",
        },
        // 设置课程考核方式权重
        evaluationMode: {
          authentic: "CourseAssessmentSetting",
          toLink: "CourseAssessmentSetting",
        },
        // 导入平时成绩/期末成绩
        targetScore: {
          authentic: "TargetScoreManage",
          toLink: "TargetScoreManage",
        },
        // 查看报告
        targetStatistics: {
          authentic: "GraduationRequirement",
          toLink: "GraduationRequirement",
        },
      },
    };
  },
  computed: {
    ...mapState("app", ["validRoutes"]),
  },
  methods: {
    checkIsLink(key) {
      return this.guidePriviledges[key] && this.guidePriviledges[key].toLink;
    },
    guideAuthentic(key) {
      if (!this.guidePriviledges[key]) return false;

      const { authentic } = this.guidePriviledges[key];

      if (!authentic) return false;

      if (objTypeOf(authentic) === "function") {
        return authentic();
      }

      if (objTypeOf(authentic) === "string") {
        return this.validRoutes.includes(authentic);
      }

      return false;
    },
    guideLink(key) {
      if (!this.guidePriviledges[key] || !this.guideAuthentic(key)) return;

      const { toLink, params } = this.guidePriviledges[key];

      if (!toLink) return;

      if (objTypeOf(toLink) === "function") {
        toLink();
        return;
      }

      if (objTypeOf(toLink) === "string") {
        this.$router.push({ name: toLink, query: params || {} });
        return;
      }
    },
  },
};
</script>
