<template>
  <div class="container">
    <div class="page-title">
      检索记录
    </div>

    <div class="card" v-for="item in list" :key="item.id">
      <div class="name">
        <div class="text1">
          检查情况
        </div>
        <div class="text2">
          {{ item.createdAt }}
        </div>
      </div>
      <div class="content">
        {{ item.content }}
      </div>

      <div class="imgs">
        <van-image
          :src="img"
          v-for="(img, imgIndex) in item.file"
          :key="imgIndex"
          fit="contain"
          @click="preview(imgIndex, item.file)"
        />
      </div>
    </div>

    <van-empty v-if="empty" description="暂无检索记录" />

    <div class="btn">
      <van-button
        :color="$colors.prim"
        block
        round
        @click="$router.push('recordAdd?recordId=' + recordId)"
        >添加检索记录</van-button
      >
    </div>
  </div>
</template>

<script>
import { ImagePreview } from "vant";
export default {
  metaInfo() {
    return {
      title: "检索记录"
    };
  },
  data() {
    return {
      recordId: "",
      list: [],
      empty: false
    };
  },
  mounted() {
    this.recordId = this.$route.query.recordId;
    this.$http
      .post(
        "/recordCheck/all",
        {
          query: {
            recordId: this.recordId
          }
        },
        { body: "json" }
      )
      .then(res => {
        this.list = res.content;
        this.empty = res.empty;
      });
  },
  methods: {
    preview(index, imgs) {
      ImagePreview({
        images: imgs,
        startPosition: index,
        closeable: true
      });
    }
  }
};
</script>

<style lang="less" scoped>
.btn {
  position: fixed;
  bottom: 0;
  padding: 6px 47px;
  left: 0;
  right: 0;
  z-index: 20;
  background: #fff;
}
.container {
  padding: 10px 20px 100px;
}
.page-title {
  font-size: 20px;
  font-weight: bold;
  color: #313233;
  line-height: 28px;
  padding: 16px;
  background: #ffffff;
  border-radius: 12px;
}

.card {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  margin-top: 12px;

  .name {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .text1 {
      font-size: 16px;
      font-weight: bold;
      color: #313233;
      line-height: 28px;
    }

    .text2 {
      font-size: 12px;
      color: #969799;
      line-height: 17px;
    }
  }

  .content {
    font-size: 13px;
    color: #939599;
    line-height: 22px;
  }

  .imgs {
    display: flex;
    margin-top: 16px;

    .van-image {
      width: 72px;
      height: 72px;
      border-radius: 8px;
      overflow: hidden;
    }
  }
}
</style>
