<template>
  <div class="edit-add-detail detail show-scrollbar">
    <div
      v-loading="detailLoading"
      class="form-content"
      element-loading-background="rgba(10 ,38 ,61, 0.9)"
      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 :offset="0" :span="24">
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="账号名">
                <span :title="detailForm.account" class="text">
                  {{ detailForm.account || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="所属路段">
                <span :title="detailForm.roadName" class="text">
                  {{ detailForm.roadName || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="队员姓名">
                <span :title="detailForm.name" class="text">
                  {{ detailForm.name || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="手机号">
                <span :title="detailForm.tel" class="text">
                  {{ detailForm.tel || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="身份证号">
                <span :title="detailForm.code" class="text">
                  {{ detailForm.code || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="外包公司">
                <span :title="detailForm.outCompanyName" class="text">
                  {{ detailForm.outCompanyName || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="人员类型">
                <span :title="dictionaryEscape('rylx-xcjyry',detailForm.type)" class="text">
                  {{ dictionaryEscape('rylx-xcjyry', detailForm.type) || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="人员职务">
                <span :title="dictionaryEscape('ryzw-xcjyry',detailForm.post)" class="text">
                  {{ dictionaryEscape('ryzw-xcjyry', detailForm.post) || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24" style="flex-wrap: wrap;margin-left: 80px" type="flex">
              <el-col :span="6">
                <el-form-item label="是否外派人员">
                <span :title="dictionaryEscape('sfpj',detailForm.isOut)" class="text">
                  {{ dictionaryEscape('sfpj', detailForm.isOut) || '-' }}
                </span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <el-backtop :visibility-height="20" target=".detail-form">
      <div class="top-box">UP</div>
    </el-backtop>
  </div>
</template>

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

export default {
  name: 'DetailPage',
  props: {
    componentName: {
      default: 'TablePage',
      type: String
    }
  },
  components: {},
  data() {
    return {
      detailForm: {},
      detailLoading: true,
      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) {
      try {
        let {...detailForm} = await tableDetail(id)
        this.detailForm = detailForm
      } finally {
        this.detailLoading = false
      }
    }
  },
  beforeDestroy() {
    // 在组件销毁之前 清除订阅消息
    PubSub.unsubscribe(this.pubSub)
  }
}
</script>

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