<!-- 会员机构管理-机构管理-产业会员管理 -->
<template>
    <app-view>
        <template #header>
            <app-filter :option="filterOption" />
        </template>
        <app-table :data="dataList" :columns="tableColumns" :loading="loading">
            <template #headerLeft>
                <app-operation :data-list="getActionButtons(['member_institution_industry_add'])"
                    @click="openComponent" />
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-operation size="small" :data-list="getActionButtons(['member_institution_industry_details', 'member_institution_industry_delete'])"
                    @click="(code: string) => openComponent(code, row)" circle />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="onSearch" />
            </template>
        </app-table>
        <component :is="componentMap.get(componentId)" v-bind="{ record }" @closed="closeComponent"
            v-if="componentId" />
    </app-view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { useDataFilter } from '@/hooks/datatable-v2'
import { useRequest } from '@/hooks/request'
import { useOperation } from '@/hooks/operation'
import { queryRole } from '@/services/api/member'
import { i18n } from '@/stores'
import { formatDate } from '@/filters'
import { useEnum } from '@/hooks/enum'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppOperation from '@pc/components/base/operation/index.vue'
import AppFilter from '@pc/components/base/table-filter-v2/index.vue'

const { global: { t } } = i18n
// 状态
const areastatusEnum = useEnum('areastatus')

const { componentMap, componentId, record, openComponent, closeComponent, getActionButtons } = useOperation<Member.OrganRoleRsp>({
    onClose: () => onSearch()
})

const { dataList, total, pageSize, pageIndex, loading, run } = useRequest(queryRole, {
    params: {
        roleid: 9,
        orgztypes: 'industry',
        pageNum: 1,
        pageSize: 20
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = ref<Model.TableColumn[]>([
    { field: 'memberuserid', label: 'member.institution.industry.memberuserid' },
    { field: 'accountname', label: 'member.institution.industry.accountname' },
    { field: 'accountid', label: 'member.institution.industry.accountid' },
    { field: 'accountstatus', label: 'member.institution.industry.accountstatus', formatValue: (val) => areastatusEnum.getEnumTypeName(val) },
    { field: 'operation', label: 'member.institution.industry.operation' },
    { field: 'rolemodifytime', label: 'member.institution.industry.rolemodifytime', formatValue:(val) => formatDate(val) },
    { field: 'operate', label: 'common.operate', fixed: 'right' }
])

const { filterOption, getQueryParams, resetFilters } = useDataFilter<Member.OrganRoleReq>({
    filters: [
        {
            field: 'accountname',
            label: t('member.institution.industry.accountname'),
            required: true,
        }
    ],
    buttons: [
        { label: t('operation.search'), className: 'el-button--primary', onClick: () => onSearch() },
        { label: t('operation.reset'), className: 'el-button--primary', validateEvent: false, onClick: () => resetFilters() }
    ]
})

const onSearch = () => {
    const qs = getQueryParams()
    run(qs)
}

</script>