<template>
    <Table url="/api/v1/parameters/operation" rowKey="paramId" addBtn ref="table" :buttons="buttons">
        <template #drawer="drawer">
            <Form v-bind="drawer" />
        </template>
        <template #search="{ query }">
            <MoreItem :label="$t('paramter.moduleParameters')">
                <a-input v-model="query.paramModule" :placeholder="$t('input.placeholder')" />
            </MoreItem>
            <MoreItem :label="$t('paramter.parameterCoding')">
                <a-input v-model="query.paramCode" :placeholder="$t('input.placeholder')" />
            </MoreItem>
            <MoreItem :label="$t('paramter.paramValue')">
                <a-input v-model="query.paramValue" :placeholder="$t('input.placeholder')" />
            </MoreItem>
        </template>
        <a-table-column :title="$t('paramter.moduleParameters')" data-index="paramModule" />
        <a-table-column :title="$t('paramter.parameterCoding')" data-index="paramCode" />
        <a-table-column :title="$t('paramter.paramValue')" data-index="paramValue" />
        <a-table-column :title="$t('table.remark')" data-index="remark" />
    </Table>
</template>

<script>
import Form from './form.vue';
import { Table, MoreItem } from '@/components/table';

export default {
    components: { Form, Table, MoreItem },
    computed: {
        buttons() {
            return [
                { label: this.$t('table.edit'), click: this.edit },
                {
                    type: 'confirm',
                    url: (row) => `/api/v1/parameters/operation/${row.paramId}`,
                    after: this.refreshTable,
                },
            ];
        },
    },
    methods: {
        refreshTable() {
            this.$refs['table']?.getData();
        },

        edit(row) {
            this.$refs['table']?.show({ row, title: this.$t('table.edit'), type: 'edit' });
        },
    },
};
</script>
