<template>
  <div class="doc-wrap">
    <div class="table-title">
      <span>
        {{ title }}
      </span>
    </div>
    <div class="data-list">
      <div
        class="item"
        v-for="(item, index) in docDataList"
        :key="item.id"
        @click="toDetail(item)"
      >
        <span>{{ item.title }}</span>
        <span>{{ item.createTime }}</span>
      </div>

      <pagination
        :total="total"
        :page.sync="queryForm.pageNum"
        :limit.sync="queryForm.pageSize"
        :pageSizes="pageSizes"
        @pagination="getResult"
        style="display: unset;text-align: right;"
      />
    </div>
  </div>
</template>
<script>
import { zhxxList } from "@/api/zhxx";
export default {
  name: "docWrap",
  props: {
    isSearch: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: "政策文件"
    },
    type: {
      type: String,
      default: "1"
    },
    proTotal: {
      type: Number,
      default: 0
    },
    docData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      total: 0,
      pageSizes: [10, 20, 30, 50],
      docDataList: [],
      queryForm: {
        cv: {
          name: "title",
          type: "like",
          value: ""
        },
        data: {
          textType: this.type
        },
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  mounted() {
    if (!this.isSearch) {
      this.getResult();
    } else {
      this.docDataList = this.docData;
      this.total = this.proTotal;
    }
  },
  methods: {
    getResult() {
      zhxxList(this.queryForm).then(res => {
        this.docDataList = res.data.records;
        this.total = res.data.total;
        console.log("xxxxxx", res);
      });
    },
    toDetail(item) {
      this.$router.push(
        "/summarizedDetail?title=" +
          item.title +
          "&id=" +
          item.id +
          "&fromDoc=1"
      );
    }
  }
};
</script>
<style scoped lang="less">
.doc-wrap {
  overflow: hidden;
  width: 100%;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  .table-title {
    height: 47px;
    line-height: 47px;
    background-color: #f6f6f6;

    span {
      font-family: PingFangSC, PingFang SC;
      font-weight: 600;
      font-size: 16px;
      color: #333333;
      font-style: normal;

      &::before {
        content: "";
        display: inline-block;
        width: 3px;
        height: 16px;
        background: #005eb7;
        margin-right: 10px;
        vertical-align: middle;
      }
    }
  }

  .data-list {
    .item {
      padding-left: 10px;
      position: relative;
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #f0f0f0;
      cursor: pointer;

      &::hover {
        span {
          color: #005eb7;
        }
      }
      span {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #333333;
        font-style: normal;
      }

      &::before {
        position: absolute;
        top: 18px;
        left: 0;
        content: "";
        display: inline-block;
        width: 5px;
        height: 5px;
        background: #005eb7;
        margin-right: 10px;
        vertical-align: middle;
      }
    }
  }
}
</style>
