<template>
  <block>
    <view class="container theme-container">
      <!-- 筛选部分 -->
      <view class="select-content-activity">
        <view class="top-title" v-if="!type">
          <view :class="['content-title', !contentDetail.IsJump && 'jump-title']" @click="jumpHandler">
            <text class="jump-label">{{ contentDetail.Label }}</text>
            <text v-if="contentDetail.IsJump" class="jump-text"> 查看资源包>></text>
            <image v-if="contentDetail.IndustryNewLabel" class="new_icon" src="https://hzstatic.hzinsights.com/cygx/icon/new_report.png" mode=""></image>
          </view>
        </view>
        <view :class="['screen-item', (isEndActivity || !type) && 'end-select-item']">
          <block v-if="!isEndActivity && type">
            <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>
          </block>
          <block v-if="isEndActivity">
            <text @click="selectMultipleHandler(item, '类型')" v-for="item in activityTypeList" :key="item.Id" :class="['select-item-multiple', item.IsChoose && 'active']">{{ item.StatusName }}</text>
          </block>
          <block v-else>
            <text @click="selectMultipleHandler(item, '日期')" v-for="item in activityTimeList" :key="item.Id" :class="['select-item-multiple', item.IsChoose && 'active']">{{ item.StatusName }}</text>
          </block>
        </view>
        <view class="research-external-item" v-if="!isEndActivity && type && contentDetail.IsShowResearchPoints">
          <text @click="selectMultipleHandler(item, '扣点')" v-for="item in ResearchExternal" :key="item.Id" :class="['select-item-multiple', item.IsChoose && 'active']">{{ item.StatusName }}</text>
        </view>
        <view class="screen-item screen-item-ul" v-if="isEndActivity">
          <text @click="monthWeekHandler(item)" v-for="item in activityMonthWeekList" :key="item.Id" :class="['text-item', item.IsChoose && 'active']">{{ item.StatusName }}</text>
        </view>
      </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.SourceType == 2 ? "" : item.ActivityTimeText }}
              <view class="audio-back" v-if="item.AudioLink" @click.stop="playBack(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>
                <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)">
                  <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-if="item.IsExternalLabel" src="https://hzstatic.hzinsights.com/cygx/icon/activity_external.png"></image>
                    {{ item.ActivityName }}
                  </view>
                  <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', 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/cygx/czbk/location.png"></image>
                        {{ item.City }}
                      </view>
                      <view style="display: flex">
                        <text v-if="item.IsShowOutboundCall && item.ActivityTypeId == 1" class="button"
												 @click="signupCheck(item, 1)">{{
                          item.IsSignup == 1 ? "取消外呼" : "预约外呼"
                        }}</text>
                        <text v-if="item.IsShowAppointment" @click="summaryHandelCheck(item)">{{
                          item.IsAppointment == 1 ? "取消纪要" : "预约纪要"
                        }}</text>
                        <text v-if="item.IsShowMeetingReminder" @click="meetingReminderCheck(item.ActivityId, item.IsCancelMeetingReminder)">
                          {{ item.IsCancelMeetingReminder == 0 ? "消息提醒" : "取消提醒" }}
                        </text>
                        <view v-if="item.IsShowHelpSsk" style="width: 130rpx">
                          <text @click="askingCheck(item)">帮我带问</text>
                        </view>
                        <text v-if="item.IsShowOutboundCall && item.ActivityTypeId != 1" class="button" @click="signupCheck(item, 1)">{{
                          item.IsSignup == 1 ? "取消外呼" : "预约外呼"
                        }}</text>
                        <text v-if="item.IsShowDetails" @click="goDetailCheck(item)" class="button">查看详情</text>
                        <block v-if="item.IsShowSignup">
                          <block v-if="item.IsCClassMeeting && !item.IsYidongConduct">
                            <text class="button" @click="signupCheck(item, 3, 'CClass')">{{
                              item.IsSignup == 1 ? "取消报名" : "我要报名"
                            }}</text>
                          </block>
                          <block v-else>
                            <text class="button" v-if="item.IsSignup !== 1" @click="wanttosignupCheck(item)">我要报名</text>
                            <text class="button" v-else @click="signupCheck(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>
                  </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-else>
          <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
          <text>暂时没有符合条件的活动</text>
        </view>
        <SelectPopup :selectShow.sync="selectShow" @signupIsAddOfCancel="signupIsAddOfCancel" :selectYdong="selectYdong" />

        <!-- 所有自定义弹框 -->
        <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>
      <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
      <view v-if="showAudioBox">
        <audioModule :showAudioPop.sync="showAudioPop" />
      </view>
      <videoModule :showVideoPop.sync="showVideoPop" :videoPopList="videoPopList" />
    </view>
    <!-- <not-have-login v-else /> -->
    <ShowResearchDlg :isResearchModalShow.sync="isResearchModalShow" :jurisdictionList="jurisdictionList" :checkResearchList.sync="checkResearchList" />
    <Loading />
  </block>
</template>

<script>
import { activity, User } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
import modalDialog from "@/components/modalDialog.vue";
import myActivityMixin from "@/components/activity/indexActivity.js";
import freeCharge from "@/components/freeCharge";
import selectMixins from "../components/selectMixins.js";
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 NotHaveLogin from "../../components/notHaveLogin.vue";

import ShowResearchDlg from "@/components/activity/showResearchDlg.vue";
export default {
  mixins: [myActivityMixin, selectMixins, mediaMixins],
  data() {
    return {
      hasPermission: "", //是否有权限
      contentImg: "",
      contentLabel: "",
      contentDetail: {},
      label: "",
      type: "",
      activityId: "",
      haveData: true,
      isEndActivity: false,
      hideResearch:false, 
    };
  },
  components: {
    modalDialog,
    freeCharge,
    audioModule,
    videoModule,
    SelectPopup,
    NotHaveLogin,
    ShowResearchDlg,
  },
  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.getActivityListNew({
        PageSize: this.pageSize,
        CurrentIndex: this.page_no,
        Label: this.type ? "" : this.label,
        ActiveState: this.isEndActivity ? 3 : 1,
        ActivityTypeId: this.type ? this.label : "",
        ChartPermissionIds: this.chartPermissionIds,
        WhichDay: this.whichDay,
        ActivityId: this.activityId,
        TypeName: this.selectActiveId,
        IsResearchPoints: this.ResearchExternalAct,
      });
      if (res.Ret === 200) {
        if (this.type) {
          uni.setNavigationBarTitle({
            title: this.type,
          });
        }
        this.contentImg = res.Data.ImgUrl;
        this.contentDetail = res.Data;
        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);
        }
      }
    },

    // 点击了top的标签
    async jumpHandler() {
			await this.$store.dispatch("showLoginModal")
      if (this.contentDetail.IsJump) {
        if (this.contentDetail.IsResearch) {
          //严选
          uni.navigateTo({ url: "/reportPages/researchTheme/researchTheme?id=" + this.contentDetail.IndustrialManagementId });
        } else {
          //非严选
          uni.navigateTo({
            url: "/reportPages/IndustryReport/IndustryReport?id=" + this.contentDetail.IndustrialManagementId + "&entrance=活动详情",
          });
        }
      }
    },

    // 进入页面的筛选的方法
    selectInitHandler(value, list) {
      list.forEach((item) => {
        if (value.includes(item.Id)) {
          item.IsChoose = true;
        }
      });
    },

    //查看行程的事件
    lookImg(item) {
      this.getRecordTracking(this.$store.state.pageRouterActivity, { ActivityId: item.ActivityId, Source: "查看行程" });
      uni.previewImage({
        urls: [item.TripImgLink], //查看图片的数组
      });
    },

    // 进入页面的初始化
    loadInit(option) {
			console.log(option);
      this.label = option.title;
      this.type = option.type;
      this.chartPermissionIds = option.permissionIds || "";
      this.activityId = option.id;
      this.whichDay = option.whichDay || "";
      this.isShowJurisdiction = option.showJurisdiction == "show" ? true : false;
      this.isGetJurisdiction = this.isShowJurisdiction ? 1 : 2;
      this.whichDay && this.selectInitHandler(this.whichDay, this.activityTimeList);
      if (option.endList) {
        this.isEndActivity = true;
        let obj = JSON.parse(option.endList);
        this.whichDay = obj.data_activeId;
        this.selectActiveId = obj.select_activeId;
        this.selectInitHandler(this.whichDay, this.activityMonthWeekList);
        this.selectInitHandler(this.selectActiveId, this.activityTypeList);
      }
      // this.isUserBindingPhoneNumber && 
			this.getActivityList();
    },
		// 操作之前 是否登录判断
		async playBack(item){
			await this.$store.dispatch("showLoginModal")
			this.PlayBackAll(item)
		},
		async signupCheck(item,type,valName = ""){
			await this.$store.dispatch("showLoginModal")
			this.signupIsAddOfCancel(item,type,valName)
		},
		async summaryHandelCheck(item){
			await this.$store.dispatch("showLoginModal")
			this.summaryIsHandel(item)
		},
		async meetingReminderCheck(id, type){
			await this.$store.dispatch("showLoginModal")
			this.meetingReminderAdd(id, type)
		},
		async askingCheck(item, type = ""){
			await this.$store.dispatch("showLoginModal")
			this.askingGo(item, type)
		},
		async wanttosignupCheck(item){
			await this.$store.dispatch("showLoginModal")
			this.wanttosignup(item)
		},
		async goDetailCheck(item){
			await this.$store.dispatch("showLoginModal")
			this.goDetail(item)
		}
  },
  onLoad(option) {
    this.loadInit(option);
  },
  onShow() {
    this.$store.commit("setRouterReport", "活动列表");
    this.$store.commit("setRouterActivity", "活动列表");
    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();
  }),
  /** 用户点击分享 */
  onShareAppMessage: function (res) {
    return {
      title: this.isHorzMobile ? "好友向您推荐此内容，上传名片享查研观向免费月卡！" : this.type || this.label,
      path: "/activityPages/themeActivity/themeActivity?title=" + this.label + "&permissionIds=" + this.chartPermissionIds + "&whichDay=" + this.whichDay + "&type=" + this.type,
    };
  },
};
</script>

<style lang="scss" scoped>
.theme-container {
  background: #f7f7f7;
  padding-bottom: 30rpx;
  position: relative;
  .top-title {
    position: sticky;
    top: 0;
    z-index: 99;
    background-color: #fff;
    display: flex;
    align-items: center;
    color: #3385ff;
    font-size: 30rpx;
    padding: 30rpx 30rpx 20rpx;
    border-bottom: 2rpx solid #dcdfe6;
    .content-title {
      display: flex;
      align-items: center;
      .jump-text {
        margin-left: 10rpx;
        font-size: 24rpx;
        color: #3385ff;
      }
      .jump-label {
        font-size: 28rpx;
        padding: 6rpx 18rpx;
        background-color: #3385ff;
        border-radius: 52rpx;
        color: #fff;
      }
      .new_icon {
        width: 60rpx;
        height: 30rpx;
        margin-left: 10rpx;
      }
    }
    .jump-title {
      .jump-label {
        background-color: #f8f8fa;
        color: #999;
      }
    }
  }
  .collect-ul {
    padding-top: 10rpx;
  }
  .research-external-item {
    width: 100%;
    background-color: #fff;
    height: 60rpx;
    padding: 0 34rpx;
    font-size: 24rpx;
    margin-top: -15rpx;
    color: #333;
    display: flex;
    align-items: center;
    .active {
      background-color: #3385ff !important;
      color: #fff !important;
    }
  }
  .end-select-item {
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
  }
  .select-item-multiple {
    margin-right: 38rpx;
  }
  @import "../components/selectCss.scss";
  @import "@/components/activity/indexActivity.scss";

  .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;
    }
  }
}
</style>
