<!-- 会员机构管理-机构管理-运营机构管理-详情 -->
<template>
    <app-drawer :title="t('member.institution.operation.details.title')" width="900" v-model:show="show" :loading="loading" :refresh="refresh">
        <app-table-details :title="t('member.institution.operation.details.subtitle')" :data="data?.organ" :label-width="160" :cell-props="detailProps1" :column="2" />
        <span>
            <span>{{ t('member.institution.operation.details.subtitle2') }}</span>
            <span v-for="item in goodslimit" v-bind:key="item.id">
                <span>{{ item.title }}: </span>
                <span>{{ item.value }}</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: 'operate',
        userid: props.record.userid
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

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

const goodslimit = computed(() => {
    return data.value?.operatemarkets.map(e => {
        return {
            id: e.marketid,
            title: e.marketname,
            value: data.value?.operategoodsinfo?.filter(g => g.marketid === e.marketid).map(e => e.goodsname).join(','),
        }
    }) ?? []
})

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

</script>