<template>
    <Table
        url="/ranger/inspection/api/v1/specialities"
        rowKey="specialityId"
        addBtn
        :buttons="buttons"
        ref="table"
    >
        <template #search="{ query }">
            <MoreItem :label="$t('table.region')">
                <UrlSelect
                    url="/ranger/inspection/api/v1/region/list"
                    v-model="query.regionId"
                    labelFiled="regionName"
                    valueFiled="regionId"
                    :placeholder="$t('select.placeholder')"
                />
            </MoreItem>
            <MoreItem :label="$t('table.majorName')">
                <a-input v-model="query.specialityName" :placeholder="$t('input.placeholder')" />
            </MoreItem>
        </template>

        <template #drawer="drawer">
            <Member v-if="drawer.type === 'member'" v-bind="drawer" />
            <AddAndEdit v-bind="drawer" v-else />
        </template>

        <a-table-column :title="$t('table.majorName')" data-index="specialityName" />
        <a-table-column :title="$t('table.regionName')" data-index="regionName" />
        <a-table-column :title="$t('table.reviser')" data-index="editorName" />
        <a-table-column :title="$t('table.revisionTime')" data-index="editTime" />
    </Table>
</template>

<script>
import Table from '@/components/table/table.vue';
import UrlSelect from '@/components/MySelect/url_select.vue';
import MoreItem from '@/components/table/more_item.vue';
import AddAndEdit from './add_edit.vue';
import Member from './member.vue';

export default {
    components: { Table, UrlSelect, MoreItem, AddAndEdit, Member },
    data() {
        return {
            buttons: [
                { label: this.$t('table.edit'), click: this.edit },
                { label: this.$t('table.details'), click: this.view },
                { label: this.$t('table.personnel'), click: this.showMember },
                {
                    type: 'confirm',
                    url: (row) => `/ranger/inspection/api/v1/specialities/${row.specialityId}`,
                    after: this.refresh,
                },
            ],
        };
    },
    methods: {
        refresh() {
            this.$refs.table.getData();
        },
        edit(row) {
            this.$refs.table.show({ row, title: this.$t('table.edit'), type: 'edit' });
        },
        view(row) {
            this.$refs.table.show({ row, title: this.$t('table.details'), type: 'view' });
        },
        showMember(row) {
            this.$refs.table.show({ row, title: this.$t('table.personnel'), type: 'member' });
        },
    },
};
</script>
