<template>
  <div class="wrapper">
    <div class="top display-default">
      <div class="left text">{{ obj.pipeName }}</div>
      <div class="right text">
        <img @click="close" src="../../assets/images/closeBtn.png" alt="" />
      </div>
    </div>

    <!-- 报警设备信息 -->
    <div class="content">
      <div class="eq-content display-default">
        <div class="text-wrapper">
          <!-- <div :title="obj.pipeName" class="eq-text">
          <span>管道名称：</span>
          <span>{{ obj.pipeName }}</span>
        </div> -->
          <div class="eq-text">
            <span>管道编号：</span>
            <span>{{ obj.pipeCode }} </span>
          </div>
          <div class="eq-text">
            <span>管道长度：</span>
            <span>{{ `${obj.pipeLength ? obj.pipeLength + "米" : ""}` }}</span>
          </div>
          <div class="eq-text">
            <span>管道类型：</span>
            <span>{{ ["地埋管线", "地表管线"][obj.pipeType - 1] }}</span>
          </div>
          <div class="eq-text">
            <span>管道压力：</span>
            <span>{{
              ["低压", "中压", "次高压", "高压"][obj.pipePressure - 1]
            }}</span>
          </div>
        </div>

        <div class="pic">
          <img @mousedown.stop="mousedown" :src="obj.iconUrl" alt="" />
          <el-image
            v-show="false"
            id="img"
            ref="previewImg"
            :src="obj.iconUrl"
            :preview-src-list="bigImageArr"
            :z-index="9999999"
          ></el-image>
        </div>
      </div>

      <div class="maintain-content">
        <el-col :span="11">
          <div>
            <span>安装日期：</span>
            <span>{{ moment(obj.installationTime).format("YYYY-MM-DD") }}</span>
          </div>
        </el-col>

        <el-col :span="13">
          <div>
            <span>最后巡检日期：</span>
            <span>{{ obj.inspectionTime ? obj.inspectionTime : "-" }}</span>
          </div>
        </el-col>

        <div>
          <span>管道所在地址：</span>
          <span>{{ obj.pipeAddr }}</span>
        </div>
        <div style="padding: 0">
          <span>备注信息：</span>
          <span>{{ obj.remarks }} </span>
        </div>
      </div>
    </div>

    <!-- 报警状态 -->
    <div class="warn-wrapper" v-if="true">
      <div class="warn-content">
        <div>
          报警状态：<span>报警({{ alarmType }})</span>
        </div>
        <div>
          详细信息：<span>{{ alarmValue ? alarmValue : "-" }}</span>
        </div>
        <div v-if="!orderId">
          工单编号：<span>{{
            obj.polyline.getExtData().lineData.orderId
          }}</span>
        </div>
      </div>
      <div @click.stop="stopPropatation" class="btn">
        <span @mousedown.stop="deviceMore">
          <el-button class="elbtn" type="primary">设备详情</el-button>
        </span>
        <span v-if="orderId" @mousedown.stop="createWork">
          <el-button class="elbtn" type="primary">生成工单</el-button>
        </span>
        <span v-else @mousedown.stop="checkWork">
          <el-button class="elbtn" type="primary">查看工单</el-button>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
//line移入时的的infowindow
import moment from "moment";
export default {
  props: {
    obj: { typs: Object },
  },
  data() {
    return {};
  },
  created() {
    // console.log("created", this.obj);
  },
  mounted() {},
  computed: {
    bigImageArr() {
      return [this.obj.iconUrl];
    },
    alarmType() {
      return this.obj.polyline.getExtData().lineData.alarmType;
    },
    alarmValue() {
      return this.obj.polyline.getExtData().lineData.alarmValue;
    },
    orderId() {
      // 如果已经生成过工单，就不能再次生成了
      return this.obj.polyline.getExtData().lineData.orderId ? false : true;
    },
  },
  methods: {
    moment,
    mousedown(e) {
      // console.log("??");
      return;
      // console.log(this.$refs.previewImg)
      this.$refs.previewImg.showViewer = true;
      console.log(this.$refs.previewImg.showViewer);
      // 加载出来的dom给个事件阻止冒泡
      setTimeout(() => {
        const dom = document.getElementsByClassName(
          "el-image-viewer__wrapper"
        )[0];
        dom.addEventListener("mousedown", (e) => {
          e.stopPropagation();
          console.log("?");
        });
      });
    },
    createWork() {
      // 控制外层弹框 可能有点长

      this.obj.polyline.getExtData().lineData.view.$refs.CreateWork.alarmId =
        this.obj.polyline.getExtData().lineData.alarmId;
      this.obj.polyline.getExtData().lineData.view.$refs.CreateWork.open = true;
      // 改变外层回调
      this.obj.polyline.getExtData().lineData.view.alarmObjChange({
        alarmId: this.obj.polyline.getExtData().lineData.alarmId,
        type: "pipe",
      });
      // this.obj.polyline.getExtData().lineData.view.CreateWorkCallBack(this.CreateWorkCallBack)
    },
    checkWork() {
      this.obj.polyline.getExtData().class.view.$router.push({
        path: "/workOrder/detail",
        query: {
          orderId: this.obj.polyline.getExtData().lineData.orderId,
        },
      });
    },
    // // CreateWorkCallBack(e) {
    // //   console.log("生成工单后传过来的参数", e);
    // //   const polyline = this.obj.polyline
    // //     .getExtData()
    // //     .lineData.view.gaoMap.polyLines.filter((item) => {
    // //       return (
    // //         item.getExtData().lineData.alarmId ==
    // //         this.obj.polyline.getExtData().lineData.alarmId
    // //       );
    // //     })[0];
    // //   let options = polyline.getExtData();
    // //   // 暂时传值，到时候回重新刷新
    // //   options.lineData.orderId = e;
    // //   polyline.setExtData(options);
    // },
    deviceMore() {
      console.log(this.obj.polyline.getExtData().lineData);
      this.obj.polyline.getExtData().class.view.$router.push({
        path: "/dataMonitoring/alarmdetail",
        query: {
          alarmId: this.obj.polyline.getExtData().lineData.alarmId,
          deviceType:"管道"
        },
      });
    },
    close() {
      this.obj.polyline.infoWindow.close();
    },
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 406px;
  max-height: 430px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  .top {
    width: 100%;
    height: 51px;
    background-color: #ff5a67;
    .text {
      font-weight: 600;
      font-size: 16px;
      color: #ffffff;
      line-height: 51px;
    }
    .left {
      padding-left: 22px;
    }
    .right {
      padding-right: 22px;
      img {
        cursor: pointer;
      }
    }
  }
  .content {
    position: relative;
    max-height: 300px;
    overflow: hidden;
    overflow-y: auto;
    padding-bottom: 2px;
    border-bottom: 1px solid #eeeeee;
    .eq-content {
      // min-height: 156px;
      box-sizing: border-box;
      padding: 13px 22px 0px 22px;
      // border-bottom: 1px solid #e2e2e2;
      .text-wrapper {
        padding-top: 1px;
        & > div {
          margin-bottom: 6px;
        }
        .eq-text {
          font-size: 14px;
          font-weight: 400;
          color: #1d1d1d;
          opacity: 1;
          & > span {
            vertical-align: top;
            display: inline-block;
            // white-space: nowrap;
            // text-overflow: ellipsis;
            // overflow: hidden;
            word-break: break-all;
            max-width: 100px;
          }
        }
      }
      .pic {
        width: 180px;
        height: 103px;
        // background-color: black;
        img {
          width: 100%;
          height: 100%;
          // cursor: pointer;
        }
      }
    }
  }

  .maintain-content {
    width: 100%;
    max-height: 119px;
    padding-left: 22px;
    // padding-right: 22px;
    // padding-bottom: 10px;
    // padding-top: 16px;
    box-sizing: border-box;
    // border-bottom: 1px solid #e2e2e2;
    & > div {
      margin-bottom: 8px;
      font-size: 14px;
      font-weight: 400;
      span {
        vertical-align: top;
        display: inline-block;
        word-break: break-all;
        max-width: 280px;
      }
    }
  }
  .warn-wrapper {
    .warn-content {
      box-sizing: border-box;
      padding: 10px 0 2px 22px;
      border-bottom: 1px solid #e2e2e2;
      color: #fe5966;
      & > div {
        font-size: 14px;
        font-weight: 400;
        margin-bottom: 8px;
      }
    }
    .btn {
      padding: 16px 0;
      text-align: center;
      span {
        display: inline-block;
        padding: 0 10px;
        .elbtn {
          background-color: #053b6a;
          box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
          width: 95px;
          height: 33px;
          border: none;
        }
      }
    }
  }
}

.wrapperEditorPage {
}
.display-default {
  display: flex;
  justify-content: space-between;
}
</style>
