<template>
    <hc-new-dialog is-table :footer="false" widths="1200px" :show="isShow" title="清单明细" @close="modalClose">
        <hc-table ref="tableRef" is-new is-expand :index-style="{ width: 60 }" :column="tableColumn" :datas="tableData" :loading="tableLoading">
            <template #table-expand="{ row, index: index1 }">
                <div class="relative p-2">
                    <hc-table is-new :is-index="false" :column="tableColumn1" :datas="tableData1">
                        <template #index-key="{ index: index2 }">
                            {{ index1 + 1 }}-{{ index2 + 1 }}
                        </template>
                    </hc-table>
                </div>
            </template>
            <template #action="{ row }">
                <el-link v-if="!row.isExpands" hc @click="unfoldClick(row)">展开明细</el-link>
                <el-link v-else type="warning" @click="awayClick(row)">收起明细</el-link>
            </template>
        </hc-table>
    </hc-new-dialog>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
    ids: {
        type: [String, Number],
        default: '',
    },
})

//事件
const emit = defineEmits(['close'])
const tableRef = ref(null)

//双向绑定
// eslint-disable-next-line no-undef
const isShow = defineModel('modelValue', {
    default: false,
})

//监听
watch(() => [
    props.ids,
], ([ids]) => {
    console.log('ids', ids)
}, { immediate: true })

//监听
watch(isShow, (val) => {
    if (val) {}
})

//表格数据
const tableLoading = ref(false)
const tableColumn = [
    { key: 'action', name: '操作', width: 130, align: 'center' },
    { key: 'key1', name: '清单编号', width: 120, align: 'center' },
    { key: 'key2', name: '清单名称' },
    { key: 'key3', name: '变更后数量', width: 120, align: 'center' },
    { key: 'key4', name: '收方数量', width: 120, align: 'center' },
    { key: 'key5', name: '单价', width: 120, align: 'center' },
    { key: 'key6', name: '完成金额', width: 120, align: 'center' },
]
const tableData = ref([
    { id: '1', key1: '1111' }, { id: '2', key1: '2222' }, { id: '3', key1: '3333' },
])


//展开
const unfoldClick = (row) => {
    row.isExpands = true
    tableRef.value?.toggleRowExpansion(row)
}

//收起
const awayClick = (row) => {
    row.isExpands = false
    tableRef.value?.toggleRowExpansion(row, false)
}

const tableColumn1 = [
    { key: 'index-key', name: '序号', width: 90, align: 'center' },
    { key: 'key1', name: '凭证编号', width: 100, align: 'center' },
    { key: 'key2', name: '收方期', width: 100, align: 'center' },
    { key: 'key3', name: '工程部位' },
    { key: 'key4', name: '审核状态', width: 120, align: 'center' },
    { key: 'key5', name: '本期收方数量', width: 120, align: 'center' },
    { key: 'key6', name: '收方总金额', width: 120, align: 'center' },
]
const tableData1 = ref([
    { key1: '1111' }, { key1: '2222' }, { key1: '3333' },
])

const modalClose = () => {
    isShow.value = false
    emit('close')
}
</script>

<style scoped lang="scss">

</style>
