<template>
  <!-- 双师一生详情 -->
  <div class="ssysDetail">
    <el-card>
      <div style="padding: 0 75px;">
        <span class="title">{{detailInfo.ks_name}}</span>
        <span class="subTitle">我的课程 - 我创建的 - <span class="pointer" @click="goBack">双师一生</span> - <span style="color: #000;">{{detailInfo.ks_name}}</span></span>
      </div>
    </el-card>

    <el-card v-loading="loading">
      <div class="contentDiv">
        <div class="leftContent">
          <div class="contentTitle">{{detailInfo.ks_name}}</div>
          <div class="image">
            <!-- <img src="/zbktssys/1.png" alt="" /> -->
            <img v-show="!showVideo" :src="commonUrl" alt="">
            <video ref="videoPlay" v-show="showVideo" controls>
              <source :src="commonUrl" type="video/mp4" />
              <source :src="commonUrl" type="video/ogg" />
            </video>
          </div>
        </div>
        <div class="rightContent">
          <div class="contentTitle">互评</div>
          <el-rate size="large" v-model="comment" allow-half :disabled="disabled" disabled-void-color="#fff" />
          <div v-show="!disabled" class="h-26px leading-26px px-4 bg-gradient-to-l from-green-400 to-blue-500 text-white rounded-14px cursor-pointer btn" @click="commitComment">评价</div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { ssyskc_detail } from "./api";
import { getFullUrl } from '@/utils/helper';
import empty from '/images/personal/empty.png';
export default {
  data() {
    return {
      loading: false,
      detailId: "",
      detailInfo: {},
      showVideo: true,
      commonUrl: "",
      comment: "",
      disabled: false,
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    initDetailData() {
      this.loading = true;
      ssyskc_detail({ ks_id: this.detailId }).then((res) => {
        if (res.code == 1) {
          this.detailInfo = res.data.one_info;
          let suffix = this.detailInfo.ks_kj.substr(this.detailInfo.ks_kj.lastIndexOf(".") + 1);
          if (suffix == "mp4" || suffix == "MP4") {
            this.showVideo = true;
            this.commonUrl = getFullUrl(this.detailInfo.ks_kj);
            this.$refs.videoPlay.load()
          } else {
            this.showVideo = false;
            this.commonUrl = empty;
          }

          if (this.detailInfo.hpjl_star) {
            this.comment = this.detailInfo.hpjl_star;
            this.disabled = true;
          }
          this.loading = false;
        }
      });
    },
    commitComment() {
      request({
        url: '/kzkt/ssyskc_hpjl/add',
        data: {
          kzkt_ssyskc_hpjl: {
            ks_id: this.detailId,
            ksh_star: this.comment
          }
        }
      }).then(res => {
        if (res.code == 1) {
          this.$message.success("互评成功！");
          this.initDetailData();
        }
      })
    }
  },
  created() {
    this.detailId = this.$route.params.id;
    this.initDetailData();
  }
}
</script>

<style lang="scss" scoped>
.ssysDetail::v-deep {
  .el-card {
    margin-bottom: 15px;
    background: #fff;
  }
  .pointer {
    cursor: pointer;
  }
  .title {
    font-size: 18px;
    color: #050026;
  }
  .subTitle {
    font-size: 14px;
    color: #949494;
    margin-left: 45px;
  }
  .contentDiv {
    display: flex;
    .contentTitle {
      margin-bottom: 20px;
      font-size: 16px;
      color: #050026;
    }
    .leftContent {
      flex: 1;
      padding-right: 20px;
      .image {
        height: 600px;
        // background: #dff3ff;
        // border-radius: 10px;
        img,
        video {
          width: 100%;
          height: 100%;
        }
      }
    }
    .rightContent {
      width: 280px;
      padding-left: 20px;
      border-left: 1px dashed #dbdbdb;
      .el-rate__decimal {
        color: #f7ba2a !important;
      }
      .btn {
        width: 110px;
        height: 32px;
        line-height: 32px;
        text-align: center;
        margin-top: 15px;
        border-radius: 38px;
        font-size: 14px;
      }
    }
  }
}
</style>