<template>
  <block>
    <view class="container container-play-back">
      <!-- 筛选部分 -->
      <view class="select-content-activity">
        <view class="screen-item" style="justify-content: flex-start">
          <text :class="[isShowJurisdiction ? 'active' : '', 'text-item']" @click="permissioActivity">有权限行业</text>
          <!-- 各种状态选择 -->
          <view class="select-conyent" ref="select-conyent" style="margin-left: 20rpx">
            <van-dropdown-menu active-color="#333333">
              <van-dropdown-item id="industry" :title="chartPermissionName">
                <view class="menu-items">
                  <view class="menu-items-box" v-for="item in listChartPermission" :key="item.ChartPermissionId" @click="overallClick(item)">
                    <view class="items-box">
                      <u-icon v-if="item.IsChoose" name="checkbox-mark" :color="isShowJurisdiction ? '#ccc' : '#376cbb'" size="24"></u-icon>
                    </view>
                    <text>{{ item.PermissionName }}</text>
                  </view>
                </view>
                <view class="replacement">
                  <text @click="replacementBtn" class="replacement-box">重置</text>
                  <text @click="replacementConfirm">确定</text>
                </view>
              </van-dropdown-item>
            </van-dropdown-menu>
          </view>
        </view>
      </view>
      <!-- 活动列表 -->
      <view class="collect-ul" v-if="haveData">
        <view class="collect-ltem global_card_content" v-for="(item, index) in collectList" :key="index">
          <image class="top-img-box" v-if="detailData.IsResearchPoints" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/research_points.png"></image>
          <image class="top-img-box" v-else-if="detailData.IsResearch" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/Research_normal.png"></image>
          <view class="title-date" @click="goDetail(item)">
            <text :class="item.ActivityType == 1 ? '' : 'xianxia'">{{ item.ActivityType == 1 ? "线上" : "线下" }}</text>
            {{ item.ActivityTimeText }}
            <view :class="['global_content_center', 'audio-back', item.FileType == 2 ? 'is-video-sing' : 'is-audio-sing']">
              <image v-if="item.FileType == 2" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/video_icon.png"></image>
              <image v-else src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/audio_icon.png"></image>
              {{ totalSeconds(item) }}
            </view>
          </view>
          <view class="item-li">
            <view class="item-img" @click="goDetail(item)">
              <image :src="item.ImgUrl"> </image>
              <image v-if="item.ActiveState == 1" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/not_started_activity.png" class="img-status"></image>
              <image v-else-if="item.ActiveState == 2" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/in_progress_activity.png" class="img-status"></image>
              <image v-else src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/end_activity.png" class="img-status"></image>
              <view class="img-type">
                <image :src="item.ImgUrlText" mode=""></image>
              </view>
            </view>
            <view class="item">
              <view class="item-text" @click="goDetail(item)">
                <text class="activity-title"> {{ item.ActivityName }} </text>
                <text class="text_twoLine" v-if="item.Expert">专家背景：{{ item.Expert }} </text>
                <text class="text_twoLine" v-if="item.DistinguishedGuest">嘉宾：{{ item.DistinguishedGuest }} </text>
                <text class="text_twoLine" v-if="item.Speaker">主讲人：{{ item.Speaker }}</text>
              </view>
              <view class="content-item-flex iten-buttom">
                <view class="global_content_center" @click.stop="playBack(item)">
                  <image
                    v-if="item.FileType == 1 && curVoiceId === item.ActivityId && !curAudioPaused"
                    class="play-img"
                    src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/suspend_play_list.png"
                  ></image>
                  <image v-else class="play-img" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/play-circle-filled.png"></image>
                  {{ item.FileType == 1 && curVoiceId === item.ActivityId && !curAudioPaused ? "暂停" : "播放" }}
                </view>
                <view v-if="item.FileType == 1" class="global_content_center" @click="joinPlaylist(item)">
                  <image class="play-list" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/paly_list.png"></image>
                  添加
                </view>
              </view>
            </view>
          </view>
        </view>
        <u-loadmore :status="status" icon-type="flower" :load-text="loadText" margin-top="20" v-if="totalPage > 1" />
      </view>
      <view class="nodata" v-else>
        <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
        <text>暂无活动</text>
      </view>
      <view v-if="showAudioBox">
        <audioModule :showAudioPop.sync="showAudioPop" />
      </view>
      <videoModule :showVideoPop.sync="showVideoPop" :videoPopList="videoPopList" />

      <!-- 所有自定义弹框 -->
      <modalDialog :isShowhasPermission="isShowhasPermission" :applyForIsShow="applyForIsShow" :jurisdictionList="jurisdictionList" :hasPermission="hasPermission" />
      <view class="paly-list-image" v-if="playlistData.length > 0" @click="showAudioBoxPlayList">
        <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/Joined_play_list.png"></image>
      </view>
    </view>

    <Loading />
  </block>
</template>

<script>
import { activity, User } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
import audioModule from "@/components/audioModule/index";
import modalDialog from "@/components/modalDialog.vue";
import videoModule from "@/components/videoModule/index";
import mediaMixins from "@/components/activity/mediaMixins";
import selectMixins from "../components/selectMixins.js";
import NotHaveLogin from "../../components/notHaveLogin.vue";
export default {
  data() {
    return {
      page_no: 1,
      pageSize: 10,
      collectList: [],
      status: "loadmore",
      refresh: false, //正在下拉
      loadText: {
        loadmore: "上拉加载更多",
        loading: "加载中",
        nomore: "已经到底了",
      },
      totalPage: "",
      isShowhasPermission: false, //  联系销售的提交申请
      applyForIsShow: false, // 提交申请
      jurisdictionList: {},
      hasPermission: "", //权限
      mediumSelect: [
        { name: "视频", value: 1, IsChoose: false },
        { name: "音频", value: 2, IsChoose: false },
      ],
      mediumActive: "",
      haveData: true,
      hideResearch: true,
    };
  },
  mixins: [mediaMixins, selectMixins],
  components: { audioModule, modalDialog, videoModule, NotHaveLogin },
  methods: {
    // 获取活动
    async getActivityList() {
      const res = await activity.getActivityListNew({
        PageSize: this.pageSize,
        CurrentIndex: this.page_no,
        ActiveState: "3",
        PlayBack: 1,
        IsShowJurisdiction: this.isGetJurisdiction,
        ChartPermissionIds: this.chartPermissionIds,
        Filter: this.mediumActive == "1,2" || !this.mediumActive ? 0 : Number(this.mediumActive),
      });
      if (res.Ret === 200) {
        this.status = this.page_no < res.Data.Paging.Pages ? "loadmore" : "nomore";
        this.totalPage = res.Data.Paging.Pages; //总页数
        if (this.page_no === 1) {
          this.collectList = res.Data.List || [];
          this.haveData = this.collectList.length ? true : false;
          if (this.refresh) {
            uni.stopPullDownRefresh();
            this.refresh = false;
          }
        } else {
          this.collectList = this.collectList.concat(res.Data.List);
        }
      }
    },
    // 去往详情页面
    goDetail(item) {
      uni.navigateTo({ url: "/activityPages/activityDetail/activityDetail?id=" + item.ActivityId + "&PageRouter=活动回放" });
    },

    // 点击视频 、音频 的筛选
    mediumClickHandler(item) {
      item.IsChoose = !item.IsChoose;
      let arr = [];
      this.mediumSelect.forEach((item) => {
        if (item.IsChoose) {
          arr.push(item.value);
        }
      });
      this.mediumActive = arr.join(",");
      this.page_no = 1;
      this.getActivityList();
    },
    async playBack(item) {
      await this.$store.dispatch("showLoginModal");
      this.PlayBackAll(item);
    },
    // 播放时长的转换
    totalSeconds(item) {
      let PlaySeconds = item.FileType == 2 ? item.VideoDetail.VideoDuration : item.VoiceList.PlaySeconds;
      let minutes = Math.floor(PlaySeconds / 60);
      let seconds = PlaySeconds % 60;
      let time = minutes.toString().padStart(2, "0") + ":" + seconds.toString().padStart(2, "0");
      return time;
    },
    // 加入播放列表
    async joinPlaylist(item) {
      if (!item.BackAudioPlay) {
        const res = await activity.getActivityDetail({
          ActivityId: item.ActivityId,
        });
        if (res.Ret === 200) {
          item.BackAudioPlay = res.Data;
        }
      }
      this.hasPermission = item.BackAudioPlay.HasPermission;
      this.jurisdictionList.ActivityId = item.ActivityId;
      if (this.hasPermission == 1) {
        let recordList = {
          Type: 1,
          SourceId: item.ActivityId,
        };
        let dataList = {
          Url: item.VoiceList.Url,
          Name: item.VoiceList.Name,
          PlaySeconds: item.VoiceList.PlaySeconds,
          indexId: item.ActivityId,
          activityTitle: item.ActivityName,
          recordList,
        };
        const playlist = this.$store.state.audioJoinPlaylist.playlist.some((key) => key.indexId === dataList.indexId);
        if (!playlist) {
          this.$store.commit("audioJoinPlaylist/addPlaylist", { dataList });
        }
        uni.showToast({
          title: "已加入播放列表",
          icon: "success",
          duration: 500,
        });
      } else if (this.hasPermission == 2) {
        this.jurisdictionList.SellerMobile = item.BackAudioPlay.SellerMobile;
        this.jurisdictionList.SellerName = item.BackAudioPlay.SellerName;
        this.jurisdictionList.PopupMsg = item.BackAudioPlay.PopupMsg;
        this.isShowhasPermission = true;
      } else if (this.hasPermission == 3 || this.hasPermission == 4 || this.hasPermission == 5) {
        this.jurisdictionList.PopupMsg = item.BackAudioPlay.PopupMsg;
        this.applyForIsShow = true;
      }
    },
    // 展示播放列表
    showAudioBoxPlayList() {
      this.$store.commit("audioBg/parseIntAudio", true);
      this.showAudioPop = true;
      uni.$emit("play-list-emit", {});
    },
  },
  onLoad() {
    this.getActivityList();
  },
  async onShow() {
    this.$store.commit("setRouterActivity", "活动回放");
    this.$store.commit("setRouterReport", "活动回放");
    this.$store.commit("audioBg/parseIntAudio", true);
  },
  onHide() {
    this.$store.commit("audioBg/parseIntAudio", false);
  },
  /* 触底 */
  onReachBottom: Throttle(function () {
    if (this.status === "nomore") return;
    this.status = "loading";
    this.page_no++;
    this.getActivityList();
  }),
  /* 用户点击分享  */
  onShareAppMessage: function (res) {
    return {
      title: this.isHorzMobile ? "好友向您推荐此内容，上传名片享查研观向免费月卡！" : "活动回放",
      path: "/activityPages/playBack/playBack",
      success: (res) => {},
      fail: (err) => {},
    };
  },
};
</script>

<style lang="scss" scoped>
.container-play-back {
  background-color: $uni-bg-color;
  padding-bottom: 30rpx;
  .paly-list-image {
    position: fixed;
    right: 50rpx;
    bottom: 150rpx;
    z-index: 99;
    width: 100rpx;
    height: 100rpx;
    image {
      width: 100rpx;
      height: 100rpx;
    }
  }
  .title-date {
    position: relative;
    .audio-back {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 132rpx;
      height: 42rpx;
      border-radius: 38rpx;
      font-size: 24rpx;
      image {
        width: 32rpx;
        height: 32rpx;
        margin-right: 8rpx;
      }
    }
    .is-video-sing {
      color: #e37318;
      background-color: #fff1e9;
    }
    .is-audio-sing {
      color: $uni-color-new;
      background-color: #e5efff;
    }
  }
  .content-item-flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .iten-buttom {
    flex-direction: row-reverse;
    view {
      height: 48rpx;
      border-radius: 8rpx;
      font-size: 24rpx;
      font-weight: 600;
    }
    view:nth-child(1) {
      width: 200rpx;
      background-color: $uni-color-new;
      color: #fff;
    }
    view:nth-child(2) {
      width: 200rpx;
      border-radius: 8rpx;
      background-color: #e5efff;
      color: $uni-color-new;
    }
    .play-img,
    .play-list {
      width: 30rpx;
      height: 30rpx;
      margin-right: 6rpx;
    }
  }

  @import "../components/selectCss.scss";
  @import "@/components/activity/indexActivity.scss";
}
</style>
