<template>
  <div id="containt">
    <el-tabs v-model="activeName" class="tab-box">
      <el-tab-pane :label="$t1('常规')" name="first">
        <editView v-if="showEdit" visible-key="showEdit" :_dataId.sync="dataId" :parent-target="_self"
                  @reload="$reloadHandle"></editView>
      </el-tab-pane>
      <el-tab-pane :label="$t1('列表')" name="second">
        <div class="grid-height">
          <vxe-grid ref="table-m1" v-bind="vxeOption" @resizable-change="$vxeTableUtil.onColumnWitchChange"
                    @custom="$vxeTableUtil.customHandle">
            <template #form>
              <div class="clearfix screen-btns">
                <div class="fl">
                  <base-table-export :option="{ title: $t1('操作日志导出'), targetRef: 'table-m1'}"
                                     :parent-target="_self"/>
                </div>
                <div class="fr">
                  <vxe-button icon="el-icon-brush" class="button-sty" @click="resetEvent" type="text" status="primary"
                              plain>{{ $t1('重置') }}
                  </vxe-button>
                  <vxe-button status="warning" icon="el-icon-search" class="button-sty" @click="searchEvent">
                    {{ $t1('搜索') }}
                  </vxe-button>
                </div>
              </div>
              <vxe-form ref="form" class="screen-box" title-width="92px" title-align="right" :data="formData"
                        @submit="searchEvent" @reset="searchEvent">
                <vxe-form-item :title="$t1('操作对象')+':'" field="code">
                  <template v-slot>
                    <el-input v-model="formData.code" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('操作内容')+':'" field="content">
                  <template v-slot>
                    <el-input v-model="formData.content" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('操作类型')+':'" field="type">
                  <template v-slot>
                    <el-select v-model="formData.type" clearable>
                      <el-option v-for="(dict,index) in typeDicts" :key="index" :value="dict.sn"
                                 :label="dict.value"></el-option>
                    </el-select>
                  </template>
                </vxe-form-item>
              </vxe-form>
            </template>
          </vxe-grid>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import editView from './edit.vue';

export default {
  name: 'oplog:list',
  components: {
    editView
  },
  created() {
  },
  mounted() {
    this.$getBaseDicts({
      code: 'oplogType',
      success: ({dicts, dictMap}) => {
        this.typeDicts = dicts;
      }
    });
    this.initTableList();
  },
  data() {
    return {
      activeName: 'second',
      dataId: 0,
      showEdit: false,
      vxeOption: {},
      formData: {},
      typeDicts: []
    };
  },
  methods: {
    searchEvent({$form}) {
      this.$refs['table-m1'].commitProxy('reload');
    },
    resetEvent() {
      this.formData = {};
      this.$refs['table-m1'].commitProxy('reload');
    },
    openEditDialog(id) {
      this.dataId = !id || typeof id == 'object' ? 0 : id;
      this.activeName = 'first';
      this.$openEditView('showEdit');
    },
    initTableList() {
      let tableOption = {
        vue: this,
        tableRef: 'table-m1',
        tableName: 'basic_oplog_list-m1',
        isQueryAllPage: false,
        path: USER_PREFIX + '/oplog/listPage',
        param: () => {
          return this.formData;
        },
        config: {
          pagerConfig: {
            autoHidden: false
          }
        },
        columns: [
          {type: 'checkbox', width: 48, resizable: false, fixed: 'left'},
          {
            title: this.$t1('操作类型'),
            field: 'typeName',
            width: 150,
            fixed: 'left'
          },
          {field: 'ip', title: this.$t1('访问IP'), width: 150},
          {field: 'content', title: this.$t1('操作内容'), width: 250},
          {field: 'code', title: this.$t1('操作对象'), width: 150},
          {field: 'operDate', title: this.$t1('产生日志时间'), width: 150},
          {field: 'serverName', title: this.$t1('服务名'), width: 250},
          {field: 'field1', title: this.$t1('冗余字段1'), width: 150},
          {field: 'field2', title: this.$t1('冗余字段2'), width: 150},
          {field: 'field3', title: this.$t1('冗余字段3'), width: 150},
          {field: 'field4', title: this.$t1('冗余字段4'), width: 150},
          {field: 'field5', title: this.$t1('冗余字段5'), width: 150},
          {field: 'createBy', title: this.$t1('创建人'), width: 150},
          {field: 'modifyBy', title: this.$t1('更新人'), width: 150},
          {field: 'modifyDate', title: this.$t1('更新时间'), width: 150},
          {field: 'createDate', title: this.$t1('创建时间'), width: 150},
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false,
            slots: {
              default: ({row}) => {
                return [
                  <a
                    href="javascript:void(0);"
                    class="a-link"
                    onclick={() => {
                      this.openEditDialog(row.id);
                    }}
                  >
                    <el-tooltip enterable={false} effect="dark" content={this.$t1('查看')} placement="top"
                                popper-class="tooltip-skin">
                      <i class="el-icon-edit"/>
                    </el-tooltip>
                  </a>
                ];
              }
            }
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        this.vxeOption = opts;
      });
    }
  }
};
</script>
