<template>
  <block>
    <view class="container reportDetail-container">
      <block v-if="haveAuth == 1">
        <web-view :src="strategyUrl + '&isBinding=' + isUserBindingPhoneNumber"> </web-view>
      </block>
      <view class="noauth-cont" v-else>
        <image src="https://hzstatic.hzinsights.com/cygx/czbk/noauth.png" class="noauth-ico"></image>
        <view class="noauth-title">暂无权限查看此文章</view>
        <view v-if="haveAuth == 6 || haveAuth == 7" class="tip">您可申请开通试用</view>
        <view class="tip" v-else> 点击提交申请，提醒对口销售为你开通试用 </view>
        <view class="btn-cont" @click="applyAuth"> 提交申请</view>
        <view class="btn-cont back-btn" @click="backIndex"> 返回 </view>
      </view>
    </view>
    <Loading />
  </block>
</template>

<script>
import { Report, User, Reports, FreeButton } from "@/config/api.js";
import freeCharge from "@/components/freeCharge";
import { ficcReport } from "@/config/config";
let app = getApp({ allowDefault: true });
export default {
  data() {
    return {
      readTiem: 0,
      access_token: "", //用户标识
      reportInfo: "",
      id: "",
      linkurl: "",
      setIntervalTiem: null,
      fileLink: false,
      isCollection: false,
      isInterviewApply: false,
      isShowTip: false,
      showNav: false,
      haveAuth: 1,
      isSendWx: "",
      lableListForm: {
        CategoryName: "",
        FieldName: "",
        Frequency: "月度",
        SubCategoryName: "渠道新声",
      },
      shareTitle: "",
    };
  },
  components: {
    freeCharge,
  },
  computed: {
    strategyUrl() {
      let token = this.$db.get("access_token");
      let link = `?id=${this.id}&fromType=mpwechat&token=${token}`;
      return ficcReport + link;
    },
  },
  methods: {
    /* 获取详情 */
    getDetail() {
      Reports.getFiccYbReportDetails({
        ReportId: this.id,
      }).then((res) => {
        if (res.Ret === 200) {
          this.haveAuth = res.Data.HasPermission;
          this.reportInfo = res.Data;
          this.shareTitle = this.reportInfo.report_info.title;
        }
      });
    },
    /* 无权限申请开通权限 */
    applyAuth() {
      /* 区分是否是潜在用户 */
      this.haveAuth === 3 || this.haveAuth === 5
        ? User.applyTry({
            ApplyMethod: 3,
            TryType: "ficcreport",
            DetailId: this.id,
          }).then((res) => {
            if (res.Ret === 200) {
              uni.navigateTo({
                url: "/pageMy/applyResult/applyResult",
              });
            }
          })
        : this.haveAuth === 7
        ? uni.navigateTo({
            url: "/pageMy/applyTrial/applyTrial?tryType=ficcreport&detailId=" + this.id,
          })
        : uni.showModal({
            title: "",
            content: "您已经提交过申请了，请耐心等待",
            showCancel: false,
            confirmColor: "#365595",
            success: function (res) {},
          });
    },

    // 返回首頁
    backIndex() {
      uni.navigateBack({
        fail() {
          uni.switchTab({
            url: "/pages/index/index",
          });
        },
      });
    },

    /* 错误 */
    errorDetails() {
      uni.showModal({
        confirmText: "知道了",
        showCancel: false,
        confirmColor: "#376cbb",
        content: "网络不好,请刷新重试",
        success: (res) => {
          uni.navigateBack({
            fail() {
              uni.switchTab({
                url: "/pages/index/index",
              });
            },
          });
        },
      });
    },
    Search() {
      uni.navigateTo({ url: "/pages-search/indedxSearch/indedxSearch?source=报告详情页面" });
    },

    setDisableCapture() {
      wx.setVisualEffectOnCapture({
        visualEffect: "hidden",
        complete: (res) => {
          console.log(res);
        },
      });
    },
    closeDisableCapture() {
      wx.setVisualEffectOnCapture({
        visualEffect: "none",
      });
    },
  },
  async onShow() {
    this.readTiem = 0;
    this.setIntervalTiem = setInterval(() => {
      this.readTiem++;
    }, 1000);
    let page = getCurrentPages(); //查看路径
    if (page.length === 1) {
      this.getDetail();
    } else {
      // 跳转入口
      this.id > 0 && this.getDetail();
    }
  },
  onLoad(option) {
    uni.setNavigationBarTitle({
      title: "报告详情",
    });
    this.id = option.id ? +option.id : "";
    this.isSendWx = option.IsSendWx || "";
    if (!this.id && !this.id > 0) {
      this.errorDetails();
    }
  },
  /**
   * 用户点击分享
   */
  onShareAppMessage: function (res) {
    if (this.id) {
      return {
        title: this.isHorzMobile ? "好友向您推荐此内容，上传名片享查研观向免费月卡！" : this.shareTitle,
        path: "/pages-ficc/reportDetail/reportDetail?id=" + this.id,
        success: (res) => {},
        fail: (err) => {},
      };
    }
  },
  onHide() {
    //页面退出
    if (this.id && this.id > 0) {
      clearInterval(this.setIntervalTiem);
      Reports.addStopTime({
        ArticleId: this.reportInfo.report_info.ArticleId,
        StopTime: this.readTiem,
        OutType: 2,
        Source: "MOBILE",
      }).then((res) => {});
    }
    this.closeDisableCapture();
  },
  onUnload() {
    if (this.id && this.id > 0) {
      //页面返回
      clearInterval(this.setIntervalTiem);
      Reports.addStopTime({
        ArticleId: this.reportInfo.report_info.ArticleId,
        StopTime: this.readTiem,
        OutType: 1,
        Source: "MOBILE",
      }).then((res) => {});
    }
    this.closeDisableCapture();
  },
};
</script>

<style lang="scss" scoped>
.reportDetail-container {
  background-color: #fff;

  .search-view {
    position: fixed;
    width: 100%;
    height: 60rpx;
    background: #fff;
    z-index: 99999;
    font-size: 24rpx;
    box-sizing: border-box;
    .search-view-box {
      display: flex;
      align-items: center;
      justify-content: center;
      background: #376cbb;
      color: #fff;
      height: 60rpx;
      z-index: 99999;
    }
    .search-icon {
      width: 147rpx;
      height: 40rpx;
      margin: 0 15rpx;
      z-index: 99999;
    }
  }
  .footer-con {
    position: fixed;
    z-index: 99999;
    bottom: 0;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    left: 0;
    width: 100%;
    background-color: #ffffff;
    display: flex;
    justify-content: space-around;
    height: 100rpx;
    border-top: 1px solid #dddddd;
    .handle-item {
      align-items: center;
      display: flex;
      flex-direction: column;
      justify-content: center;
      position: relative;
      z-index: 99999;
      .download-img {
        width: 44rpx;
        height: 44rpx;
        margin-bottom: 4rpx;
      }
    }
  }
  .footer-free-charge {
    .img {
      width: 156rpx;
      height: 156rpx;
    }
    .remove-icon {
      width: 31rpx;
      height: 31rpx;
      position: absolute;
      right: 0;
      top: 0;
    }
  }
  .noauth-cont {
    padding-top: 170rpx;
    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: 500rpx;
      height: 52rpx;
      background: $uni-color-new;
      color: #fff;
      font-size: 24rpx;
      font-weight: 600;
      border-radius: 8rpx;
      margin: 0 auto;
      text-align: center;
      line-height: 52rpx;
      &.back-btn {
        background: #e5efff !important;
        color: $uni-color-new;
        margin-top: 30rpx;
      }
      .btn_bg {
        width: 100%;
        height: 80rpx;
        position: absolute;
        left: 0;
        top: 0;
      }
      .btn-txt {
        width: 100%;
        position: absolute;
        z-index: 1;
      }
    }
    .product-introduction-box {
      background-color: $uni-bg-color;
      padding-top: 10rpx;
      margin-top: 60rpx;
      .product-introduction {
        padding: 60rpx 0 0 60rpx;
        background-color: white;
        .introduction-header {
          margin-bottom: 40rpx;
          display: flex;
          .introduction-header-left {
            background-color: #caaf8b;
            height: 90rpx;
            width: 14rpx;
            margin-right: 20rpx;
          }
          .introduction-header-right {
            text-align: left;
            .introduction-title-CN {
              font-weight: 500;
              font-size: 34rpx;
              color: #333333;
              line-height: 42rpx;
              margin-bottom: 8rpx;
            }
            .introduction-title-US {
              font-weight: 400;
              font-size: 28rpx;
              color: #c0c4cc;
              line-height: 42rpx;
            }
          }
        }
        .introduction-body {
          .introduction-body-box {
            text-align: left;
            margin-bottom: 40rpx;
            .body-row-content {
              margin-bottom: 40rpx;
              font-size: 34rpx;
              line-height: 48rpx;
              font-weight: 600;
              color: #caaf8b;
              .body-row-title {
                margin-left: 40rpx;
              }
            }
            .body-box-title {
              font-weight: 600;
              font-size: 34rpx;
              line-height: 48rpx;
              padding-left: 40rpx;
              position: relative;
              margin-bottom: 22rpx;
              &::before {
                content: "";
                height: 20rpx;
                width: 20rpx;
                background-color: #caaf8b;
                border-radius: 20rpx;
                position: absolute;
                left: 0;
                top: 16rpx;
              }
            }
            .introduction-body-row {
              margin-left: 40rpx;
              font-weight: 400;
              font-size: 26rpx;
              color: #333333;
              line-height: 36rpx;
            }
            .highHight-text {
              color: #caaf8b;
            }
          }
        }
      }
    }
  }
  .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;
  }
  .research-noauth {
    color: #333;
    font-size: 36rpx;
    width: calc(100% + 80rpx);
    margin-left: -40rpx;
    .strong-text {
      display: inline-block;
      padding: 0 10rpx;
      font-weight: 500;
    }
    text:last-child {
      font-size: 32rpx;
      font-size: 34rpx;
      color: #999999;
      margin-top: 10rpx;
    }
  }
}
.no-binding {
  padding: 30rpx;
  background-color: #f0f1f5;
  .lable-content {
    display: flex;
    flex-wrap: wrap;
    .item {
      font-size: 24rpx;
      height: 34rpx;
      padding: 0 16rpx;
      display: flex;
      align-items: center;
      border: 1rpx solid #ccc;
      border-radius: 2rpx;
      margin-right: 20rpx;
      margin-bottom: 20rpx;
    }
  }
  .no-binding-content {
    width: 100%;
    background-color: #fff;
    padding: 40rpx 20rpx;
    .title {
      font-size: 34rpx;
      font-weight: 500;
      line-height: 48rpx;
      color: #333;
    }
    .tiem {
      font-size: 24rpx;
      color: #999999;
      margin: 20rpx 0;
    }
    .content {
      display: flex;
      .content-line {
        width: 4rpx;
        background-color: #333;
        margin-right: 20rpx;
      }
      .content-text {
        font-size: 34rpx;
        font-weight: 500;
        color: #333;
      }
      .describe {
        margin-top: 20rpx;
      }
    }
  }
  .please-login {
    margin: 50rpx auto 150rpx;
    width: 556rpx;
    height: 64rpx;
    color: #fff;
    font-size: 24rpx;
    font-weight: 600;
    background-color: #376cbb;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9rpx;
  }
}
.noauth-title {
  font-size: 32rpx;
  font-weight: 600;
  margin-bottom: 15rpx;
}
</style>
