<template>
  <block>
    <view class="container reportDetail-container">
      <block v-if="haveAuth === 1">
        <!-- 链接地址 -->
        <web-view :src="linkurl + '?id=' + id + '&fromType=mpwechat&token=' + access_token + '&IsSendWx=' + isSendWx + '&isBinding=' + isUserBindingPhoneNumber"></web-view>
      </block>
      <view class="noauth-cont" v-else-if="haveAuth === 2 || haveAuth === 3 || haveAuth === 4 || haveAuth === 5">
        <block v-if="isSpecialArticle_report">
          <image src="https://hzstatic.hzinsights.com/cygx/czbk/noauth.png" class="noauth-ico"></image>
          <view class="tip" v-if="haveAuth === 3">
            需要升级行业套餐权限才可查看此报告,请联系对口销售
            <view class="btn-cont back-btn" @click="backIndex"> 返回 </view>
          </view>
        </block>
        <block v-else>
          <block v-if="!isShowAlert">
            <image src="https://hzstatic.hzinsights.com/cygx/czbk/noauth.png" class="noauth-ico"></image>
            <block v-if="haveAuth !== 3">
              <view v-if="reportInfo.IsResearch" class="research-noauth">
                暂无 <text class="strong-text">买方研选</text> 权限
                <text style="margin-bottom: 30rpx"> 您可申请开通试用 </text>
              </view>
              <view class="tip" v-else>您暂无权限查看此报告内容,若想查看可以申请开通对应的试用权限</view>
              <view class="btn-cont" @click="applyAuth">{{ isShowAlert ? "立即上传" : "立即申请" }} </view>
            </block>
            <view class="tip" v-if="haveAuth === 3">
              <view v-if="reportInfo.IsResearch" class="research-noauth">
                暂无 <text class="strong-text">买方研选</text> 权限
                <text> 点击提交申请,提醒对口销售为你开通试用 </text>
              </view>
              <block v-else>
                您暂无权限查看此报告内容
                <view class="contract">
                  若想查看可以联系对口销售
                  <text @click="callPhone(reportInfo.SellerMobile)">
                    {{ reportInfo.SellerName }}:<text style="color: #d4bf86">{{ reportInfo.SellerMobile }}</text>
                  </text>
                </view>
                <view>申请开通对应的试用权限</view>
              </block>
            </view>
            <view v-if="haveAuth === 3" class="btn-cont" @click="sellerApplyAuth"> {{ isShowText ? "提交申请" : "立即申请" }}</view>
            <view class="btn-cont back-btn" @click="backIndex"> 返回 </view>
            <view class="product-introduction-box" v-if="reportInfo.IsResearch">
              <view class="product-introduction">
                <view class="introduction-header">
                  <view class="introduction-header-left"></view>
                  <view class="introduction-header-right">
                    <view class="introduction-title-CN"> 产品介绍 </view>
                    <view class="introduction-title-US"> Product Introduction </view>
                  </view>
                </view>
                <view class="introduction-body">
                  <view class="introduction-body-box">
                    <view class="body-box-title"> 独家亮点 </view>
                    <view class="introduction-body-row"><span class="highHight-text">市场低价访谈优质专家 </span></view>
                    <view class="introduction-body-row">重点公司小范围交流<span class="highHight-text">破圈</span>参加</view>
                    <view class="introduction-body-row"><span class="highHight-text">海量</span>调研过程及纪要共享</view>
                  </view>
                  <view class="introduction-body-box">
                    <view class="body-box-title"> 优质资源 </view>
                    <view class="introduction-body-row"><span class="highHight-text">500+</span>篇/年调研纪要更新</view>
                    <view class="introduction-body-row"><span class="highHight-text">300+</span>场/年海内外重点公司小范围交流</view>
                    <view class="introduction-body-row"><span class="highHight-text">100+</span>场/年热点线下调研</view>
                    <view class="introduction-body-row"><span class="highHight-text">30000+</span>名优质行业专家长期合作</view>
                  </view>
                  <view class="introduction-body-box">
                    <view class="body-box-title" style="margin-bottom: 18rpx"> 服务报价 </view>
                    <view class="body-row-content">
                      <view class="body-row-title"> 订阅包:3万/年 </view>
                      <view class="introduction-body-row">无限量调研纪要及常规研选专栏查阅,公开活动参与</view>
                    </view>
                    <view class="body-row-content">
                      <view class="body-row-title"> 扣点包:5万/年 </view>
                      <view class="introduction-body-row">低至2000元/场专家、同业访谈</view>
                      <view class="introduction-body-row">1000元/场重点公司小范围交流</view>
                    </view>
                    <view style="font-size:26rpx">欢迎联系买方研选,了解更多服务详情,获取试用体验</view>
                  </view>
                </view>
              </view>
            </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>
        </block>
      </view>
    </view>
    <Loading />
  </block>
</template>

<script>
import { Report, User, Reports, FreeButton } from "@/config/api.js";
import { reportLinkUrl } from "@/config/config";
import notHaveLogin from "@/components/notHaveLogin.vue";
export default {
  components: { notHaveLogin },
  data() {
    return {
      access_token: "", //用户标识
      reportInfo: "",
      id: "",
      readTiem: 0,
      setIntervalTiem: null,
      isShowAlert: false,
      haveAuth: false,
      isSpecialArticle_report: false,
      isSendWx: "",
    };
  },
  computed: {
    linkurl() {
      return reportLinkUrl;
    },
    isShowText() {
      return this.haveAuth === 3 && this.reportInfo.IsResearch;
    },
  },
  methods: {
    /* 获取详情 */
    getDetail() {
      Report.reportDtl({
        ArticleId: this.id,
        PageRouter: this.$store.state.pageRouterReport,
        IsSendWx: this.isSendWx,
      }).then((res) => {
        if (res.Ret === 200) {
          this.$store.commit("setRouterReport", "报告详情");
          uni.setNavigationBarTitle({
            title: res.Data.Detail.IsSummary == 1 ? "纪要详情" : "报告详情",
          });
          this.haveAuth = res.Data.HasPermission;
          this.isShowWriter = res.Data.IsShow;
          this.isSpecialArticle_report = res.Data.IsSpecialArticle;
          this.reportInfo = res.Data.Detail;
          if (res.Data.HasPermission === 1) {
            //有访问权限
            if (res.Data.Detail.IsNeedJump) {
              uni.redirectTo({
                url: "/pageMy/reportPage/reportPage?id=" + this.id + "&IsSendWx=" + this.isSendWx,
              });
            }
            this.access_token = this.access_token || this.$db.get("access_token");
            this.$store.dispatch("statistics", { PageType: "ReportParticulars", DetailId: this.id + "" });
          }
        }
      });
    },

    /* 无权限申请开通权限 */
    applyAuth() {
      /* 区分是否是潜在用户 */
      this.haveAuth === 2
        ? User.applyTry({
            ApplyMethod: 3,
            TryType: "Article",
            DetailId: this.id,
          }).then((res) => {
            if (res.Ret === 200) {
              uni.navigateTo({
                url: "/pageMy/applyResult/applyResult",
              });
            }
          })
        : this.haveAuth === 4
        ? uni.navigateTo({
            url: "/pageMy/applyTrial/applyTrial?tryType=Article&detailId=" + this.id,
          })
        : uni.showModal({
            title: "",
            content: "您已经提交过申请了,请耐心等待",
            showCancel: false,
            confirmColor: "#365595",
            success: function (res) {},
          });
    },

    // 销售的立即申请
    sellerApplyAuth() {
      User.applyTry({
        TryType: "Article",
        DetailId: this.id,
      }).then((res) => {
        if (res.Ret === 200) {
          uni.showModal({
            title: "",
            content: "提交申请成功,请耐心等待",
            showCancel: false,
            confirmColor: "#365595",
            success: function (res) {
              this.backIndex();
            },
          });
        }
      });
    },

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

    // 拨打电话
    callPhone(num) {
      uni.makePhoneCall({
        phoneNumber: num,
      });
    },

    /* 申请访谈 */
    applyHandle() {
      // 申请访谈
      !this.reportInfo.IsInterviewApply &&
        this.$util.modal("", "专家访谈申请会提交给您的对口销售,销售会线下与您取得联系,确定申请吗?", () => {
          this.interviewApi();
        });
      // 取消申请访谈 区分状态 '待邀请','待访谈','已完成','已取消'
      if (this.reportInfo.IsInterviewApply) {
        // this.reportInfo.InterviewApplyStatus
        this.$util.modal(
          "",
          this.reportInfo.InterviewApplyStatus == "待访谈"
            ? "当前无法取消访谈,若有疑问,请联系对口销售"
            : this.reportInfo.InterviewApplyStatus == "待邀请"
            ? "您要取消此次访谈申请吗?"
            : "该访谈已完成",
          () => {
            this.reportInfo.InterviewApplyStatus == "待邀请"
              ? this.interviewApi()
              : this.reportInfo.InterviewApplyStatus == "待访谈"
              ? uni.makePhoneCall({
                  phoneNumber: "18767183922",
                })
              : "";
          }
        );
      }
    },

    /* 访谈接口 */
    interviewApi() {
      Report.applyRpt({
        ArticleId: this.id,
      }).then((res) => {
        this.reportInfo.IsInterviewApply = !this.reportInfo.IsInterviewApply;
      });
    },

    /* 收藏 */
    collectHandle() {
      Report.collectRpt({
        ArticleId: this.id,
        PageRouter: this.$store.state.pageRouterReport,
      }).then((res) => {
        this.reportInfo.IsCollect = !this.reportInfo.IsCollect;
        this.$util.toast(res.Msg);
      });
    },

    /* 错误 */
    errorDetails() {
      uni.showModal({
        confirmText: "知道了",
        showCancel: false,
        confirmColor: "#376cbb",
        content: "网络不好,请刷新重试",
        success: (res) => {
          uni.navigateBack({
            fail() {
              uni.switchTab({
                url: "/pages/index/index",
              });
            },
          });
        },
      });
    },

    // 获取权限弹窗是否展示免费月卡接口
    async userIsShowAlert() {
      const res = await FreeButton.userIsShowAlert();
      if (res.Ret === 200) {
        this.isShowAlert = res.Data.IsShow;
      }
    },
    /* 跳转研选 */
    goRouterResearch(type) {
      if (type == "介绍") {
        uni.navigateTo({
          url: "/pages-purchaser/productIntroduction/productIntroduction",
        });
      } else {
        uni.navigateTo({
          url: "/pages-purchaser/ProductQuotation/ProductQuotation",
        });
      }
    },
  },
  async onShow() {
    this.readTiem = 0;
    this.setIntervalTiem = setInterval(() => {
      this.readTiem++;
    }, 1000);
    let page = getCurrentPages(); //查看路径
    if (page.length === 1) {
      if (!this.$store.state.isAuth && !this.$store.state.isBind && this.id > 0) this.getDetail();
    } else {
      // 跳转入口
      this.id > 0 && this.getDetail();
    }
  },
  onLoad(option) {
    this.id = option.id ? +option.id : "";
    this.isSendWx = option.IsSendWx || "";
    if (!this.id && !this.id > 0) {
      this.errorDetails();
    }

    // 免费送月卡
    // this.userIsShowAlert();
  },
  /**
   * 用户点击分享
   */
  onShareAppMessage: function (res) {
    if (this.id) {
      return {
        title: this.isHorzMobile ? "好友向您推荐此内容,上传名片享查研观向免费月卡!" : this.reportInfo.Title,
        path: "/pageMy/reportDetail/reportDetail?id=" + this.id,
        success: (res) => {},
        fail: (err) => {},
      };
    }
  },
  onHide() {
    //页面退出
    if (this.id && this.id > 0) {
      clearInterval(this.setIntervalTiem);
      Reports.addStopTime({
        ArticleId: this.id,
        StopTime: this.readTiem,
        OutType: 2,
        Source: "MOBILE",
      }).then((res) => {});
    }
  },
  onUnload() {
    if (this.id && this.id > 0) {
      //页面返回
      clearInterval(this.setIntervalTiem);
      Reports.addStopTime({
        ArticleId: this.id,
        StopTime: this.readTiem,
        OutType: 1,
        Source: "MOBILE",
      }).then((res) => {});
    }
  },
};
</script>

<style lang="scss" scoped>
.reportDetail-container {
  background-color: #fff;
  padding: 20rpx 0 134rpx;
  .report-top {
    color: #999999;
    .report-title {
      color: #4a4a4a;
      font-size: 34rpx;
    }
    .report_desc {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin: 20rpx 0;
    }
    .tip {
      color: #586eb5;
      display: inline;
    }
  }
  .detail-report {
    padding: 40rpx 0;
  }
  .statement {
    max-width: 670rpx;
    max-height: 900rpx;
    line-height: 42rpx;
    overflow-y: auto;
    padding: 40rpx;
  }
  .fixed_cont {
    width: 100%;
    // height: 114rpx;
    padding: 10rpx 0;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: row;
    background-color: #fff;
    box-shadow: 0 -3rpx 6rpx rgba($color: #6a6a6a, $alpha: 0.16);
    .handle-item {
      font-size: 24rpx;
      color: #d0cfd5;
      text-align: center;
      margin-right: 130rpx;
      &:last-child {
        margin-right: 0;
      }
      .img_ico {
        width: 56rpx;
        height: 54rpx;
        margin: 0 auto;
      }
    }
    .button-item {
      background-color: transparent;
      line-height: normal;
    }
  }
  .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;
    }
  }
  // .research-btn {
  //   display: flex;
  //   align-items: center;
  //   font-size: 32rpx;
  //   width: 546rpx;
  //   height: 78rpx;
  //   margin: 30rpx auto;
  //   background: #f8f8fa;
  //   border-radius: 4rpx;
  //   padding-left: 40rpx;
  //   /* 字体/333 */
  //   image {
  //     width: 40rpx;
  //     height: 40rpx;
  //     margin-right: 10rpx;
  //   }
  // }
}
</style>