<template>
  <div>
    <!-- <div style="display:flex; padding-left:20px; width:100%">
      <div style="width:100px">完成情况</div>
      <div class="progress"><div class="msg">课程完成情况</div> <el-progress :text-inside="true" :stroke-width="16" :percentage="porcessData.course"  status="warning" class="progressItem"> </el-progress> </div>
      <div class="progress" ><div class="msg">项目完成情况</div> <el-progress :text-inside="true" :stroke-width="16" :percentage="porcessData.project" status="success" class="progressItem"> </el-progress>  </div>
      <div class="progress"><div class="msg">路径图完成情况</div> <el-progress :text-inside="true" :stroke-width="16" :percentage="porcessData.router" class="progressItem"> </el-progress>  </div>
     
      </div> -->
    <div
      style="
        display: flex;
        justify-content: space-between;
        padding: 12px 32px 10px 22px;
      "
    >
      <div style="display: flex; justify-content: flex-start">
        <div>
          <el-select
            class="search-input"
            v-model="status"
            clearable
            placeholder="学习进度"
          >
            <el-option label="全部" value=""></el-option>
            <el-option label="未开始" value="0"></el-option>
            <el-option label="进行中" value="1"></el-option>
            <el-option label="已完成" value="2"></el-option>
          </el-select>
        </div>
        <div style="padding-left: 10px">
          <el-input
            v-model="params.cmtask_name"
            clearable
            placeholder="搜索名称"
          ></el-input>
        </div>
        <div class="button-class" style="padding-left: 10px">
          <el-button type="primary" icon="el-icon-search" @click="search()"
            >搜索</el-button
          >
        </div>
        <div class="button-class" style="padding-left: 10px">
          <el-button
            type="primary"
            icon="el-icon-refresh-right"
            @click="reset()"
            >重置</el-button
          >
        </div>
      </div>
    </div>
    <!--课程列表内容-->
    <div class="uc-list" v-if="couresList.length > 0">
      <div
        class="uc-course"
        v-for="(item, idx) in couresList"
        @click="jumpRouter(item)"
        :key="idx"
      >
        <div class="uc-course-img">
          <img :src="item.cmtask_imgurl" />
          <span class="spanname" v-if="item.cmtask_type == 1">学习路径图</span>
          <span class="spanname" v-if="item.cmtask_type == 2">学习项目</span>
          <!-- 类型3不显示，20230307 东吴说已确认的修改 -->
          <!-- <span class="spanname" v-if="item.cmtask_type==3">老系统必修任务</span> -->
        </div>
        <div class="uc-course-info">
          <!-- 任务名称 -->
          <div class="uc-course-name one-line-ellipsis" style="cursor: pointer">
            <span v-if="item.type == 10" class="uc-course-type2">录播</span>
            <span v-if="item.type == 20" class="uc-course-type2">录播</span>
            <!-- <a href="/course/detail?id=" target="_blank"> {{item.name}}</a> -->
            <span v-html="item.cmtask_name"></span>
          </div>
          <!-- <div class="uc-course-source" @click="jumpRouter(item)">来源：{{ item.cmtask_name }}</div> -->
          <div style="padding-top: 18px" class="uc-course-text">
            学习进度：
            <span v-if="item.cmtask_user_status == 0">未开始</span>
            <span v-if="item.cmtask_user_status == 1">进行中</span>
            <span v-if="item.cmtask_user_status == 2">已完成</span>
          </div>
          <!-- <div class="uc-course-time">推送时间：{{ formatsec(Number(item.updated_at)  * 1000 )}}</div> -->
          <div class="uc-course-time">推送时间：{{ item.created_at }}</div>
        </div>
        <div class="uc-course-btns">
          <el-button @click="jumpRouter(item)" type="primary" size="small"
            >开始学习</el-button
          >
        </div>
      </div>
      <div style="height: 150px; text-align: center; margin-top: 57px">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 40]"
          :current-page="page"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <!-- </div> -->
    <div v-else class="zan-wu">
      <div v-if="loading">
        <span v-if="couresList.length == 0">正在加载数据...</span>
        <span v-else>查询中...</span>
      </div>
      <div v-else>
        <span v-if="couresList.length == 0">没有查询到相关内容</span>
      </div>
    </div>
  </div>
</template>

<script>
import studyItem from "@/components/Course/studyItem.vue";
import apiManage from "@/api/manage/manage.js";
import { getToken } from "@/utils/token";
import { formatsec } from "@/utils/datetime.js";
import axios from "axios";
export default {
  name: "ucStudyTask",
  components: { studyItem },
  data() {
    return {
      status: "",
      params: {
        cmtask_name: "",
        cmtask_status: "",
        type: "",
      },
      porcessData: {
        course: 0,
        project: 0,
        router: 0,
      },
      loading: true,
      size: 10,
      page: 1,
      keyword: "",
      formatsec,
      couresList: [],
      total: 0,
    };
  },
  mounted() {
    this.loadBoeData();
    this.getPossData();
  },
  methods: {
    jumpRouter(item) {
      if (item.szxygProjectFlag == 1) {
        this.$router.push("/new-employee/study");
        return;
      }
      //location.href=`${this.webBaseUrl}/course/boeframe?id=${item.cmtask_id}`;

      //let urlPre=window.location.protocol+'//'+window.location.host;
      let studentPath = process.env.VUE_APP_STUDENT_PATH;
      if (item.cmtask_type == 1) {
        //学习路径图
        let params = encodeURIComponent("routerId=" + item.cmtask_id);
        //this.$router.push('/forward?to='+studentPath+'/pathdetails&params='+params);
        this.$router.push(
          "/forward?to=" + studentPath + "/pathchapterdetails&params=" + params
        );
      } else if (item.cmtask_type == 2) {
        //学习项目
        let params = encodeURIComponent("projectId=" + item.cmtask_id);
        this.$router.push(
          "/forward?to=" + studentPath + "/projectdetails&params=" + params
        );
      } else if (item.cmtask_type == 3) {
        let pushUrl = `/course/boeframe?id=${item.cmtask_id}&type=3`;
        this.$router.push(pushUrl);
      }
    },
    getPossData() {
      axios({
        method: "POST",
        url: "/report/boeu/studyInfo",
        params: {},
        headers: { token: getToken() },
      }).then((res) => {
        console.log("111", res.data.result);
        // this.porcessData=response.data.data
        this.porcessData.course = Math.floor(
          res.data.result.course.total === 0
            ? 0
            : (res.data.result.course.completion /
                res.data.result.course.total) *
                100
        );
        this.porcessData.project = Math.floor(
          res.data.result.project.total === 0
            ? 0
            : (res.data.result.project.completion /
                res.data.result.project.total) *
                100
        );
        this.porcessData.router = Math.floor(
          res.data.result.router.total === 0
            ? 0
            : (res.data.result.router.completion /
                res.data.result.router.total) *
                100
        );
      });
    },
    loadBoeData() {
      if (this.status !== "5") {
        this.params.cmtask_status = this.status;
      }
      let params = {
        pageNo: this.page,
        pageSize: this.size,
        cmtask_user_status: this.params.cmtask_status,
        cmtask_name: this.params.cmtask_name,
      };
      this.loading = true;
      apiManage
        .userTaskList(params)
        .then((res) => {
          if (res.code == 200) {
            this.total = parseInt(res.data.total);
            this.couresList = res.data.records;
          } else {
            this.$message.error("查询数据失败：" + res.msg);
          }
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    search() {
      this.page = 1;
      this.loadBoeData();
    },
    reset() {
      this.loading = false;
      (this.params.cmtask_name = ""),
        (this.params.type = ""),
        (this.params.cmtask_status = "");
      this.status = "";
      this.page = 1;
      this.loadBoeData();
    },
    handleSizeChange(value) {
      this.size = value;
      this.loadBoeData();
    },
    //改变条数的回调
    handleCurrentChange(value) {
      this.page = value;
      this.loadBoeData();
    },
  },
};
</script>

<style scoped lang="scss">
.progress {
  width: calc((100% - 100px) / 3);
  display: flex;
  .msg {
    width: 120px;
  }
  .progressItem {
    margin-left: 20px;
    width: calc(100% - 160px);
    height: 10px;
  }
}
.zan-wu {
  text-align: center;
  font-size: 20px;
  margin-top: 70px;
  color: #ccc;
}
.one-line-ellipsis {
  display: -webkit-box;
  white-space: pre-wrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  box-sizing: border-box;
}
.button-class {
  // height: 42px;
}

.uc-list {
  padding-left: 22px;
}
.uc-course-time {
  color: #666;
  font-size: 14px;
}
.uc-badge {
  margin-top: 10px;
  margin-right: 40px;
}
.spanname {
  position: absolute;
  background-color: #6a99a4;
  color: #ffffff;
  padding: 4px 10px;
  font-size: 12px;
  bottom: 0px;
  z-index: 100;
  left: 0px;
}
.uc-course {
  cursor: pointer;
  display: flex;
  justify-content: space-around;
  border-bottom: 1px solid #e8e8e8;
  margin-right: 32px;
  padding: 20px 0px 15px 0px;
  .uc-course-img {
    width: 212px;
    height: 119px;
    position: relative;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .uc-course-info {
    // width: 50%;
    flex: 1;
    line-height: 28px;
    padding: 0px 10px;
    .uc-course-name {
      font-size: 18px;
      color: #333;
      margin-top: -3px;
      font-weight: 700;
    }
    .uc-course-text {
      color: #444;
      margin-bottom: 3px;
      font-size: 16px;
      margin-top: 20px;
    }
  }
  .uc-course-btns {
    text-align: right;
    margin-top: 80px;
    width: 100px;
    height: 44px;
  }
}
</style>
