<template>
  <h2 class="contentTitle">课程列表</h2>
  <div class="course_select">
    <span class="grandTitle">年级：</span>
    <el-button :class="selectGrand == '三年级' ? 'el_button_active' : ''" @click="clickGrand('三年级')">三年级</el-button>
    <el-button :class="selectGrand == '四年级' ? 'el_button_active' : ''" @click="clickGrand('四年级')">四年级</el-button>
    <el-button :class="selectGrand == '五年级' ? 'el_button_active' : ''" @click="clickGrand('五年级')">五年级</el-button>
    <el-button :class="selectGrand == '六年级' ? 'el_button_active' : ''" @click="clickGrand('六年级')">六年级</el-button>
    <el-button :class="selectGrand == '七年级' ? 'el_button_active' : ''" @click="clickGrand('七年级')">七年级</el-button>
    <el-button :class="selectGrand == '八年级' ? 'el_button_active' : ''" @click="clickGrand('八年级')">八年级</el-button>
  </div>
  <div class="course_select">
    <span class="grandTitle">{{ value }}</span>
    <div v-if="currentData && currentData.shang.length > 0">
      <el-row :gutter="20">
        <el-col :span="6" v-for="item in currentData.shang" :key="item.title">
          <div class="grid-content ep-bg-purple">
            <img :src="getImageUrl(item.url)" alt="">
            <div class="course_content">
              <p>{{ item.title }}<span>上册</span></p>
              <div class="class_button" v-if="isupdateCourse">
                <el-button
                  style="width: 30%;background: rgba(240, 242, 245, 1);color: rgba(0, 0, 0, 0.6);">还原</el-button>
                <el-button style="width: 30%;background: #fff" @click="updateCourse(item.id)">修改</el-button>FF
                <el-button class="el_button_active" @click="openCourseDetail(item.id)">查看</el-button>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div v-if="currentData && currentData.xia.length > 0">
      <el-row :gutter="20">
        <el-col :span="6" v-for="item in currentData.xia" :key="item.title">
          <div class="grid-content ep-bg-purple">
            <img :src="getImageUrl(item.url)" alt="">
            <div class="course_content">
              <p>{{ item.title }} <span>下册</span></p>
            </div>
            <div class="class_button" v-if="isupdateCourse">
              <el-button style="width: 30%;background: rgba(240, 242, 245, 1);color: rgba(0, 0, 0, 0.6);"
                @click="ReductionCourse(item.id)">还原</el-button>
              <el-button style="width: 30%;background: #fff" @click="updateCourse(item.id)">修改</el-button>
              <el-button style="width: 30%;" class="el_button_active" @click="openCourseDetail(item.id)">查看</el-button>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
  <el-dialog v-model="dialogVisible" :before-close="handleClose" width=500>
    <template #header>
      <div class="dialog-header img_text_middle">
        <img :src="WarningImg" alt="">
        <span class="warning_text">操作警告</span>
      </div>
    </template>
    <span>启用还原功能将重置当前修改，并将课程内容恢复至标准版本。请确认是否继续执行相关操作。</span>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="updateReduction()">
          确认修改
        </el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, onMounted, watchEffect } from 'vue';
import { userInfoStore } from '../../stores/counter'
import WarningImg from '@/assets/icon/icon.png'
import san1 from '../../assets/img/三下1.png'
import san2 from '@/assets/img/三下2.png'
import san3 from '@/assets/img/三下3.png'
import san4 from '@/assets/img/三下4.png'
import si1 from '@/assets/img/四下1.png'
import si2 from '@/assets/img/四下2.png'
import si3 from '@/assets/img/四下3.png'
import si4 from '@/assets/img/四下4.png'
import wu1 from '@/assets/img/五下1.png'
import wu2 from '@/assets/img/五下2.png'
import wu3 from '@/assets/img/五下3.png'
import wu4 from '@/assets/img/五下4.png'
import liu1 from '@/assets/img/六下1.png'
import liu2 from '@/assets/img/六下2.png'
import liu3 from '@/assets/img/六下3.png'
import liu4 from '@/assets/img/六下4.png'
import qi1 from '@/assets/img/七下1.png'
import qi2 from '@/assets/img/七下2.png'
import qi3 from '@/assets/img/七下3.png'
import qi4 from '@/assets/img/七下4.png'
import ba1 from '@/assets/img/八下1.png'
import ba2 from '@/assets/img/八下2.png'
import ba3 from '@/assets/img/八下3.png'
import ba4 from '@/assets/img/八下4.png'

const user = userInfoStore()
const selectGrand = ref('三年级')
const isupdateCourse = ref(false)
const currentData = ref({
  shang: [
  ],
  xia: [
    {
      id: "",
      title: "智能安防",
      url: "../../assets/img/三下1.png"
    }, {
      id: "",
      title: "人脸检测与识别",
      url: "../../assets/img/三下1.png"
    }, {
      id: "",
      title: "电子警察",
      url: "../../assets/img/三下1.png"
    }, {
      id: "",
      title: "音频播报",
      url: "../../assets/img/三下1.png"
    },
  ]
})
const dialogVisible = ref(false)
const updateReductionId = ref("")

const courseData = {
  "三年级": {
    shang: [
    ],
    xia: [
      {
        id: "",
        title: "智能安防",
        url: san1
      }, {
        id: "",
        title: "人脸检测与识别",
        url: san2
      }, {
        id: "",
        title: "电子警察",
        url: san3
      }, {
        id: "",
        title: "音频播报",
        url: san4
      },
    ]
  },
  "四年级": {
    shang: [
    ],
    xia: [
      {
        id: "",
        title: "智能出行",
        url: si1
      }, {
        id: "",
        title: "数字识别与车牌识别",
        url: si2
      }, {
        id: "",
        title: "摆动起来",
        url: si3
      }, {
        id: "",
        title: "停车场助手",
        url: si4
      },
    ]
  },
  "五年级": {
    shang: [
    ],
    xia: [
      {
        id: "",
        title: "游戏与生活概率",
        url: wu1
      }, {
        id: "",
        title: "手势识别",
        url: wu2
      }, {
        id: "",
        title: "猜拳机器人",
        url: wu3
      }, {
        id: "",
        title: "猜拳大战",
        url: wu4
      },
    ]
  },
  "六年级": {
    shang: [
    ],
    xia: [
      {
        id: "",
        title: "人脸检测知多少",
        url: liu1
      }, {
        id: "",
        title: "人脸检测全流程",
        url: liu2
      }, {
        id: "",
        title: "人脸检测功能实现",
        url: liu3
      }, {
        id: "",
        title: "人脸追踪向日葵功能实现",
        url: liu4
      },
    ]
  },
  "七年级": {
    shang: [
    ],
    xia: [
      {
        id: "",
        title: "机器学习",
        url: qi1
      }, {
        id: "",
        title: "萌宠生活（一）",
        url: qi2
      }, {
        id: "",
        title: "萌宠生活（二）",
        url: qi3
      }, {
        id: "",
        title: "萌宠生活（三）",
        url: qi4
      },
    ]
  },
  "八年级": {
    shang: [
    ],
    xia: [
      {
        id: "",
        title: "初识人工智能",
        url: ba1
      }, {
        id: "",
        title: "无所不在的人工智能",
        url: ba2
      }, {
        id: "",
        title: "机器翻译鸟（上）",
        url: ba3
      }, {
        id: "",
        title: "机器翻译鸟（下）",
        url: ba4
      },
    ]
  }
}
onMounted(() => {
  currentData.value = courseData["三年级"]
})
const clickGrand = val => {
  selectGrand.value = val
  currentData.value = courseData[val]
}
const getImageUrl = (url) => {
  return new URL(url, import.meta.url).href
}

const openCourseDetail = (id) => {
  top.U.MD.D.I.openInApplication("studyDetail", id, 2, 1); //这个是打开指定的课程接口
}
const updateCourse = id => {
  top.U.MD.D.I.openInApplication('openCourseUpdate', id)
}

const ReductionCourse = id => {
  dialogVisible.value = true
  updateReductionId.value = id
}

const updateReduction = () => {

}

watchEffect(() => {
  if (JSON.stringify(user.user) != "{}") {
    if (user.user.currentRole == "areaAdministrator" || user.user.currentRole == "userAdministrator" || user.user.currentRole == "securityAuditor" || user.user.currentRole == "schoolAdministrator" || user.user.currentRole == "schoolSecurityAuditor" || user.user.currentRole == "teacher" || user.user.currentRole == "visitor") {
      isupdateCourse.value = true
    }
  }
})
</script>
<style lang="scss" scoped>
.course_select {
  margin-top: 10px;

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
    background: #fff;
    padding: 12px;

    // height: 300px;
    img {
      width: 100%;
      border-radius: 5px;
    }

    .course_content {
      p {
        margin-top: 10px;

        span {
          // display: inline-block;
          padding: 2px 8px;
          background: rgba(224, 234, 251, 1);
          border-radius: 5px;
          font-size: 12px;
          float: right;
          color: rgba(54, 129, 252, 1);
        }
      }
    }
  }

  .Screening {
    font-size: 20px;
    font-weight: 400;
    line-height: 28px;
    letter-spacing: 0em;
    text-align: center;
    color: rgba(0, 0, 0, 0.9);
  }

  .grandTitle {
    font-size: 20px;
    font-weight: 400;
    line-height: 28px;
    letter-spacing: 0em;
    text-align: center;

  }

  .el-button {
    // background:  rgba(54, 129, 252, 1);
    color: rgba(54, 129, 252, 1);
  }

  .el_button_active {
    background: rgba(54, 129, 252, 1);
    color: #fff;
  }

  .class_button {
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
  }
}

.el-row {
  margin-top: 20px;
  margin-bottom: 20px;
}

.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}
.warning_text{
  font-weight: bold;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.9);
  margin-left: 8px;
}
</style>