<template>
    <div>
        <div>
            <el-table
                :data="pager.lists"
                v-loading="pager.loading"
                @selection-change="handleSelectionChange"
            >
                <el-table-column
                    label="商品信息"
                    prop="store_name"
                    show-overflow-tooltip
                    width="400"
                >
                    <template #default="{ row }">
                        <div class="flex items-center">
                            <el-image
                                :src="row.image"
                                class="w-16 h-16 mr-2"
                                :preview-teleported="true"
                            ></el-image>
                            <div>{{ row.store_name }}</div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="规格" prop="store_info" show-overflow-tooltip />
                <el-table-column label="数量" prop="cart_num" show-overflow-tooltip />
                <el-table-column label="合计" prop="total_price" show-overflow-tooltip />
            </el-table>
        </div>
        <div class="flex mt-4 justify-end" v-if="pager.lists.length < pager.count">
            <pagination v-model="pager" @change="getLists" />
        </div>
    </div>
</template>

<script lang="ts" setup name="storeTable">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiPurchaseOrderInfoLists } from '@/api/purchase_order'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'

const emit = defineEmits(['change'])

// 选中的数据
const selectionList = ref([])

// 选中数据时触发
const handleSelectionChange = (val: any) => {
    selectionList.value = val
    emit('change', selectionList.value)
}

// 查询条件
const queryParams = reactive({
    oid: '',
    pay_type: ''
})

// 获取字典数据
const { dictData } = useDictData('')

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiPurchaseOrderInfoLists,
    params: queryParams
})

const getList = (e: any) => {
    queryParams.oid = e.oid
    getLists()
}

defineExpose({
    getList,
    getLists
})
</script>
