<template>
  <div class="color-list">
    <div
      class="list-item"
      v-for="(item, index) in colorListL"
      :key="index"
      @click="handlerExportIsD(item.name)"
    >
      <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 class="color-value">{{ item.house }}</span>
        <span> 户 </span>
        <span class="color-value">{{ item.person }}</span>
        <span> 人 </span>
      </div>
    </div>

    <!-- 导出弹窗 -->
    <el-dialog
      :visible.sync="open"
      append-to-body
      custom-class="taicang-dialog-small"
    >
      <div class="dialog-main">
        <div class="dialog-title"><span></span>{{ title }}</div>

        <export-table></export-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import ColorCell from "@/components/ColorCell";
import { getColorList } from "@/api/taicangpop/new.js";
import exportTable from "./exportTable.vue";
export default {
  components: {
    ColorCell,
    exportTable,
  },
  data() {
    return {
      title: "",
      open: false,
      colorListL: [],
    };
  },
  watch: {
    queryParamsXiaoqu: {
      handler(val) {
        this.getColor();
      },
      deep: true,
    },
  },
  computed: {
    ...mapGetters(["queryParamsXiaoqu", "leftColor", "rightTopColor"]),
  },
  created() {
    this.getColor();
  },
  methods: {
    handlerExportIsD(name) {
      if (name == "中共党员") {
        this.title = name;
        this.open = true;
      }
    },
    async getColor() {
      let res = await getColorList(this.queryParamsXiaoqu);
      this.colorListL = this.resetColor(res.data);

      this.$store.commit("SET_PERSON_NUM", {
        cz: this.colorListL[8].person,
        zz: this.colorListL[9].person,
      });
    },
    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];
            }
          }
        }
      });

      colorList.sort((a, b) => {
        const indexA = nameOrder.indexOf(a.name);
        const indexB = nameOrder.indexOf(b.name);

        // 如果找不到，设置一个较大的索引以保证它排在最后
        return (
          (indexA === -1 ? nameOrder.length : indexA) -
          (indexB === -1 ? nameOrder.length : indexB)
        );
      });

      return colorList;
    },
  },
};
</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>
