<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="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" type="flex">
          <el-col :span="6">
            <el-form-item label="模版名称">
              <span :title="detailForm.confName" class="text">
                {{ detailForm.confName || '-' }}
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="flex-wrap: wrap" type="flex">
          <el-col :span="6">
            <el-form-item label="巡检类型">
              <span
                :title="dictionaryEscape('xjlx-xjrw', detailForm.type)"
                class="text"
              >
                {{ dictionaryEscape('xjlx-xjrw', detailForm.type) || '-' }}
              </span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="巡检视频点位"> </el-form-item>
            <el-row v-show="detailForm.taskConfVideo.length">
              <el-table
                stripe
                row-key="id"
                class="table-list"
                ref="multipleSelection"
                :height="tableMaxHeight"
                :data="detailForm.taskConfVideo"
              >
                <el-table-column
                  align="center"
                  label="序号"
                  type="index"
                  width="120"
                />
                <el-table-column
                  align="center"
                  label="视频点名称"
                  prop="videoName"
                  show-overflow-tooltip
                />
                <el-table-column
                  align="center"
                  label="视频点编码"
                  prop="videoId"
                  show-overflow-tooltip
                />
                <!-- <el-table-column
                    align="center"
                    label="排序号"
                    prop="rank"
                    width="200"
                    show-overflow-tooltip
                >
                </el-table-column> -->
              </el-table>
            </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 {taskDetail} from '@/api/patrolAndRescue/videoPatrol/videoConfig'
import PubSub from 'pubsub-js'
import {dictionaryEscape} from '@/utils/dictionary'

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

        this.detailForm = {
          taskConfVideo,
          confType: confType.toString(),
          type: type.toString(),
          ...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;
    }
  }
}
</style>
