<template>
  <div class="color-list">
    <div class="list-item" v-for="(item, index) in colorListL" :key="index">
      <div class="item-name">
        <ColorCell
          :item="item"
          v-if="item.color"
          size="small"
          class="color-item"
        />
        <span>
          {{ item.name }}
          <!-- <span v-show="item.name == '户籍'"
            >(空关{{ colorListL[2].house }}户)</span
          >
          <span v-show="item.name == '流动'"
            >(空关{{ colorListL[6].house }}户)</span
          > -->
        </span>
      </div>
      <div class="item-value">
        <span>{{ item.house }}</span>
        <span> 户 </span>
        <span>{{ item.person }}</span>
        <span> 人 </span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import ColorCell from "@/components/ColorCell";
import { getColorList } from "@/api/taicangpop/new.js";
export default {
  components: {
    ColorCell,
  },
  data() {
    return {
      colorListL: [],
    };
  },
  watch: {
    queryParamsXiaoqu: {
      handler(val) {
        this.getColor();
      },
      deep: true,
    },
  },
  computed: {
    ...mapGetters(["queryParamsXiaoqu", "leftColor", "rightTopColor"]),
  },
  created() {
    this.getColor();
  },
  methods: {
    async getColor() {
      let res = await getColorList(this.queryParamsXiaoqu);
      this.colorListL = this.resetColor(res.data);
    },
    resetColor(colorList) {
      const nameOrder = ["HZ", "HL", "HO", "HF", "NZ", "NL", "NO", "NF"];
      colorList.map((item) => {
        let isColor = /^[a-zA-Z]+$/.test(item.name);
        if (isColor) {
          item.color = item.name;
          for (let key in this.leftColor) {
            if (item.name == key) {
              item.leftColor = this.leftColor[key];
              item.rightTopColor = this.rightTopColor[key];
            }
          }
        }
      });
      // 创建一个映射表，方便查找顺序
      const orderMap = nameOrder.reduce((map, name, index) => {
        map[name] = index;
        return map;
      }, {});

      // 根据映射表进行排序
      let sortedArr = colorList.sort((obj1, obj2) => {
        return orderMap[obj1.name] - orderMap[obj2.name];
      });
      return sortedArr;
    },
  },
};
</script>

<style lang="scss" scoped>
.color-list {
  margin-top: 6px;
  height: 59%;
  background: rgba(15, 42, 79, 0.6);
  border: 1px solid #1d5acc;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  padding: 10px 13px;

  .list-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 156, 255, 0.2);
    .item-name {
      display: flex;
      align-items: center;
      font-size: 15px;
      color: #abc7ed;
      font-family: "Alibaba-PuHuiTi-Regular.otf";
    }
    .item-value {
      span:nth-child(odd) {
        font-size: 15px;
        color: #52ccff;
        font-family: "DIN-Medium-2.otf";
      }
      span:nth-child(even) {
        font-size: 14px;
        color: #c9e1f5;
      }
    }
  }
  & > .list-item:last-child {
    border: 0;
  }
  .list-item:nth-child(9) .item-value,
  .list-item:nth-child(10) .item-value {
    span:nth-child(odd) {
      font-size: 15px;
      color: #ffb400;
      font-family: "DIN-Medium-2.otf";
    }
  }
  .list-item:nth-child(9),
  .list-item:nth-child(10) {
    .item-name {
      color: #fff;
    }
  }
  // .list-item:nth-child(10) {
  //   border: 0;
  // }
}
.color-item {
  margin-right: 10px;
}
</style>
