<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.SourceType == 2 ? "" : item.ActivityTimeText }}
          <view class="audio-back" v-if="item.AudioLink" @click.stop="PlayBackAll(item)">
            <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 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>
            <block v-else>
              <text v-if="item.TripStatus != 1" class="img-status">已结束</text>
            </block>
            <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.SourceType == 1">专家背景:{{ 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 style="display: flex" class="text_twoLine" v-if="item.ActivityTimeText && item.SourceType == 2">
                <text style="flex-shrink: 0"> 活动时间:</text>
                <text> {{ item.ActivityTimeText }}</text>
              </view>
            </view>
            <block v-if="item.SourceType == 1">
              <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>
                    <text v-if="item.IsShowDetails" @click="goDetail(item)" class="button">查看详情</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)">我要报名</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>
            </block>
            <block v-if="item.SourceType == 2">
              <view class="bottom-box">
                <view class="" style="width: 130rpx"> </view>
                <text @click="lookImg(item)">行程安排</text>
                <text v-if="item.ActiveState == 1" class="button" @click="applyOfcancel(item, index)">{{ item.IsSignup == 0 ? "我要报名" : "取消报名" }}</text>
              </view>
            </block>
          </view>
        </view>
        <view class="reminder-item" v-if="item.SourceType == 2">
          <image class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/confirm_XC.png"></image>
        </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"
      :hasPermission="hasPermission"
      :jurisdictionList="jurisdictionList"
      :editIsShow="editIsShow"
      :isCancelShow="isCancelShow"
      :idTypeCancel="idTypeCancel"
      :countryCode="countryCode"
      :mobileEdit="mobileEdit"
      :goOnNextStep="goOnNextStep"
      :isShowhasPermission="isShowhasPermission"
      :applyForIsShow="applyForIsShow"
      :mailboxBinding="mailboxBinding"
    />
    <view class="select-box">
      <u-popup v-model="selectShow" mode="bottom">
        <view style="color: #333333; font-size: 28rpxrpx">请选择参会方式</view>
        <view style="color: #2c83ff" @click="signupIsAddOfCancel('', 1)">预约外呼</view>
        <view style="color: #2c83ff" @click="signupIsAddOfCancel('', 2)">自主拨入</view>
        <view style="color: #a9afb8" @click="selectShow = false">取消</view>
      </u-popup>
    </view>
    <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
    <view v-if="showAudioBox">
      <audioModule :showAudioPop.sync="showAudioPop" />
    </view>
    <videoModule :showVideoPop="showVideoPop" :videoPopList="videoPopList" />
  </view>
</template>

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

let app = getApp();
export default {
  mixins: [myActivityMixin, mediaMixins],
  components: {
    modalDialog,
    freeCharge,
    audioModule,
    videoModule,
  },
  data() {
    return {
      isGetJurisdiction: 0,
      whichDay: "",
      chartPermissionIds: "",
      activityTypeId: "",
      haveData: true,
      isShowJurisdiction: false, //
      isrefresh: true,
      selectShow: false,
      listChartPermission: [],
      listChartPermissionInit: [],
      collectTypeList: [],
    };
  },
  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);
        }
      }
    },

    //查看行程的事件
    lookImg(item) {
      uni.previewImage({
        urls: [item.TripImgLink], //查看图片的数组
      });
    },

    //报名或者取消报名
    async applyOfcancel(item, index) {
      const str = item.ActivityTime.replace(/-/g, "/");
      const date = new Date(str);
      const times = date.getTime();
      const num = new Date().getTime();
      let twoDays = times - num <= 3600000 * 48;
      uni.showModal({
        content: twoDays ? "活动开始前48小时内,取消报名仍会维持扣点,确定要取消报名吗?" : "您要取消此次专项调研的预报名吗?",
        confirmColor: "#3385FF",
        cancelColor: "#606266",
        success: async (res) => {
          if (res.confirm) {
            const res = await activity.activityApecialCancel({
              ActivityId: item.ActivityId,
            });
            if (res.Ret === 200) {
              uni.showToast({
                title: res.Msg,
                duration: 2000,
              });
              this.collectList.splice(index, 1);
            }
          }
        },
      });
    },
  },
  //load
  onLoad(option) {
    this.getActivityList();
  },
  async onShow() {
    await this.$store.dispatch("checkHandle", "noGO");
    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();
  }),
  /* 下拉刷新 */
  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 "@/components/activity/indexActivity.scss";
</style>