<template>
  <el-card shadow="always" class="box-card">
    <div class="box-header">
      <h4>分析介绍:</h4>
      <div class="box-header-min">
        <el-descriptions>
          <el-descriptions-item label="分析主题">{{
            analysisInfo.analysisName
          }}</el-descriptions-item>
          <el-descriptions-item label="分析人">{{
            analysisInfo.updateByName
          }}</el-descriptions-item>
          <el-descriptions-item label="分析简述">{{
            analysisInfo.sketch
          }}</el-descriptions-item>
          <el-descriptions-item label="分析创建时间">
            {{ analysisInfo.createTime }}
          </el-descriptions-item>
          <el-descriptions-item label="分析开始执行时间">{{
            analysisInfo.analysisStartTime
          }}</el-descriptions-item>
          <el-descriptions-item label="分析完成时间">{{
            analysisInfo.analysisEndTime
          }}</el-descriptions-item>
        </el-descriptions>
        <!-- <div v-if="analysisInfo.dataEndTime || analysisInfo.dataStartTime">
          分析数据时间跨度为{{ analysisInfo.dataEndTime }}至{{
            analysisInfo.dataStartTime
          }}。
        </div>
        <div v-if="analysisInfo.analysisFinishTime">
          分析完成时间为{{ analysisInfo.analysisFinishTime }}。数据分析人
          <span class="headerMessage">{{ analysisInfo.updateByName }}</span
          >。
        </div> -->
      </div>
    </div>
    <div class="box-header">
      <h4>风场信息:</h4>
      <div class="box-header-min">
        <div>
          {{ fieldInfo.fieldName }}位于{{ fieldInfo.provinceName
          }}{{ fieldInfo.cityName }}
          ，海拔高度为
          <span class="headerMessage"> {{ fieldInfo.elevationHeight }} </span>米
          ，所在经纬度为经度
          <span class="headerMessage"> {{ fieldInfo.longitude }} </span>° ，纬度
          <span class="headerMessage">{{ fieldInfo.latitude }} </span>°
        </div>
        <div>
          该风电场由{{ fieldInfo.companyName }}管理，风场总容量为
          <span class="headerMessage"
            >{{ fieldInfo.ratedCapacityNumber }} MW
          </span>
          ，共安装
          <span class="headerMessage">{{ fieldInfo.engineCount }} 台</span>

          风机，使用的机型为
          <span class="headerMessage">
            {{
              fieldInfo.engineMillTypes && fieldInfo.engineMillTypes.join(",")
            }}
          </span>
          。
        </div>
        <div v-if="analysisInfo.dataEndTime || analysisInfo.dataStartTime">
          分析数据时间跨度为{{ analysisInfo.dataStartTime }}至{{
            analysisInfo.dataEndTime
          }}。
        </div>

        <div v-if="analysisInfo.analysisFinishTime">
          分析完成时间为{{ analysisInfo.analysisFinishTime }}。数据分析人
          <span class="headerMessage">{{ analysisInfo.updateByName }}</span
          >。
        </div>
      </div>
    </div>
    <div class="content">
      <div class="left">
        <div class="box-content-min">
          <h4>分析完成机组：</h4>
          <div
            class="analysisCompletionUnit"
            v-if="analysisInfo && analysisInfo.windEngineGroups?.length > 0"
          >
            <div
              class="itemAnalysisCompletionUnit"
              v-for="itemData in analysisInfo.windEngineGroups"
              :key="itemData.engineCode"
            >
              <el-popover
                placement="right"
                width="600"
                trigger="hover"
                @show="getEngineInfo(itemData.engineCode)"
              >
                <el-descriptions class="margin-top" size="mini" border>
                  <!-- :column="3" -->
                  <el-descriptions-item>
                    <template slot="label"> 风机名称 </template>
                    {{ windDetail.engineName }}
                  </el-descriptions-item>
                  <!-- <el-descriptions-item>
                    <template slot="label"> 机型编号 </template>
                    {{ windDetail.millTypeCode }}
                  </el-descriptions-item> -->
                  <el-descriptions-item>
                    <template slot="label"> 额定容量 </template>
                    {{ windDetail.ratedCapacity }}/KW
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 轮毂高度 </template>
                    {{ windDetail.hubHeight }}/米
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 海拔高度 </template>
                    {{ windDetail.elevationHeight }}/米
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 经度 </template>
                    {{ windDetail.longitude }}
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 纬度 </template>
                    {{ windDetail.latitude }}
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 是否标杆风机 </template>
                    {{ windDetail.sightcing == 1 ? "是" : "否" }}
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 额定风速 </template>
                    {{ windDetail.rated_wind_speed }} m/s
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 切入风速 </template>
                    {{ windDetail.ratedCutInWindspeed }} m/s
                  </el-descriptions-item>
                  <el-descriptions-item>
                    <template slot="label"> 切出风速 </template>
                    {{ windDetail.ratedCutOutWindspeed }} m/s
                  </el-descriptions-item>
                </el-descriptions>
                <div slot="reference">
                  <SvgIcons
                    name="WindPower3"
                    class="WindPower3"
                    width="40px"
                    height="42px"
                    color="#222"
                  ></SvgIcons>
                  <span>{{ itemData.engineName }}机组</span>
                </div>
                <!-- <el-button>click 激活</el-button> -->
              </el-popover>
            </div>
          </div>
          <el-empty v-else description="暂无分析完成机组"></el-empty>
        </div>
      </div>
      <div class="right">
        <Map :batchCode="initBatchCode" :fieldCode="fieldInfo.fieldCode"></Map>
      </div>
    </div>
    <div class="box-min">
      <h4>完成分析类型:</h4>
      <template v-if="analysisInfo && analysisInfo.analysisTypes?.length > 0">
        <div
          class="analysisTypes"
          v-for="analysis in analysisInfo.analysisTypes"
          :key="analysis.id"
        >
          <h6>{{ analysis.typeName }}:</h6>
          <div class="completeAssetssType">
            <el-tag
              v-for="analysisChild in analysis.children"
              :key="analysisChild.id"
              type="warning"
              >{{ analysisChild.typeName }}
            </el-tag>
          </div>
        </div>
      </template>

      <el-empty v-else description="暂无完成分析类型"></el-empty>
    </div>
  </el-card>
</template>

<script>
import Map from "../map/index.vue";
import { getFieldInfo } from "@/api/overview";
import { getWindEngineGroup } from "@/api/ledger";
import { aW } from "plotly.js-dist";
export default {
  name: "AnalysisInformation",
  components: {
    Map,
  },
  props: {
    initBatchCode: {
      default: "",
      type: String,
    },
  },

  data() {
    return {
      fieldInfo: {
        fieldCode: "",
      }, //风场信息
      fieldCode: "", //风场编号
      analysisInfo: {}, //分析类型编号
      activeNames: ["1", "2", "3"],
      data: [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
      ],
      windDetail: {},
    };
  },
  watch: {
    initBatchCode(newVal, oldVal) {
      if (newVal) {
        this.getFieldInfoMess();
      }
    },
  },
  mounted() {
    if (this.$route.query.batchCode) {
      this.initBatchCode = this.$route.query.batchCode;
    }
    if (this.$route.query.fieldCode) {
      this.fieldInfo.fieldCode = this.$route.query.fieldCode;
    }
  },
  created() {
    if (this.initBatchCode !== "") {
      this.getFieldInfoMess();
    }
  },
  methods: {
    //获取风机信息
    async getEngineInfo(engineCode) {
      console.log(engineCode, "engineCode");
      await getWindEngineGroup({ engineCode }).then((res) => {
        console.log(res, "res");
        if (res.code === 200) {
          this.windDetail = res.data;
        }
      });
    },
    async getWindEngList() {
      this.loading = true;
      try {
        const res = await getWindEngineGroup({
          engineCode: this.engineCode,
        });
        this.loading = false;
        this.windDetail = res.data;
      } catch (error) {
        this.loading = false;
        console.error(error);
      }
    },
    //获取分析信息
    async getFieldInfoMess() {
      //分析详情
      try {
        const res = await getFieldInfo({ batchCode: this.initBatchCode });

        if (res.code === 200) {
          this.fieldInfo = res.data.fieldInfo; //风场信息
          this.analysisInfo = res.data.analysisInfo; //分析类型编号
        }
      } catch (err) {}
    },
    handleChange(val) {
      console.log(val);
    },
  },
};
</script>

<style scoped lang="scss">
.completeAssetssType {
  display: flex;
  flex-wrap: wrap;

  .el-tag {
    margin-right: 10px;
    margin-bottom: 10px;
  }

  ::v-deep .el-tag--warning {
    background-color: #0080803a !important;
    border-color: #0080803a !important;
    color: #008080 !important;
  }
}

.el-card__body {
  width: 100%;
  height: 100%;
  // margin-bottom: 20px !important;
}

.content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  // align-items: flex-start;
  /* 上对齐 */
  height: 100%;
  border-bottom: 1px solid #ebeef5;
  /* 确保内容区域有高度 */
}
.box-min {
  padding: 10px;

  color: #303133;

  h4 {
    color: #303133;
    // border-bottom: 1px solid #ebeef5;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 10px;
  }
  ::v-deep .analysisTypes {
    h6 {
      font-weight: 500 !important;
      font-size: 12px;
      margin: 5px 0;
    }
  }
  .analysisTypes:last-child {
    margin-bottom: 50px;
  }
}

.left {
  width: 70%;

  // flex: 1;
  .box-content-min {
    padding: 10px;
    // border-bottom: 1px solid #ebeef5;
    color: #303133;

    h4 {
      color: #303133;
      // border-bottom: 1px solid #ebeef5;
      font-size: 13px;
      font-weight: 500;
      margin-bottom: 10px;
    }
  }

  .analysisCompletionUnit {
    display: flex;
    flex-wrap: wrap;
    margin: 20px 0;
    padding-bottom: 10px;

    .itemAnalysisCompletionUnit {
      text-align: center;
      margin-bottom: 10px;
      border: #eaeef6 solid 1px;
      margin-right: 10px;
      border-radius: 10px;
      padding: 10px 5px;
      span {
        font-size: 12px;
      }
      .WindPower3 {
        padding: 10px 5px;
        text-align: center;
      }
    }
  }
}

.right {
  width: 30%;
  height: 100%;
  /* 确保容器高度为100% */
  // flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.right .map-ditu {
  width: 100%;
  /* 设置地图的宽度 */
  height: 40vh;
  border-radius: 90px;

  /* 设置地图的高度 */
}

.box-card {
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  /* 滚动条整体样式 */
  &::-webkit-scrollbar {
    width: 6px; /* 滚动条宽度 */
  }

  /* 滚动条轨道 */
  &::-webkit-scrollbar-track {
    background: #f5f7fa;
    border-radius: 3px;
  }

  /* 滚动条滑块 */
  &::-webkit-scrollbar-thumb {
    background: #c0c4cc;
    border-radius: 3px;
  }

  /* 滚动条滑块悬停时 */
  &::-webkit-scrollbar-thumb:hover {
    background: #909399;
  }

  .box-header {
    padding: 10px;
    border-bottom: 1px solid #ebeef5;
    color: #303133;

    h4 {
      color: #303133;
      font-size: 13px;
      font-weight: 500;
      // margin-bottom: 10px;
    }
  }

  .box-header-min {
    padding: 10px;
    font-size: 14px;
    color: #606266;
    line-height: 22px;

    .headerMessage {
      font-size: 16px;
    }
  }
}
</style>
