<template>
    <Table
        url="/ranger/inspection/api/v1/specialities"
        rowKey="specialityId"
        addBtn
        :buttons="buttons"
        ref="table"
    >
        <template #search="{ query }">
            <MoreItem label="地区">
                <UrlSelect
                    url="/ranger/inspection/api/v1/region/list"
                    v-model="query.regionId"
                    labelFiled="regionName"
                    valueFiled="regionId"
                />
            </MoreItem>
            <MoreItem label="专业名称">
                <a-input v-model="query.specialityName" />
            </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="专业名称" data-index="specialityName" />
        <a-table-column title="所属地区" data-index="regionName" />
        <a-table-column title="修改人" data-index="editorName" />
        <a-table-column title="修改时间" 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: '编辑', click: this.edit },
                { label: '详情', click: this.view },
                { label: '人员', 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: '编辑', type: 'edit' });
        },
        view(row) {
            this.$refs.table.show({ row, title: '详情', type: 'view' });
        },
        showMember(row) {
            this.$refs.table.show({ row, title: '人员', type: 'member' });
        },
    },
};
</script>
