<template>
  <div style="">
    <!-- 最新版设计 -->
    <div  class="coures-box" @click="jumpRouter(item)" v-for="(item, idx) in items" :key="idx">
      <div class="coures-head">
        <div class="share-name" v-if="type=='myShare'">
          分享给了<span>{{ item.toAname }}</span>
        </div>
        <div class="share-name" v-else>
          <span>{{ item.sysCreateBy }}</span>分享给了我
        </div>
        <div class="islook" v-if="item.isRead">已查看</div>
        <div class="isunlook" v-else>未查看</div>
        <div class="share-time">{{ item.time }}</div>
      </div>
      <div class="coures-content">
          <div style="width: 100%;">【课程】{{item.title}}</div>
          <div v-if="!item.isRead&&type=='myShare'" @click.stop="deleteshares(item)" style="color: #999999;font-size: 12px;font-weight: normal;width: 50px;">
            <svg-icon icon-class="withdraw" style="margin-right: 5px;font-size: 14px;" ></svg-icon>
            撤回</div>
      </div>

    </div>
    <!-- 旧版设计 -->
    <!-- <div class="uc-course" @click="jumpRouter(item)" v-for="(item, idx) in items" :key="idx"> -->
      <!-- <div class="uc-course-img" style="width: 212px;height: 119px;">
        <course-image :course="item"></course-image>
        <img :src="imageUrl(item)" /><span class="two-line-ellipsis">{{item.title}}</span>
        </div> -->
      <!-- <div class="uc-course-info">
        <div style="height: 100%;display: flex;justify-content:space-between;">
          <div style="display: flex;flex-direction: column;justify-content: space-between;">
            <div class="uc-course-name">
              <span class="uc-course-font" :class="contentTypeFilter(item.contentType).class">{{ contentTypeFilter(item.contentType).text }}</span>
              <span v-html="$keywordActiveShow(item.title,keyword)"></span>
            </div>
            <div class="uc-course-text" v-if="type=='myShare'">
              分享给：{{ item.toAname }}
            </div>
            <div class="uc-course-text" v-else>分享人：{{ item.toAname }}</div>
            <div style="display:flex;flex-direction: column;">
               <div class="uc-course-textTo">分享时间：{{ item.time }}</div>
               <div class="uc-course-textToInfo">
                 <span v-if="type=='myShare'" style="margin-right:10px">分享给{{item.toAname}}</span>
                 <span v-else style="margin-right:10px">{{item.authorName}}分享给我</span>
                  <el-button type="text" v-if="item.isRead" icon="el-icon-folder-opened" style="color: #8590A6;padding:0;">已查看</el-button>
                  <el-button type="text" icon="el-icon-folder" v-else  style="color: #8590A6;padding:0;">未查看</el-button>
                  <el-button v-if="!item.isRead&&type=='myShare'" type="text" @click.stop="deleteshares(item)" icon="el-icon-refresh-right"  style="color: #8590A6;">撤回</el-button>
               </div>
            </div>
          </div>
          <div class="btn" >
            <span>{{item.isRead?'[已查看]':'[未查看]'}}</span>
          </div>
        </div>
      </div> -->
    <!-- </div> -->
  </div>
</template>

<script>
// import interactBar from '@/components/Portal/interactBar.vue';
import courseImage from "@/components/Course/courseImage.vue"
import apiShares from '@/api/modules/shares.js';
export default {
  name: 'comStudyItem',
  props: {
    items: {
      //name,
      type: Array,
      default: () => []
    },
    type:{
      type:String,
      default:()=>{
        return 'myShare'
      }
    },
    keyword:{
      type:String,
      default:()=>{
        return ''
      }
    }
  },
  methods: {
    imageUrl(item) {
      if (item && item.image && item.image != '') {
        return process.env.VUE_APP_FILE_BASE_URL + item.image;
      } else {
        return this.webBaseUrl + "/images/bgimg/course.png";
      }
    },
    deleteshares(item){
      this.$emit('confirm',item)
    },
    contentTypeFilter(value) {
      let obj = {};
      switch (value) {
        case '10': {
          obj.class = 'uc-course-type2';
          obj.text = '录播';
          break;
        }
        case '21': {
          obj.class = 'uc-course-type2';
          obj.text = '直播';
          break;
        }
        case '20': {
          obj.class = 'uc-course-type2';
          obj.text = '录播';
          break;
        }
        case '30': {
          obj.class = 'uc-course-type2';
          obj.text = '面授';
          break;
        }
        case '90': {
          obj.class = 'uc-course-type2';
          obj.text = '混合';
          break;
        }
      }
      return obj;
    },
    jumpRouter(item){
      if(item.type){
         if(this.type!='myShare'){
        apiShares.updateIsRead(item.shareId).then(res=>{
          if(res.status==200){
            this.$emit('confirm',item)
          }
        })
      }
      }else{
        if(this.type!='myShare'){
        apiShares.updateIsRead(item.id).then(res=>{
          if(res.status==200){
            this.$emit('confirm',item)
          }
        })
      }
      }
      
      // if(item.contentType == 20) {
        this.$router.push({path:'/course/detail',query:{id:item.objId || item.id}})
      // } else {
      //   this.$router.push({path:'/course/micro',query:{id:item.objId || item.id}})
      // }

     // window.open(`${this.webBaseUrl}/course/detail?id=${item.objId}`)
    },
  },
  components: {
    courseImage
  }
};
</script>

<style lang="scss" scoped>
.coures-box{
  width: 100%;
  padding: 30px 0;
  border-bottom:1px solid #e9e9e9 ;
  .coures-content{
    margin-top: 20px;
    font-size: 16px;
    color: #333333;
    font-weight: 600;
    word-break:break-all;
    display: flex;
    justify-content: space-between;
    span{
    font-size: 16px;
    margin-left: -9px;
    }
  }
  .coures-head{
    display: flex;
    .share-name{
      font-size: 14px;
      color: #666666;
      margin-right: 17px;
    }
    .share-time{
      font-size: 14px;
      color: #666666;
      line-height: 25px;
      margin-left: auto;
    }
    .islook{
      width: 46px;
      height: 24px;
      background: #eee;
      font-size: 12px;
      color: #666666;
      line-height: 24px;
      text-align: center;
      border-radius: 2px;
    }
    .isunlook{
      width: 46px;
      height: 24px;
      background: #FF6562;
      border-radius: 2px;
      font-size: 12px;
      color: #fff;
      line-height: 24px;
      text-align: center;

    }

  }
}
// .uc-course-type1 {
//   padding: 3px;
//   border: 1px dotted #1ea0fa;
//   color: #1ea0fa;
// }
// .uc-course-type2 {
//   padding: 3px;
//   border: 1px dotted #ffaa00;
//   color: #ffaa00;
// }
.uc-course {
  display: flex;
  justify-content: space-around;
  // border: 1px solid #f0f0f0;
  // padding: 10px;
  padding-bottom: 24px;
  margin-top: 24px;
  border-bottom: 1px solid #eeeeee;
  cursor: pointer;
  .uc-course-img {
    position: relative;
    img {
      width: 160px;
      height: 90px;
      border: 1px solid #f4f4f5;
    }
    >span{
      position: absolute;
      top: 30px;
      left: 10px;
      width: 100%;
      height: 100%;
      color: #ffffff;
      font-size: 16px;
    }
  }
  .uc-course-info {
    flex: 1;
    line-height: 28px;
    padding: 0px 12px;
    .uc-course-name {
      font-size: 18px;
      font-weight: 400;
      .uc-course-font{
        width: 58px;
        height: 26px;
        font-size: 14px;
        margin-right: 8px;
      }
    }
    .uc-course-text {
      color: #747474;
      font-size: 16px;
    }
    .uc-course-textTo{
      font-size: 14px;
      color: #666666;
    }
    .readed{
      color: #2AB28B;
    }
    .noRead{
      color:#FF3E3E;
    }
    .btn{
      text-align: right;
      width: 250px;
      font-size: 14px;
      // margin-top: 70px;
      padding-top:90px;
    }
  }
}
</style>
