<!--
 * @Description: 技能培训
 * @Author: 空白格
 * @Date: 2022-08-11 17:53:41
 * @LastEditors: 空白格
 * @LastEditTime: 2022-08-12 13:34:34
 * @FilePath: \veterans_client_web\src\views\SkillTraining\SkillTrainingIndex.vue
 * @Copyright: Copyright (c) 2016~2022 by 空白格, All Rights Reserved.
-->
<template>
  <div class="app-main skill-training">
    <BannerBreadcrumb title="技能培训" />
    <div class="app-main-box skill-training-content">
      <!-- 轮播课程 -->
      <div class="app-main-box-content skill-training-content-slider">
        <el-row>
          <el-col :xs="24" :sm="24" :md="18" :lg="18" :xl="18">
            <div class="stcs-left">
              <el-carousel height="200px" :autoplay="false" arrow="never">
                <el-carousel-item
                  class="stcs-left-item"
                  v-for="(item, index) in classNoticeList"
                  :key="index"
                >
                  <div class="stcs-left-item-left">
                    <el-image :src="item.img" class="image" fit="cover">
                      <div slot="placeholder" class="image-slot">
                        加载中<span class="dot">...</span>
                      </div>
                    </el-image>
                  </div>
                  <div class="stcs-left-item-right">
                    <div class="class-name">{{ item.name }}</div>
                    <div class="school-name">{{ item.schoolName }}</div>
                    <div class="description" v-html="item.description"></div>
                    <div class="sign-up">
                      <el-button
                        round
                        class="sign-up-btn"
                        @click="signUp(item.id)"
                        >报名</el-button
                      >
                    </div>
                  </div>
                </el-carousel-item>
              </el-carousel>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
            <div class="stcs-right">
              <div class="stcs-right-title">我的培训</div>
              <div class="stcs-right-duration">
                <div class="stcs-right-duration-left">学习<br />时长</div>
                <div class="stcs-right-duration-right">
                  <span>{{ learnTime || 0 }}</span
                  >小时
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
      <!-- 技能包 -->
      <div
        class="app-main-box-content skill-training-content-package"
        v-loading="loading"
      >
        <div class="stcp-title">技能包</div>
        <div class="stcp-list">
          <el-row :gutter="27">
            <el-col
              :xs="24"
              :sm="12"
              :md="12"
              :lg="6"
              :xl="6"
              v-for="(item, index) in packageList"
              :key="index"
            >
              <div class="stcp-list-item">
                <div class="stcp-list-item-image">
                  <el-image :src="item.img" class="image" fit="cover">
                    <div slot="placeholder" class="image-slot">
                      加载中<span class="dot">...</span>
                    </div>
                  </el-image>
                </div>
                <div class="stcp-list-item-content">
                  <div>{{ item.name || "-" }}</div>
                  <div>{{ item.schoolName || "-" }}</div>
                </div>
              </div>
            </el-col>
          </el-row>
          <div class="pagination" v-if="total">
            <el-pagination
              background
              layout="prev, pager, next"
              :page-size="queryParams.pageSize"
              :total="total"
              @current-change="currentChange"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import BannerBreadcrumb from "@/components/BannerBreadcrumb";
import {
  getClassNoticeData,
  signUpClass,
  getPackageData,
  getDurationCount,
} from "@/api/SkillTraining";
export default {
  name: "SkillTrainingIndex",
  components: {
    BannerBreadcrumb,
  },
  data() {
    return {
      classNoticeList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 8,
      },
      packageList: [],
      total: 0,
      loading: false,
      learnTime: 0,
    };
  },
  computed: {
    ...mapState({
      isLogin: (state) => state.user.isLogin,
    }),
  },
  created() {
    this.getClassNotice();
    this.getPackageList();
    if (this.isLogin) {
      this.getDuration();
    }
  },
  methods: {
    /**
     * 获取报班通知
     * @date 2022-08-12
     * @returns {any}
     */
    getClassNotice() {
      getClassNoticeData({ pageNum: 1, pageSize: 5 }).then((res) => {
        this.classNoticeList = res.rows;
      });
    },
    /**
     * 获取技能包
     * @date 2022-08-12
     * @returns {any}
     */
    getPackageList() {
      this.loading = true;
      getPackageData(this.queryParams).then((res) => {
        this.packageList = res.rows;
        this.total = Number(res.total);
        this.loading = false;
      });
    },
    /**
     * 报名操作
     * @date 2022-08-12
     * @param {any} packageId
     * @returns {any}
     */
    signUp(packageId) {
      signUpClass({ packageId }).then((res) => {
        console.log(res);
      });
    },
    /**
     * 获取学习时长
     * @date 2022-08-12
     * @returns {any}
     */
    getDuration() {
      getDurationCount().then((res) => {
        this.learnTime = (Number(res.data.learnTime) / 3600).toFixed(2);
      });
    },
    /**
     * 分页切换
     * @date 2022-08-12
     * @param {any} page
     * @returns {any}
     */
    currentChange(page) {
      this.queryParams.pageNum = page;
      this.getPackageList();
    },
  },
};
</script>

<style lang="scss" scoped>
.skill-training {
  &-content {
    padding-bottom: 30px;
    &-slider {
      margin-bottom: 20px;
      padding: 0;
      .stcs-left {
        padding: 40px;
        :deep(.el-carousel__indicators) {
          // 指示器
          right: -40px;
          left: auto;
        }
        :deep(.el-carousel__button) {
          // 指示器按钮
          width: 10px;
          height: 10px;
          border: none;
          border-radius: 50%;
          background-color: #d8d8d8;
        }
        :deep(.is-active .el-carousel__button) {
          // 指示器激活按钮
          width: 25px;
          border-radius: 10px;
        }
        &-item {
          display: flex;
          &-left {
            margin-right: 20px;
            border: solid 1px #e0e0e0;
            border-radius: 5px;
            margin-left: 10px;
            .image {
              height: 100%;
              width: 180px;
            }
          }
          &-right {
            width: calc(100% - 222px);
            .class-name {
              color: #101010;
              font-size: 30px;
              font-weight: 500;
              margin-bottom: 8px;
            }
            .school-name {
              color: #525252;
              font-size: 20px;
              margin-bottom: 8px;
            }
            .description {
              color: #9a9a9a;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
              word-break: break-all;
              margin-bottom: 30px;
            }
            .sign-up {
              &-btn {
                background-color: #709078;
                color: #fff;
              }
            }
          }
        }
      }
      .stcs-right {
        height: 240px;
        padding-top: 40px;
        background-image: linear-gradient(157deg, #287b4f 0%, #3d5d4c 100%);
        &-title {
          text-align: right;
          color: #fff;
          font-size: 30px;
          font-weight: 500;
          position: relative;
          width: 160px;
          margin: 0 auto 60px;
          &::before {
            content: "";
            display: block;
            width: 40px;
            height: 38px;
            background: url("./../../assets/images/my-training-icon.svg")
              no-repeat center center;
            position: absolute;
            left: -10px;
          }
        }
        &-duration {
          width: 155px;
          height: 60px;
          padding: 0 20px;
          margin: 0 auto;
          background: #fe7401;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 30px;
          color: #fff;
          &-left {
            border-right: solid 1px #fff;
            padding-right: 10px;
            font-size: 16px;
          }
          &-right {
            padding-left: 10px;
            font-size: 14px;
            span {
              font-size: 30px;
            }
          }
        }
      }
    }
    &-package {
      .stcp-title {
        color: #1a1a1a;
        font-size: 26px;
        padding-top: 10px;
        margin-bottom: 10px;
      }
      .stcp-list {
        &-item {
          cursor: pointer;
          &-image {
            height: 160px;
            padding: 10px 5;
            .image {
              width: 100%;
              height: 100%;
            }
          }
          &-content {
            font-size: 22px;
            color: #3f3f3f;
            div {
              margin: 5px 0;
            }
            div:last-child {
              color: #a2a2a2;
              font-size: 16px;
            }
          }
        }
        .pagination {
          text-align: center;
          margin-top: 20px;
          :deep(.el-pager .active) {
            background-color: #ff3939;
          }
          :deep(.el-pagination.is-background
              .el-pager
              li:not(.disabled).active) {
            background-color: #ff3939;
          }
        }
      }
    }
  }
}
</style>
