<!--  -->
<template>
  <div class="tab1Look">
    <div class="insideTop">
      文物典藏管理 > 查看文物典藏
      <div class="add">
        <el-button type="primary" @click="goBack">返 回</el-button>
      </div>
    </div>
    <div class="obstruct"></div>
    <!-- 主要内容2 -->
    <div class="conten" v-if="conLeftId === 'img'">
      <div class="con_top">基本信息</div>
      <div class="row">
        <div>标题：</div>
        <span>{{ myObj.name }}</span>
      </div>
      <div class="row">
        <div>精品类型：</div>
        <span>专题图库</span>
      </div>
      <div class="row">
        <div>显示设置：</div>
        <el-switch
          disabled
          v-model="myObj.display"
          active-color="#b9412e"
          :active-value="1"
          :inactive-value="0"
        >
        </el-switch>
      </div>
      <div class="row">
        <div>图片：</div>
        <div class="imgList">
          <div class="imgParcel" v-for="(item, index) in srcList2" :key="index">
            <el-image
              style="width: 200px; height: 200px"
              :src="item"
              :preview-src-list="srcList2"
            >
            </el-image>
            <!-- 封面显示 -->
            <div class="cover" v-if="imgActive === index">封面图片</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 主要内容1-3 -->
    <div class="conten" v-else>
      <div class="con_top">基本信息</div>
      <div class="row">
        <div>标题：</div>
        <span>{{ myObj.name }}</span>
      </div>
      <div class="row">
        <div>精品类型：</div>
        <span>{{ myObj.type === "model" ? "实物模型" : "视频档案" }}</span>
      </div>
      <div class="row">
        <div>{{ conLeftId === "model" ? "实物图片" : "封面图片" }}：</div>
        <el-image
          v-if="srcList.length !== 0"
          style="width: 200px; height: 200px"
          :src="srcList[0]"
          :preview-src-list="srcList"
        >
        </el-image>
      </div>
      <div class="row">
        <div>{{ conLeftId === "model" ? "模型文件" : "视频文件" }}：</div>
        <a :href="baseURL + myObj.filePath" download>{{ myObj.fileName }}</a>
      </div>
      <div class="row">
        <div>显示设置：</div>
        <el-switch
          disabled
          v-model="myObj.display"
          active-color="#b9412e"
          :active-value="1"
          :inactive-value="0"
        >
        </el-switch>
      </div>
    </div>
  </div>
</template>

<script>
import axios from '@/utils/request'
import { goodsDetail } from '@/apis/tab1'
export default {
  name: 'tab1Look',
  components: {},
  data () {
    // 这里存放数据
    return {
      imgActive: null,
      myArr: [],
      // 服务器前缀地址
      baseURL: '',
      myObj: {},
      conLeftId: '',
      srcList: [],
      srcList2: []
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // 点击返回
    goBack () {
      this.$router.push({
        path: '/layout/tab1',
        query: { conLeftId: this.conLeftId }
      })
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  async created () {
    // 获取服务器前缀地址
    this.baseURL = axios.defaults.baseURL
    // 拿到路由跳转传过来的数据
    this.conLeftId = this.$route.query.conLeftId
    // 通过父亲传过来的id获取详情
    if (this.$route.query.id) {
      const res = await goodsDetail(Number(this.$route.query.id))
      this.myObj = res.data.entity
      this.srcList = [this.baseURL + this.myObj.thumb]
      console.log(998, this.myObj)
      this.myArr = res.data.file
      this.myArr.forEach((v, i) => {
        this.srcList2.push(this.baseURL + v.filePath)
        if (v.isIndex === 1) this.imgActive = i
      })
    }
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {},
  beforeCreate () {}, // 生命周期 - 创建之前
  beforeMount () {}, // 生命周期 - 挂载之前
  beforeUpdate () {}, // 生命周期 - 更新之前
  updated () {}, // 生命周期 - 更新之后
  beforeDestroy () {}, // 生命周期 - 销毁之前
  destroyed () {}, // 生命周期 - 销毁完成
  activated () {} // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='less' scoped>
.tab1Look {
  height: 100%;
  .conten {
    overflow-y: auto;
    position: relative;
    height: calc(100% - 32px);
    .con_top {
      margin-bottom: 12px;
      height: 40px;
      line-height: 40px;
      padding-left: 20px;
      background-color: #fbfbfb;
    }
    .row {
      display: flex;
      margin: 25px 0;
      & > div {
        width: 120px;
        text-align: right;
      }
      .imgList {
        width: 1500px;
        display: flex;
        flex-wrap: wrap;
      }
      .imgParcel {
        position: relative;
        width: 200px;
        height: 200px;
        margin-right: 30px;
        margin-bottom: 30px;
      }
      .cover {
        pointer-events: none;
        font-size: 16px;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        z-index: 999;
        position: absolute;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        height: 40px;
        background-color: rgba(255, 255, 255, 0.4);
      }
    }
  }
}
</style>
