<template>
  <div class="m-container">
    <h2>
      <el-page-header @back="onCancel" content="直播详情"></el-page-header>
    </h2>
    <div class="m-core">
      <div class="titleWrap">
        <h2 class="squrtTitle">
          <div class="squrt"></div>
          直播数据
        </h2>
        <el-row class="row">
          <p class="teacherName">
            主讲人：<span>{{ detail.speakerName }}</span>
          </p>
          <p class="teacherName sub">
            主题：<span>{{ detail.roomTitle }}</span>
          </p>
          <el-button
            type="text"
            class="fontBtn"
            @click="payVisible = true"
            v-if="videoList.length > 0"
            >直播回放 <i class="el-icon-video-play"></i
          ></el-button>
        </el-row>
        <p class="liveRemark">
          直播内容：<span>{{ detail.liveRemark }}</span>
        </p>
      </div>

      <div class="infoWrap">
        <statistic class="statistic" :cols="0">
          <statistic-item>
            <span> 参与学员 </span>
            <span>{{ detail.totalLookNum }}</span>
          </statistic-item>
          <statistic-item>
            <span> 累计点赞 </span>
            <span>{{ detail.totalLikeNum }}</span>
          </statistic-item>
          <statistic-item>
            <span> 直播时长(分钟) </span>
            <span>{{ detail.totalLiveTime }}</span>
          </statistic-item>
        </statistic>
      </div>
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
        ref="searchForm"
      >
        <el-form-item>
          <el-input
            v-model.trim="searchForm.search"
            clearable
            @keyup.enter.native="
              (e) => {
                e.target.blur();
                $refs.searchForm.save();
                search();
              }
            "
            placeholder="学员编号/姓名"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="primary">搜索</el-button>
          <el-button native-type="reset" type="danger">重置</el-button>
          <el-button
            type="primary"
            v-if="tableList.length > 0"
            v-permission="'export/liveBroadcastRoomMember'"
            @click="exportStudent"
            >导出</el-button
          >
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column
            align="center"
            prop="studentId"
            label="学员编号"
          ></el-table-column>

          <el-table-column
            align="center"
            prop="studentName"
            label="学员姓名"
          ></el-table-column>
          <el-table-column align="center" prop="organName" label="分部"></el-table-column>
          <el-table-column
            align="center"
            prop="musicGroupName"
            label="乐团"
          ></el-table-column>
          <el-table-column align="center" prop="phone" label="手机号"></el-table-column>
          <el-table-column align="center" prop="subName" label="声部"></el-table-column>
          <el-table-column
            align="center"
            prop="joinTime"
            label="进入时间"
          ></el-table-column>
          <el-table-column align="center" prop="totalViewTime" label="观看时长">
            <template slot-scope="scope">
              <div>{{ scope.row.totalViewTime }}分钟</div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
      </div>
    </div>
    <el-dialog
      :visible.sync="payVisible"
      v-if="payVisible"
      width="500px"
      title="直播回放"
    >
      <div class="lineWrap">
        <div
          class="linkItem"
          v-for="(item, index) in videoList"
          :key="index"
          @click="opneVideo(item)"
        >
          <div class="linkItemWrap">
            <!-- <video width="110px" :src="item.url"></video> -->
            <img width="110px" :src="videoPlace" alt="" />
            <i class="el-icon-video-play linkIcon"></i>
          </div>

          <p :underline="false" type="text" class="lineTitle">
            {{ item.endTime | dateForMinFormat }}
          </p>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <!-- <el-button @click="payVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="payVisible = false">确 定</el-button>
      </div></el-dialog
    >
    <el-dialog
      :title="activeVideo.endTime | dateForMinFormat"
      width="680px"
      append-to-body
      :visible.sync="videoVisible"
      v-if="videoVisible"
    >
      <!-- activeUrl -->
      <div class="activeVideoWrap">
        <vue-core-video-player
          v-if="activeVideo.os == 'mobile' && activeVideo.videoType == 'mp4'"
          style="width: 320px"
          :src="activeVideo.url"
          ref="dialogVideo"
        >
          您的浏览器不支持视频播放
        </vue-core-video-player>
        <vue-core-video-player
          v-else-if="activeVideo.os == 'mobile' && activeVideo.videoType != 'mp4'"
          style="width: 320px"
          :src="activeVideo.url"
          ref="dialogVideo"
          :core="activeVideo.videoType == 'mp4' ? null : HLSCore"
        >
          您的浏览器不支持视频播放
        </vue-core-video-player>
        <vue-core-video-player
          v-else-if="activeVideo.os == 'pc' && activeVideo.videoType != 'mp4'"
          style="width: 640px"
          :src="activeVideo.url"
          ref="dialogVideo"
          :core="HLSCore"
        >
          您的浏览器不支持视频播放
        </vue-core-video-player>
        <vue-core-video-player
          v-else-if="activeVideo.os == 'pc' && activeVideo.videoType == 'mp4'"
          style="width: 640px"
          :src="activeVideo.url"
          ref="dialogVideo"
        >
          您的浏览器不支持视频播放
        </vue-core-video-player>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import pagination from "@/components/Pagination/index";
import cleanDeep from "clean-deep";
import qs from "qs";
import { getLiveBroadcastRoomDetail, getLiveBroadcastRoomDetailList } from "./api";
import { Export } from "@/utils/downLoadFile";
import videoPlace from "./images/video-place.png";
import HLSCore from "@core-player/playcore-hls";
export default {
  components: { pagination },
  data() {
    return {
      searchForm: {
        search: "",
      },
      tableList: [],
      detail: {
        list: null,
        liveRemark: "",
        roomTitle: "",
        roomUid: "",
        speakerName: "",
        totalLikeNum: 0,
        totalLiveTime: 0,
        totalLookNum: 0,
      },
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      videoList: [],
      payVisible: false,
      videoVisible: false,
      activeVideo: { endTime: "" },
      HLSCore,
      videoPlace,
    };
  },
  mounted() {
    this.getDetail();
    this.getList();
  },
  methods: {
    onCancel() {
      this.$router.push("/liveClassManager");
      this.$store.dispatch("delVisitedViews", this.$route);
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      this.searchForm.search = "";
      this.search();
    },
    async getList() {
      try {
        let obj = {
          rows: this.rules.limit,
          page: this.rules.page,
          roomUid: this.$route.query.roomUid,
          search: this.searchForm.search,
        };
        const res = await getLiveBroadcastRoomDetailList(obj);
        this.tableList = res.data.rows;
        this.rules.total = res.data.total;
      } catch (e) {
        console.log(e);
      }
    },
    async getDetail() {
      try {
        let obj = {
          roomUid: this.$route.query.roomUid,
        };

        const res = await getLiveBroadcastRoomDetail(obj);
        this.detail = { ...res.data };
        this.videoList = res.data.videoList;
      } catch (e) {
        console.log(e);
      }
    },
    opneVideo(row) {
      this.activeVideo = row;
      this.videoVisible = true;
    },
    exportStudent() {
      let obj = {
        rows: this.rules.limit,
        page: this.rules.page,
        roomUid: this.$route.query.roomUid,
        search: this.searchForm.search,
      };
      Export(
        this,
        {
          url: "/api-web/export/liveBroadcastRoomMember",
          fileName: `"${this.detail.roomTitle}"参与学员.xls`,
          method: "post",
          params: qs.stringify(cleanDeep(obj)),
        },
        `您确定导出"${this.detail.roomTitle}"参与学员?`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.infoWrap {
  // width: 500px;
}
.sub.teacherName {
  margin-right: 10px;
}
.fontBtn {
  font-size: 18px;
}
.teacherName,
.liveRemark {
  font-size: 16px;
  color: #222325;
  line-height: 30px;
  font-weight: 600;
  margin-right: 60px;
  span {
    color: #666666;
    font-weight: 400;
  }
}
.titleWrap {
  position: relative;
  // display: flex;
  // flex-direction: row;
  // align-items: center;
  padding: 5px;
  h2 {
    margin-right: 10px;
  }
  .squrtTitle {
    position: relative;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 600;
    color: #222325;
    line-height: 25px;
    margin-bottom: 25px;
    .squrt {
      position: absolute;
      left: -12px;
      top: 5px;
      width: 3px;
      height: 16px;
      background-color: var(--color-primary);
    }
  }
  .row {
    display: flex;
    flex-direction: row;
    align-items: center;
  }
}
.statistic .statistic-content > span {
  font-size: 16px;
}
.lineWrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;

  .linkItem {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 5px;
    cursor: pointer;
    position: relative;
    &:hover {
      color: var(--color-primary);
      .lineTitle {
        color: var(--color-primary);
        font-weight: bold;
      }
    }
    .linkItemWrap {
      position: relative;
      .linkIcon {
        font-size: 25px;
        position: absolute;
        top: 50%;
        margin-top: -13px;
        left: 50%;
        margin-left: -13px;
        color: #fff;
      }
    }
  }
  .lineTitle {
    height: 40px;
    line-height: 40px;
    color: rgba(102, 102, 102, 0.9);
    padding: 0 17px;
    overflow: hidden;
    margin-bottom: 10px;
    position: relative;
    border-radius: 4px;
  }
}
.activeVideoWrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}
</style>
