<template>
  <div class="page">
    <el-form :model="search" ref="ruleForm" label-width="120px" size="mini">
      <el-form-item label="原文内容：" prop="fileContent">
        <el-input v-model="search.fileContent" placeholder="请输入原文内容" clearable ></el-input>
      </el-form-item>
      <div class="btn">
        <el-button  type="primary" size="mini" @click="searchClick">查询</el-button>
        <el-button @click="handleReset" size="mini">重置</el-button>
      </div>
    </el-form>
    <el-table v-loading="loading" border :data="tableData" max-height="550px">
      <el-table-column prop="fileName" label="文件名称" align="center" width="250px" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="fileContent" label="原文内容" align="center">
      </el-table-column>
    </el-table>
    <el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange"
      layout="total, prev, pager, next, sizes" :page-size="pagination.pageSize" :page-sizes="[10, 20, 30, 50]"
      :current-page="pagination.pageNum" :total="pagination.total">
    </el-pagination>
  </div>
</template>

<script>
  import { searchFileContent } from "@/api/archives-management/fileManagement/dataBrowsing"

  export default {
    props: {
      oriTable: {
        type: Object,
        default: () => {}
      },
      orirow: {
        type: Object,
        default: () => {}
      },
      drawer: {
        type: Boolean,
        default: () => false
      }
    },
    watch: {
      drawer:{
        handler(newVal,val){
          if(newVal){
            this.searchClick()
          }
        },
        immediate: true,
        deep: true
      }
    },
    data() {
      return {
         search: {
           fileContent: '',
         },
         tableData: [],
         loading: false,
         pagination: {
            pageNum: 1,
            pageSize: 10,
            total: 0,
         }
      };
    },
    methods: {
      searchClick() {
        this.pagination.pageNum = 1
        this.getTableData()
      },
      getTableData(){
        // console.log(this.oriTable,89)
        const params = {
          tableName: this.oriTable.tableName,
          recId: this.orirow.id,
          page: this.pagination.pageNum,
          limit: this.pagination.pageSize,
          ...this.search,
        }
        this.loading = true
        searchFileContent(params).then(res => {
          if(res.code === '100'){
            this.tableData = res.body.list
            this.pagination.total = res.body.total
          }
        }).finally(() => {
          this.loading = false
        })
      },
      handleReset(){
         this.$refs.ruleForm.resetFields()
      },
      handleCurrentChange(val) {
        this.pagination.pageNum = val;
        this.getTableData()
      },
      handleSizeChange(val) {
        this.pagination.pageSize = val;
        this.pagination.pageNum = 1;
        this.getTableData()
      },
    },
  };

</script>

<style lang="scss" scoped>
  .page {
    width: 100%;
    background-color: #fff;
    padding: 20px 10px 0 10px;
    box-sizing: border-box;

    .el-form {
      display: flex;
      flex-wrap: wrap;

      .el-form-item {
        margin-bottom: 10px;
      }

      .btn {
        margin-left: 10px;
      }
    }
  }

</style>
