<template>
  <div class="g-cpt">
    <div class="g-l">
      <div class="m-people">
        <cpt-card>
          <div class="title">
            <img src="@/assets/img/shuju/title-tip.png" />
            <span>人员情况</span>
          </div>
          <div class="more" @click="showedMoreInfo = true">查看更多</div>
          <div class="ren">
            <img class="pic-ren" src="@/assets/img/shuju/people/ren.png" />
            <div class="ren-name">
              <span>{{ info.name }}</span>
              <img src="@/assets/img/shuju/people/arrow.png" />
            </div>
            <div class="ren-prop z-1">
              <img src="@/assets/img/shuju/people/ren-prop-1.png" />
              <span>所属网格</span>

              <div class="ren-cnt">
                <h5>所属网格：</h5>
                <p>
                  {{ info.gridName }}
                </p>
              </div>
            </div>

            <div class="ren-prop z-2">
              <img src="@/assets/img/shuju/people/ren-prop-2.png" />
              <span>人员类别</span>

              <div class="ren-cnt">
                <h5>人员类别：</h5>
                <p>
                  {{
                    info.personCategory.length == 0
                      ? "--"
                      : info.personCategory.join("、")
                  }}
                </p>
              </div>
            </div>

            <div class="ren-prop z-3">
              <img src="@/assets/img/shuju/people/ren-prop-3.png" />
              <span>工作单位</span>

              <div class="ren-cnt">
                <h5>工作单位：</h5>
                <p>
                  {{ info.workUnit || "--" }}
                </p>
              </div>
            </div>

            <div class="ren-prop z-4">
              <img src="@/assets/img/shuju/people/ren-prop-4.png" />
              <span>志愿者类别</span>

              <div class="ren-cnt">
                <h5>志愿者类别：</h5>
                <p>
                  {{
                    info.volunteerCategory.length == 0
                      ? "--"
                      : info.volunteerCategory.join("、")
                  }}
                </p>
              </div>
            </div>

            <div class="ren-prop z-5">
              <img src="@/assets/img/shuju/people/ren-prop-5.png" />
              <span>房屋信息</span>

              <div class="ren-cnt">
                <h5>房屋信息：</h5>
                <p>
                  {{
                    info.houseInfo.length == 0
                      ? "--"
                      : info.houseInfo.join("、")
                  }}
                </p>
              </div>
            </div>

            <div class="ren-prop z-6">
              <img src="@/assets/img/shuju/people/ren-prop-6.png" />
              <span>经济状况</span>

              <div class="ren-cnt">
                <h5>经济状况：</h5>
                <p>
                  月薪:
                  {{
                    info.financialSituation.monthlyIncome || "--"
                  }}，退休金：{{
                    info.financialSituation.retirementAmount || "--"
                  }}
                </p>
              </div>
            </div>
          </div>
        </cpt-card>
      </div>

      <people-more
        v-show="showedMoreInfo"
        v-if="userId"
        :userId="userId"
        :gridName="info.gridName"
        @close="showedMoreInfo = false"
      />

      <div class="m-relation">
        <cpt-card>
          <div class="title">
            <img src="@/assets/img/shuju/title-tip.png" />
            <span>家庭关系</span>
          </div>
          <div class="info">
            <div class="huzhu">
              <img class="huzhu-bg" src="@/assets/img/shuju/people/huzhu.png" />
              <img
                class="huzhu-ico"
                src="@/assets/img/shuju/people/huzhu-home.png"
              />
              <div class="huzhu-name">{{ houseInfo.ownerName }}</div>
              <p>（户主）</p>
            </div>

            <div
              class="rel z-zuo-2"
              @click="userId = houseInfo.userList[0].userId"
              v-if="houseInfo.userList[0]"
            >
              <img
                class="rel-bg"
                src="@/assets/img/shuju/people/huzhu-kuang-zuo.png"
              />
              <img
                class="rel-line"
                src="@/assets/img/shuju/people/huzhu-line/zuo2.png"
              />
              <div
                class="rel-text"
                :class="houseInfo.userList[0].isSelf == '1' ? 'z-on' : ''"
              >
                <span class="rel-call">{{
                  houseInfo.userList[0].relation
                }}</span>
                <span class="rel-name"
                  >（{{ houseInfo.userList[0].userName }}）</span
                >
              </div>
            </div>

            <div
              class="rel z-you-2"
              @click="userId = houseInfo.userList[1].userId"
              v-if="houseInfo.userList[1]"
            >
              <img
                class="rel-bg"
                src="@/assets/img/shuju/people/huzhu-kuang-you.png"
              />
              <img
                class="rel-line"
                src="@/assets/img/shuju/people/huzhu-line/you2.png"
              />
              <div
                class="rel-text"
                :class="houseInfo.userList[1].isSelf == '1' ? 'z-on' : ''"
              >
                <span class="rel-call">{{
                  houseInfo.userList[1].relation
                }}</span>
                <span class="rel-name"
                  >（{{ houseInfo.userList[1].userName }}）</span
                >
              </div>
            </div>

            <div
              class="rel z-zuo-1"
              @click="userId = houseInfo.userList[2].userId"
              v-if="houseInfo.userList[2]"
            >
              <img
                class="rel-bg"
                src="@/assets/img/shuju/people/huzhu-kuang-zuo.png"
              />
              <img
                class="rel-line"
                src="@/assets/img/shuju/people/huzhu-line/zuo1.png"
              />
              <div
                class="rel-text"
                :class="houseInfo.userList[2].isSelf == '1' ? 'z-on' : ''"
              >
                <span class="rel-call">{{
                  houseInfo.userList[2].relation
                }}</span>
                <span class="rel-name"
                  >（{{ houseInfo.userList[2].userName }}）</span
                >
              </div>
            </div>

            <div
              class="rel z-you-1"
              @click="userId = houseInfo.userList[3].userId"
              v-if="houseInfo.userList[3]"
            >
              <img
                class="rel-bg"
                src="@/assets/img/shuju/people/huzhu-kuang-you.png"
              />
              <img
                class="rel-line"
                src="@/assets/img/shuju/people/huzhu-line/you1.png"
              />
              <div
                class="rel-text"
                :class="houseInfo.userList[3].isSelf == '1' ? 'z-on' : ''"
              >
                <span class="rel-call">{{
                  houseInfo.userList[3].relation
                }}</span>
                <span class="rel-name"
                  >（{{ houseInfo.userList[3].userName }}）</span
                >
              </div>
            </div>

            <div
              class="rel z-zuo-3"
              @click="userId = houseInfo.userList[4].userId"
              v-if="houseInfo.userList[4]"
            >
              <img
                class="rel-bg"
                src="@/assets/img/shuju/people/huzhu-kuang-zuo.png"
              />
              <img
                class="rel-line"
                src="@/assets/img/shuju/people/huzhu-line/zuo3.png"
              />
              <div
                class="rel-text"
                :class="houseInfo.userList[4].isSelf == '1' ? 'z-on' : ''"
              >
                <span class="rel-call">{{
                  houseInfo.userList[4].relation
                }}</span>
                <span class="rel-name"
                  >（{{ houseInfo.userList[4].userName }}）</span
                >
              </div>
            </div>

            <div
              class="rel z-you-3"
              @click="userId = houseInfo.userList[5].userId"
              v-if="houseInfo.userList[5]"
            >
              <img
                class="rel-bg"
                src="@/assets/img/shuju/people/huzhu-kuang-you.png"
              />
              <img
                class="rel-line"
                src="@/assets/img/shuju/people/huzhu-line/you3.png"
              />
              <div
                class="rel-text"
                :class="houseInfo.userList[5].isSelf == '1' ? 'z-on' : ''"
              >
                <span class="rel-call">{{
                  houseInfo.userList[5].relation
                }}</span>
                <span class="rel-name"
                  >（{{ houseInfo.userList[5].userName }}）</span
                >
              </div>
            </div>
          </div>
        </cpt-card>
      </div>
    </div>
    <div class="g-r"></div>
  </div>
</template>

<script>
import { Loading } from "element-ui"; //引入Loading服务
import { requestPost } from "@/js/dai/request";
import cptCard from "@/views/modules/visual/cpts/card";
import peopleMore from "@/views/modules/visual/basicinfo/cpts/people-more";

export default {
  name: "HomeMap",
  data() {
    return {
      showedMoreInfo: false,

      userId: "",

      info: {
        financialSituation: { monthlyIncome: "", retirementAmount: "" },
        gridName: "",
        houseInfo: [],
        name: "",
        personCategory: [],
        volunteerCategory: [],
        workUnit: "",
      },

      houseInfo: {
        ownerName: "",
        userList: [
          // {
          //   userId: "",
          //   userName: "",
          //   isSelf: "",
          //   relation: "",
          // },
        ],
      },
    };
  },

  props: {
    uid: {
      type: String,
      default: "",
      // default: "8ada68cb6f1e4b9a8333348a39ef3aee",
    },
  },

  computed: {},

  components: {
    cptCard,
    peopleMore,
  },

  watch: {
    uid(id) {
      this.userId = id;
    },
    userId() {
      this.getApiData();
    },
  },

  async mounted() {
    this.userId = this.uid;
    this.getApiData();
  },

  methods: {
    handleSearch() {},

    getApiData() {
      this.getInfo();
      this.getHouseInfo();
    },

    //加载组织数据
    async getInfo() {
      const url = "/epmetuser/icresiuser/persondata";
      let params = {
        userId: this.userId,
      };

      const { data, code, msg } = await requestPost(url, params);

      if (code === 0) {
        this.info = { ...this.info, ...data };
      } else {
        this.$message.error(msg);
      }
    },

    //加载组织数据
    async getHouseInfo() {
      const url = "/epmetuser/icresiuser/ownerrelation";
      let params = {
        userId: this.userId,
      };

      const { data, code, msg } = await requestPost(url, params);

      if (code === 0) {
        this.houseInfo = { ...this.houseInfo, ...data };
      } else {
        this.$message.error(msg);
      }
    },
  },
};
</script>

<style lang="scss" src="@/assets/scss/people.scss" scoped></style>
