<template>
  <div class="maintenance-supervision">
    <div class="maintenance-supervision_header">
      <button-group @change="change" :defaultValue="checked">
        <button-group-item> 重大风险 </button-group-item>
        <button-group-item> 较大风险 </button-group-item>
        <button-group-item> 一般风险 </button-group-item>
        <button-group-item> 低风险 </button-group-item>
      </button-group>
    </div>
    <div>
      <div class="row header">
        <span class="type">序号</span>
        <span class="person">区域</span>
        <span class="result">风险数(栋)</span>
      </div>
      <VueSeamlessScroll
        :data="list"
        v-if="reload"
        :class-option="classOption"
        class="warp"
      >
        <ul class="item">
          <li
            class="row"
            :class="{
              active: item.isActive,
            }"
            v-for="(item, index) in list"
            :key="index"
            @click="openBasicModal1(item.qy)"
          >
            <span class="type">{{ index + 1 }}</span>
            <span class="person">{{ item.qy }}</span>
            <span class="result">{{ item.sl }}</span>
          </li>
        </ul>
      </VueSeamlessScroll>
    </div>
    <basic-modal top="120px" ref="yhModal">
      <YhModalContent :default="params" />
      <YlycModalHeader slot="title" />
    </basic-modal>
  </div>
</template>
<script>
import VueSeamlessScroll from "vue-seamless-scroll";
import { fxfb } from "@/api/risk";
import { toFirst } from "@/utils";
import YhModalContent from "../../Detail/components/YhModalContent.vue";
export default {
  name: "MaintenanceSupervision",
  props: {
    qx: String,
  },
  data() {
    return {
      list: [],
      originData: [],
      reload: true,
      checked: 0,
      type: ["重大风险", "较大风险", "一般风险", "低风险"],
      unit: "",
      params: null
    };
  },
  components: {
    VueSeamlessScroll,
    YhModalContent,
  },
  computed: {
    classOption() {
      return {
        singleHeight: 43,
        autoPlay: this.qx === "重庆市" && this.list.length >= 10,
      };
    },
  },
  watch: {
    qx: {
      handler() {
        this.loadData();
      },
      deep: true,
    },
  },
  created() {
    this.loadData(true);
  },
  methods: {
    change(idx) {
      if (this.checked !== idx) {
        this.reload = false
        this.checked = idx;
        let tempData = this.originData.filter(
          (item) => item.fxdj === this.type[idx]
        );
        this.list = toFirst(tempData, this.qx, "qy");
        setTimeout(() => {
          this.reload = true
        }, 200)
        // this.$emit('selectData', tempData)
      }
    },
    loadData(bool) {
      this.reload = false;
      fxfb({
        pageNum: 1,
        pageSize: 200,
      }).then((res) => {
        this.originData = res.data.rows.map((item) => ({
          ...item,
          isActive: item.qy === this.qx,
        }));
        let tempData = this.originData.filter(
          (item) => item.fxdj === this.type[this.checked]
        );
        this.list = toFirst(tempData, this.qx, "qy");
        this.reload = true;
        if (bool) {
          this.$emit("selectData", tempData);
        }
      });
    },
    openBasicModal1(val) {
      // this.unit = val;
      this.params = {
        qx: val,
        fxdjYs: this.type[this.checked]
      }
      this.showModal("yhModal");
    },
  },
};
</script>
<style scoped lang="less">
.maintenance-supervision {
  .maintenance-supervision_header {
    border-bottom: 1px solid #154956;
    padding-bottom: 2px;
  }
  .warp {
    height: 520px;
    margin: 0 auto;
    overflow: hidden;
    .item {
      list-style: none;
      padding: 0;
      margin: 0 auto;
      cursor: pointer;
    }
    &:hover {
      overflow: auto;
    }
  }

  .header {
    color: #fff;
    height: 33px !important;
    line-height: 33px !important;
    background-color: rgba(0, 163, 255, 0.3) !important;
    color: #61dbff;
    margin-top: 15px;
    margin-bottom: 6px;
  }
  li.row.active {
    background-color: rgba(0, 213, 255, 0.2);
  }

  .row,
  li,
  a {
    display: block;
    height: 39px;
    line-height: 39px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    background-color: rgba(0, 0, 0, 0.2);
    .time,
    .person,
    .type,
    .result {
      flex: 0.33;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .person {
      text-align: center;
      display: inline-block;
      overflow: hidden;
      text-overflow: ellipsis !important; // 超出隐藏
      white-space: nowrap;
    }
    .type {
      flex: 0.15;
    }
  }

}
</style>
