<template>
  <view class="container theme-container">
    <view class="top-title" v-if="!type">
      <image class="img"/>
      <text>{{ contentLabel }}</text>
    </view>
    <!-- 活动列表 -->
    <view>
      <view class="collect-ul">
        <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>
          <view class="item-li">
            <view class="item-img" @click="goDetail(item)">
              <image :src="item.ImgUrl">
              <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">
                  <text style="white-space: nowrap;">
                      {{item.ActivityTypeName}}
                  </text>
                  <view class="type-icn" v-if="item.IsShowSustainable">限免</view>
              </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.ActivityTypeName == '专家电话会' || item.ActivityTypeName == '专家线下沙龙'">专家背景：{{ item.Expert }} </text>
                <text class="text_twoLine" v-if="item.ActivityTypeName == '公司调研电话会' || item.ActivityTypeName == '公司线下调研'">嘉宾：{{ item.DistinguishedGuest }} </text>
                <text class="text_twoLine" v-if="item.ActivityTypeName == '分析师电话会' || item.ActivityTypeName == '分析师线下沙龙'">主讲人：{{ item.Speaker }}</text>
              </view>
              <block v-if="item.ActiveState == 1">
                <view class="bottom-box city" v-if="item.ActiveState == 1 && item.IsLimitPeople == 1 && item.ActivityTypeName == '公司调研电话会'">
                  <view class="city-img">
                    <image v-if="item.City" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/location.png" />
                    {{ item.City }}
                  </view>
                  <text class="button" v-if="item.IsSignup !== 1" @click="wanttosignup(item.ActivityId)">我要报名</text>
                  <text class="button" v-else @click="signupCancel(item.ActivityId, 2, item.ActivityTime)">{{ item.SignupType == 1 ? "取消外呼" : "取消报名" }}</text>
                </view>
                <view class="bottom-box" v-else-if="item.ActivityType == 1">
                  <view class="" style="width: 130rpx">
                    <text v-if="item.ActivityTypeId == 1" @click="askingGo(item)">帮我代问</text>
                  </view>
                  <text @click="meetingReminderAdd(item.ActivityId)" v-if="item.IsCancelMeetingReminder == 0">会议提醒</text>
                  <text @click="meetingReminderCancel(item.ActivityId)" v-else>取消提醒</text>
                  <text class="button" v-if="item.IsSignup !== 1" @click="signupAdd(item.ActivityId, 1)">预约外呼</text>
                  <text class="button" @click="signupCancel(item.ActivityId, 1, item.ActivityTime)" v-else>取消外呼</text>
                </view>
                <view class="bottom-box city" v-else>
                  <view class="city-img">
                    <image v-if="item.City" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/location.png" />
                    {{ item.City }}
                  </view>
                  <text class="button" v-if="item.IsSignup !== 1" @click="signupAdd(item.ActivityId, 3)">我要报名</text>
                  <text class="button" v-else @click="signupCancel(item.ActivityId, 3, item.ActivityTime)">取消报名</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="select-box">
        <u-popup v-model="selectShow" mode="bottom">
          <view style="color: #333333; font-size: 28rpxrpx">请选择参会方式</view>
          <view style="color: #2c83ff" @click="signupAdd('id', 1)">预约外呼</view>
          <view style="color: #2c83ff" @click="signupAdd('id', 2)">自主拨入</view>
          <view style="color: #a9afb8" @click="selectShow = false">取消</view>
        </u-popup>
      </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"
      />
    </view>
    <areaCode :isAreaCode="isAreaCode" :areaCode="areaCode" />
  </view>
</template>

<script>
import { activity, User } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
import modalDialog from "@/components/modalDialog.vue";
import myMixin from "../components/index.js";
import myActivityMixin from "../components/indexActivity.js";
import areaCode from "@/activityPages/components/areaCode.vue";
export default {
  mixins: [myMixin, myActivityMixin],
  data() {
    return {
      hasPermission: "", //是否有权限
      contentImg: "",
      contentLabel: "",
      label: "",
      type:"",
      permissionIds:'',
      whichDay:'',
    };
  },
  components: {
    areaCode,
    modalDialog,
  },
  methods: {
    async getActivityList() {
      const res = await activity.getActivityListNew({
        PageSize: this.pageSize,
        CurrentIndex: this.page_no,
        Label: this.type ? '' : this.label,
        ActiveState: 1,
        ActivityTypeId:this.type ? this.label : '',
        ChartPermissionIds: this.permissionIds,
        WhichDay: this.whichDay,
      });
      if (res.Ret === 200) {
        if(this.type) {
              uni.setNavigationBarTitle({
              title: this.type
            });
          }
        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 || [];
          if (this.refresh) {
            uni.stopPullDownRefresh();
            this.refresh = false;
          }
        } else {
          this.collectList = this.collectList.concat(res.Data.List);
        }
      }
    },
    //获取是否需要填写区号接口
    countryCcode() {
      User.countryCcode().then((res) => {
        if (res.Ret == 200) {
          this.isNeedAddCountryCode = res.Data.IsNeedAddCountryCode;
        }
      });
    },
  },
  onLoad(option) {
      this.label = option.title 
      this.type = option.type
      this.permissionIds = option.permissionIds || ""
      this.whichDay = option.whichDay || ""
      this.getActivityList();
      this.countryCcode();
  },
  onShow() {
    this.$store.dispatch("checkHandle")
  },
  /* 触底 */
  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.type || this.label,
      path: "/activityPages/themeActivity/themeActivity?title=" + this.label + "&permissionIds=" + this.permissionIds + "&whichDay="+ this.whichDay,
    };
  },
};
</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;
    height: 96rpx;
    color: #3385ff;
    font-size: 30rpx;
    .img {
      width: 38rpx;
      height: 38rpx;
    }
  }
  .collect-ul{
    padding-top: 10rpx;
  } 
}
@import "../components/indexActivity.scss";
</style>
