<!-- 会员机构管理-机构管理-仓库机构管理-详情 -->
<template>
    <app-drawer title="详情" width="900" v-model:show="show" :loading="loading" :refresh="refresh">
        <app-table-details title="基本信息" :data="data?.organ" :label-width="160" :cell-props="detailProps1" :column="2" />
        <!-- <app-table-details title="" :data="goodslimit" :label-width="160" :cell-props="detailProps2" :column="1">
            
        </app-table-details> -->
        <span>
            <span>仓库</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<Model.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: '名称' },
    { prop: 'userName', label: '管理员', formatValue: () => {
        return data.value?.users.username
    }, },
    { prop: 'reckonaccountid', label: '资金账户' }
]

const warehouse = computed(() => {
    return data.value?.warehouse.map(e => {
        return {
            id: e.warehousecode,
            title: e.warehousename,
            label: '仓库'
        }
    }) ?? []
})

// const detailProps2 = computed(() => {
//     return data.value?.markets.map<CellProp>(e =>({ 
//         prop: e.marketid.toString(), 
//         label: e.marketname,
//         formatValue: (val) => {
//             return data.value?.operategoodsinfo.filter(e => e.marketid === val).map(e => e.goodsname).join(',')
//         },
//      }) ) ?? []
// }) 

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

</script>