<template>
  <view class="container activity-content">
    <view class="collect-ul" v-if="haveData">
      <view class="collect-ltem global_card_content" v-for="(item, index) in collectList" :key="index">
        <view class="reminder-item" v-if="item.SourceType == 2">
          <image class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/trip_icon.png"></image>
        </view>
        <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>
            <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>
            <block v-else>
              <image v-if="item.TripStatus != 1" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/end_activity.png" class="img-status"></image>
            </block>
            <view class="img-type">
              <image :src="item.ImgUrlText" mode=""></image>
            </view>
          </view>
          <view class="item">
            <view class="item-text" @click="goDetail(item)">
              <view class="activity-title text_twoLine">
                <image v-if="item.IsResearchPoints" src="https://hzstatic.hzinsights.com/cygx/icon/Research_Points.png"></image>
                <image v-else-if="item.IsResearch" src="https://hzstatic.hzinsights.com/cygx/icon/Research_normal.png"></image>
                <image v-else-if="item.IsExternalLabel" src="https://hzstatic.hzinsights.com/cygx/icon/activity_external.png"></image>
                {{ item.ActivityName }}
              </view>
              <text class="global_activity_content text_twoLine" v-if="item.Expert && item.SourceType == 1">专家背景：{{ item.Expert }} </text>
              <text class="global_activity_content text_twoLine" v-if="item.DistinguishedGuest">嘉宾：{{ item.DistinguishedGuest }} </text>
              <text class="global_activity_content text_twoLine" v-if="item.Speaker">主讲人：{{ item.Speaker }}</text>
              <view style="display: flex" class="global_activity_content 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', isEndBtn(item) > 3 && 'expert-item', item.City && 'city']">
                  <view class="city-img" v-if="item.City">
                    <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/position.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>
                    <text v-if="item.IsShowHelpSsk" @click="askingGo(item)">帮我带问</text>
                    <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 && !item.IsYidongConduct">
                        <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/new_cygx/position.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>
      <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"
    />
    <SelectPopup :selectShow.sync="selectShow" @signupIsAddOfCancel="signupIsAddOfCancel" :selectYdong="selectYdong" />
    <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
    <view v-if="showAudioBox">
      <audioModule :showAudioPop.sync="showAudioPop" />
    </view>
    <videoModule :showVideoPop.sync="showVideoPop" :videoPopList="videoPopList" />
    <ShowResearchDlg :isResearchModalShow.sync="isResearchModalShow" :jurisdictionList="jurisdictionList" :checkResearchList.sync="checkResearchList" />
    <Loading />
  </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";
import SelectPopup from "@/components/activity/selectPopup";
import ShowResearchDlg from "@/components/activity/showResearchDlg.vue";

let app = getApp();
export default {
  mixins: [myActivityMixin, mediaMixins],
  components: {
    modalDialog,
    freeCharge,
    audioModule,
    videoModule,
    SelectPopup,
    ShowResearchDlg,
  },
  data() {
    return {
      isGetJurisdiction: 0,
      whichDay: "",
      chartPermissionIds: "",
      activityTypeId: "",
      haveData: true,
      isShowJurisdiction: false, //
      isrefresh: true,
      listChartPermission: [],
      listChartPermissionInit: [],
      collectTypeList: [],
      isResearchModalShow: false,
      checkResearchList: {},
    };
  },
  methods: {
    // 判断几个按钮
    isEndBtn(item) {
      let isKeys = ["IsShowOutboundCall", "IsShowAppointment", "IsShowMeetingReminder", "IsShowHelpSsk", "IsShowDetails", "IsShowSignup"];
      let arr = [];
      Object.keys(item).forEach((key) => {
        if (isKeys.includes(key)) {
          item[key] && arr.push(item[key]);
        }
      });
      return arr.length;
    },
    //获取数据
    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) {
      this.getRecordTracking(this.$store.state.pageRouterActivity, { ActivityId: item.ActivityId, Source: "查看行程" });
      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: "#376cbb",
        cancelColor: "#606266",
        success: async (res) => {
          if (res.confirm) {
            const res = await activity.activityApecialCancel({
              ActivityId: item.ActivityId,
              PageRouter: this.$store.state.pageRouterActivity,
            });
            if (res.Ret === 200) {
              uni.showToast({
                title: res.Msg,
                duration: 2000,
              });
              this.collectList.splice(index, 1);
            }
          }
        },
      });
    },
  },
  //load
  onLoad(option) {
    this.$store.commit("setRouterActivity", "我的日程");
    this.getActivityList();
  },
  async onShow() {
    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: $uni-bg-color;
  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: #376cbb;
      border-radius: 20rpx;
      padding-left: 4rpx;
      .audio-img {
        width: 30rpx;
        height: 30rpx;
        margin: 0 5rpx;
      }
    }
  }
}
@import "@/components/activity/indexActivity.scss";
</style>
