<template>
  <section class="AppResident">
    <ai-list v-if="!showDetail" isTabs>
      <ai-title slot="title" title="居民档案" :instance="instance" :hideLevel="hideLevel-1" isShowArea
                v-model="areaId"/>
      <template #tabs>
        <el-tabs v-model="activeName">
          <el-tab-pane v-for="op in tabs" :key="op.value" :name="op.value" :label="op.label">
            <component v-if="op.value==activeName" :is="op.comp" :areaId="areaId" :active="activeName"/>
          </el-tab-pane>
        </el-tabs>
      </template>
    </ai-list>
    <component v-else :is="detailComponent" :instance="instance" :dict="dict" :permissions="permissions"/>
  </section>
</template>
<script>
import {mapState} from "vuex";
import localResident from "./localResident";
import ListTpl from "./listTpl";
import MobileResident from "./mobileResident";
import ResidentSta from "./residentSta";

export default {
  name: "AppResident",
  label: "居民档案",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function,
  },
  provide() {
    return {
      resident: this
    }
  },
  components: {ResidentSta, MobileResident, ListTpl, localResident},
  computed: {
    ...mapState(["user"]),
    tabs() {
      let details = {
        "本地居民": localResident,
        "流动人员": MobileResident,
      }
      return [
        ...this.dict.getDict('residentType').map(e => ({
          label: e.dictName,
          value: e.dictValue,
          comp: ListTpl,
          detail: details[e.dictName]
        })),
        {label: "居民统计", value: "3", comp: ResidentSta},
      ]
    },
    hideLevel() {
      return this.user.info.areaList?.length || 0
    },
    showDetail() {
      this.activeName = this.activeName || this.$route.query?.type || 0
      return !!this.$route.query?.type || !!this.$route.query?.id
    },
    detailComponent() {
      return this.tabs.find(e => e.value == this.activeName)?.detail || ""
    }
  },
  data() {
    return {
      areaId: '',
      activeName: "0",
    }
  },
  created() {
    this.activeName = this.$route.query?.type
    this.areaId = JSON.parse(JSON.stringify(this.user.info.areaId))
    this.dict.load('residentType', "sex", "faithType", "fileStatus",
        "legality",
        "education",
        "maritalStatus",
        "politicsStatus",
        "householdName",
        "nation",
        "liveReason",
        "certificateType",
        "job",
        "militaryStatus",
        "householdRelation",
        "logoutReason",
        "nation",
        "registerStatus",
        "residentTipType",
        "liveCategory",
        "livePeriod",
        "language",
        "nationality");
  },
}
</script>
<style lang="scss" scoped>
.AppResident {
  width: 100%;
  height: 100%;
  background: rgba(243, 246, 249, 1);

  .iconfont {
    cursor: pointer;
  }

  .tab-content-box {
    padding: 16px 0;
    width: 100%;
    box-sizing: border-box;
    background-color: #f3f6f9;
    overflow-y: auto;
  }

  .list {
    box-sizing: border-box;
    background-color: #fff;
    border-radius: 4px;
    border: solid 1px #d8e0e8;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;

    .searchBar {
      padding: 8px 0;

      .el-col {
        margin-bottom: 8px;

        span {
          display: inline-block;
          width: 100px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          font-size: 14px;
          background-color: #f5f5f5;
          border-radius: 2px;
          border: solid 1px #d0d4dc;
          border-right: none;
          margin: 0;
        }
      }
    }

    .addClass {
      height: 64px;
    }
  }

  .dataStatistic {
    width: 100%;
    margin-top: 16px;
    padding: 0 16px 16px 16px;
    box-sizing: border-box;

    .above {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .data-item {
        width: 32%;
        height: 380px;
        background: rgba(255, 255, 255, 1);
        border-radius: 4px;
        padding: 16px;
        box-sizing: border-box;
        position: relative;

        p {
          position: absolute;
          right: 16px;
          top: 16px;
          font-size: 14px;
          font-weight: bold;

          span:nth-of-type(1) {
            color: #999999;
          }

          span:nth-of-type(2) {
            color: #333333;
          }
        }
      }
    }
  }
}
</style>
