<template>
  <view class="container activity-content">
    <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="audioPlayBack(item)">
            <image
              class="audio-img"
              :src="
                curVoiceId === item.ActivityId && !curAudioPaused
                  ? 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/back_stop.png'
                  : 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/back_group.png'
              "
            ></image>
            {{ curVoiceId === item.ActivityId && !curAudioPaused ? "暂停" : "回放" }}
          </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>
            <block v-if="item.ActiveState == 1">
              <view :class="['bottom-box', item.ActivityTypeId == 1 && item.IsLimitPeople == 0 && 'expert-item', item.City && 'city']">
                <view class="city-img" v-if="item.City">
                  <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/location.png"></image>
                  {{ item.City }}
                </view>
                <view style="display: flex">
                  <text v-if="item.IsShowOutboundCall && item.ActivityTypeId == 1" class="button" @click="signupIsAddOfCancel(item, 1)">{{ item.IsSignup == 1 ? "取消外呼" : "预约外呼" }}</text>
                  <text v-if="item.IsShowAppointment" @click="summaryIsHandel(item)">{{ item.IsAppointment == 1 ? "取消纪要" : "预约纪要" }}</text>
                  <text v-if="item.IsShowMeetingReminder" @click="meetingReminderAdd(item.ActivityId, item.IsCancelMeetingReminder)">
                    {{ item.IsCancelMeetingReminder == 0 ? "消息提醒" : "取消提醒" }}
                  </text>
                  <view v-if="item.IsShowHelpSsk" style="width: 130rpx">
                    <text @click="askingGo(item)">帮我带问</text>
                  </view>
                  <text v-if="item.IsShowOutboundCall && item.ActivityTypeId != 1" class="button" @click="signupIsAddOfCancel(item, 1)">{{ item.IsSignup == 1 ? "取消外呼" : "预约外呼" }}</text>
                  <block v-if="item.IsShowSignup">
                    <block v-if="item.IsCClassMeeting">
                      <text class="button" @click="signupIsAddOfCancel(item, 3, 'CClass')">{{ item.IsSignup == 1 ? "取消报名" : "我要报名" }}</text>
                    </block>
                    <block v-else>
                      <text class="button" v-if="item.IsSignup !== 1" @click="wanttosignup(item.ActivityId)">我要报名</text>
                      <text class="button" v-else @click="signupIsAddOfCancel(item, 2)">{{ item.SignupType == 1 ? "取消外呼" : "取消报名" }}</text>
                    </block>
                  </block>
                </view>
              </view>
            </block>
            <block v-else>
              <view class="bottom-box city" v-if="item.City">
                <view class="city-img">
                  <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/location.png"></image>
                  {{ item.City }}
                </view>
              </view>
              <view class="bottom-box real-time" v-if="item.ActiveState == 2 && item.ActivityTypeId == 1">
                <text class="button" @click="askingGo(item, '提问')">实时提问</text>
              </view>
            </block>
          </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-if="!haveData">
      <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
      <text>{{ tabsActive == 0 ? "暂时没有符合条件的活动" : "暂无我的日程" }}</text>
    </view>
    <!-- 所有自定义弹框 -->
    <modalDialog
      :isShow="isShow"
      :signupType="signupType"
      :goFollow="goFollow"
      :signupStatus="signupStatus"
      :hasPermission="hasPermission"
      :jurisdictionList="jurisdictionList"
      :editIsShow="editIsShow"
      :isCancelShow="isCancelShow"
      :idTypeCancel="idTypeCancel"
      @cancelShowBtn="cancelEnsure"
      :countryCode="countryCode"
      :mobileEdit="mobileEdit"
      :goOnNextStep="goOnNextStep"
      :isShowhasPermission="isShowhasPermission"
      :applyForIsShow="applyForIsShow"
      :mailboxBinding="mailboxBinding"
    />
    <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
    <view v-if="showAudioBox">
      <audioModule :showAudioPop.sync="showAudioPop" />
    </view>
  </view>
</template>

<script>
import { activity } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
import myActivityMixin from "@/activityPages/components/indexActivity.js";
import modalDialog from "@/components/modalDialog.vue";
import freeCharge from "@/components/freeCharge";
import audioModule from "@/components/audioModule/index";

let app = getApp();
export default {
  mixins: [myActivityMixin],
  components: {
    modalDialog,
    freeCharge,
    audioModule,
  },
  data() {
    return {
      collectTypeList: [],
      haveData: true,
      whichDay: "",
      listChartPermission: [],
      listChartPermissionInit: [],
      chartPermissionIds: "",
      isShowJurisdiction: false, //
      isGetJurisdiction: 0,
      isrefresh: true,
      activityTypeId: "",
      showAudioPop: false,
      showAudioBox: false,
    };
  },
  computed: {
    curVoiceId() {
      //当前正在播放的音频id
      return this.$store.state.audioBg.activityId;
    },
    curAudioPaused() {
      //当前音频是否暂停状态
      return this.$store.state.audioBg.paused;
    },
  },
  methods: {
    //
    async getActivityList() {
      const res = await activity.getScheduleList({ PageSize: this.pageSize, CurrentIndex: this.page_no });
      if (res.Ret === 200) {
        this.contentImg = res.Data.ImgUrl;
        this.contentLabel = res.Data.Label;
        this.status = this.page_no < res.Data.Paging.Pages ? "loadmore" : "nomore";
        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);
        }
      }
    },
    //点击了回放
    audioPlayBack(item) {
      // 判断是否为同一个音频
      if (this.$store.state.audioBg.activityId == item.ActivityId) {
        if (this.globalBgAudioManager.paused) {
          this.globalBgAudioManager.play();
        } else {
          this.globalBgAudioManager.pause();
        }
      } else {
        this.$store.commit("audioBg/addAudio", { list: item.VoiceList, activityId: item.ActivityId, activityTitle: item.ActivityName });
      }
      this.showAudioPop = true;
    },
  },
  //load
  onLoad(option) {
    this.getActivityList();
  },
  async onShow() {
    await this.$store.dispatch("checkHandle", "noGO");
    this.showAudioBox = true;
  },
  onHide() {
    this.showAudioBox = false;
  },
  /* 触底 */
  onReachBottom: Throttle(function () {
    if (this.status === "nomore") return;
    this.status = "loading";
    this.page_no++;
    this.getActivityList();
  }),
  /* 下拉刷新 */
  onPullDownRefresh: Throttle(function () {
    this.page_no = 1;
    this.refresh = true;
    this.getActivityList();
  }),
};
</script>

<style scoped lang="scss">
.activity-content {
  background-color: #f7f7f7;
  padding-bottom: 90rpx;
  position: relative;
  padding-top: 20rpx;
  .nodata_ico {
    width: 374rpx;
    height: 288rpx;
  }
  .title-date {
    position: relative;
    .audio-back {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 99rpx;
      height: 39rpx;
      font-size: 24rpx;
      color: #fff;
      display: flex;
      align-items: center;
      background-color: #3385ff;
      border-radius: 20rpx;
      padding-left: 4rpx;
      .audio-img {
        width: 30rpx;
        height: 30rpx;
        margin: 0 5rpx;
      }
    }
  }
}
@import "@/activityPages/components/indexActivity.scss";
</style>
