<template>
  <block>
    <view class="container container-play-back" v-if="isUserBindingPhoneNumber">
      <!-- 筛选部分 -->
      <view class="select-content-activity">
        <view class="screen-item">
          <text :class="[isShowJurisdiction ? 'active' : '', 'text-item']" @click="permissioActivity">有权限行业</text>
          <!-- 各种状态选择 -->
          <view class="select-conyent" ref="select-conyent">
            <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' : '#2C83FF'" 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>
          <text
            @click="mediumClickHandler(item)"
            v-for="item in mediumSelect"
            :key="item.value"
            :class="[item.IsChoose ? 'active' : '', 'text-item', 'medium-item']"
            >{{ item.name }}</text
          >
        </view>
      </view>
      <!-- 活动列表 -->
      <view class="collect-ul" v-if="haveData">
        <view class="collect-ltem" v-for="(item, index) in collectList" :key="index">
          <view class="title-date" @click="goDetail(item)">
            <text :class="item.ActivityType == 1 ? '' : 'xianxia'">{{ item.ActivityType == 1 ? "线上" : "线下" }}</text>
            {{ item.ActivityTimeText }}
            <view class="audio-back" v-if="item.AudioLink" @click.stop="PlayBackAll(item)">
              <view class="audio-box">
                <block v-if="item.FileType == 2">
                  <image class="audio-img" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/video_play.png"></image>
                </block>
                <image
                  v-else
                  class="audio-img"
                  :src="
                    curVoiceId === item.ActivityId && !curAudioPaused
                      ? 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/stop_play.png'
                      : 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/audio_play.png'
                  "
                ></image>
                {{ curVoiceId === item.ActivityId && !curAudioPaused ? "暂停" : "回放" }}
              </view>
            </view>
          </view>
          <view class="item-li">
            <view class="item-img" @click="goDetail(item)">
              <image :src="item.ImgUrl"> </image>
              <text v-if="item.ActiveState == 1" class="img-status begin">未开始</text>
              <text v-else-if="item.ActiveState == 2" class="img-status proceed">进行中</text>
              <text v-else class="img-status">已结束</text>
              <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>
          </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>
    <not-have-login v-else />
  </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,
    };
  },
  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();
    },
  },
  onLoad() {
    this.isUserBindingPhoneNumber && 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: #f7f7f7;
  padding-bottom: 30rpx;
  .title-date {
    position: relative;
    .audio-back {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 125rpx;
      height: 90rpx;
      font-size: 24rpx;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      color: #fff;
      .audio-box {
        width: 99rpx;
        height: 39rpx;
        display: flex;
        align-items: center;
        border-radius: 20rpx;
        padding-left: 4rpx;
        background-color: #3385ff;
        .audio-img {
          width: 30rpx;
          height: 30rpx;
          margin: 0 5rpx;
        }
      }
    }
  }
  @import "../components/selectCss.scss";
  @import "@/components/activity/indexActivity.scss";
}
</style>
