<template>
  <div>
    <!-- 文物清单表格 -->
    <TablePage
      :data="list.records"
      :tableTitle="crTabletitle"
      needExpand
      height="500px"
    >
      <template v-slot:status="data">
        <el-switch
          slot="reference"
          :value="Boolean(Number(data.scope.status))"
        ></el-switch>
      </template>
      <template v-slot:expand="data">
        <CulturalRelicBaseInfo :info="list.records[data.scope]" />
      </template>
      <template v-slot:faceImagePressUrl="data">
        <img
          :src="$getFullUrl(data.scope.faceImagePressUrl)"
          alt="暂无图片"
          style="
            cursor: pointer;
            width: 80px;
            height: 80px;
            object-fit: contain;
          "
          @click="handelPreviewImages(data.scope.faceImagePressUrl)"
        />
      </template>
    </TablePage>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="Number(list.current)"
      :page-sizes="[10, 20, 40, 50]"
      :page-size="Number(list.size)"
      layout="total, sizes, prev, pager, next, jumper"
      :total="Number(list.total)"
      class="pagination"
    >
    </el-pagination>
  </div>
</template>

<script>
import CulturalRelicBaseInfo from "@/components/CulturalRelicInfo";
import { crTabletitle } from "../../config";
import { getListFlowCulturalRelicByPage } from "@/api/approval";
export default {
  components: {
    CulturalRelicBaseInfo,
  },
  props: {
    crList: {
      type: Object,
      default: () => ({}),
    },
    flowId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      crTabletitle,
      list: {
        records: {},
        size: 10,
        current: 1,
        total: 0,
      },
    };
  },
  watch: {
    crList: {
      handler(value) {
        const { records, size, current, total } = value;
        this.list = { records, size, current, total };
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    // 改变页容量
    handleSizeChange(value) {
      this.list.size = value;
      this.loadData();
    },

    // 改变当前显示页
    handleCurrentChange(value) {
      this.list.current = value;
      this.loadData();
    },

    async loadData(form) {
      const { current, size } = this.list;
      var params = {
        page: current,
        limit: size,
        flowId: this.flowId,
      };
      const res = await getListFlowCulturalRelicByPage(params);
      if (res.code == 0) {
        this.list = res.data;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.pagination {
  margin-top: 20px;
}
</style>
