<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" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="所属区域">
              <span :title="detailForm.regionName" class="text">
                {{ detailForm.regionName || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <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" type="flex">
          <el-col :span="8">
            <el-form-item label="检查类型">
              <span
                :title="dictionaryEscape('spxj-jclx', detailForm.checkType)"
                class="text"
              >
                {{ dictionaryEscape('spxj-jclx', detailForm.checkType) || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="巡检类型">
              <span
                :title="
                  dictionaryEscape('spxj-xjlx', detailForm.inspectionType)
                "
                class="text"
              >
                {{
                  dictionaryEscape('spxj-xjlx', detailForm.inspectionType) ||
                  '-'
                }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="巡检地点">
              <span :title="detailForm.placeName" class="text">
                {{ detailForm.placeName || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="巡检日期">
              <span :title="detailForm.inspectionDate" class="text">
                {{ detailForm.inspectionDate || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="巡检时间">
              <span :title="detailForm.inspectionTime" class="text">
                {{ detailForm.inspectionTime || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="巡检结果">
              <i
                class="el-icon-close"
                style="
                  color: #f56c6c;
                  font-size: 15px;
                  display: block;
                  margin-right: 4px;
                "
                v-if="detailForm.inspectionResult === '2'"
              ></i>
              <i
                class="el-icon-check"
                style="
                  color: #67c23a;
                  font-size: 15px;
                  display: block;
                  margin-right: 4px;
                "
                v-if="detailForm.inspectionResult === '1'"
              ></i>
              <span
                :title="
                  dictionaryEscape('spxj-xjjg', detailForm.inspectionResult)
                "
                class="text"
              >
                {{
                  dictionaryEscape('spxj-xjjg', detailForm.inspectionResult) ||
                  '-'
                }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="记录人">
              <span :title="detailForm.recordUser" class="text">
                {{ detailForm.recordUser || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="异常处理记录">
              <span :title="detailForm.resultRecord" class="text">
                {{ detailForm.resultRecord || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="8">
            <el-form-item label="备注">
              <span :title="detailForm.remark" class="text">
                {{ detailForm.remark || '-' }}
              </span>
            </el-form-item>
          </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 {taskDetail} from '@/api/patrolAndRescue/videoPatrol/videoPatrolRecord'
import PubSub from 'pubsub-js'
import {dictionaryEscape} from '@/utils/dictionary'

export default {
  name: 'DetailPage',
  props: {
    componentName: {
      default: 'TablePage',
      type: String,
    },
  },
  components: {},
  data() {
    return {
      //   tableMaxHeight: 550,
      detailForm: {
        taskConfVideo: [],
      },
      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) => {
      console.log(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 {
        const {...detailForm} = await taskDetail(id)

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

<style lang="scss" scoped>
.image-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 15px;
  margin: 5px 0;

  ::v-deep .el-image {
    width: 100px;
    height: 100px;
    border-radius: 4px;
    user-select: none;
    position: relative;
    transition: all 0.15s;
    box-shadow: 3px 3px 10px rgba(darken($--system-background-color, 30%), 0.3);

    .el-image__inner {
      transition: transform 0.2s;
      position: absolute;
    }

    &:hover {
      .el-image__inner {
        transform: scale(1.5);
      }
    }

    .el-image__error {
      background-color: $--system-box-color2;
    }

    .el-image__placeholder {
      background-color: $--color-text-placeholder;
    }

    &:has(.el-image__error, .el-image__placeholder) {
      box-shadow: none;
    }
  }
}
::v-deep .el-row{
        margin-left: 80px!important;
    }

</style>
