<template>
  <block v-if="isUserBindingPhoneNumber">
    <block v-if="hasPermission === 1">
      <view class="container internal-detials" v-if="haveData">
        <web-view :src="linkurl + '?id=' + reportId + '&token=' + access_token"></web-view>
      </view>
      <view class="nodata" v-else>
        <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/report_loading_icon.png" class="nodata_img"></image>
        <view class="nodata-tip">正在努力编辑中，请耐心等待...</view>
      </view>
    </block>
    <view class="noauth-cont" v-else-if="hasPermission == 3 || hasPermission == 4">
      <block v-if="!isShowAlert">
        <image src="https://hzstatic.hzinsights.com/cygx/czbk/noauth.png" class="noauth-ico"></image>
        <block>
          <view class="tip">您暂无权限查看此文章内容，若想查看可以申请开通哦</view>
          <view class="btn-cont" @click="applyAuth"> 立即申请 </view>
        </block>
        <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>
    <Loading />
  </block>
  <not-have-login v-else />
</template>

<script>
import { Reports } from "@/config/api.js";
import statement from "@/reportPages/components/statement.vue";
import NotHaveLogin from "@/components/notHaveLogin.vue";
import { intemalLinkUrl } from "@/config/config.js";
export default {
  data() {
    return {
      reportDetail: {},
      isShowStatement: false,
      haveData: true,
      hasPermission: "",
      reportId: 0,
      titleTxT: "",
      access_token: "",
    };
  },
  computed: {
    linkurl() {
      return intemalLinkUrl;
    },
  },
  components: { statement, NotHaveLogin },
  methods: {
    async reportSelectionDetail() {
      const res = await Reports.getProductInteriorDetail({
        ProductInteriorId: this.reportId,
      });
      if (res.Ret === 200) {
        this.hasPermission = res.Data.HasPermission;
        this.reportDetail = res.Data.Detail;
        this.haveData = this.reportDetail ? true : false;
        this.titleTxT = this.reportDetail.ColumnName;
        uni.setNavigationBarTitle({
          title: this.titleTxT,
        });
        this.access_token = this.access_token || this.$db.get("access_token");
      } else {
        this.haveData = false;
      }
    },
    /* 无权限申请开通权限 */
    applyAuth() {
      this.hasPermission === 4
        ? uni.navigateTo({
            url: "/pageMy/applyTrial/applyTrial?tryType=ProductInterior&detailId=" + this.id,
          })
        : uni.showModal({
            title: "",
            content: "您已经提交过申请了，请耐心等待",
            showCancel: false,
            confirmColor: "#365595",
            success: function (res) {
              uni.navigateBack({
                fail() {
                  uni.switchTab({
                    url: "/pages/index/index",
                  });
                },
              });
            },
          });
    },
    // 去往不同的详情页
    goIsTypeDetails(item) {
      if (item.Type == 1) return;
      switch (item.Type) {
        case 2:
          uni.navigateTo({
            url: "/pageMy/reportDetail/reportDetail?id=" + item.SourceId,
          });
          break;
        case 3:
          uni.navigateTo({
            url: "/activityPages/activityDetail/activityDetail?id=" + item.SourceId,
          });
          break;
        case 4:
          uni.navigateTo({
            url: "/reportPages/IndustryReport/IndustryReport?id=" + item.SourceId,
          });
          break;
        default:
          "";
      }
    },
    // 返回首頁
    backIndex() {
      uni.switchTab({
        url: "/pages/index/index",
      });
    },
  },
  onLoad(options) {
    this.reportId = Number(options.id) || "";
    this.reportId > 0 && this.reportSelectionDetail();
  },
  onShareAppMessage() {
    return {
      title: this.titleTxT,
      path: "/reportPages/internalDetials/internalDetials?id=" + this.reportId,
    };
  },
};
</script>

<style lang="scss" scoped>
.internal-detials {
  padding: 30rpx 34rpx;
  color: #333;
  font-size: 28rpx;
  .author-time {
    display: flex;
    justify-content: space-between;
    line-height: 39rpx;
    margin: 25rpx 0 35rpx;
  }
  .content-statement {
    display: flex;
    color: #707070;
    .statement {
      margin-left: 10rpx;
      color: #3385ff;
    }
  }
  .content-abstract {
    position: relative;
    margin: 30rpx 0 20rpx;
    text-indent: 0.5em;
    line-height: 50rpx;
    padding-bottom: 30rpx;
    border-bottom: 1rpx dashed #ececec;
    &::before {
      content: "";
      width: 4rpx;
      height: 28rpx;
      position: absolute;
      top: 11rpx;
      left: 0;
      background-color: #3385ff;
    }
    // .abstract {
    //   display: inline-block;
    // }
  }
  .nodata-tip {
    color: #999;
    font-size: 30rpx;
  }
}
.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;
    // position: relative;
    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;
    }
  }
}
</style>
