<template>
  <div>
    <h4>操作记录</h4>
    <div class="table">
      <zj-table
        :loading="loading"
        :table-attributes="tableAttributes"
        :is-drop="true"
        :columns="columns"
        :table-data="tableData"
      />
    </div>
    <!-- 分页 -->
    <div style="margin: 20px 0">
      <el-pagination
        :current-page="currentPages"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="listTotal"
        @size-change="handleSizeChanges"
        @current-change="handleCurrentChanges"
      />
    </div>

  </div>
</template>

<script>
import { commonLogList } from '@/api/common'
export default {
  props: {
    policyId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      tableAttributes: {
        height: '100%'
      },
      tableData: [],
      listTotal: 0,
      currentPages: 1, // 当前页码
      pageSizes: 10, // 每页数量
      loading: false
    }
  },
  computed: {
    columns() {
      return [{
        columnAttributes: {
          label: '帐号',
          prop: 'userName'
        }
      },
      {
        columnAttributes: {
          label: '操作内容',
          prop: 'content'
        }
      },
      {
        columnAttributes: {
          label: 'ip',
          prop: 'ip'
        }
      },
      {
        columnAttributes: {
          label: '模块名称',
          prop: 'moduleName'
        }
      },
      {
        columnAttributes: {
          label: '操作时间',
          prop: 'createTime'
        }
      }]
    }
  },
  mounted() {
    this.getCommonLogList()
  },
  methods: {
    getCommonLogList() {
      this.loading = true
      commonLogList({
        objId: this.policyId,
        pageNum: this.currentPages,
        pageSize: this.pageSizes
      }).then(res => {
        this.tableData = res.data.records
        this.listTotal = res.data.total
        this.loading = false
      })
    },
    // 更改每页数量
    handleSizeChanges(val) {
      this.pageSizes = val
      this.currentPages = 1
      this.getCommonLogList()
    },
    // 更改当前页
    handleCurrentChanges(val) {
      this.currentPages = val
      this.getCommonLogList()
    }
  }

}
</script>

<style lang="scss" scoped>
.table{
  height: 600px;
}
</style>
