<template>
    <div>
        <a-button type="primary" style="margin: 10px 0;" :loading="state.exportLoading" @click="onExport">
            导出 </a-button>
    </div>
</template>
<script setup>
import { defineProps, reactive, watch } from 'vue';
import { exportExcelFunc } from './exportExcel';
const props = defineProps({
    tableData: []
})

const state = reactive({
    exportLoading: false,
    dataSource: []
})

const onExport = () => {
    console.log('export')
    if (!state.dataSource || state.dataSource.length === 0) {
        window.alert('表格数据为空')
        return
    }
    state.exportLoading = true
    exportExcelFunc(state.dataSource, '用户质量分').then(res => {
        state.exportLoading = false
        console.log('res', res)
    }).catch(r => {
        state.exportLoading = false
        console.log('r', r)
    })
}
watch(() => props.tableData,
    (val) => {
        state.dataSource = val
    }, {
    deep: true,
    immediate: true
})
</script>