<template>
  <div class="dashboard-container">
    <!-- 首页 -->
    <header class="header_title">
      漏缆({{ form.baseInfo.leakyCableDescribe }})
    </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">历史记录</div>
              </el-col>
              <el-col :span="8">
                <div class="item_data">{{ form.log.all }}条</div>
              </el-col>
              <el-col :span="6">
                <el-button
                  class="picbtn"
                  type="success"
                  size="mini"
                  @click="trendAnalysis"
                >趋势分析图形</el-button>
              </el-col>
            </el-row> -->
            <el-row class="text" :gutter="24">
              <el-col :span="10">
                <div class="item_name">维修记录</div>
              </el-col>
              <el-col :span="8">
                <div class="item_data">{{ form.log.monitor }}条</div>
              </el-col>
              <el-col :span="6" />
              <el-button
                class="picbtn"
                type="success"
                size="mini"
                @click="trendAnalysis"
                >趋势分析图形</el-button
              >
            </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 class="item_data">{{ form.baseInfo.leakyCableCode }}</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.leakyCableDescribe }}
                </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.siteName }}</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="colspan">
                <div class="item_data">{{ form.baseInfo.fsuName }}</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.equipName }}</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.leakyCableMode }}</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.leakyCableLength }}m
                </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.hundredMetersLoss"
                    clearable
                    placeholder="请输入内容"
                    :disabled="flag"
                    ><template slot="append">dB/m</template></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 class="item_data">{{ form.baseInfo.reductRatio }}Np/m</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.sendPower }}dB/m</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.kmSign }}</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.jumperLength }}m</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.inserterLength }}m</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.antennaFeederLength }}m
                </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">
                <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>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12" class="mb20 specialCard">
        <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="8">
                <div
                  v-if="stateEmergency.length != 0"
                  class="item_data levelData"
                  :style="acolor"
                >
                  {{ stateEmergency[0].value }}
                </div>
              </el-col>
              <el-col :span="6">
                <el-button
                  v-if="
                    form.status.length &&
                    (form.status[0].value == '紧急告警' ||
                      form.status[0].value == '重要告警' ||
                      form.status[0].value == '一般告警')
                  "
                  class="alarmbtn"
                  type="primary"
                  size="mini"
                  @click="toalarm()"
                  >处理告警</el-button
                >
              </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 v-if="stateEmergency.length != 0" class="item_data">
                  {{ stateEmergency[1].value }}
                </div>
              </el-col>
            </el-row>
            <el-row
              v-for="(item, i) in distanceList"
              :key="i"
              class="text"
              :gutter="24"
            >
              <el-col :span="10">
                <div class="item_name">
                  距({{ form.baseInfo.leakyCableDescribe }}方向){{
                    item.value
                  }}米
                </div>
              </el-col>
              <el-col :span="colspan">
                <div class="item_data">驻波比：{{ standingWaveRatio[i].value }}</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="8">
                <div class="item_data">
                  {{ form.baseInfo.hundredMetersLoss }}dB/m
                </div>
              </el-col>
              <el-col :span="6">
                <el-button
                  class="picbtn"
                  type="success"
                  size="mini"
                  @click="generateChart"
                  >生成图形</el-button
                >
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <picAnalysis :flag="curflag" :curInfo="curObj" @cancel="cancel" />
    <trendAnalysis
      :flag="trendflag"
      :selectId="selectId"
      :curInfo="curInfo"
      :type="type == 5 ? 0 : 1"
      @cancel="cancel"
    />
  </div>
</template>

<script>
import { DetailMixins } from './mixins';
import { leakyCableOpen } from '../api';
import picAnalysis from '@/views/history/leakyCableStatus/components/picAnalysis.vue';
import trendAnalysis from './trendAnalysis.vue';

export default {
  name: 'Type5',
  mixins: [DetailMixins],
  data() {
    return {
      colspan: 14,
      acolor: {
        color: ''
      },
      standingWaveRatio: [], // 驻波比
      distanceList: [], // 距离数组
      stateEmergency: [], // 状态
      curflag: 0,
      trendflag: 0,
      curObj: []
    }
  },
  components: { picAnalysis, trendAnalysis },
  computed: {
    statusAlarmfun() {
      return this.form.status || [];
    }
  },
  watch: {
    statusAlarmfun: {
      handler(newV) {
        if (newV) {
          this.handleData();
          this.$nextTick(function () {
            this.leakylevelcolor();
          })
        }
      }
    },
    deep: true
  },
  methods: {
    // 趋势分析图形
    trendAnalysis() {
      this.trendflag = 1;
    },
    // 生成图形
    generateChart() {
      this.curObj = [];
      this.curflag = 1;
      this.curObj.push(this.curInfo.baseInfo.leakyCableDescribe);
    },
    // 取消
    cancel() {
      this.curflag = 0;
      this.trendflag = 0;
    },
    // 保存
    savebtn() {
      this.flag = true;
      const params = {
        id: this.form.baseInfo.id,
        isOpen: this.form.baseInfo.isOpen,
        hundredMetersLoss: this.form.baseInfo.hundredMetersLoss
      }
      leakyCableOpen(params).then((res) => {
        this.$message.success('修改成功');
      })
    },
    // 数据更改，判断状态更改
    leakylevelcolor() {
      if (this.form.status[0].value === '正常') {
        this.acolor.color = 'green';
      } else if (this.form.status[0].value === '紧急') {
        this.acolor.color = '#f00';
        this.form.status[0].value = '紧急告警';
      } else if (this.form.status[0].value === '重要') {
        this.acolor.color = '#f89850';
        this.form.status[0].value = '重要告警';
      } else if (this.form.status[0].value === '一般') {
        this.acolor.color = '#ead906';
        this.form.status[0].value = '一般告警';
      }
    },
    // 处理告警
    toalarm() {
      this.$router.push({
        path: '/alarm/cableTime',
        query: {
          alarmTargetName: this.form.baseInfo.leakyCableDescribe
        }
      })
    },
    // 处理数据
    handleData() {
      const arr1 = []; const arr2 = []; const arr3 = []
      if (this.statusAlarmfun.length !== 0) {
        for (let i = 0; i < this.statusAlarmfun.length; i++) {
          if (i % 2 !== 0) {
            if (this.statusAlarmfun[i].name === '最后更新时间') {
              this.statusAlarmfun[i].value = this.dateFormat(this.statusAlarmfun[i].value, 'yyyy-MM-dd HH:mm:ss');
              arr1.push(this.statusAlarmfun[i]);
            } else {
              arr2.push(this.statusAlarmfun[i]);
            }
          } else {
            if (this.statusAlarmfun[i].name === '漏缆状态') {
              arr1.push(this.statusAlarmfun[i]);
            } else {
              arr3.push(this.statusAlarmfun[i]);
            }
          }
        }
        this.stateEmergency = arr1;
        this.standingWaveRatio = arr2;
        this.distanceList = arr3;
      }
    }
  }
}
</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;
  }
}
.specialCard {
  position: absolute;
  top: 170px;
}
.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 {
    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;
  }

  .el-card:last-child .text {
    border-bottom: none !important;
  }
}
</style>
