<!-- 查询管理-仓单查询-仓单汇总查询-详情 -->
<template>
    <teleport to="#appPageTeleport">
        <app-view>
            <app-table :data="dataList" :columns="tableColumns">
                <template #headerLeft>
                    <span>{{ t('query.warehouse_receipt.wrsumm.details.wrstandardname') }}{{ record.wrstandardname }}</span>
                    <span>{{ t('query.warehouse_receipt.wrsumm.details.warehousename') }}{{ record.warehousename }}</span>
                    <span>{{ t('query.warehouse_receipt.wrsumm.details.enumdicname') }} }}{{ record.enumdicname }}</span>
                </template>
                <template #headerRight>
                    <div style="display: flex;">
                        <el-select v-model="selectedUsers" :placeholder="t('query.warehouse_receipt.wrsumm.details.selectedUsers')" multiple style="width: 180px;margin-right: 12px;">
                            <el-option v-for="item in userList" :key="item.userid" :label="item.accountname"
                                :value="item.userid">
                                <div style="display: flex;justify-content: space-between;">
                                    <span>{{ item.userid }}</span>
                                    <span>{{ item.accountname }}</span>
                                </div>
                            </el-option>
                        </el-select>
                        <el-button type="primary" :loading="loading" @click="onSearch">{{ t('operation.search') }}</el-button>
                        <el-button @click="emit('closed')">{{ t('operation.close') }}</el-button>
                    </div>
                </template>
                <template #footer>
                    <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                        @change="run" />
                </template>
            </app-table>
        </app-view>
    </teleport>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { useRequest } from '@/hooks/request'
import { summaryQueryInit, summaryQueryDetail } from '@/services/api/order'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import { i18n } from '@/stores'

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

const { global: { t } } = i18n
const emit = defineEmits(['closed'])
const loading = shallowRef(false)
const selectedUsers = shallowRef<string[]>([])

const { dataList: userList } = useRequest(summaryQueryInit)

const { dataList, total, pageSize, pageIndex, run } = useRequest(summaryQueryDetail, {
    params: {
        pageNum: 1,
        pageSize: 20,
        ishis: props.record.ishis,
        wrstandardid: props.record.wrstandardid
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Model.TableColumn[]>([
    { field: 'accountname', label: 'query.warehouse_receipt.wrsumm.details.accountname' },
    { field: 'accountid', label: 'query.warehouse_receipt.wrsumm.details.accountid' },
    { field: 'ladingbillid', label: 'query.warehouse_receipt.wrsumm.details.ladingbillid' },
    { field: 'qty', label: 'query.warehouse_receipt.wrsumm.details.qty' },
    { field: 'freezerqty', label: 'query.warehouse_receipt.wrsumm.details.freezerqty' },
    { field: 'wrfactortypename', label: 'query.warehouse_receipt.wrsumm.details.wrfactortypename' },
])

const onSearch = () => {
    run({
        userids: selectedUsers.value.join(',')
    })
}
</script>