<template>
  <div class="edit-add-detail detail">
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="detailForm"
        label-position="right"
        label-suffix="："
      >
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">预警信息</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="12">
            <el-form-item label="预警名称">
              <span :title="detailForm.warningName" class="text">
                {{ detailForm.warningName || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预警发布单位">
              <span :title="detailForm.warningUnit" class="text">
                {{ detailForm.warningUnit || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预警灾害类型">
              <span :title="detailForm.warningValue" class="text">
                {{
                  dictionaryEscape('yjlxdm', detailForm.warningValue + '') ||
                  '-'
                }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="6">
            <el-form-item label="所属省份">
              <span
                :title="detailForm.province"
                class="text"
                style="white-space:normal"
              >
                {{ detailForm.province || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属区域">
              <span :title="detailForm.regionalName" class="text">
                {{ detailForm.regionalName || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="可能受影响区县">
              <span :title="detailForm.warnRange" class="text">
                {{ detailForm.warnRange || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="可能受影响路段">
              <span
                :title="detailForm.roadName"
                class="text"
                style="white-space:normal"
              >
                {{ detailForm.roadName || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="6">
            <el-form-item label="起始桩号">
              <span :title="detailForm.pegSVal" class="text">
                  {{ detailForm.pegSVal || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结束桩号">
              <span :title="detailForm.pegEVal" class="text">
                  {{ detailForm.pegEVal || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预警时间">
              <span :title="detailForm.warningTime" class="text">
                {{ detailForm.warningTime || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="12">
            <el-form-item label="预警等级">
              <span :title="detailForm.warningLevel" class="text">
                {{
                  dictionaryEscape('yxjc-yjdj', detailForm.warningLevel + '') ||
                  '-'
                }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="24">
            <el-form-item label="预警内容">
              <span :title="detailForm.warningContent" class="text">
                {{ detailForm.warningContent || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">叫应信息</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="6">
            <el-form-item label="是否落实“叫应”机制">
              <span :title="detailForm.responseMechanism" class="text">
                {{ detailForm.responseMechanism === '1' ? '是' : '否' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="6">
            <el-form-item label="巡查里程(公里)">
              <span :title="detailForm.inspectMileage" class="text">
                {{ detailForm.inspectMileage || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出动巡查人员(人)">
              <span :title="detailForm.peopleSituation" class="text">
                {{ detailForm.peopleSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预置养护队伍(支)">
              <span
                :title="detailForm.presetsTeamSituation"
                class="text"
                style="white-space:normal"
              >
                {{ detailForm.presetsTeamSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预置养护人数(人)">
              <span
                :title="detailForm.presetsPeopleSituation"
                class="text"
                style="white-space:normal"
              >
                {{ detailForm.presetsPeopleSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="6">
            <el-form-item label="出动巡查车辆(台)">
              <span
                :title="detailForm.carSituation"
                class="text"
                style="white-space:normal"
              >
                {{ detailForm.carSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预置车辆(台)">
              <span
                :title="detailForm.presetsCarSituation"
                class="text"
                style="white-space:normal"
              >
                {{ detailForm.presetsCarSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="边坡土壤含水率">
              <span :title="detailForm.waterContent" class="text">
                {{ detailForm.waterContent || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="灾害天气(汛期)路段分级分类管控阈值">
              <span
                :title="detailForm.controlThreshold"
                class="text"
                style="white-space:normal"
              >
                {{ detailForm.controlThreshold || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="24">
            <el-form-item label="采取的措施">
              <span :title="detailForm.takeAction" class="text">
                {{ detailForm.takeAction || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="24">
            <el-form-item label="管制情况">
              <span :title="detailForm.controlSituation" class="text">
                {{ detailForm.controlSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="24">
            <el-form-item label="出行信息发布情况">
              <span :title="detailForm.publishSituation" class="text">
                {{ detailForm.publishSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="24">
            <el-form-item label="预置物资">
              <span :title="detailForm.presetsGoodsSituation" class="text">
                {{ detailForm.presetsGoodsSituation || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import {dictionaryEscape} from '@/utils/dictionary'
import {tableDetail} from '@/api/patrolAndRescue/operationalMonitoring/calledPartyAnswer'
import PubSub from 'pubsub-js'

export default {
  name: 'DetailPage',
  props: {
    componentName: {
      default: 'TablePage',
      type: String
    }
  },
  components: {},
  data() {
    return {
      detailForm: {},
      pubSub: null
    }
  },
  watch: {
    componentName: {
      handler(newVal) {
        if (newVal === this.$options.name) {
          this.openPage()
        } else {
          this.closePage()
        }
      }
    }
  },
  mounted() {
    this.pubSub = PubSub.subscribe('DetailPage', (_, data) => {
      if (data.id) {
        this.getDetail(data.id)
      }
    })
  },
  methods: {
    dictionaryEscape,
    // 打开页面执行
    openPage() {
    },
    // 关闭页面执行
    closePage() {
      // 重置组件数据
      Object.assign(this.$data, this.$options.data.call(this), {
        pubSub: this.pubSub
      })
      this.$nextTick(_ => {
        this.$refs.formInfo.$el.scrollTop = 0
      })
    },
    // 获取详情
    async getDetail(id) {
      const data = await tableDetail(id)
      this.detailForm = {...data}
    }
  },
  beforeDestroy() {
    // 在组件销毁之前 清除订阅消息
    PubSub.unsubscribe(this.pubSub)
  }
}
</script>

<style lang="scss" scoped>
.form-content {
  height: 0;
}
</style>
