<template>
  <view class="container special-research">
    <view class="top-notice">
      <view class="notice">
        <van-notice-bar color="#FFFFFF" background="#FE9000" text="专项调研行程持续更新中，满五家即开团，欢迎点击感兴趣预报名" />
      </view>
      <view class="inform-btn" @click="specialFollow">{{ isFollow ? "取消通知" : "新调研通知" }}</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" />
            </view>
            <view class="item">
              <view class="item-text" @click="goDetail(item)">
                <text class="activity-title"> {{ item.ResearchTheme }} </text>
                <text class="text_twoLine">预期时间：{{ item.ActivityTimeText }} </text>
              </view>
              <view class="bottom-box">
                <view class="" style="width: 130rpx"> </view>
                <text @click="lookImg(item)">行程安排</text>
                <text class="button" v-if="item.IsSignup !== 1" @click="interest(item)">感兴趣</text>
                <text class="button" @click="beNotInterested(item)" v-else>已预报名</text>
              </view>
            </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"> </view>
      <!-- 所有自定义弹框 -->
    </view>
    <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
    <u-modal
      v-model="goFollowShow"
      :content-style="{ fontSize: '32rpx' }"
      :show-cancel-button="false"
      confirm-text="知道了"
      @cancel="isCancelBtn = false"
      :show-title="false"
      :cancel-style="{ borderRight: '1rpx solid #EBEBEB' }"
      :confirm-style="{ fontWeight: '700' }"
    >
      <view class="slot-content">
        <rich-text :nodes="accounts"></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";
export default {
  data() {
    return {
      page_no: 1,
      pageSize: 10,
      collectList: [],
      status: "loadmore",
      refresh: false, //正在下拉
      loadText: {
        loadmore: "上拉加载更多",
        loading: "加载中",
        nomore: "已经到底了",
      },
      isFollow: false,
      accounts: `您已开启【专项调研】新活动通知<br/><br/>请关注【查研观向小助手】公众号，及时获取微信消息提醒`,
      goFollowShow: false,
    };
  },
  components: {
    freeCharge,
  },
  methods: {
    //获取事件
    async getActivityList() {
      const res = await activity.getSpecialList({
        PageSize: this.pageSize,
        CurrentIndex: this.page_no,
      });
      if (res.Ret === 200) {
        this.isFollow = 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;
        uni.showModal({
          content: "预报名成功，已通知您的销售",
          confirmText: "知道了",
          showCancel: false,
          confirmColor: "#3385FF",
        });
      }
    },
    //已预报名、就是不感兴趣
    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() {
      if (this.isFollow) {
        uni.showModal({
          content: "您要取消【专项调研】新活动通知吗？",
          confirmColor: "#3385FF",
          cancelColor: "#606266",
          success: async (res) => {
            if (res.confirm) {
              const res = await activity.postSpecialFollow();
              if (res.Ret === 200) {
                this.isFollow = !this.isFollow;
              }
            }
          },
        });
      } else {
        const res = await activity.postSpecialFollow();
        if (res.Ret === 200) {
          this.isFollow = !this.isFollow;
          this.goFollowShow = 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>
