<!--
  revit内嵌详情页，由revit调起，Java后台数据
 -->
<template>
  <div id="mod">
    <div class="mod_title">
      <div class="qr_code">
        <img
          v-if="pointList.PointId"
          :src="'api/ScanBuilding/service/qrcode/point?projectId=' + pointId + '&pointId=' + pointList.PointId + '&width=200&height=200'"
          alt
        >
        <p v-else>暂无二维码</p>
      </div>
      <div class="msg_main">
        <p :title="pointList.position">现场位置：{{pointList.position ? pointList.position : '暂无'}}</p>
        <input
          type="text"
          v-model="pointList.PointName"
          @keyup.enter="savePointChange"
          placeholder="点位标签的名称"
        >
        <input
          type="text"
          v-model="pointList.PointLocalId"
          @keyup.enter="savePointChange"
          placeholder="点位标签的本地编码"
        >
      </div>
    </div>
    <div class="cant_mod">
      <div class="msg_table">
        <div class="table_header">编码及关系</div>
        <table>
          <tbody>
            <tr>
              <td>点位标签id</td>
              <td>{{pointList.PointId}}</td>
            </tr>
            <tr>
              <td>模型id</td>
              <td>{{pointList.BimId ? pointList.BimId : '暂无'}}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="locale_pic">
        <p>现场照片</p>
        <div v-if="pointList.ImageList.length">
          <ul>
            <li v-for="(item,index) in imgList.place" v-if="imgList.place.length" class="img_view">
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li
              v-for="(item,index) in imgList.nameplate"
              v-if="imgList.nameplate.length"
              class="img_view"
            >
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li v-for="(item,index) in imgList.ahead" v-if="imgList.ahead.length" class="img_view">
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li
              v-for="(item,index) in imgList.qrCodeLooger"
              v-if="imgList.qrCodeLooger.length"
              class="img_view"
            >
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li v-for="(item,index) in imgList.left" v-if="imgList.left.length" class="img_view">
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li v-for="(item,index) in imgList.right" v-if="imgList.right.length" class="img_view">
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li
              v-for="(item,index) in imgList.bottom"
              v-if="imgList.bottom.length"
              class="img_view"
            >
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li
              v-for="(item,index) in imgList.qrCode"
              v-if="imgList.qrCode.length"
              class="img_view"
            >
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li
              v-for="(item,index) in imgList.panorama"
              v-if="imgList.panorama.length"
              class="img_view"
            >
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li v-for="(item,index) in imgList.else" v-if="imgList.else.length" class="img_view">
              <img
                @click="seeBig(item.key,item.name,item.type)"
                :src="'img/image-service/common/image_get?systemId=dataPlatform&key='+ item.key +'&width=200'"
                alt
              >
              <i class="iconfont icon-shuaxin icon" @click.stop="changeImage(index)"></i>
            </li>
            <li v-for="item in imgList.video">
              <video
                style="width:100%;height:100%;"
                :src="'img/image-service/common/file_get/'+ item.key + '?systemId=dataPlatform'"
                controls
                :poster="'img/image-service/common/image_get?systemId=dataPlatform&key='+ delVideo(item.key) +'&width=200'"
              ></video>
            </li>
          </ul>
        </div>
        <div v-else>暂无照片</div>
      </div>
    </div>
    <div class="iframe_view" v-if="iframeShow">
      <div class="iframe_no" @click="iframeShow = false">
        <i class="iconfont icon-guanbi"></i>
      </div>
      <iframe
        id="google_ads_frame2"
        name="google_ads_frame2"
        frameborder="0"
        :src="iframeSrc"
        marginwidth="0"
        marginheight="0"
        vspace="0"
        hspace="0"
        allowtransparency="true"
        scrolling="no"
        allowfullscreen="true"
      ></iframe>
    </div>
  </div>
</template>

<script>
import {
  getPoint, //获取点位标签详情
  updatePoint //修改点位标签
} from "../api/request";

export default {
  data() {
    return {
      pointList: "", //点位标签详情数组
      pointId: this.$route.query.pointId, //this.$route.query.pointId"Pt0d075b6f2e0d4c2b8b1ca2a9a23bca21"
      projId: this.$route.query.perjectId, //this.$route.query.projId
      userId: this.$route.query.userId, //this.$route.query.userId
      iframeSrc: "", //iframe的src
      iframeShow: false, //iframe的显示
      imgList: ""
    };
  },
  mounted() {
    this.getPointDetail();
  },
  methods: {
    //获取点位标签详情
    getPointDetail() {
      let param = {
        PointId: this.pointId,
        UserId: this.userId,
        ProjId: this.projId
      };
      getPoint(param).then(result => {
        this.pointList = result.data.PointList[0];
        this.imgList = this.delImage(result.data.PointList[0].ImageList);
      });
    },
    delVideo(key) {
      return key.split(".")[0] + ".png";
    },
    //保存点位标签详情的修改
    savePoint() {
      let param = {
        ProjId: this.projId,
        UserId: this.userId,
        PointList: this.pointList
      };
      updatePoint(param).then(result => {
        if (result.data.Result == "success") {
          this.$message({
            message: "保存成功",
            type: "success"
          });
          return;
        } else {
          this.$message.error("保存失败");
        }
      });
    },
    //点位标签详情中的enter事件
    savePointChange() {
      this.savePoint();
    },
    seeBig(key, name, type) {
      this.iframeSrc =
        process.env.BASE_URL + ":8890/photo-View.html?type=" +
        // "http://172.16.0.181:8890/photo-View.html?type=" +
        type +
        "&key=" +
        key +
        "&name=" +
        name;
      this.iframeShow = true;
    },
    changeImage(index) {
      let data = this.pointList.ImageList[index];
      if (data.key.indexOf("time") != "-1") {
        let url = data.key.split("time");
        data.key = url[0] + "time=" + new Date().getTime();
      } else {
        data.key = data.key + "&time=" + new Date().getTime();
      }
    },
    delImage(imageList) {
      let list = {
        place: [],
        nameplate: [],
        ahead: [],
        qrCodeLooger: [],
        left: [],
        right: [],
        bottom: [],
        video: [],
        else: [],
        qrCode: [],
        panorama: []
      };
      let imgList = imageList;
      for (let i = 0; i < imgList.length; i++) {
        switch (imgList[i].name) {
          case "安装位置":
            list.place.push(imgList[i]);
            break;
          case "设备铭牌照片":
            list.nameplate.push(imgList[i]);
            break;
          case "设备正面照片":
            list.ahead.push(imgList[i]);
            break;
          case "带二维码的设备远景照片":
            list.qrCodeLooger.push(imgList[i]);
            break;
          case "设备左侧照片":
            list.left.push(imgList[i]);
            break;
          case "设备右侧照片":
            list.right.push(imgList[i]);
            break;
          case "设备背面照片":
            list.right.push(imgList[i]);
            break;
          case "带二维码的设备近景照片":
            list.qrCode.push(imgList[i]);
            break;
          case "视频":
            list.video.push(imgList[i]);
            break;
          case "全景照片":
            list.panorama.push(imgList[i]);
            break;
          default:
            list.else.push(imgList[i]);
        }
      }
      return list;
    }
  }
};
</script>

<style lang="less" scoped>
#app {
  min-width: 600px;
  min-height: 500px;
}
.mod_title {
  margin: 2px;
  overflow: hidden;
}

.mod_title .qr_code,
.msg_main {
  float: left;
  overflow: hidden;
}

.mod_title .qr_code img {
  width: 100%;
  height: 100%;
}

.qr_code {
  width: 200px;
  height: 200px;
}

input {
  width: 300px;
  height: 24px;
  padding-left: 5px;
  display: block;
  margin-top: 8px;
}

table {
  width: 100%;
  line-height: 25px;
  text-align: center;
  border-collapse: collapse;
}

img::after {
  content: "\e87d";
  font-family: "iconfont" !important;
  font-size: 30px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: FontAwesome;
  color: rgb(100, 100, 100);
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #ddd;
}

table tr,
td {
  border: 1px solid #000;
}
.msg_table,
.mod_title {
  width: 600px;
}

.msg_table .table_header {
  border: 1px solid #000;
  border-bottom: none;
}

.cant_mod {
  clear: both;
  padding: 0 5px;
}

ul {
  width: 100%;
  overflow: hidden;
  padding-left: 0;
  padding-left: 10px;
  li {
    width: 40%;
    height: 15rem;
    float: left;
    margin: 10px;
    overflow: hidden;
    box-sizing: border-box;
    position: relative;
  }
}
.locale_pic {
  p {
    line-height: 1.8rem;
    font-weight: 900;
    margin-top: 0.5rem;
    border-bottom: 1px solid #000;
  }
}
.iframe_view {
  position: fixed;
  z-index: 99999;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  .iframe_no {
    position: fixed;
    z-index: 99999;
    border-radius: 50%;
    cursor: pointer;
    height: 80px;
    overflow: hidden;
    right: -40px;
    top: -40px;
    transition: background-color 0.15s;
    width: 80px;
    background-color: rgba(0, 0, 0, 0.6);
    // background-color: #b6ff00;
    .iconfont {
      margin-top: 48px;
      display: inline-block;
      margin-left: 16px;
      font-size: 16px;
      color: #fff;
    }
  }
  iframe {
    width: 100%;
    height: 100%;
  }
}
</style>

