<template>
  <div class="edit-add-detail detail">
    <div v-loading="formLoading" class="form-content" element-loading-background="rgba(10 ,38 ,61, 0.95)"
         element-loading-text="数据加载中...">
      <el-form ref="formInfo" :model="detailForm" class="detail-form" 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">
          <el-col :span="6">
            <el-form-item label="报案电话">
              <span :title="detailForm.rescueTel" class="text">
                {{ detailForm.rescueTel || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报案时间">
              <span :title="detailForm.rescueTime" class="text">
                {{ detailForm.rescueTime || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报案来源">
              <span :title="detailForm.rescueSrc" class="text">
                {{ dictionaryEscape('baly', detailForm.rescueSrc + '') || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属路段">
              <span :title="detailForm.roadName" class="text">
                {{ detailForm.roadName }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开始巡查站">
              <span :title="detailForm.startPatrolName" class="text">
                {{ detailForm.startPatrolName || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结束巡查站">
              <span :title="detailForm.endPatrolName" class="text">
                {{ detailForm.endPatrolName || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="占道情况">
              <span :title="detailForm.occupy" class="text">
                {{ detailForm.occupy || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="6">
            <el-form-item label="现场情况">
              <span :title="detailForm.sceneInfo" class="text">
                {{ detailForm.sceneInfo || '-' }}
              </span>
            </el-form-item>
          </el-col> -->
          <el-col :span="6">
            <el-form-item label="事件开始点位桩号全值">
              <span :title="detailForm.pegVal" class="text">
                {{ detailForm.pegVal || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="经度">
              <span :title="detailForm.lng" class="text">
                {{ detailForm.lng || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="纬度">
              <span :title="detailForm.lat" class="text">
                {{ detailForm.lat || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="事发天气">
              <span :title="detailForm.weather" class="text">
                {{ detailForm.weather || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="事件上报时间">
              <span :title="detailForm.uploadTime" class="text">
                {{ detailForm.uploadTime || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="事件上报部门">
              <span :title="detailForm.uploadTeamName" class="text">
                {{ detailForm.uploadTeamName || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="事件上报人员">
              <span :title="detailForm.uploadUserName" class="text">
                {{ detailForm.uploadUserName || '-' }}
              </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.receiveOrgName" class="text">
                {{ detailForm.receiveOrgName || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="接收人员">
              <span :title="detailForm.receiveUserName" class="text">
                {{ detailForm.receiveUserName || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="救援类型">
              <span :title="detailForm.rescueType" class="text">
                {{ dictionaryEscape('jylx', detailForm.rescueType + '') || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="故障车牌">
              <span :title="detailForm.carCode" class="text">
                {{ detailForm.carCode || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="故障车类">
              <span :title="detailForm.carCalss" class="text">
                {{ dictionaryEscape('gzcl', detailForm.carCalss + '') || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="故障车型">
              <span :title="detailForm.carType" class="text">
                {{ dictionaryEscape('gzcx', detailForm.carType + '') || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="车载重量（吨）">
              <span :title="detailForm.carWeight" class="text">
                {{ detailForm.carWeight || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="行驶方向">
              <span :title="detailForm.direction" class="text">
                {{ dictionaryEscape('xsfx', detailForm.direction + '') || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="车主姓名">
              <span :title="detailForm.carUser" class="text">
                {{ detailForm.carUser || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="车主电话">
              <span :title="detailForm.carUserTel" class="text">
                {{ detailForm.carUserTel || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button v-if="eventStatus < 2 && !formLoading" :loading="confirmLoading" type="primary" @click="eventConfirm">
        核实登记
      </el-button>
      <el-button @click="changePage('TablePage')">
        {{ $t('domestic.cancel') }}
      </el-button>
    </div>
    <el-backtop :visibility-height="10" target=".detail-form">
      <div class="top-box">UP</div>
    </el-backtop>
  </div>
</template>

<script>
import {dictionaryEscape} from '@/utils/dictionary'
import {eventConfirm, tableDetail} from '@/api/patrolAndRescue/obstacleClearingRescue/reportRescueQuery'
import PubSub from 'pubsub-js'

export default {
  name: 'DetailPage',
  props: {
    componentName: {
      default: 'TablePage',
      type: String
    }
  },
  components: {},
  data() {
    return {
      formLoading: false,
      detailForm: {},
      pubSub: null,
      eventStatus: 0,
      confirmLoading: false
    }
  },
  computed: {},
  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.eventStatus = data.status
        this.getDetail(data.id)
      }
    })
  },
  methods: {
    dictionaryEscape,
    eventConfirm() {
      this.$confirm('确定救援信息核实登记吗？', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        this.confirmLoading = true
        const {state} = await eventConfirm(this.detailForm.id)
        if (state) {
          this.$message.success(`救援信息核实登记成功`)
          this.confirmLoading = false
          this.changePage('TablePage', 'add')
        }
      })
    },
    // 打开页面执行
    openPage() {
    },
    changePage(pageName = '', type = '') {
      if (!pageName) return
      this.$emit('changePage', pageName, _ => {
        PubSub.publish(pageName, {type})
      })
    },
    // 关闭页面执行
    closePage() {
      // 重置组件数据
      Object.assign(this.$data, this.$options.data.call(this), {pubSub: this.pubSub})
      this.$nextTick(_ => {
        this.$refs.formInfo.$el.scrollTop = 0
      })
    },


    // 获取详情
    async getDetail(id) {
      try {
        this.formLoading = true
        const {...detailForm} = await tableDetail(id)
        this.detailForm = {
          ...detailForm
        }
      } finally {
        this.formLoading = false
      }

    }
  },
  beforeDestroy() {
    // 在组件销毁之前 清除订阅消息
    PubSub.unsubscribe(this.pubSub)
  }
}
</script>

<style lang="scss" scoped></style>
