<template>
  <div class="previewContain" v-loading="previewLoading">
    <!-- {{ previewData }} -->
    <!-- {{ previewData.name }}______{{ previewData.id }} -->
    <div class="pictureBox">
      <el-row
        v-for="i in rowNum"
        :key="'row-' + i"
        :style="{ height: 100 / rowNum + '%' }"
      >
        <el-col
          :span="24 / colNum"
          v-for="(item, index) in picList"
          :key="'col-' + index"
          v-if="index < colNum * i && index >= colNum * (i - 1)"
        >
          <div class="imgcloum" @click="handleTowerPic(item)">
            <!-- 首先判断是否是图片mediatype=0,并且path不为空  展示图片 -->
            <img
              :src="item.path + '!1366x768'"
              v-if="item.mediatype == 0 && item.path !== null"
            />
            <!-- 判断是否是视频mediatype=1,并且path不为空  展示图片 -->
            <img
              v-else-if="item.mediatype == 1 && item.thumb !== null"
              :src="item.thumb + '!1366x768'"
            />
            <!-- 判断是否是视频mediatype=bull,并且path为空  展示暂无图片 -->
            <img
              v-else-if="item.mediatype == null"
              src="../../assets/img/nodatapic2.jpg"
            />
            <div class="picInfo">
              <p>
                {{ item.linename }}-{{ item.towername }}-（{{
                  item.alias !== null && item.alias !== ""
                    ? item.alias
                    : item.channnelname
                }}）
              </p>
              <p class="timeinfo" v-if="item.mediatype !== null">
                {{ $moment(item.photoTime).format("YYYY-MM-DD HH:mm:ss") }}
              </p>
              <p class="timeinfo" v-else>无抓拍</p>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <div class="pageNation" v-if="picList.length !== 0">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-size="pageSize"
        layout=" prev, pager, next, jumper,total"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { getTowerAndPhotoList } from "@/utils/api/index";

export default {
  props: ["previewData"],
  data() {
    return {
      rowNum: 4,
      colNum: 4,
      page: 1, // 当前页数
      pageSize: 16, // 每页数量
      totalPage: 0, //总页数
      total: 0, //总条数
      picList: [], //图片列表数据
      id: "",
      type: "",
      previewLoading: false,
    };
  },
  mounted: function () {},
  methods: {
    //获取所有杆塔图片列表
    getPicList(id, type, page) {
      this.id = id;
      this.type = type;
      this.page = page;
      console.log(id, type);
      this.previewLoading = true;
      getTowerAndPhotoList({
        id: id,
        type: type,
        pageindex: page,
        pagesize: this.rowNum * this.colNum,
      })
        .then((res) => {
          this.previewLoading = false;
          console.log(res);
          this.picList = res.data.list;
          this.totalPage = res.data.totalpage;
          this.total = res.data.total;
        })
        .catch((err) => {
          console.log(err); //代码错误、请求失败捕获
        });
    },
    handleTowerPic(val) {
      console.log(val);
      this.$parent.jumpTowerPic(val);
      console.log("调用父组件方法");
    },
    //点击分页
    handleCurrentChange(val) {
      this.page = val;
      this.picList = [];
      this.getPicList(this.id, this.type, this.page);
    },
  },
};
</script>

<style lang="less">
.previewContain {
  width: 100%;
  padding: 16px;
  height: auto;
  //background: #fcc;
  .pictureBox {
    height: calc(100% - 38px);
    //background-color: aquamarine;
    .el-col {
      height: 100%;
      padding-right: 0.3%;
      padding-left: 0.3%;
      padding-top: 0.3%;
      padding-bottom: 0.3%;
      border-radius: 4px;
      overflow: hidden;
    }
    .imgcloum {
      width: 100%;
      height: 100%;
      //   background: #f00;
      cursor: pointer;
      position: relative;
      border: 1px solid transparent;
      border-radius: 4px;
      overflow: hidden;
      &:hover {
        border: 1px solid #169e8c;
      }
      img {
        width: 100%;
        height: 100%;
      }
      .picInfo {
        position: absolute;
        background: #169e8ca1;
        color: #fff;
        height: auto;
        font-size: 12px;
        left: 0;
        bottom: 0;
        width: 100%;
        text-align: center;
        .timeinfo {
          margin-top: 4px;
          margin-bottom: 4px;
        }
      }
    }
  }
}
</style>
