<template>
  <view class="container special-research">
    <view class="top-notice">
      <view class="notice">
        <van-notice-bar color="#FFFFFF" background="#FE9000" :text="wholeShowListData.ActivitySpecialExplain" />
      </view>
      <view class="inform-btn" @click="specialFollow">{{ specialIsFollow ? "取消通知" : "新调研通知" }}</view>
    </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.SpecialType == 1 ? '' : 'xianxia'">{{ item.SpecialType == 1 ? "线上" : "线下" }}</text>
            <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>
          <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-if="item.ActiveState == 0 && item.TripStatus == 2" class="img-status">已结束</text>
            </view>
            <view class="item">
              <view class="item-text" @click="goDetail(item)">
                <text class="activity-title"> {{ item.ResearchTheme }} </text>
                <view style="display: flex" class="text_twoLine" v-if="item.TripStatus == 2">
                  <text style="flex-shrink: 0"> 活动时间：</text>
                  <text> {{ item.ActivityTimeTextByDay }}</text>
                </view>
                <text class="text_twoLine" v-else>预期时间：{{ item.ActivityTimeText }} </text>
              </view>
              <view class="bottom-box">
                <view class="" style="width: 130rpx"> </view>
                <text @click="lookImg(item)">行程安排</text>
                <block v-if="item.TripStatus == 2">
                  <text v-if="item.ActiveState == 1" class="button" @click="applyOfcancel(item)">{{ item.IsTrip == 0 ? "我要报名" : "取消报名" }}</text>
                </block>
                <block v-else>
                  <text class="button" v-if="item.IsSignup !== 1" @click="interest(item)">感兴趣</text>
                  <text class="button" @click="beNotInterested(item)" v-else>已预报名</text>
                </block>
              </view>
            </view>
          </view>
          <view class="reminder-item">
            <image v-if="item.TripStatus == 1" class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/Y_apply.png"></image>
            <image v-if="item.TripStatus == 2" class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/confirm_XC.png"></image>
            <image v-if="item.Explain" @click="reminderTextHandler(item)" class="reminder" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/reminder_icon.png"></image>
          </view>
        </view>
        <u-loadmore :status="status" icon-type="flower" :load-text="loadText" margin-top="20" v-if="totalPage > 1" />
      </view>
      <view class="select-box"> </view>
      <!-- 所有自定义弹框 -->
    </view>
    <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
    <u-modal
      v-model="specialGoFollowShow"
      :content-style="{ fontSize: '32rpx' }"
      :show-cancel-button="show_cancel_button"
      confirm-text="知道了"
      :show-confirm-button="show_confirm_button"
      :show-title="false"
      :cancel-style="{ borderRight: '1rpx solid #EBEBEB' }"
      :confirm-style="{ fontWeight: '700' }"
      :mask-close-able="specialIsHintShow"
      @confirm="ininModalHandler"
      @cancel="ininModalHandler"
    >
      <view class="slot-content">
        <block v-if="specialPopupMsg">
          <text>{{ specialAccounts }}</text>
          <text class="light-hint">{{ specialPopupMsg }}</text>
        </block>
        <rich-text v-else :nodes="specialAccounts"></rich-text>
      </view>
    </u-modal>
  </view>
</template>

<script>
import { activity, User } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
import freeCharge from "@/components/freeCharge";
import specialMixins from "../components/specialMixins";
export default {
  data() {
    return {
      page_no: 1,
      pageSize: 10,
      collectList: [],
      status: "loadmore",
      refresh: false, //正在下拉
      loadText: {
        loadmore: "上拉加载更多",
        loading: "加载中",
        nomore: "已经到底了",
      },
    };
  },
  mixins: [specialMixins],
  components: {
    freeCharge,
  },
  methods: {
    // 获取事件
    async getActivityList() {
      const res = await activity.getSpecialList({
        PageSize: this.pageSize,
        CurrentIndex: this.page_no,
      });
      if (res.Ret === 200) {
        this.specialIsFollow = res.Data.IsFollow;
        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);
        }
      }
    },

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

    // 去往详情页面
    goDetail(item) {
      this.$store.dispatch("checkHandle", "/activityPages/specialDetail/specialDetail?id=" + item.ActivityId);
    },

    // 点击感兴趣
    async interest(item) {
      const res = await activity.postSpecialSignupAdd({
        ActivityId: item.ActivityId,
      });
      if (res.Ret === 200) {
        item.IsSignup = 1;
        this.modalShow(res);
      }
    },

    // 已预报名、就是不感兴趣
    beNotInterested(item) {
      uni.showModal({
        content: "您要取消此次专研调研的预报名吗？",
        confirmColor: "#3385FF",
        cancelColor: "#606266",
        success: async (res) => {
          if (res.confirm) {
            const res = await activity.postSpecialSignupAdd({
              ActivityId: item.ActivityId,
            });
            if (res.Ret === 200) {
              item.IsSignup = 0;
            }
          }
        },
      });
    },

    // 新调研通知
    async specialFollow() {
      this.show_confirm_button = true;
      if (this.specialIsFollow) {
        uni.showModal({
          content: "您要取消【专项调研】新活动通知吗？",
          confirmColor: "#3385FF",
          cancelColor: "#606266",
          success: async (res) => {
            if (res.confirm) {
              const res = await activity.postSpecialFollow();
              if (res.Ret === 200) {
                this.specialIsFollow = !this.specialIsFollow;
              }
            }
          },
        });
      } else {
        const res = await activity.postSpecialFollow();
        if (res.Ret === 200) {
          this.show_cancel_button = true;
          this.specialIsFollow = !this.specialIsFollow;
          this.specialGoFollowShow = true;
        }
      }
    },
  },
  onLoad(option) {
    this.getActivityList();
  },
  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.isHorzMobile ? "好友向您推荐此内容，上传名片享查研观向免费试用月卡！" : "专项产业调研",
      path: "/activityPages/specialResearchPage/specialResearchPage",
    };
  },
};
</script>

<style lang="scss" scoped>
.special-research {
  background: #f7f7f7;
  padding-bottom: 30rpx;
  position: relative;
  .top-notice {
    position: sticky;
    top: 0;
    z-index: 99;
    background-color: #fe9000;
    display: flex;
    align-items: center;
    height: 60rpx;
    padding-right: 20rpx;
    overflow: hidden;
    .notice {
      width: 80%;
    }
    .inform-btn {
      width: 147rpx;
      height: 40rpx;
      background: #ffffff;
      border-radius: 4rpx;
      text-align: center;
      line-height: 40rpx;
      font-size: 24rpx;
      color: #ff9e58;
    }
  }
  .collect-ul {
    padding-top: 10rpx;
  }

  .city-img {
    display: flex;
    align-items: center;
    image {
      width: 27rpx;
      height: 32rpx;
      margin-right: 12rpx;
    }
  }
}
@import "@/components/activity/indexActivity.scss";
</style>
