<template>
  <div class="maintenance-supervision">
    <div class="maintenance-supervision_header">
      <button-group @change="change">
        <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 v-if="checked === 0">
      <template v-if="list1 && list1.length > 0">
        <div class="row header" @click="openModal(0)">
          <span class="time">巡查日期</span>
          <span class="person">巡查人</span>
          <span class="result">检查结果</span>
        </div>
        <ul class="item" @click="openModal(0)">
          <li class="row" v-for="(item, index) in list1" :key="index">
            <span class="time" :tilte="item[0]">{{ item[0] }}</span>
            <span class="person" :tilte="item[1]">{{ item[1] }}</span>
            <span
              class="result"
              :style="{
                color: resultType(item[2]),
              }"
              :tilte="item[2]"
              >{{ item[2] }}</span
            >
          </li>
        </ul>
      </template>
      <template v-else>
        <div class="empty">
          <img src="../../../assets/images/null2.png" style="" />
        </div>
      </template>
    </div>

    <div v-if="checked === 1">
      <template>
        <div class="row header" @click="openModal(1)">
          <span class="time">检查日期</span>
          <span class="person">检查单位</span>
          <span class="person">检查对象</span>
          <span class="result">检查结果</span>
        </div>
        <ul class="item" @click="openModal(1)" v-if="list2 && list2.length > 0">
          <li class="row" v-for="(item, index) in list2" :key="index">
            <span class="time" :tilte="item[0]">{{ item[0] }}</span>
            <span class="time" :tilte="item[1]" :title="item[1]">{{
              getShort(item[1], 5)
            }}</span>
            <span class="person" :tilte="item[2]" :title="item[2]">{{
              getShort(item[2], 5)
            }}</span>
            <span
              class="result"
              :style="{
                color: resultType(item[3]),
              }"
              :tilte="item[3]"
              >{{ item[3] }}</span
            >
          </li>
        </ul>
        <template v-else>
          <div class="empty">
            <img src="../../../assets/images/null2.png" style="" />
          </div>
        </template>
      </template>
    </div>
    <div v-if="checked === 2">
      <template>
        <div class="row header" @click="openModal(2)">
          <span class="time">检查日期</span>
          <span class="person">排查人员</span>
          <span class="result">发现隐患数</span>
        </div>
        <ul class="item" @click="openModal(2)" v-if="list3 && list3.length > 0">
          <li class="row" v-for="(item, index) in list3" :key="index">
            <span class="time" :tilte="item[0]">{{ item[0] }}</span>
            <span class="person" :tilte="item[1]">{{ item[1] }}</span>
            <span
              class="result"
              :style="{
                color: resultType(item[2]),
              }"
              :tilte="item[2]"
              >{{ item[2] }}</span
            >
          </li>
        </ul>
        <ul class="item" @click="openModal(2)" v-if="list3 && list3.length == 0">
          <li class="row" >
            <span class="time" :tilte="detailInfo.modedatacreatedate ">{{ detailInfo.modedatacreatedate}}</span>
            <span class="person" :tilte="detailInfo.xtxtdlr ">{{ detailInfo.xtxtdlr }}</span>
            <span
              class="result"
              :style="{
                color: resultType(detailInfo.yhs),
              }"
              :tilte="detailInfo.yhs"
              >{{ detailInfo.yhs }}</span
            >
          </li>
        </ul>
        <!-- <template v-else>
          <div class="empty">
            <img src="../../../assets/images/null2.png" style="" />
          </div>
        </template> -->
      </template>
    </div>
    <div v-if="checked === 3">
      <template>
        <div class="row header" @click="openModal(3)">
          <span class="time">维保日期</span>
          <span class="person">现场检查人</span>
          <span class="result">维保结果</span>
        </div>
        <ul class="item" @click="openModal(3)" v-if="list4 && list4.length > 0">
          <li class="row" v-for="(item, index) in list4" :key="index">
            <span class="time" :tilte="item[0]">{{ item[0] }}</span>
            <span class="person" :tilte="item[1]">{{ item[1] }}</span>
            <span
              class="result"
              :style="{
                color: resultType(item[2]),
              }"
              :tilte="item[2]"
              >{{ item[2] }}</span
            >
          </li>
        </ul>
        <template v-else>
          <div class="empty">
            <img src="../../../assets/images/null2.png" style="" />
          </div>
        </template>
      </template>
    </div>
  </div>
</template>
<script>
import VueSeamlessScroll from "vue-seamless-scroll";
import {
  getZcqk,
  getJdjc,
  getWgpc,
  getWbqk,
  getCjzjcxxcjList,
} from "@/api/iot.js";
export default {
  name: "MaintenanceSupervision",
  props: ["detail",'id'],
  data() {
    return {
      list1: [],
      list2: [],
      list3: [],
      list4: [],
      checked: 0,
      detailInfo:null
    };
  },
  components: {
    VueSeamlessScroll,
  },
  computed: {
    classOption() {
      return {
        singleHeight: 48,
      };
    },
  },
  methods: {
    getShort(txt, len) {
      console.log(txt);
      if (txt && txt.length > len) {
        return txt.substr(0, len) + "…";
      }
      return txt;
    },
    openModal(checked) {
      this.$emit("openModal", {
        name: "zcModal",
        params: { jzid: this.detail.id, checked: checked },
      });
    },
    change(idx) {
      this.checked = idx;
      console.log("切换索引", idx);
    },
    resultType(text) {
      return {
        合格: "#23f59d",
        不合格: "#df575b",
        是: "#23f59d",
        否: "#df575b",
        未检: "#df575b",
        已检查: "#23f59d",
      }[text];
    },
    getList() {
      const param = {
        pageNum: 1,
        pageSize: 100,
        jzid: this.detail.id,
      };

      // 自查情况
      getZcqk(param).then((res) => {
        const list = [];
        if (res.data.rows) {
          res.data.rows.forEach((p) => {
            list.push([p.stime, p.userName, p.taskFlag]);
          });
        }
        this.list1 = list;
      });

      // 监督检查
      getJdjc(param).then((res) => {
        const list = [];
        if (res.data.rows) {
          res.data.rows.forEach((p) => {
            list.push([p.startTime, p.jcdw, p.bjcdwmc, p.jcjg]);
          });
        }
        this.list2 = list;
      });

      // 网格排查
      getWgpc(param).then((res) => {
        const list = [];
        if (res.data.rows) {
          res.data.rows.forEach((p) => {
            const exist = list.find(
              (k) => k.djsj === p.djsj && k.fxyhr === p.fxyhr
            );
            if (exist) {
              exist.sl = exist.sl + 1;
            } else {
              list.push({
                djsj: p.djsj,
                fxyhr: p.fxyhr,
                sl: 1,
              });
            }
          });
        }
        if (list && list.length > 0) {
          const list3 = [];
          list.forEach((p) => {
            list3.push([p.djsj, p.fxyhr, p.sl]);
          });
          // console.log(this.list3);
          this.list3 = list3;
        }
        if(list&&list.length==0){
          getCjzjcxxcjList({id:this.id}).then(res=>{
           this.detailInfo=res.data.data
          })
        }
      });

      // 维保情况
      getWbqk(param).then((res) => {
        console.log(res);
        const list = [];
        if (res.data.rows) {
          res.data.rows.forEach((p) => {
            list.push([p.wbsj, p.xcjcr, p.zyzt]);
          });
        }

        this.list4 = list;
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>

<style scoped lang="less">
.maintenance-supervision {
  padding: 10px 10px 0px 10px;
  .maintenance-supervision_header {
    border-bottom: 1px solid #154956;
    padding-bottom: 2px;
  }
  .warp {
    height: 280px;
    margin: 0 auto;
    overflow: hidden;
    .item {
      list-style: none;
      padding: 0;
      margin: 0 auto;
      cursor: pointer;
    }
  }

  .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;
  }

  .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,
    .result {
      flex: 0.33;
      height: 39px;
      overflow: hidden;
      display: flex;
      justify-content: center;
      align-items: center;
      white-space: nowrap;
      padding: 0 12px;
      box-sizing: border-box;
    }
  }
}
.empty {
  display: flex;
  justify-content: center;
  margin-top: 30px;
}
</style>
