<template>
  <transition
    v-on:before-enter="beforeEnter"
    v-on:enter="enter"
    v-on:before-leave="beforeLeave"
    v-on:leave="leave"
    v-bind:css="false"
  >
    <div v-show="show" class="wrapper center">
      <div class="left">
        <div class="title-wrapper">
          <div class="title">{{title}}报警器列表</div>
          <div class="close" @click="close">
            <img src="@/assets/images/closeBtn.png" alt="" />
          </div>
        </div>detectorInfo.
        <div class="bottom right-bottom-data-left">
          <el-table
            size="mini"
            :data="tableData"
            style="width: 100%"
            :height="tableHeight"
            class="el-bottom"
            :key="Math.random()"
          >
            <!-- :height="tableHeight" -->
            <el-table-column prop="detectorCode" label="设备编号" width="180">
              <template slot-scope="scope">
                <div :title="scope.row.detectorCode" class="ddd" v-un-content>
                  {{ scope.row.detectorCode }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="detectorName" label="设备名称" width="100">
              <template slot-scope="scope">
                <div :title="scope.row.detectorName" class="ddd" v-un-content>
                  {{ scope.row.detectorName }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="medium" label="监测介质" width="">
              <template slot-scope="scope">
                <div v-un-content>{{ scope.row.medium }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="linkman" label="联系人" width="100">
            </el-table-column>
            <el-table-column prop="phone" label="联系电话" width="">
            </el-table-column>
            <el-table-column prop="detectorStatus" label="设备状态" width="100">
            </el-table-column>
            <el-table-column prop="alarmTime" label="报警时间" width="200">
              <template slot-scope="scope">
                <div v-un-content>{{ scope.row.alarmTime }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="alarmValue" label="定位" width="50">
              <template slot-scope="scope">
                <div
                  @click="createDetector(scope)"
                  class="iconfont icon-bjqdw"
                ></div>
                <!-- {{ scope.row.userId }} -->
              </template>
            </el-table-column>
          </el-table>
          <div>
            <el-pagination
              @current-change="handleCurrentChangvale"
              :page-size="pageSize"
              layout="prev, pager, next, jumper"
              :total="total"
              :hide-on-single-page="total <= pageSize"
              :key="total+''+pageSize"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import Velocity from "velocity-animate";
import { listDeviceAlarm } from "@/api/dataMonitoring/deviceAlarm";

export default {
  props: {
    detcetorList: {
      type: Array,
    },
    show: {
      type: Boolean,
    },
    title: {
      type: String,
    },
    userId: {
      type: [Number, String],
    },
    total: {
      type: Number,
    },
    pageSize: {
      type: Number,
    },
  },
  data() {
    return {
      // 动画效果的切换
      animateChange: 0,
      fade: "fade",
      tableHeight: 600,
      tableData: [
        // {
        //   deviceCode: "2016-05-05",
        //   name: "王小虎",
        //   province: "上海",
        //   city: "普陀区",
        //   address: "上海市普陀区金沙江路",
        // },
      ],
      moveX: 0,
      moveY: 0,
    };
  },
  created() {
    console.log("list", this.detcetorList);
    // this.getList();
  },
  watch: {
    // 当组件显示的时候
    detcetorList(newData) {
      // console.log(bol);
      // if (bol) {
      console.log(newData);
      this.tableData = [...newData];
      // }
    },
  },

  methods: {
    handleSizeChange(val) {
      console.log(val);
    },
    handleCurrentChangvale(val) {
      this.$parent.getDetectorInfoList({
        userId: this.userId,
        pageNum: val,
        pageSize: this.pageSize,
      },this.title);
    },
    close() {
      this.fade = "fade";
      this.$parent.centerShow = false;
      this.$parent.circleShow = false;
    },

    // 点击创建点并且定位过去
    createDetector(data) {
      // 如果有经纬度才能走通，没有套弹框提示
      if (data.row.latitude && data.row.longitude) {
        this.fade = "scale";
        this.$parent.centerShow = false;
        this.$parent.circleShow = true;
        this.$parent.gaoMap.addMarker("detector_only", data.row);
      } else {
        this.msgError("数据不完善，无法定位");
      }
    },

    beforeEnter: function (el) {
      //  如果点的是关闭
      if (this.fade == "fade") {
        // 如果点的是定位
        el.style.opacity = 0;

        console.log(el);
      } else {
        el.style.transfrom = `translate(${this.moveX},${this.moveY})`;
        el.style.transfrom = "scale(0,0)";
      }
    },
    enter: function (el, done) {
      if (this.fade == "fade") {
        Velocity(
          el,
          {
            opacity: 1,
            translateX: "0px",
            translateY: "0px",
            scaleX: 1,
            scaleY: 1,
            // scaleX:1,
            // scaleY:1
          },
          { duration: 0, complete: done }
        );
      } else {
        Velocity(
          el,
          {
            translateX: "0px",
            translateY: "0px",
            scaleX: 1,
            scaleY: 1,
          },
          { duration: 300, complete: done }
        );
      }
    },
    beforeLeave(el) {
      if (this.fade == "fade") {
        el.style.opacity = 1;
      } else {
        el.style.transfrom = "translate(0px,0px)";
        el.style.transfrom = "scale(1,1)";
      }
    },
    leave: function (el, done) {
      if (this.fade == "fade") {
        Velocity(
          el,
          {
            opacity: 0,
          },
          { duration: 0, complete: done }
        );
      } else {
        // 列表的位置参数
        const { top, left, height, width } = el.getBoundingClientRect();
        // 当列表缩下去的右下角的位置参数
        const {
          top: topC,
          left: leftC,
          height: heightC,
          width: widthC,
        } = this.$parent.$refs.circle.getBoundingClientRect();

        const moveX = Math.abs(leftC - left) - width / 2 + heightC / 2 + "px";
        const moveY = Math.abs(topC - top) - height / 2 + heightC / 2 + "px";
        this.moveX = moveX;
        this.moveY = moveY;

        Velocity(
          el,
          {
            translateX: moveX,
            translateY: moveY,
            scaleX: 0,
            scaleY: 0,
          },
          { duration: 300, complete: done }
        );
      }
    },
  },
};
</script>

<style lang="scss"  scoped>
.wrapper {
  // width: 978px;
  max-height: 600px;
  position: fixed;
  top: 50%;
  left: 50%;
  margin-top: -300px;
  margin-left: -500px;
  // background-color: #fff;
  display: flex;
  justify-content: space-between;
  z-index: 9999;

  & > div {
  }
  .left {
    // width: 100px;
    max-height: 598px;
    margin-right: 12px;
    // box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.16);
    // background-color: #fff;
    // color: #fff;
    font-size: 14px;
    font-weight: 400;
    .title-wrapper {
      width: 100%;
      height: 30px;
      display: flex;
      justify-content: space-between;
      background: #1890ff;
      padding: 5px;
      .title {
        width: 100%;
        color: #fff;
        text-align: center;
      }
      .close {
        box-sizing: border-box;
        padding-top: 2px;
        padding-right: 5px;
        cursor: pointer;
      }
    }
    .el-table__body-wrappe {
      height: 140px !important;
    }
    .top {
      height: 19px;
      // background-color: #053b6a;
      color: #fff;
      // line-height: 32px;
      // padding-left: 12px;
      position: relative;

      .title {
        position: absolute;
        left: 50%;
        margin-left: -92px;
        top: -5px;
      }
      .repeat {
        position: absolute;
        top: -5px;
        right: 160px;
        color: #fff;
        cursor: pointer;
        &:hover {
          color: #2788ea;
        }
      }
      .repeat2 {
        position: absolute;
        right: 206px;
        color: #67c23a;
      }
      .more {
        position: absolute;
        right: 38px;
        top: -5px;
        color: #fff;
        float: right;
        margin-right: 20px;
        cursor: pointer;
        &:hover {
          color: #2788ea;
        }
      }
    }
    .bottom {
      width: 1000px;
      margin: 0 auto;
      position: relative;
    }
  }
  .right {
    width: 740px;
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-between;
    align-content: flex-start;
    // margin-top: 7px;
    & > .right-content {
      background-color: #fff;
      width: 238px;
      height: 82px;
      margin-bottom: 29px;
      box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.16);
      margin-right: 10px;
      display: flex;
      &.three {
        margin-right: 0px;
      }
      // align-items: center;
      .text-icon {
        line-height: 82px;
        padding-left: 22px;
        margin-right: 22px;
        i {
          color: #053b6a;
          font-size: 60px;
        }
      }
      .text {
        font-size: 14px;
        padding-top: 16px;
        .top {
          color: #000;
          margin-bottom: 10px;
          font-weight: 600;
        }
        .bottom {
          color: #2788ea;
        }
      }
    }
  }

  .iconfont {
    cursor: pointer;
  }
  // 单独调整下最后一个icon的大小
  .iconFontSize {
    font-size: 50px !important;
  }
}
</style>