<template>
  <block>
    <view class="container special-detail" v-if="isUserBindingPhoneNumber">
      <view class="" v-if="haveAuth == 1">
        <view class="top-notice-special">
          <view class="notice">
            <van-notice-bar color="#FFFFFF" background="#FE9000" text="专项调研行程持续更新中，满五家即开团，欢迎点击感兴趣预报名" />
          </view>
          <view class="inform-btn" @click="specialFollow">{{ specialIsFollow ? "取消通知" : "新调研通知" }}</view>
        </view>
        <view class="content">
          <view class="dialog-title" :class="1 == 1 ? 'brackets-title' : ''">{{ detailData.ResearchTheme }}</view>
          <view class="network">
            <view class="network-left">活动类型：</view>
            <view class="network-right">{{ detailData.ActivityTypeName }}</view>
          </view>
          <view class="network">
            <view class="network-left">所属行业：</view>
            <view class="network-right">{{ detailData.ChartPermissionName }}</view>
          </view>
          <view class="network" v-if="detailData.TripStatus == 2">
            <view class="network-left">开始时间：</view>
            <view class="network-right">{{ detailData.ActivityTimeTextByDay }}</view>
          </view>
          <view class="network" v-else>
            <view class="network-left">预期时间：</view>
            <view class="network-right">{{ detailData.ActivityTimeText }}</view>
          </view>
          <view class="network">
            <view class="network-left">调研形式：</view>
            <view class="network-right">
              {{ detailData.SpecialType == 1 ? "线上" : "线下" }}
              <block v-if="detailData.SpecialType == 2">({{ detailData.City }})</block>
            </view>
          </view>
          <block v-if="detailData.IndustrialName || detailData.IndustrialSubjectName">
            <view class="network">
              <view class="network-left">产业名称：</view>
              <view class="network-right">{{ detailData.IndustrialName }}</view>
            </view>
            <view class="network">
              <view class="network-left">相关公司：</view>
              <view class="network-right">{{ detailData.IndustrialSubjectName }}</view>
            </view>
          </block>
          <block v-else>
            <view class="network">
              <view class="network-left">相关主题：</view>
              <view class="network-right">{{ detailData.Label }}</view>
            </view>
          </block>
          <view class="reminder-item">
            <image v-if="detailData.TripStatus == 1" class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/Y_apply.png"></image>
            <image v-if="detailData.TripStatus == 2" class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/confirm_XC.png"></image>
            <image
              v-if="detailData.Explain"
              @click="reminderTextHandler(detailData)"
              class="reminder"
              src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/reminder_icon.png"
            ></image>
          </view>
        </view>
        <view class="" style="height: 50rpx"></view>
        <view class="look-Trip" @click="lookImg">
          查看行程安排
          <van-icon name="arrow" />
        </view>
        <view class="interest-btn">
          <block v-if="detailData.TripStatus == 2">
            <text v-if="detailData.ActiveState == 1" class="button" @click="applyOfcancel(detailData)">
              {{ detailData.IsTrip == 0 ? `我要报名(${detailData.TripNum}/${detailData.LimitPeopleNum})` : "取消报名" }}
            </text>
          </block>
          <block v-else>
            <text class="button" v-if="detailData.IsSignup !== 1" @click="interest">感兴趣</text>
            <text class="button" @click="beNotInterested" v-else>已预报名</text>
          </block>
        </view>
      </view>
      <!-- 权限部分 -->
      <view v-else>
        <jurisdiction :idAct="id" :jurisdictionList="jurisdictionList"></jurisdiction>
      </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>
    <not-have-login v-else />
    <Loading />
  </block>
</template>

<script>
import { activity, User } from "@/config/api.js";
import jurisdiction from "../activityDetail/jurisdiction/components.vue";
import freeCharge from "@/components/freeCharge";
import specialMixins from "../components/specialMixins";
import NotHaveLogin from "@/components/notHaveLogin.vue";
let app = getApp({ allowDefault: true });
export default {
  data() {
    return {
      id: "",
      detailData: {},
      haveAuth: "",
      specialIsFollow: false,
      jurisdictionList: {},
    };
  },
  components: {
    jurisdiction,
    freeCharge,
    NotHaveLogin,
  },
  mixins: [specialMixins],

  methods: {
    // 获取详情
    async getActivityDetail() {
      const res = await activity.getSpecialDetailList({ ActivityId: this.id, PageRouter: this.$store.state.pageRouterActivity });
      if (res.Ret == 200) {
        this.specialIsFollow = res.Data.IsFollow;
        this.haveAuth = res.Data.HasPermission;
        this.jurisdictionList = res.Data;
        this.jurisdictionList.Type = "专项调研";
        if (res.Data.HasPermission == 1) {
          this.detailData = res.Data.Detail;
        }
      }
    },

    //感兴趣
    async interest() {
      const res = await activity.postSpecialSignupAdd({
        ActivityId: this.detailData.ActivityId,
        PageRouter: this.$store.state.pageRouterActivity,
      });
      if (res.Ret === 200) {
        this.currentPages();
        this.modalShow(res);
        if (res.Data.SignupStatus == 1) {
          this.detailData.IsSignup = 1;
        }
      }
    },

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

    // 控制列表页面的状态
    currentPages() {
      let pages = getCurrentPages();
      let prevPage = pages[pages.length - 2];
      let path = prevPage.$page.fullPath;
      if (path == "/activityPages/specialResearchPage/specialResearchPage") {
        const index = prevPage.$vm.collectList.findIndex((item) => item.ActivityId == this.id);
        prevPage.$vm.collectList[index].IsSignup = this.detailData.IsSignup;
      }
    },

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

    //新调研通知
    async specialFollow() {
      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.specialIsFollow = !this.specialIsFollow;
          this.specialGoFollowShow = true;
        }
      }
    },
  },
  onLoad(option) {
    this.id = option.id || "";
  },
  onShow() {
    if (!this.$store.state.isAuth && !this.$store.state.isBind) {
      //已授权已绑定
      this.getActivityDetail();
    }
  },
  /**
   * 用户点击分享
   */
  onShareAppMessage: function (res) {
    return {
      title: this.isHorzMobile ? "好友向您推荐此内容，上传名片享查研观向免费试用月卡！" : "活动详情",
      path: "/activityPages/specialDetail/specialDetail?id=" + this.id,
      success: (res) => {},
      fail: (err) => {},
    };
  },
};
</script>

<style lang="scss" scoped>
.special-detail {
  padding-bottom: 100rpx;
  .top-notice-special {
    height: 96rpx;
    padding-right: 20rpx;
    background-color: #fe9000;
    position: relative;
    .notice {
      width: 80%;
    }
    .inform-btn {
      position: absolute;
      right: 20rpx;
      top: 50%;
      transform: translateY(-50%);
      width: 147rpx;
      height: 40rpx;
      background: #ffffff;
      border-radius: 4rpx;
      text-align: center;
      line-height: 40rpx;
      font-size: 24rpx;
      color: #ff9e58;
    }
  }
  .notice {
    height: 60rpx;
    width: 100%;
  }
  .choose-limit {
    position: relative;
    display: flex;
    align-items: center;
    // margin-left: 20rpx;
    image {
      width: 93rpx;
      height: 38rpx;
    }
    .limit-img {
      position: absolute;
      top: -13rpx;
      right: -30rpx;
      width: 46rpx;
      height: 26rpx;
    }
  }
  .content {
    padding: 34rpx 34rpx 0rpx;
    margin-bottom: -20rpx;
    color: #333333;
    font-size: 28rpx;
    position: relative;
    view {
      padding-left: 20rpx;
    }

    text {
      line-height: 80rpx;
      padding-left: 20rpx;
    }

    .phone {
      padding: 0;
      display: inline-block;
      color: #2c83ff;
    }
    .reminder-item {
      position: absolute;
      top: 0;
      right: 0;
      width: 204rpx;
      height: 118rpx;
      z-index: 9;
      .item {
        width: 100%;
        height: 100%;
      }
      .reminder {
        position: absolute;
        top: 0rpx;
        right: 0rpx;
        width: 28rpx;
        height: 28rpx;
        z-index: 10;
        padding: 10rpx 10rpx 20rpx 20rpx;
      }
    }
    .dialog-title {
      width: 682rpx;
      padding: 20rpx;
      background: #f2f2f2;
      opacity: 0.8;
      text-align: center;
      font-size: 30rpx;
      font-weight: bold;
      margin-bottom: 30rpx;
      color: #000;
    }
    .brackets-title {
      padding-left: 20rpx;
    }
    .city-box {
      display: flex;
      align-items: center;

      text {
        padding: 0;
      }

      .city {
        display: flex;
        color: #2088ff;
        align-items: center;

        image {
          width: 27rpx;
          height: 32rpx;
          margin-right: 12rpx;
        }
      }
    }
  }
  .light-hint {
    color: #999;
    font-size: 24rpx;
  }
  .network {
    margin-bottom: 30rpx;
    padding: 0 !important;
    display: flex;
    .network-left {
      width: 160rpx;
      text-align-last: justify;
      text-align: justify;
    }

    .network-right {
      width: 480rpx;
    }
    .network-zoom {
      .text_zoom {
        width: 100%;
        word-break: break-all;
        color: #333333;
      }
      view {
        padding: 0 !important;
        margin: 0 !important;
      }
      .copy-zoom {
        display: inline-block;
        padding: 5rpx 17rpx !important;
        border-radius: 34rpx;
        background-color: #ebf4ff;
        font-size: 24rpx;
        color: #2c83ff;
        margin: 0 10rpx;
        margin-top: 30rpx;
      }
    }
    .network-link {
      width: 520rpx !important;
      view {
        padding: 0 !important;
        margin: 0 !important;
        width: 100%;
        display: flex;
        justify-content: space-between;
        :first-child {
          width: 350rpx;
        }
        .copy-link {
          padding: 5rpx 17rpx !important;
          border-radius: 34rpx;
          background-color: #ebf4ff;
          font-size: 24rpx;
          color: #2c83ff;
        }
      }
    }
  }

  .look-Trip {
    width: 100%;
    text-align: center;
    font-size: 28rpx;
    color: #3385ff;
    font-weight: 500;
  }
  .interest-btn {
    width: 100%;
    text-align: center;
    text {
      width: 318rpx;
      height: 67rpx;
      background: #3385ff;
      font-size: 28rpx;
      color: #fff;
      font-weight: 500;
      border-radius: 4rpx;
      line-height: 67rpx;
      margin: 90rpx auto 40rpx;
    }
  }
}
</style>
