<!-- 会员机构管理-机构管理-仓库机构管理-详情 -->
<template>
    <app-drawer :title="t('member.institution.warehouse.details.title')" width="900" v-model:show="show" :loading="loading" :refresh="refresh">
        <app-table-details :title="t('member.institution.warehouse.details.subtitle')" :data="data?.organ" :label-width="160" :cell-props="detailProps1" :column="2" />
        <span>
            <span>{{ t('member.institution.warehouse.details.subtitle2') }}</span>
            <span v-for="item in warehouse" v-bind:key="item.id">
                <span>{{ item.label }}: </span>
                <span>{{ item.title }}</span>
            </span> 
        </span>
        <template #footer>
            <el-button @click="onCancel(false)">{{ t('operation.close') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { i18n } from '@/stores'
import { useRequest } from '@/hooks/request'
import { CellProp } from '@pc/components/base/table-details/types'

import { queryRoleDetail } from '@/services/api/member'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTableDetails from '@pc/components/base/table-details/index.vue'

const { global: { t } } = i18n

const props = defineProps({
    record: {
        type: Object as PropType<Member.OrganRoleRsp>,
        required: true
    }
})

const show = shallowRef(true)
const refresh = shallowRef(false)
const loading = shallowRef(false)

const { data } = useRequest(queryRoleDetail, {
    params: {
        rolename: 'warehouse',
        userid: props.record.userid
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const detailProps1: CellProp[] = [
    { prop: 'accountname', label: 'member.institution.warehouse.details.accountname' },
    { prop: 'userName', label: 'member.institution.warehouse.details.userName', formatValue: () => {
        return data.value?.users.username
    }, },
    { prop: 'reckonaccountid', label: 'member.institution.warehouse.details.reckonaccountid' }
]

const warehouse = computed(() => {
    return data.value?.warehouse.map(e => {
        return {
            id: e.warehousecode,
            title: e.warehousename,
            label: t('member.institution.warehouse.details.subtitle2')
        }
    }) ?? []
})

const onCancel = (isRefresh = false) => {
    show.value = false
    refresh.value = isRefresh
}

</script>