<template>
  <div class="dashboard-container" v-if="form.status">
    <!-- 首页 -->
    <header class="header_title">站点({{ form.baseInfo.siteName }})</header>
    <el-row :gutter="24">
      <el-col :span="12" class="mb20">
        <el-card shadow="never">
          <div slot="header" class="clearfix posa">
            <span>管理范围</span>
          </div>
          <div>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">FSU</div>
              </el-col>
              <el-col :span="10">
                <div class="item_data">{{ form.type3 }}台</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">监测设备</div>
              </el-col>
              <el-col :span="10">
                <div class="item_data">{{ form.type4 }}台</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">漏缆</div>
              </el-col>
              <el-col :span="10">
                <div class="item_data">{{ form.type5 }}根</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">天馈线</div>
              </el-col>
              <el-col :span="10">
                <div class="item_data">{{ form.type6 }}根</div>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="mb20">
        <el-card shadow="never">
          <div slot="header" class="clearfix posa">
            <span>基础信息</span>
            <el-button
              style="float: right; padding: 3px 0; margin-right: 20px"
              type="text"
              class="savebtn"
              v-if="flag == true"
              @click="editbtn()"
              ><svg-icon icon-class="edit" /> 编辑</el-button
            >
            <el-button
              style="float: right; padding: 3px 0; margin-right: 20px"
              type="text"
              class="savebtn"
              v-else
              @click="savebtn()"
              ><svg-icon icon-class="save" /> 保存</el-button
            >
          </div>
          <div>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点编号</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.baseInfo.siteCode }}</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站名</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.baseInfo.siteName }}</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点地址</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.baseInfo.siteAddress }}</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">所在铁路线</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.baseInfo.railWayName }}</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点所在局</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.baseInfo.siteArea }}</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点所在段号</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.baseInfo.siteSectionCode }}</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点所在铁路公里标</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.baseInfo.siteKmSign }}</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点经度</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">
                  {{ changeToLngDFM(form.baseInfo.siteLatitude) }}
                </div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点纬度</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">
                  {{ changeToLatDFM(form.baseInfo.siteLongitude) }}
                </div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">漏缆根数</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.count.LEAKY }}根</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">天馈线根数</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">{{ form.type6 }}根</div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">站点其他信息</div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">
                  {{ form.baseInfo.siteOtherMessage }}
                </div>
              </el-col>
            </el-row>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">开通状态</div>
              </el-col>
              <el-col :span="10">
                <el-select
                  v-model="form.baseInfo.isOpen"
                  :disabled="flag"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in isOpenSelect"
                    :key="item.key"
                    :label="item.label"
                    :value="item.key"
                  ></el-option>
                </el-select>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="mb20 specialCard" v-if="form.status">
        <el-card shadow="never">
          <div slot="header" class="clearfix posa">
            <span>当前状态</span>
          </div>
          <div>
            <el-row
              v-for="(item, i) in statusAlarmfun"
              class="text"
              :gutter="24"
            >
              <el-col :span="10">
                <div class="item_name">{{ item.name }}</div>
              </el-col>
              <el-col :span="8">
                <div class="item_data levelData">{{ item.value }}</div>
              </el-col>
              <el-col :span="6"
                ><el-button
                  class="alarmbtn"
                  type="primary"
                  size="mini"
                  v-if="
                    item.value == '连接异常' ||
                    item.value == '紧急' ||
                    item.value == '重要' ||
                    item.value == '一般'
                  "
                  @click="toalarm(item.name)"
                  >处理告警</el-button
                ></el-col
              >
            </el-row>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { changeToLngDFM, changeToLatDFM } from '@/utils/index';
import { DetailMixins } from "./mixins";
import { siteOpen } from "../api";

export default {
  name: "Type2",
  mixins: [DetailMixins],
  data() {
    return {
      flag: true,
      colspan: 14,
      defaultList: [
        {
          name: '设备状态',
          value: '正常'
        }
      ]
    };
  },
  computed: {
    statusAlarmfun() {
      if (this.form.status) {
        return this.form.status;
      } else {
        return this.defaultList;
      }
    },
  },
  watch: {
    statusAlarmfun: {
      immediate: true,
      handler(newV) {
        if (newV) {
          this.$nextTick(function () {
            this.levelcolor2();
          });
        }
      },
    },
  },
  methods: {
    changeToLngDFM,
    changeToLatDFM,
    // 保存
    savebtn() {
      this.flag = true;
      siteOpen(this.info()).then((res) => {
        this.$message.success("修改成功");
      });
    },
    // 实时告警判断状态
    levelcolor2() {
      let dom = document.getElementsByClassName("levelData")
      for (var i = 0; i < this.statusAlarmfun.length; i++) {
        if (dom[i].innerHTML == "连接正常") {
          dom[i].style.color = "green";
          dom[i].innerHTML = "连接正常";
        } if (dom[i].innerHTML == "连接异常") {
          dom[i].style.color = "#f00";
          dom[i].innerHTML = "告警";
        } if (dom[i].innerHTML == "正常") {
          dom[i].style.color = "green";
        } if (dom[i].innerHTML == "紧急") {
          dom[i].style.color = "#f00";
        } if (dom[i].innerHTML == "重要") {
          dom[i].style.color = "#f89850";
          dom[i].innerHTML = "重要告警";
        } if (dom[i].innerHTML == "一般") {
          dom[i].style.color = "#ead906";
          dom[i].innerHTML = "一般告警";
        }
      }
    },
    // 处理告警
    toalarm(data) {
      let topath = ''
      if (data === '设备状态') {
        topath = '/alarm/device';
      } else {
        topath = '/alarm/cableTime';
      }
      this.$router.push({
        path: topath,
        query: {
          siteId: this.form.baseInfo.id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep.el-card {
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  .el-card__header {
    font-size: 18px;
    color: #333333;
    font-weight: 500;
    text-align: center;
    background: rgba(226, 235, 255, 0.39);
    opacity: 1;
  }
  .el-card__body {
    padding: 0px;
  }
}
.posa {
  position: relative;
}
.savebtn {
  position: absolute;
  right: 2%;
}
.specialCard {
  position: absolute;
  top: 328px;
}
.text {
  padding: 10px 20px 10px 20px;
  border-bottom: 1px solid #e3e3e3;
  &:last-child {
    border-bottom: none;
  }
  .item_name,
  .item_data,
  .value_handle {
    height: 16px;
    line-height: 16px;
    margin-top: 12px;
    margin-bottom: 12px;
  }
  .item_name {
    width: 262px;
    height: 16px;
    line-height: 16px;
    color: #7e7e7e;
    margin-top: 12px;
    margin-bottom: 12px;
  }
  .value_handle {
    color: red;
    margin-right: 10px;
  }
  .alarmbtn {
    margin-top: 6px;
    margin-bottom: 6px;
  }
  .el-card:last-child .text {
    border-bottom: none !important;
  }
}
</style>
