<template>
  <view class="noauth-cont" v-if="jurisdictionList.HasPermission === 2 || jurisdictionList.HasPermission === 3 || jurisdictionList.HasPermission === 4 || jurisdictionList.HasPermission === 5">
    <block v-if="!isShowAlert">
      <image src="https://hzstatic.hzinsights.com/cygx/czbk/noauth.png" class="noauth-ico"></image>
      <block v-if="jurisdictionList.HasPermission == 3">
        <view class="tip">{{ jurisdictionList.PopupMsg }}</view>
        <view class="btn-cont" v-if="jurisdictionList.Type !== '专项调研'" @click="applyAuth"> 立即申请 </view>
      </block>
      <block v-if="jurisdictionList.HasPermission == 4 || jurisdictionList.HasPermission == 5">
        <view class="tip">{{ jurisdictionList.PopupMsg }}</view>
        <view class="btn-cont" v-if="jurisdictionList.Type !== '专项调研'" @click="applyAuth"> 立即申请 </view>
      </block>
      <view class="tip" v-if="jurisdictionList.HasPermission === 2">
        <block v-if="jurisdictionList.Type == '专项调研'"> 需要升级行业套餐权限才可参与此活动，请联系对口销售</block>
        <block v-else>
          <text style="margin-bottom: 20rpx"> 您暂无权限参加此活动 </text>
          <text>若想参加可以联系对口销售 </text>
          <text @click="callPhone(jurisdictionList.SellerMobile)" v-if="jurisdictionList.Type !== '专项调研'">
            {{ jurisdictionList.SellerName }}：
            <text style="color: #d4bf86; display: inline-block">{{ jurisdictionList.SellerMobile }}</text>
          </text>
          <text>申请开通对应的试用权限</text>
        </block>
      </view>
      <view v-if="jurisdictionList.HasPermission === 2 && jurisdictionList.Type !== '专项调研'" class="btn-cont" @click="sellerApplyAuth"> 立即申请 </view>
      <view class="btn-cont back-btn" @click="backIndex"> 返回</view>
    </block>
    <block v-else>
      <text class="moneh-text"> 上传名片并填写简单信息，24小时内我们会为您开通一个月的免费月卡 </text>
      <img src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/month_card.png" class="month_card" alt="" />
      <view class="btn-cont btn-dl" @click="applyAuth"> 立即上传 </view>
      <view class="btn-cont month-back" @click="backIndex"> 返回</view>
    </block>
  </view>
</template>

<script>
import { User, FreeButton } from "@/config/api.js";
export default {
  props: {
    jurisdictionList: {
      type: Object,
      required: true,
      default: {},
    },
    idAct: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      isShowAlert: false,
    };
  },
  methods: {
    /* 无权限申请开通权限 */
    applyAuth() {
      /* 区分是否是潜在用户 */
      this.jurisdictionList.HasPermission === 3
        ? uni.navigateTo({
            url: "/pageMy/applyTrial/applyTrial?tryType=Activity&detailId=" + this.idAct,
          })
        : this.jurisdictionList.HasPermission === 5
        ? this.sellerApplyAuth()
        : uni.showModal({
            title: "",
            content: "您已经提交过申请了，请耐心等待",
            showCancel: false,
            confirmColor: "#3385FF",
            success: function (res) {},
          });
    },
    //销售的立即申请
    sellerApplyAuth() {
      User.applyTry({
        TryType: "Activity",
        DetailId: this.idAct,
      }).then((res) => {
        if (res.Ret === 200) {
          uni.showModal({
            title: "",
            content: "提交申请成功，请耐心等待",
            showCancel: false,
            confirmColor: "#3385FF",
            success: function (res) {
              this.backIndex();
            },
          });
        }
      });
    },
    // 返回首頁
    backIndex() {
      uni.navigateBack({
        fail() {
          uni.switchTab({
            url: "/pages/index/index",
          });
        },
      });
    },
    callPhone(num) {
      uni.makePhoneCall({
        phoneNumber: num,
      });
    },
    //获取权限弹窗是否展示免费月卡接口
    async userIsShowAlert() {
      const res = await FreeButton.userIsShowAlert();
      if (res.Ret === 200) {
        this.isShowAlert = res.Data.IsShow;
      }
    },
  },
  mounted() {
    // 免费送月卡
    // this.userIsShowAlert();
  },
};
</script>

<style scoped lang="scss">
.noauth-cont {
  padding-top: 150rpx;
  text-align: center;
  font-size: 28rpx;

  .noauth-ico {
    width: 365rpx;
    height: 229rpx;
    margin-bottom: 70rpx;
  }

  .tip {
    width: 532rpx;
    margin: 0 auto 100rpx;

    .contract {
      padding: 40rpx 90rpx 0;
      line-height: 44rpx;

      text {
        display: inline-block;
      }
    }
  }

  .btn-cont {
    width: 368rpx;
    height: 80rpx;
    background: linear-gradient(268deg, #2ddbff 0%, #1599ff 49%, #005eff 100%);
    color: #fff;
    font-size: 34rpx;
    margin: 0 auto;
    text-align: center;
    line-height: 80rpx;

    &.back-btn {
      background: #fff !important;
      color: #2c83ff;
      border: 1px solid #2c83ff;
      margin-top: 30rpx;
    }

    .btn_bg {
      width: 100%;
      height: 80rpx;
      position: absolute;
      left: 0;
      top: 0;
    }

    .btn-txt {
      width: 100%;
      position: absolute;
      z-index: 1;
    }
  }
  .month_card {
    width: 100%;
    height: 565rpx;
    padding-left: -20rpx;
  }
  .btn-dl {
    background: linear-gradient(253deg, #fcf3e9 0%, #eedec8 100%) !important;
    color: #333 !important;
    margin: 30rpx auto !important;
  }
  .month-back {
    background: #f6f6f6 !important;
    color: #999 !important;
  }
  .moneh-text {
    text-align: center;
    width: 632rpx;
    margin: 0 auto 20rpx;
    color: #999999;
  }
}
</style>
