<template>
    <el-card class="tjm_card_style_custom">
        <div class="tjm_card_title">条件检索</div>
        <div class="tjm_card_select">
            <el-form class="tjm_card_select_left" :model="params" inline label-width="80px" label-position="left">
                <el-form-item label="操作人">
                    <el-input v-model="params.userName" clearable placeholder="请输入操作人"></el-input>
                </el-form-item>
                <el-form-item label="操作名称">
                    <el-input v-model="params.operateName" clearable placeholder="请输入模块"></el-input>
                </el-form-item>
                <el-form-item label="业务类型">
                    <el-select v-model="params.operateType" clearable placeholder="请选择业务类型">
                        <el-option v-for="(label, key) in typeDic" :key="key" :label="label" :value="key"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="操作日期">
                    <el-date-picker v-model="createTime" type="daterange" value-format="YYYY-MM-DD" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="search" @click="reloadTable">搜索</el-button>
                    <el-button icon="refresh-right" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-divider></el-divider>

        <div class="tjm_card_table">
            <el-table v-loading="loading" row-key="id" header-cell-class-name="tjm_card_table_header" height="400" :data="tableData" border>
                <el-table-column type="index" label="序号" width="55"></el-table-column>
                <el-table-column label="操作人" prop="userName"></el-table-column>
                <el-table-column label="登录名" prop="loginName"></el-table-column>
                <el-table-column label="操作时间" prop="createTime" show-overflow-tooltip></el-table-column>
                <el-table-column label="业务类型" show-overflow-tooltip>
                    <template #default="scope">{{ formatType(scope.row.operateType) }}</template>
                </el-table-column>
                <el-table-column label="操作名称" prop="operateName" show-overflow-tooltip></el-table-column>
                <el-table-column label="IP" prop="ipHost" show-overflow-tooltip></el-table-column>
            </el-table>
        </div>
        <div class="tjm_card_pagination">
            <yh-pagination v-model:pageNo="params.page" v-model:pageSize="params.size" :total="total" @paginationChange="reloadTable"></yh-pagination>
        </div>
    </el-card>
</template>

<script>
import API from "@/api/system/log";
import { typeDic } from "./main";

import yhPagination from "@/components/Pagination/index.vue";

export default {
    components: {
        yhPagination
    },

    data() {
        return {
            typeDic,
            
            loading: false,
            createTime: [],
            params: {
                page: 1,
                size: 10
            },

            total: 0,
            tableData: []
        }
    },

    mounted() {
        this.reloadTable();
    },

    methods: {
        formatType(value) {
            return typeDic[value] || value;
        },

        reloadTable() {
            this.params.beginCreateTime = this.createTime && this.createTime.length && this.createTime[0] + " 00:00:00" || null;
            this.params.endCreateTime = this.createTime && this.createTime.length && this.createTime[1] + " 23:59:59" || null;

            this.loading = true;
            API.get(this.params).then(res => {
                this.loading = false;
                if (res.code === 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else ElMessage.error(res.msg);
            }).catch(() => this.loading = false);
        },

        reset() {
            this.createTime = [];
            this.params = {
                page: 1,
                size: 10
            }
                
            this.reloadTable();
        },
    }
}
</script>