<template>
  <div class="container">
    <!-- v-loading="loading" -->
    <!-- element-loading-text="页面加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#c9c0c0" -->
    <div class="topBox">
      <div class="olderVersion">
        <div class="titleBox">被征收人信息查询</div>
        <div v-if="mode == false" @click="toOlderMode()" class="mode">
          进入老年模式
        </div>
        <div v-else @click="toOlderMode()" class="mode">退出老年模式</div>
      </div>
      <div class="baseInfo">
        <img src="@/assets/img/renyuanliebiao.png" />
        <span>被征收人姓名：{{ data.userName }}</span>
      </div>
      <div class="baseInfo">
        <img src="@/assets/img/credentials_icon.png" />
        <span>身份证号码：</span>
        <div>{{ setIdCard(data.idCard) }}</div>
      </div>
      <!-- 三张背景图 -->
      <div class="gridBg">
        <div @click="scan()" style="background: #1897fb">
          <img src="@/assets/img/scan.png" />
          <span>扫一扫</span>
        </div>
        <div @click="gotoProject('pg')" style="background: #f1ae4b">
          <img src="@/assets/img/evaluation.png" />
          <span>查评估结果</span>
        </div>
        <div @click="gotoProject('xy')" style="background: #16d7ed">
          <img src="@/assets/img/compensation.png" />
          <span>查补偿协议</span>
        </div>
      </div>
    </div>
    <!-- 大背景图 -->
    <!-- <div class="bigImage">
      <img src="@/assets/img/government.png" />
    </div> -->
    <!-- 项目内容 -->
    <div :key="item.prjId" v-for="item in data.prjList">
      <div class="project">
        <!-- window图标 -->
        <div>
          <div class="projectIcon">
            <img src="@/assets/img/project.png" />
          </div>
          <span class="projectTitle">{{ item.name }}</span>
        </div>
        <!-- 补偿协议图标 -->
        <div class="projectRight">
          <div>
            <img src="@/assets/img/yhxy.png" />
          </div>
          <span>{{ item.currentState }}</span>
        </div>
      </div>
      <div class="projectCenter">
        <!-- 项目内容 -->
        <div class="projectCenterBox">
          <div>
            <div>
              <img src="@/assets/img/project_area.png" />
              <span>项目所在区域：</span>
            </div>
            <div>{{ item.area }}</div>
          </div>
          <div>
            <div>
              <img src="@/assets/img/project_dep.png" />
              <span>征收部门：</span>
            </div>
            <div>{{ item.zsbm }}</div>
          </div>
          <div>
            <div>
              <img src="@/assets/img/project_year.png" />
              <span>所属年份：</span>
            </div>
            <div>{{ item.year }}</div>
          </div>
          <div>
            <div>
              <img src="@/assets/img/project_no.png" />
              <span>征收决定号：</span>
            </div>
            <div class="blue">{{ item.zsjdh }}</div>
          </div>
        </div>
        <!-- 分户评估结果部分 -->
        <div class="assess">
          <van-image :src="require('@/assets/img/assess_1.png')" />
          <span>分户评估结果</span>
        </div>
        <div
          :key="assess.id"
          @click="toEvaluate(assess.id, assess.type)"
          class="assessCenter1"
          v-for="assess in item.fhpgList"
        >
          <div>
            <span>评估报告编号：</span>
            <span>{{ assess.assessmentNo }}</span>
          </div>
          <div>
            <span>被征收房屋地址：</span>
            <span>
              {{ assess.houseAddress }}
            </span>
          </div>
          <div>
            <span>评估总金额：</span>
            <span class="projectTitle" style="color: red"
              >¥{{ assess.countValue }}</span
            >
          </div>
        </div>
        <!-- 补偿协议部分 -->
        <div class="assess2">
          <van-image :src="require('@/assets/img/assess_2.png')" />
          <span>补偿结果</span>
        </div>
        <div
          :key="protocol.id"
          @click="toAgreement(protocol.id)"
          class="assessCenter2"
          v-for="protocol in item.bcxyList"
        >
          <div>
            <span>协议编号：</span>
            <span>{{ protocol.xyNo }}</span>
          </div>
          <div>
            <span>被征收房屋地址：</span>
            <span>
              {{ protocol.houseAddress }}
            </span>
          </div>
          <div>
            <span>补偿方式：</span>
            <span>
              {{ protocol.switchProductionWay }}
            </span>
          </div>
          <div>
            <span>合计补偿资金：</span>
            <span class="projectTitle" style="color: red"
              >¥{{ protocol.summationShouldCompensateMoney }}</span
            >
          </div>
        </div>
      </div>
    </div>
    <!-- 征收政策背景图 -->
    <!-- <div>
      <van-image :src="require('@/assets/img/expropriationPolicy.png')" />
    </div> -->
    <!-- 征收政策部分 -->
    <div class="zszc">
      <span>征收政策</span>
      <span>共{{ data.policiesRegulationsLists.totalCount }}条</span>
    </div>
    <div class="protocolBox">
      <div
        :key="i"
        @click="pageJump(item.id)"
        class="protocolList"
        v-for="(item, i) in data.policiesRegulationsLists.list"
      >
        <!-- 非最后一行有边框 -->
        <div
          style="border-bottom: 1px dashed #e8e9ec"
          v-if="i != data.policiesRegulationsLists.list.length - 1"
        >
          <div>{{ item.title }}</div>
          <div>
            <span>发布时间：{{ item.publicTime }}</span>
            <span>区域：{{ item.area }}</span>
          </div>
        </div>
        <!-- 最后一行无边框 -->
        <div v-else style="padding-bottom: 10px">
          <div>{{ item.title }}</div>
          <div>
            <span>发布时间：{{ item.publicTime }}</span>
            <span>区域：{{ item.area }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { apis } from "@/common/apis";
import { mgop } from "@aligov/jssdk-mgop";
import { SetTicket } from "@/common/util//tools";
import { changeStyle, recoverStyle } from "@/olderMode/1.js";
import $ from "jquery";
export default {
  name: "home",
  data() {
    return {
      mode: false,
      loading: true,
      data: {
        idCard: "无数据",
        userName: "无数据",
        policiesRegulationsLists: {
          totalCount: 0,
          list: [
            // {
            //   title: "无数据",
            //   publicTime: "无数据",
            //   area: "无数据"
            // },
            // { title: "无数据", publicTime: "无数据", area: "无数据" },
            // { title: "无数据", publicTime: "无数据", area: "无数据" }
          ]
        },
        prjList: [
          {
            // name: "无数据",
            // currentState: "无数据",
            // area: "无数据",
            // zsbm: "无数据",
            // year: "无数据",
            // zsjdh: "无数据",
            fhpgList: [
              // {
              //   assessmentNo: "无数据",
              //   houseAddress: "无数据",
              //   countValue: "无数据"
              // },
              // {
              //   assessmentNo: "无数据",
              //   houseAddress: "无数据",
              //   countValue: "无数据"
              // }
            ],
            bcxyList: [
              // {
              //   xyNo: "无数据",
              //   houseAddress: "无数据",
              //   switchProductionWay: "无数据",
              //   summationShouldCompensateMoney: "无数据"
              // },
              // {
              //   xyNo: "无数据",
              //   houseAddress: "无数据",
              //   switchProductionWay: "无数据",
              //   summationShouldCompensateMoney: "无数据"
              // }
            ]
          },
          {
            // name: "无数据",
            // currentState: "无数据",
            // area: "无数据",
            // zsbm: "无数据",
            // year: "无数据",
            // zsjdh: "无数据",
            fhpgList: [
              // {
              //   assessmentNo: "无数据",
              //   houseAddress: "无数据",
              //   countValue: "无数据"
              // }
            ],
            bcxyList: [
              // {
              //   xyNo: "无数据",
              //   houseAddress: "无数据",
              //   switchProductionWay: "无数据",
              //   summationShouldCompensateMoney: "无数据"
              // }
            ]
          }
        ]
      }
    };
  },
  created() {
    if (!this.$route.query.ticket) {
      window.location.replace(
        "https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=fwzs"
      );
    } else {
      this.onInit();
    }
    // this.onInit();
    this.setLocationAplus();
    SetTicket(this.$route.query.ticket);
    $(".logout").css("display", "none");
    if (sessionStorage.getItem("mode") == "older") {
      changeStyle();
      this.mode = true;
    } else {
      $("#app").addClass("old_app3");
    }
  },
  mounted() {
    if (sessionStorage.getItem("mode") == "older") {
      $(".container").addClass("old_container");
    }
  },
  methods: {
    // 获取数据
    onInit() {
      mgop({
        api: "mgop.kykj.houseexpropriat.getprjlist",
        host: "https://mapi.zjzwfw.gov.cn/",
        dataType: "JSON",
        type: "POST",
        data: {
          ticket: this.$route.query.ticket
        },
        appKey: "es4b8zmz+2001833218+dehllx",
        onSuccess: data => {
          this.loading = false;
          window.sessionStorage.setItem("homeData", JSON.stringify(data));
          if (data.data.success) {
            this.data = data.data.data;
            // 埋点
            this.setZwUserAplus(this.data.idCard, this.data.userName);
          } else {
            var errorCodes = [6001, 6501];
            // 跳转到政务系统;
            if (errorCodes.indexOf(data.data.bizCode) > -1) {
              this.$message({
                message: "登录超时，请重新登录",
                duration: 3000,
                type: "info",
                center: true
              });
              setTimeout(() => {
                window.location.replace(
                  "https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=fwzs"
                );
              }, 3000);
            } else {
              this.$message({
                message: "请求出错",
                duration: 3000,
                type: "error",
                center: true
              });
            }
          }
        },
        onFail: err => {
          this.loading = false;
          this.$notify({
            title: "错误",
            message: "请求失败",
            duration: 3000,
            type: "error"
          });
        }
      });
    },
    toOlderMode() {
      // 正常页面
      if (sessionStorage.getItem("mode") == "older") {
        sessionStorage.setItem("mode", "normal");
        this.$parent.$parent.mode = false;
        this.mode = false;
        recoverStyle();
      } else {
        // 老年化模式
        sessionStorage.setItem("mode", "older");
        this.$parent.$parent.mode = true;
        this.mode = true;
        changeStyle();
      }
    },
    setIdCard(id) {
      return id == "无数据"
        ? id
        : id.substr(0, 6) + "********" + id.substr(14, 4);
    },
    // 跳转选择项目
    gotoProject(type) {
      $(".logout").css("display", "block");
      $("#app").removeClass("old_app3");
      this.$router.push({
        name: "projectSelect",
        params: {
          type: type
        }
      });
    },
    // 直接跳转分户评估结果页面
    toEvaluate(id, type) {
      $(".logout").css("display", "block");
      $("#app").removeClass("old_app3");
      this.$router.push({
        name: "evaluatePage",
        params: {
          fhpgId: id,
          type
        }
      });
    },
    // 直接跳转协议结果pdf
    toAgreement(id) {
      $(".logout").css("display", "block");
      $("#app").removeClass("old_app3");
      this.$router.push({
        name: "showPdf",
        params: {
          id
        }
      });
    },
    // 加载项目数统计信息
    onLoadStatistic() {
      apis.projectStatistics().then(({ result }) => {
        this.statistics = result;
      });
    },
    // 政策信息页面跳转
    pageJump(id) {
      $(".logout").css("display", "block");
      $("#app").removeClass("old_app3");
      this.$router.push({
        name: "policyInfo",
        params: { id }
      });
    },
    setZwUserAplus(Userid, userName) {
      // 设置用户信息埋点
      aplus_queue.push({
        action: "aplus.setMetaInfo",
        arguments: ["_hold", "BLOCK"]
      });
      aplus_queue.push({
        action: "aplus.setMetaInfo",
        arguments: ["_user_nick", userName] // this.userInfoData.username],
      });
      aplus_queue.push({
        action: "aplus.setMetaInfo",
        arguments: ["_user_id", Userid]
      });
      aplus_queue.push({
        action: "aplus.setMetaInfo",
        arguments: ["_hold", "START"]
      });
    },
    setLocationAplus() {
      ZWJSBridge.onReady(() => {
        // console.log("初始化完成后，执行bridge方法");
        ZWJSBridge.getUserType()
          .then(result1 => {
            // console.log("getUserType():" + JSON.stringify(result1));
            // console.log("result1.userType:" + result1.userType);
            //经纬度
            ZWJSBridge.getLocation()
              .then(result2 => {
                // console.log("getLocation():" + JSON.stringify(result2));
                // console.log("result2.longitude:" + result2.longitude);
                // console.log("result2.latitude:" + result2.latitude);
                aplus_queue.push({
                  action: "aplus.sendPV",
                  arguments: [
                    {
                      is_auto: false
                    },
                    {
                      isMini: true,
                      miniAppId: "2001833218", //'应用开发管理平台-应用 ID
                      miniAppName: "房屋征收",
                      long: result2.longitude,
                      lati: result2.latitude,
                      userType: result1.userType
                    }
                  ]
                });
              })
              .catch(error => {
                // console.log(error);
              });
          })
          .catch(error => {
            // console.log(error);
          });
      });
    },
    scan() {
      //扫一扫
      ZWJSBridge.scan({ type: "qrCode" })
        .then(data => {
          // data =>{"text" : "扫描到的内容"}
          if (data.text.indexOf("http") > -1) {
            window.location.replace(data.text);
          } else {
            this.$message({
              message: data.text,
              duration: 3000,
              type: "info",
              center: true
            });
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  border-radius: 6px;
  background: #f6f7f8;
  padding-bottom: 20px;
  > div:nth-child(n + 2) {
    margin: 10px 12px 0 10px;
  }
}
// 最上面盒子
.topBox {
  background: url(../assets/img/bg.png) no-repeat;
  background-size: 100% 96%;
  .olderVersion {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    .titleBox {
      width: 173px;
      height: 36px;
      line-height: 36px;
      text-align: center;
      border-radius: 0 22px 22px 0;
      background: #2576ca;
      font-size: 16px;
      font-weight: 600;
      color: #ffffff;
    }
    :nth-child(2) {
      margin-right: 5px;
      background: #f82b36;
      width: 124px;
      height: 25px;
      text-align: center;
      line-height: 25px;
      border-radius: 2px;
      font-size: 18px;
      font-weight: 600;
      color: #ffffff;
    }
  }
  .baseInfo {
    display: flex;
    margin: 5px 0;
    align-items: center;
    color: #fff;
    img {
      height: 21px;
      padding-right: 10px;
      padding-left: 31px;
    }
    span:nth-child(2) {
      white-space: nowrap;
    }
    :nth-child(3) {
      padding-top: 1px;
    }
  }
  .gridBg {
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin: 10px 12px 0 10px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.28);
    > div {
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: center;
      width: 90px;
      height: 80px;
      margin: 20px 0 10px;
      border-radius: 10px;
      img {
        height: 35px;
      }
      span {
        padding-top: 5px;
        font-weight: 500;
        color: #fff;
      }
    }
  }
}
// 大背景图
.bigImage {
  img {
    width: 100%;
  }
}
// 项目部分
.project {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 41px;
  background: url(../assets/img/project_bg.png) no-repeat 0 -2px/101% 120%;
  > :nth-child(1) {
    display: flex;
    align-items: center;
    width: 50%;
    height: 100%;
    .projectIcon {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0 8px;
      height: 100%;
      margin-right: 10px;
      border-radius: 5px 0 0;
      background: #3284cd;
      img {
        width: 25px;
        height: 25px;
      }
    }
    span {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .projectRight {
    display: flex;
    align-items: center;
    height: 27px;
    > div {
      background: #24bca3;
      height: 100%;
      display: flex;
      align-items: center;
      border-radius: 13px 0 0 13px;
      img {
        width: 17px;
        margin-right: 3px;
        margin-left: 10px;
      }
    }
    span {
      font-size: 12px;
      font-weight: 600;
      padding-right: 10px;
      color: #fff;
      background: #24bca3;
      height: 27px;
      line-height: 27px;
    }
  }
}
.projectTitle {
  font-family: PingFangSC-Semibold, PingFang SC;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}
.projectCenter {
  padding-bottom: 25px;
  background: #fff;
  box-shadow: 0 2px 6px 1px rgba(212, 212, 212, 0.5);
  .projectCenterBox {
    > div {
      display: flex;
      align-items: flex-start;
      padding-top: 15px;
      line-height: 20px;
      > :nth-child(1) {
        display: flex;
        align-items: center;
        img {
          height: 22px;
          padding: 0 7px;
        }
        :nth-child(2) {
          font-weight: 400;
          color: #b3b5b9;
          width: 106px;
        }
      }
      > :last-child {
        color: #363a44;
        padding-top: 1px;
        // width: 55%;
      }
      .blue {
        color: #3883f1;
      }
    }
  }
  .assess {
    display: flex;
    align-items: center;
    height: 25px;
    padding: 25px 10px 0px;
    .van-image {
      width: 24px;
      height: 24px;
      margin-right: 10px;
      background: #2468f2;
    }
    span {
      font-family: PingFangSC-Regular, PingFang SC;
      font-size: 16px;
      font-weight: 400;
      color: #2468f2;
    }
  }
  .assessCenter1 {
    margin: 25px 16px 22px;
    border-left: 2px solid #24bca3;
    font-weight: 400;
    > div {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      padding-left: 12px;
      line-height: 20px;
      :nth-child(1) {
        white-space: nowrap;
        color: #b3b5b9;
      }
      :nth-child(2) {
        color: #363a44;
      }
    }
    > :nth-child(2) {
      margin: 15px 0;
    }
  }
  .assess2 {
    display: flex;
    align-items: center;
    height: 25px;
    padding: 0 10px;
    .van-image {
      width: 24px;
      height: 24px;
      margin-right: 10px;
      background: #2468f2;
    }
    span {
      font-size: 16px;
      font-weight: 400;
      color: #2468f2;
    }
  }
  .assessCenter2 {
    margin: 25px 16px 22px;
    border-left: 2px solid #ff5959;
    font-weight: 400;
    > div {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      padding-left: 12px;
      line-height: 20px;
      :nth-child(1) {
        white-space: nowrap;
        color: #b3b5b9;
      }
      :nth-child(2) {
        color: #363a44;
      }
    }
    > div:nth-child(n + 2) {
      margin: 15px 0;
    }
  }
}

// 征收政策部分
.zszc {
  span {
    font-size: 16px;
    font-weight: 800;
    color: #202020;
    display: block;
  }
  :nth-child(2) {
    margin: 10px 0;
    color: #2c2b2b;
    font-size: 12px;
  }
}

.protocolBox {
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 2px 5px 0 rgba(168, 168, 168, 0.5);
  .protocolList {
    padding: 0 20px;
    > div {
      > :nth-child(1) {
        font-size: 14px;
        font-weight: 400;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        color: #202020;
        padding-top: 20px;
      }
      > :nth-child(2) {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 18px 0;
        span {
          font-size: 12px;
          color: #9da2a3;
          font-weight: 400;
        }
      }
    }
  }
}
// 老年化
.old_container {
  .olderVersion {
    .titleBox {
      font-size: 24px;
      width: 228px;
      height: 41px;
      line-height: 41px;
    }
  }
  .baseInfo {
    align-items: flex-start;
    font-size: 22px;
    line-height: 30px;
    img {
      height: 30px;
      padding-left: 15px;
    }
    > div:nth-child(3) {
      word-break: break-all;
      padding-top: 2px;
    }
  }
  .gridBg {
    margin-left: 4px;
    margin-right: 4px;
    font-size: 20px;
    > div {
      width: 110px;
      height: 100px;
      img {
        height: 55px;
      }
    }
  }
  .project {
    display: unset;
    .projectTitle {
      font-size: 24px;
    }
    > :nth-child(1) {
      display: flex;
      align-items: center;
      height: 41px;
      padding: unset 0;
      width: 100%;
      background: url(../assets/img/project_bg.png);
      background-position: 0 -2px;
      background-size: 100% 120%;
    }
    .projectRight {
      margin-top: 10px;
      height: 27px;
      > :nth-child(1) {
        border-radius: unset !important;
        padding-right: 5px;
      }
      > span {
        font-size: 20px;
        border-radius: 0px 13px 13px 0px;
      }
    }
  }
  .projectCenterBox {
    font-size: 20px;
    > div {
      line-height: 28px;
      > :nth-child(1) {
        :nth-child(2) {
          width: unset !important;
          white-space: nowrap;
        }
      }
      > :last-child {
        width: unset;
      }
    }
  }
  .assess,
  .assess2 {
    span {
      font-size: 22px;
    }
  }
  .assessCenter1,
  .assessCenter2 {
    font-size: 20px;
    > div {
      line-height: 28px;
    }
    .projectTitle {
      font-size: 20px;
    }
  }
  .zszc {
    display: flex;
    justify-content: space-between;
    align-items: center;
    > :nth-child(1) {
      font-size: 20px;
    }
    > :nth-child(2) {
      font-size: 18px;
    }
  }
  .protocolList {
    > div {
      > :nth-child(1) {
        font-size: 20px !important;
        line-height: 28px;
        padding-top: 15px !important;
        white-space: unset !important;
      }
      > :nth-child(2) {
        display: block !important;
        padding: 15px 0 5px !important;
        span {
          font-size: 18px !important;
          display: block;
          height: unset !important;
        }
        > span:nth-child(2) {
          padding-top: 5px;
        }
      }
    }
  }
}
</style>
