<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <search @search="reload" />
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        :selection.sync="selection"
        cache-key="pinanUserTable"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar></template>
        <template v-slot:userInfo="{ row }">
          <div>{{ row.userInfo.username }}</div>
          <div>{{ row.userInfo.userCode }}</div>
        </template>
        <!-- 操作列 -->
        <template v-slot:content="{ row }">
          更新前:{{ row.beforeContent }}<br />
          更新后:{{ row.afterContent }}
        </template>
      </ele-pro-table>
    </el-card>
  </div>
</template>

<script>
  import Search from './components/search.vue';
  import { pageUserLog } from '@/api/organization/user-log';

  export default {
    name: 'UserLog',
    components: {
      Search
    },
    data() {
      return {
        // 表格列配置
        columns: [
          // {
          //   columnKey: 'selection',
          //   type: 'selection',
          //   width: 50,
          //   align: 'center',
          //   fixed: 'left'
          // },
          {
            prop: 'optUserName',
            label: '操作用户',
            align: 'center',
            showOverflowTooltip: true,
            width: 180,
            fixed: 'left'
          },
          {
            prop: 'userInfo',
            label: '更新用户',
            align: 'center',
            showOverflowTooltip: true,
            width: 180,
            slot: 'userInfo'
          },
          {
            prop: 'typeCn',
            label: '操作类型',
            align: 'center',
            showOverflowTooltip: true,
            width: 100
          },
          {
            columnKey: 'content',
            label: '更新内容',
            minWidth: 150,
            align: 'center',
            resizable: false,
            slot: 'content',
            showOverflowTooltip: true
          },
          {
            prop: 'optTime',
            label: '操作时间',
            showOverflowTooltip: true,
            width: 180,
            align: 'center',
            formatter: (_row, _column, cellValue) => {
              return this.$util.toDateString(cellValue);
            }
          }
        ],
        // 表格选中数据
        selection: [],
        // 当前编辑数据
        current: null,
        // 是否显示编辑弹窗
        showEdit: false
      };
    },
    methods: {
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return pageUserLog({ ...where, ...order, page, limit });
      },
      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ page: 1, where: where });
      },
      /* 打开编辑弹窗 */
      openEdit(row) {
        this.current = row;
        this.showEdit = true;
      }
    }
  };
</script>
