<template>
  <block>
    <view v-if="sourceType == '微信分享' && mixinIsSceneNumber == 1154" class="share-line-content">
      <view class="share-content-box">
        <view class="share-content">
          <image v-if="detailDataShare.TripStatus == 1" class="item-special" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/Ybm.png"></image>
          <image v-if="detailDataShare.TripStatus == 2" class="item-special" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/trip_icon.png"></image>
          <text class="share-title"> {{ detailDataShare.title }}</text>
          <view class="share-item" v-if="detailDataShare.time">
            <text>活动时间</text>
            <text>{{ detailDataShare.time }}</text>
          </view>
          <view class="share-item" v-if="detailDataShare.type">
            <text>调研形式</text>
            <text>{{ detailDataShare.type }}</text>
          </view>
          <view class="share-item" v-if="detailDataShare.label">
            <text>相关主题</text>
            <!-- <text>{{ detailDataShare.label }}</text> -->
            <rich-text :nodes="detailDataShare.label"></rich-text>
          </view>
        </view>
      </view>

      <image class="share-report-go_cygx_xcx" src="https://hzstatic.hzinsights.com/new_cygx/go_cygx_xcx.png"></image>
    </view>
    <block v-else>
      <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="#E37318" background="#FFF1E9" text="专项调研行程持续更新中，满五家即开团，欢迎点击感兴趣预报名" />
            </view>
            <view class="inform-btn" @click="specialFollow">{{ specialIsFollow ? "取消通知" : "新调研通知" }}</view>
          </view>
          <view class="content">
            <view class="reminder-item">
              <image v-if="detailData.TripStatus == 1" class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/Ybm.png"></image>
              <image v-if="detailData.TripStatus == 2" class="item" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/trip_icon.png"></image>
              <image v-if="detailData.Explain" @click="reminderTextHandler(detailData)" class="reminder" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/error-circle-filled.png"></image>
            </view>
            <view class="global_title content-title">{{ detailData.ResearchTheme }}</view>
            <view class="content-item">
              <view class="item-left">活动类型：</view>
              <view class="item-right">{{ detailData.ActivityTypeName }}</view>
            </view>
            <view class="content-item">
              <view class="item-left">所属行业：</view>
              <view class="item-right">{{ detailData.ChartPermissionName }}</view>
            </view>
            <view class="content-item" v-if="detailData.TripStatus == 2">
              <view class="item-left">开始时间：</view>
              <view class="item-right">{{ detailData.ActivityTimeTextByDay }}</view>
            </view>
            <view class="content-item" v-else>
              <view class="item-left">预期时间：</view>
              <view class="item-right">{{ detailData.ActivityTimeText }}</view>
            </view>
            <view class="content-item">
              <view class="item-left">调研形式：</view>
              <view class="item-right">
                {{ detailData.SpecialType == 1 ? "线上" : "线下" }}
                <block v-if="detailData.SpecialType == 2">({{ detailData.City }})</block>
              </view>
            </view>
            <block v-if="detailData.IndustrialName || detailData.IndustrialSubjectName">
              <view class="content-item">
                <view class="item-left">产业名称：</view>
                <view class="item-right">{{ detailData.IndustrialName }}</view>
              </view>
              <view class="content-item">
                <view class="item-left">相关公司：</view>
                <view class="item-right">{{ detailData.IndustrialSubjectName }}</view>
              </view>
            </block>
            <block v-else>
              <view class="content-item">
                <view class="item-left">相关主题：</view>
                <view class="item-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 class="global_content_center look-Trip" @click="lookImg"> 查看行程安排 > </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>
        <!-- 权限部分 -->
        <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>
        <Loading />
      </view>
      <not-have-login v-else />
    </block>
  </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: {},
      sourceType: "",
      detailDataShare: {},
    };
  },
  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: "#376cbb",
        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: "#376cbb",
          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_confirm_button = true;
          this.specialIsFollow = !this.specialIsFollow;
          this.specialGoFollowShow = true;
        }
      }
    },
  },
  onLoad(option) {
    this.id = option.id || "";
    this.sourceType = option.sourceType || "";
    this.detailDataShare = option.detailDataShare ? JSON.parse(decodeURIComponent(option.detailDataShare) || {}) : "";
    console.log(this.sourceType, this.detailDataShare);
  },
  onShow() {
    if (this.mixinIsSceneNumber == 1154) return;

    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) => {},
    };
  },
  /**
   * 用户点击分享朋友圈
   */
  onShareTimeline() {
    let shaerObj = {
      title: this.detailData.ResearchTheme,
      time: this.detailData.ActivityTimeTextByDay,
      type: `${this.detailData.SpecialType == 1 ? "线上" : "线下"}${this.detailData.SpecialType == 2 ? "(" + this.detailData.City + ")" : ""}`,
      label: this.detailData.Label,
      TripStatus: this.detailData.TripStatus,
    };
    let detailDataShare = JSON.stringify(shaerObj).replace(/%/g, "%25");
    return {
      title: this.detailData.ResearchTheme,
      query: "id=" + this.id + "&sourceType=微信分享&detailDataShare=" + encodeURIComponent(detailDataShare),
      imageUrl: this.detailData.ImgUrl,
    };
  },
};
</script>

<style lang="scss" scoped>
.special-detail {
  background-color: $uni-color-new;
  .top-notice-special {
    padding-right: 20rpx;
    background-color: #fff1e9;
    position: relative;
    display: flex;
    align-items: center;
    height: 60rpx;
    overflow: hidden;
    .notice {
      width: 80%;
    }
    .inform-btn {
      position: absolute;
      right: 20rpx;
      top: 50%;
      transform: translateY(-50%);
      width: 140rpx;
      height: 36rpx;
      background: #e37318;
      border-radius: 8rpx;
      text-align: center;
      line-height: 36rpx;
      font-size: 24rpx;
      color: #fff;
    }
  }
  .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 {
    margin: 30rpx 35rpx;
    background-color: #fff;
    padding: 30rpx;
    color: #333333;
    font-size: 28rpx;
    position: relative;
    border-radius: 16rpx;
    overflow: hidden;
    .content-title {
      margin: 20rpx 0 30rpx;
    }
    .content-item {
      display: flex;
      font-size: 28rpx;
      line-height: 40rpx;
      color: #333;
      margin-bottom: 20rpx;
      align-items: flex-start;
      vertical-align: text-top;
      .item-left {
        width: 140rpx;
        flex-shrink: 0;
      }
      .item-right {
        color: #333;
      }
    }
    .reminder-item {
      position: relative;
      margin: -30rpx 0 0 -30rpx;
      width: 176rpx;
      height: 48rpx;
      .item {
        width: 176rpx;
        height: 48rpx;
      }
      .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;
    }
  }
  .light-hint {
    color: #999;
    font-size: 24rpx;
  }
  .content-item {
    margin-bottom: 30rpx;
    padding: 0 !important;
    display: flex;
    .item-left {
      width: 160rpx;
      text-align-last: justify;
      text-align: justify;
    }
    .item-right {
      width: 480rpx;
    }
  }

  .look-Trip {
    margin: 50rpx auto;
    width: 188rpx;
    height: 42rpx;
    font-size: 24rpx;
    color: $uni-color-new;
    font-weight: 600;
    border-radius: 4rpx;
    background-color: #e5efff;
  }
  .interest-btn {
    width: 100%;
    text-align: center;
    text {
      width: 504rpx;
      height: 60rpx;
      background: $uni-color-new;
      font-size: 24rpx;
      color: #fff;
      font-weight: 600;
      border-radius: 8rpx;
      line-height: 60rpx;
      margin: 30rpx auto 40rpx;
    }
  }
  /deep/ .van-notice-bar {
    height: 62rpx;
  }
}
</style>
