<template>
    <div class="info-window">
        <div class="box">
            <h4>{{ data.name }}</h4>
            <div class="container">
                <div class="item">
                    <el-select
                        v-model="cameraIndexCode"
                        placeholder="请选择"
                        @change="hanldeChange"
                    >
                        <el-option
                            v-for="item in resources"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </div>
                <div class="main">
                    <div class="video-play-window">
                        <video-player
                            :playerId="'player'"
                            :cameraIndexCode="cameraIndexCode"
                            v-if="showplay"
                            ref="player"
                            :isShowScreen="true"
                            @openDialog="openDialog"
                        />
                    </div>
                    <div class="detail-info-show">
                        <div class="tag">
                            <div class="tag-item">
                                <span class="tag-active">健康状态</span>
                                <span v-if="infoObjData.healthAssessmentLevel == 4"
                                    >严重异常</span
                                >
                                <span v-if="infoObjData.healthAssessmentLevel == 3"
                                    >中等异常</span
                                >
                                <span v-if="infoObjData.healthAssessmentLevel == 2"
                                    >轻微异常</span
                                >
                                <span v-if="infoObjData.healthAssessmentLevel == 1"
                                    >基本完好</span
                                >
                            </div>
                            <div class="tag-item">
                                <span class="tag-active">健康报告</span>
                                <span>{{ infoObjData.count }} 份</span>
                            </div>
                        </div>
                        <div
                            class="info"
                            v-loading="loading"
                            element-loading-text="加载中"
                            element-loading-spinner="el-icon-loading"
                            element-loading-background="rgba(0, 0, 0, 0.1)"
                        >
                            <span>
                                <p>建设时间</p>
                                <p>:</p>
                                <p>
                                    {{ data.createTime && data.createTime.split(' ')[0] }}
                                </p>
                            </span>
                            <span>
                                <p>长度</p>
                                <p>:</p>
                                <p>{{ data.length }}</p>
                            </span>
                            <span>
                                <p>桥梁类型</p>
                                <p>:</p>
                                <p>{{ data.typeValue }}</p>
                            </span>
                            <span>
                                <p>所在路段</p>
                                <p>:</p>
                                <p>{{ data.roadSegmentName }}</p>
                            </span>
                            <span>
                                <p>桥梁方向</p>
                                <p>:</p>
                                <p>{{ data.directionValue }}</p>
                            </span>
                            <span>
                                <p>桥面铺装</p>
                                <p>:</p>
                                <p>{{ data.surfaceinstallValue }}</p>
                            </span>
                            <span>
                                <p>设计单位</p>
                                <p>:</p>
                                <p>{{ data.designUnit }}</p>
                            </span>
                            <span>
                                <p>监视单位</p>
                                <p>:</p>
                                <p>{{ data.watchUnit }}</p>
                            </span>
                            <span>
                                <p>施工单位</p>
                                <p>:</p>
                                <p>{{ data.constructUnit }}</p>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <screen-dialog
            v-if="showDialog"
            :cameraIndexCode="cameraIndexCode"
            :resources="resources"
            ref="dialog"
        />
    </div>
</template>

<script>
import videoPlayer from './videoPlayer.vue'
import ScreenDialog from './ScreenDialog.vue'
export default {
    name: 'infoWindow',
    components: {
        videoPlayer,
        ScreenDialog,
    },
    props: {
        infoData: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {
            data: {},
            loading: false,
            showplay: false,
            showDialog: false,
            infoObjData: {},
            resources: [],
            cameraIndexCode: '',
            dialogVisible: false,
        }
    },
    mounted() {
        this.loadData()
        this.showplay = true
        // 停止视频流
        if (this.infoWindow) {
            this.infoWindow.on('close', () => {
                this.$refs.player.closeVideo()
                this.showplay = false
            })
        }
    },
    methods: {
        loadData() {
            this.loading = true
            let {tpBridgeId} = this.infoData
            this.$http.get('${yhxt}/bizTpBridge/v1/detail/' + tpBridgeId).then((res) => {
                this.loading = false
                this.infoObjData = res.data
                this.data = res.data.bridgeInformation
                let resources = res.data.resources
                this.resources = resources.map((i) => {
                    return {
                        label: i.name,
                        value: i.cameraIndexCode,
                        ...i,
                    }
                })
                this.cameraIndexCode = this.resources[0].value
                this.$nextTick(() => {
                    this.$refs.player.createPlayer(this.cameraIndexCode)
                })
            })
        },
        openDialog() {
            this.showDialog = true
            this.$nextTick(() => {
                this.$refs.dialog.open()
            })
        },
        hanldeChange(val) {
            this.$refs.player.closeVideo()
            //   this.$refs.player.getVideoURL(val)
            this.$nextTick(() => {
                this.$refs.player.createPlayer(val)
            })
        },
    },
}
</script>

<style lang="scss" scoped>
/deep/ .el-select {
  min-width: 300px;
}
p {
  margin: 0;
  padding: 0;
}
h4 {
  text-align: center;
  font-size: 16px;
  margin: 0;
  padding: 0;
  line-height: 30px;
}
.info-window {
  width: 100%;
  height: 100%;
  color: #f6f9fd;
}
.container {
  display: flex;
  flex-direction: column;
}
.item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  .active {
    background-color: #ffc03c;
  }
  span {
    background-color: #156fd8;
    color: #fff;
    padding: 0 18px;
    line-height: 20px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    &:nth-child(n + 1) {
      margin-right: 10px;
    }
  }
}
.main {
  display: flex;
}
.video-play-window {
  width: 400px;
  height: 400px;
  //   background: #fff;
  margin-right: 10px;
}

.detail-info-show {
  flex: 1;
  height: 400px;
  display: flex;
  flex-direction: column;
  .tag {
    display: flex;
    .tag-item {
      &:nth-child(2) {
        margin-left: 10px;
      }
      .tag-active {
        background: #0eb6ff;
      }
      span {
        display: inline-block;
        width: 80px;
        border: 1px solid #0c6797;
        line-height: 28px;
        text-align: center;
        &:first-child {
          border-top-left-radius: 5px;
          border-bottom-left-radius: 5px;
        }
        &:nth-child(n + 1) {
          border-right: none;
        }
        &:last-child {
          border-right: 1px solid #0c6797;
          border-top-right-radius: 5px;
          border-bottom-right-radius: 5px;
        }
      }
    }
  }
  .info {
    display: flex;
    flex-direction: column;
    margin-top: 10px;
    span {
      display: flex;
      p {
        font-size: 14px;
        line-height: 40px;
        text-align-last: justify;
        &:nth-child(1) {
          width: 60px;
        }
        &:nth-child(2) {
          margin-left: 3px;
          margin-right: 5px;
        }
      }
    }
  }
}
</style>
<style lang="scss">
/* 高德地图 */
.amap-info-content {
  width: 800px;
  //   height: 460px;
  //   height: 500px;
  padding: 30px;
  padding-bottom: 40px;
  //   box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  //   border: 1px solid #037db4;
  //   background-color: rgba($color: #0d243f, $alpha: 0.6);
  background: url('../img/bg_border.png') no-repeat;
  background-size: cover;
  background-size: 100% 100%;
}
.amap-info-close {
  top: 20px;
  right: 20px !important;
  background-color: #0094ff;
  border-radius: 50%;
  padding: 5px;
}

/* minemap2D 地图 */
.minemap-popup-content {
  min-width: 800px !important;
  padding: 30px;
  padding-bottom: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  background: url('../img/bg_border.png') no-repeat;
  background-size: cover;
  background-size: 100% 100%;
}
.minemap-popup-close-button {
  width: 20px;
  height: 20px;
  display: flex;
  top: 20px;
  right: 20px !important;
  background-color: #0094ff;
  border-radius: 50%;
  /* padding: 5px; */
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 18px;
}
</style>
