<template>
  <div class="dashboard-container">
    <!-- 首页 -->
    <header class="header_title">铁路线({{ form.baseInfo.name }})</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">服务器IP</div>
              </el-col>
              <el-col :span="10">
                <div class="item_data">{{ form.operateSystem.ip }}</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.operateSystem.operateSystem }}
                </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.operateSystem.version }}</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>
          </div>
          <div>
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">设备状态</div>
              </el-col>
              <el-col :span="10">
                <el-row :gutter="20">
                  <el-col :span="10" class="value_handle" :style="acolor3">{{
                    form.status.connectAlarm
                  }}</el-col>
                  <el-col :span="10">
                    <el-button
                      v-if="
                        form.status.connectAlarm == '告警' ||
                        form.status.connectAlarm == '连接异常'
                      "
                      class="alarmbtn"
                      type="primary"
                      size="mini"
                      @click="toalarm(form.status.connectAlarm)"
                      >处理告警</el-button
                    >
                  </el-col>
                </el-row>
              </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-row :gutter="20">
                  <el-col :span="10" class="value_handle" :style="acolor">{{
                    form.status.monitorAlarm
                  }}</el-col>
                  <el-col :span="10">
                    <el-button
                      v-if="
                        form.status.monitorAlarm != '正常' &&
                        form.status.monitorAlarm != '' &&
                        form.status.monitorAlarm != undefined
                      "
                      class="alarmbtn"
                      type="primary"
                      size="mini"
                      @click="toalarm(form.status.monitorAlarm)"
                      >处理告警</el-button
                    >
                  </el-col>
                </el-row>
              </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>管理员({{ userName }})管理范围</span>
          </div>
          <div>
            <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.type2 }}个</div>
              </el-col>
            </el-row>
            <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
              v-if="flag == true"
              style="float: right; padding: 3px 0; margin-right: 20px"
              type="text"
              class="savebtn"
              @click="editbtn()"
              ><svg-icon icon-class="edit" /> 编辑</el-button
            >
            <el-button
              v-else
              style="float: right; padding: 3px 0; margin-right: 20px"
              type="text"
              class="savebtn"
              @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>
                  <el-input
                    v-model="form.baseInfo.name"
                    clearable
                    placeholder="请输入内容"
                    :disabled="flag"
                  />
                </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>
                  <el-input
                    v-model="form.baseInfo.startPointName"
                    clearable
                    placeholder="请输入内容"
                    :disabled="flag"
                  />
                </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>
                  <el-input
                    v-model="form.baseInfo.endPointName"
                    clearable
                    placeholder="请输入内容"
                    :disabled="flag"
                  ></el-input>
                </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>
                  <el-input
                    v-model="form.baseInfo.totalLong"
                    clearable
                    placeholder="请输入内容"
                    :disabled="flag"
                  ></el-input>
                </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>
                  <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-select>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { DetailMixins } from './mixins';
import { getUserName } from '@/utils/auth';
import { railWayOpen } from '../api';

export default {
  name: 'Type1',
  mixins: [DetailMixins],
  data() {
    return {
      colspan: 14,
      acolor: {
        color: ''
      },
      acolor3: {
        color: ''
      }
    }
  },
  computed: {
    userName() {
      return getUserName();
    }
  },
  watch: {
    form: {
      immediate: true,
      handler(newV) {
        if (newV) {
          this.waylevelcolor();
          this.waylevelcolor2();
        }
      }
    },
    deep: true
  },
  methods: {
    // 保存
    savebtn() {
      this.flag = true;
      const params = {
        id: this.form.baseInfo.id,
        name: this.form.baseInfo.name,
        isOpen: this.form.baseInfo.isOpen,
        startPointName: this.form.baseInfo.startPointName,
        endPointName: this.form.baseInfo.endPointName,
        totalLong: this.form.baseInfo.totalLong
      }
      railWayOpen(params).then((res) => {
        this.$message.success('修改成功');
      })
    },
    // 数据更新，判断状态更新
    waylevelcolor() {
      if (this.form.status.monitorAlarm === '正常') {
        this.acolor.color = 'green';
      } else if (this.form.status.monitorAlarm === '紧急') {
        this.acolor.color = '#f00';
        this.form.status.monitorAlarm = '紧急告警';
      } else if (this.form.status.monitorAlarm === '重要') {
        this.acolor.color = '#f89850';
        this.form.status.monitorAlarm = '重要告警';
      } else if (this.form.status.monitorAlarm === '一般') {
        this.acolor.color = '#ead906';
        this.form.status.monitorAlarm = '一般告警';
      }
    },
    // 数据更新，判断状态更新
    waylevelcolor2() {
      if (this.form.status.connectAlarm === '连接正常') {
        this.acolor3.color = 'green';
      } else if (this.form.status.connectAlarm === '连接异常') {
        this.acolor3.color = '#f00';
        this.form.status.connectAlarm = '告警';
      }
    },
    // 处理告警
    toalarm(data) {
      let topath = '';
      if (data === '告警') {
        topath = '/alarm/device';
      } else {
        topath = '/alarm/cableTime';
      }
      this.$router.push({
        path: topath,
        query: {
          wayId: this.form.baseInfo.id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep.el-card {
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  min-height: 243px;
  .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%;
}
.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 {
    margin-right: 10px;
    min-width: 52px;
  }
  .alarmbtn {
    margin-top: 6px;
    margin-bottom: 6px;
  }
  .el-card:last-child .text {
    border-bottom: none !important;
  }
}
</style>
