<template>
  <div class="iot-project-details-warp">
    <div class="info-tabs">
      <div class="breadcrumb-wrap" v-show="breadcrumbList.length > 1">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item v-for="(item, index) in breadcrumbList" :key="index">
            <span @click="deviceClick(item, index)" :class="item.deviceId === deviceId ? 'breadcrumb-span show-wrap' : 'breadcrumb-span'">{{item.deviceName}}</span>
          </el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <el-tabs
        v-model="activeName"
        :class="breadcrumbList.length > 1 ? 'children-wrap' : ''"
        type="border-card"
      >
        <el-tab-pane label="运行状态" name="runingState">
          <div class="tabs-body protocol-wrap">
            <device-run-starts-wrap
              v-if="devudeRunState"
              :sourceId="deviceId"
              :deviceInfo="infoData"
              :prodId="infoData.prodKey"
              :wsUrl="iotWebSocketBaseUrl"
            ></device-run-starts-wrap>
          </div>
        </el-tab-pane>

        <el-tab-pane label="设备信息" name="info">
          <div class="tabs-body">
            <info-wrap :infoData="infoData" @updateInfo="updateInfo($event)" />
          </div>
        </el-tab-pane>
        <el-tab-pane label="子设备" name="child" v-if="infoData.deviceType === 'GATEWAY_CONTROLLER'">
          <div class="tabs-body">
            <child-device
              v-if="activeName === 'child'"
              :pDevcieInfo="infoData"
              :sourceId="infoData.deviceId"
              @toChildEvent="toNewDevice"
            ></child-device>
          </div>
        </el-tab-pane>

        <el-tab-pane label="触发器" name="trigger">
          <div class="tabs-body protocol-wrap">
            <trigger-wrap :sourceId="infoData.deviceId" :deviceInfo="infoData"></trigger-wrap>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import { getDevice } from "@/api/iot/device";
import InfoWrap from "./info";
import ChildDevice from "./childDevice";
import DeviceRunStartsWrap from "@/views/profile/DeviceRunStarts/index";
import { iotWebSocketBaseUrl } from "@/config/env";
import TriggerWrap from "@/views/profile/DeviceTrigger/index";
export default {
  name: "DetailsWrap",
  props: ["sourceId"],
  components: {
    InfoWrap,
    ChildDevice,
    DeviceRunStartsWrap,
    TriggerWrap
  },
  data() {
    return {
      infoData: {},
      iotWebSocketBaseUrl,
      activeName: "runingState",
      breadcrumbList: [],
      tempType: "bs",
      deviceId: "",
      devudeRunState: false
    };
  },
  created() {
    this.deviceId = this.sourceId;
    this.deviceInfo();
  },
  methods: {
    // 点击查看设备详情
    deviceClick(row, index) {
      if (row.deviceId === this.deviceId) {
        return;
      }
      const leng = this.breadcrumbList.length - 1;
      this.breadcrumbList.splice(index + 1, leng);
      this.activeName = "runingState";
      this.deviceId = row.deviceId;
      this.devudeRunState = false;
      this.deviceInfo();
    },
    // 设备详情
    deviceInfo() {
      getDevice(this.deviceId).then(response => {
        this.infoData = response.data;
        if (this.breadcrumbList.length <= 0) {
          this.breadcrumbList.push(this.infoData);
        }
        for (var i = 0; i < this.breadcrumbList.length; i++) {
          if (
            this.breadcrumbList[i]["deviceId"] === this.infoData["deviceId"]
          ) {
            this.breadcrumbList[i] = this.infoData;
          } else if (i === this.breadcrumbList.length - 1) {
            this.breadcrumbList.push(this.infoData);
          }
        }
        this.devudeRunState = true;
      });
    },
    toNewDevice(data) {
      this.tempType = "children";
      this.deviceId = data.deviceId;
      this.devudeRunState = false;
      this.deviceInfo();
      this.activeName = "runingState";
    },
    updateInfo(...data) {
      this.deviceInfo();
    }
  }
};
</script>
<style lang="scss">
.iot-project-details-warp {
  .breadcrumb-wrap {
    position: absolute;
    top: 15px;
    z-index: 10;
    left: 20px;
    width: 90%;
    overflow: hidden;
    .breadcrumb-span:hover {
      color: #1890ff;
      cursor: default;
    }
    .show-wrap {
      color: #1890ff;
    }
  }
  .product-release-dialog {
    .title-i {
      font-size: 20px;
      color: #9c9a9a;
      line-height: 18px;
    }
    .i-color {
      color: rgb(0, 193, 222);
    }
    .el-dialog__header {
      border-bottom: 1px solid rgb(116, 115, 115);
    }
    .top-tigs {
      background: #fbfbfc;
      border: 1px solid #ecedee;
      padding: 20px;
      margin-bottom: 25px;
      color: #999;
    }
    .form-bottom-prod-details {
      margin-top: 40px;
      height: 10px;
      border-top: 1px solid rgb(116, 115, 115);
      text-align: right;
      width: 100%;
      padding-top: 15px;
      width: calc(100% + 20px);
      .el-button {
        margin-right: 10px;
        margin-left: 0px;
      }
    }
    .bottom-div {
      height: 70px;
      font-size: 12px;
      border: 1px solid #ecedee;
      margin: -1px;
    }
    .one-div {
      width: 15%;
      float: left;
      border-right: 1px solid #ecedee;
      height: 30px;
      line-height: 30px;
      /* padding-left: 10px; */
      text-align: center;
      font-size: 18px;

      height: 70px;
      line-height: 76px;
      text-align: center;
      font-size: 18px;
    }
    .two-div {
      width: calc(100% - 36%);
      float: left;
      padding: 22px 10px 10px 10px;
      font-size: 12px;
    }
    .there-div {
      width: 10%;
      float: left;
      padding-top: 28px;
    }
    .four-div {
      width: 5%;
      float: left;
      padding-top: 28px;
    }
  }
  .heard {
    padding: 20px 40px 0;
    background-color: #fff;
    height: 112px;
    padding: 0px;
  }
  .info-title {
    margin-top: 0px;
    margin-bottom: 16px;
    line-height: 29px;
    overflow: hidden;
    height: 30px;
    .title {
      float: left;
      font-size: 20px;
      margin: 0 8px 0 0;
      line-height: 28px;
    }
    .el-button--small,
    .el-button--small.is-round {
      padding: 8px 15px;
      float: right;
    }
  }
  .info-icon {
    margin-top: -70px;
    float: left;
    width: 101px;
    border: 1px dotted rgb(205, 203, 203);
    height: 101px;
    .image {
      width: 100px;
      height: 100px;
    }
  }
  .info-des {
    font-size: 14px;
    width: 100%;
    float: left;
    .info-row {
      overflow: hidden;
      display: block;
      text-overflow: ellipsis;
      line-height: 20px;
      white-space: nowrap;
      .label {
        color: #aaa;
      }
      .centent {
        color: #999;
        margin-right: 8px;
      }
    }
  }

  .info-tabs {
    position: relative;
    box-sizing: border-box;
    .el-tabs__content {
      height: calc(100vh - 191px);
      overflow: auto;
    }
    .el-tabs__header {
      background-color: #fff;
      position: relative;
      //   top: -10px;
      .el-tabs__nav-wrap {
        margin-left: 0px;
        .el-tabs__item {
          font-size: 16px;
        }
      }
    }
    .el-tabs__nav-scroll {
      height: 65px;
      padding-top: 25px;
      padding-left: 15px;
      background: #e4eaf3;
    }
    .el-tabs--border-card > .el-tabs__header .el-tabs__item.is-active {
      background: #fff;
      color: #333;
      border: 0;
    }
    .el-tabs--border-card > .el-tabs__header .el-tabs__item {
      // border-color: red;
      color: #909399;
      background: #d3deec;
      border-radius: 8px 8px 0 0;
      border-bottom: 0;
      margin-left: 15px;
    }
    .tabs-body {
      margin-left: 0px;
      margin-right: 0px;
      padding: 0px;
      overflow: hidden;
      background-color: #fff;
      margin-bottom: 0px;
    }
    .protocol-wrap {
      .el-tabs__nav-scroll {
        height: auto;
        padding-top: 0;
        padding-left: 0;
        background: #fff;
      }
    }
  }
  .children-wrap {
    .el-tabs__header {
      .el-tabs__nav-scroll {
        height: 85px;
        .el-tabs__nav {
          margin-top: 20px;
        }
      }
    }
  }
  .child-table {
    margin-top: 25px;
    // margin-left: 20px;
    margin-right: 0px;
    padding: 0px;
    overflow: hidden;
    background-color: #fff;
  }
}
.product-release-dialog {
  .title-i {
    font-size: 20px;
    color: #9c9a9a;
    line-height: 18px;
  }
  .i-color {
    color: rgb(0, 193, 222);
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .top-tigs {
    background: #fbfbfc;
    border: 1px solid #ecedee;
    padding: 20px;
    margin-bottom: 25px;
    color: #999;
  }
  .form-bottom-prod-details {
    margin-top: 15px;
    height: 30px;
    border-top: 1px solid #747373;
    text-align: right;
    width: 100%;
    padding-top: 15px;
    width: calc(100% + 20px);
    .el-button {
      margin-right: 10px;
      margin-left: 0px;
    }
  }
  .bottom-div {
    height: 70px;
    font-size: 12px;
    border: 1px solid #ecedee;
    margin: 0px;
  }
  .one-div {
    width: 15%;
    float: left;
    border-right: 1px solid #ecedee;
    height: 30px;
    line-height: 30px;
    /* padding-left: 10px; */
    text-align: center;
    font-size: 18px;

    height: 70px;
    line-height: 76px;
    text-align: center;
    font-size: 18px;
  }
  .two-div {
    width: calc(100% - 36%);
    float: left;
    padding: 22px 10px 10px 10px;
    font-size: 12px;
  }
  .there-div {
    width: 10%;
    float: left;
    padding-top: 28px;
  }
  .four-div {
    width: 5%;
    float: left;
    padding-top: 28px;
  }
}
.product-detail-info {
  .el-textarea {
    width: 92%;
  }
  .el-input {
    width: 92%;
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .form-buttons-div {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    width: 100%;
    padding-top: 15px;
  }
  .question-button.el-button--text {
    padding-bottom: 0px;
    color: rgb(204, 204, 204);
    background: 0 0;
    padding-left: 0;
    padding-right: 0;
    font-size: 18px;
    padding-top: 0px;
    margin-top: 0px;
  }
  .el-form-item--mini.el-form-item,
  .el-form-item--small.el-form-item {
    margin-bottom: 10px;
    margin-left: 60px;
  }
  .el-form--label-top .el-form-item__label {
    padding: 0 0 9px;
    margin-top: 10px;
  }
  .el-form-item--mini .el-form-item__content,
  .el-form-item--mini .el-form-item__label {
    line-height: 17px;
  }
  .avue-input-number,
  .el-cascader,
  .el-date-editor.el-input,
  .el-date-editor.el-input__inner,
  .el-select {
    width: 100%;
  }
  .el-dialog__body {
    padding: 0px;
    padding-right: 20px;
  }
  .form-buttons-div {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    width: 100%;
    padding-top: 15px;
  }
}
.product-topic-dialog {
  .top-tips {
    height: 150px;
    margin: 20px;
    margin-top: 30px;
    margin-right: 0px;
    border: 1px solid #00c1df;
    padding: 10px 10px 0;
    background: #e6f9fc;
    display: flex;
    border-radius: 3px;
    padding-left: 20px;
    padding-top: 20px;
    margin-bottom: 0px;
  }
  .el-form-item__error {
    left: 80px;
  }
  .el-dialog__body {
    padding: 0px;
    padding-right: 20px;
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .el-form--label-top .el-form-item__label {
    padding-top: 23px;
    padding-bottom: 0px;
  }
  .el-form-item {
    margin-bottom: -17px;
    width: 90%;
  }
  .el-form-item--mini .el-form-item__content,
  .el-form-item--mini .el-form-item__label {
    padding-left: 40px;
  }
  .el-select {
    width: 100%;
  }
  .form-buttonx-div {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    width: 100%;
    padding-top: 15px;
    width: calc(100% + 20px);
    .el-button {
      margin-right: 10px;
      margin-left: 0px;
    }
  }
  .funType-div {
    // margin-left: 40px;
  }
}
.product-fun-dialog {
  .insert-div {
    width: 100%;
    margin-bottom: 10px;
    padding-top: 10px;
    padding-left: 30px;
  }
  .el-transfer-panel {
    // margin-left: 10px;
    width: 225px;
  }
  .el-transfer__buttons {
    padding: 0px 10px;
  }
  .el-textarea {
    width: 92%;
  }
  .el-input {
    width: 92%;
  }
  .question-button.el-button--text {
    padding-bottom: 0px;
    color: rgb(204, 204, 204);
    background: 0 0;
    padding-left: 0;
    padding-right: 0;
    font-size: 18px;
    padding-top: 0px;
    margin-top: 0px;
  }
  .fw {
    .el-input--mini {
      width: 155px;
    }
  }
  .el-form-item__error {
    left: 120px;
  }
  .el-dialog__body {
    padding: 0px;
    padding-right: 20px;
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .el-form--label-top .el-form-item__label {
    padding-top: 23px;
    padding-bottom: 0px;
  }
  .el-form-item {
    margin-bottom: -17px;
    width: 92%;
  }
  .el-form-item--mini .el-form-item__content,
  .el-form-item--mini .el-form-item__label {
    padding-left: 40px;
  }
  .form-buttonb-div {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    width: 100%;
    padding-top: 15px;
    width: calc(100% + 20px);
    .el-button {
      margin-right: 10px;
      margin-left: 0px;
    }
  }
  .funType-div {
    // margin-left: 40px;
  }
}
.product-custom-fun {
  .el-textarea {
    width: 92%;
  }
  .el-input {
    width: 92%;
  }
  .question-button.el-button--text {
    padding-bottom: 0px;
    color: rgb(204, 204, 204);
    background: 0 0;
    padding-left: 0;
    padding-right: 0;
    font-size: 18px;
    padding-top: 0px;
    margin-top: 0px;
  }
  .fw {
    .el-input--mini {
      width: 155px;
    }
  }
  .el-form-item__error {
    left: 120px;
  }
  .el-dialog__body {
    padding: 0px;
    padding-right: 20px;
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .el-form--label-top .el-form-item__label {
    padding-top: 23px;
    padding-bottom: 0px;
  }
  .el-form-item {
    margin-bottom: -17px;
    width: 92%;
  }
  .el-select {
    width: 100%;
  }
  .el-form-item--mini .el-form-item__content,
  .el-form-item--mini .el-form-item__label {
    padding-left: 40px;
  }
  .form-buttona-div {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    width: 100%;
    padding-top: 15px;
    width: calc(100% + 20px);
    .el-button {
      margin-right: 10px;
      margin-left: 0px;
    }
  }
  .funType-div {
    // margin-left: 40px;
  }
}
.product-prop-standard-dialog {
  .insert-div {
    width: 100%;
    margin-bottom: 10px;
    padding-top: 10px;
    padding-left: 30px;
  }
  .el-transfer-panel {
    // margin-left: 10px;
    width: 225px;
  }
  .el-transfer__buttons {
    padding: 0px 10px;
  }
  .el-textarea {
    width: 92%;
  }
  .el-input {
    width: 92%;
  }
  .question-button.el-button--text {
    padding-bottom: 0px;
    color: rgb(204, 204, 204);
    background: 0 0;
    padding-left: 0;
    padding-right: 0;
    font-size: 18px;
    padding-top: 0px;
    margin-top: 0px;
  }
  .fw {
    .el-input--mini {
      width: 155px;
    }
  }
  .el-form-item__error {
    left: 120px;
  }
  .el-dialog__body {
    padding: 0px;
    padding-right: 20px;
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .el-form--label-top .el-form-item__label {
    padding-top: 23px;
    padding-bottom: 0px;
  }
  .el-form-item {
    margin-bottom: -17px;
    width: 92%;
  }
  .el-form-item--mini .el-form-item__content,
  .el-form-item--mini .el-form-item__label {
    padding-left: 40px;
  }
  .form-buttonb-div {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    width: 100%;
    padding-top: 15px;
    width: calc(100% + 20px);
    .el-button {
      margin-right: 10px;
      margin-left: 0px;
    }
  }
  .funType-div {
    // margin-left: 40px;
  }
}
.product-prop-custom-dialog {
  .el-textarea {
    width: 92%;
  }
  .el-input {
    width: 92%;
  }
  .question-button.el-button--text {
    padding-bottom: 0px;
    color: rgb(204, 204, 204);
    background: 0 0;
    padding-left: 0;
    padding-right: 0;
    font-size: 18px;
    padding-top: 0px;
    margin-top: 0px;
  }
  .fw {
    .el-input--mini {
      width: 155px;
    }
  }
  .el-form-item__error {
    left: 120px;
  }
  .el-dialog__body {
    padding: 0px;
    padding-right: 20px;
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .el-form--label-top .el-form-item__label {
    padding-top: 23px;
    padding-bottom: 0px;
  }
  .el-form-item {
    margin-bottom: -17px;
    width: 92%;
  }
  .el-form-item--mini .el-form-item__content,
  .el-form-item--mini .el-form-item__label {
    padding-left: 40px;
  }
  .form-buttona-div {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    width: 100%;
    padding-top: 15px;
    width: calc(100% + 20px);
    .el-button {
      margin-right: 10px;
      margin-left: 0px;
    }
  }
  .funType-div {
    // margin-left: 40px;
  }
}

.model-function-dialog {
  .el-textarea {
    width: 92%;
  }
  .el-input {
    width: 92%;
  }
  .question-button.el-button--text {
    padding-bottom: 0px;
    color: rgb(204, 204, 204);
    background: 0 0;
    padding-left: 0;
    padding-right: 0;
    font-size: 18px;
    padding-top: 0px;
    margin-top: 0px;
  }
  .fw {
    .el-input--mini {
      width: 155px;
    }
  }
  .el-form-item__error {
    left: 120px;
  }
  .el-dialog__body {
    padding: 0px;
    padding-right: 20px;
  }
  .el-dialog__header {
    border-bottom: 1px solid rgb(116, 115, 115);
  }
  .el-form--label-top .el-form-item__label {
    padding-top: 23px;
    padding-bottom: 0px;
  }
  .el-form-item {
    margin-bottom: -17px;
    width: 92%;
  }
  .el-form-item--mini .el-form-item__content,
  .el-form-item--mini .el-form-item__label {
    padding-left: 40px;
  }
  .el-select {
    width: 100%;
  }
  .form-bottom-prod-details {
    margin-top: 30px;
    height: 50px;
    border-top: 1px solid rgb(116, 115, 115);
    text-align: right;
    padding-top: 15px;
    width: calc(100% + 20px);
    .el-button {
      margin-right: 10px;
      margin-left: 0px;
    }
  }
  .funType-div {
    // margin-left: 40px;
  }
}
.sr {
  .el-form-item {
    margin-bottom: -17px;
    width: 100%;
  }
}
.iot-project-details-warp .info-tabs .el-tabs__content::-webkit-scrollbar {
  /*滚动条整体样式*/
  width: 8px; /*高宽分别对应横竖滚动条的尺寸*/
  height: 3px;
}
.iot-project-details-warp
  .info-tabs
  .el-tabs__content::-webkit-scrollbar-thumb {
  /*滚动条里面小方块*/
  border-radius: 10px;
  box-shadow: inset 0 0 5px #9e9d9d;
  background: #ffffff;
}
.iot-project-details-warp
  .info-tabs
  .el-tabs__content::-webkit-scrollbar-track {
  /*滚动条里面轨道*/
  box-shadow: inset 0 0 5px #f6f6f6;
  border-radius: 10px;
  background: #ffffff;
}
</style>
