<script setup>
import {read} from "@/api/report/index.js";

const tableData2=ref([])
const childCurrentRow = ref()
const emit = defineEmits(['getExisting'])
const singleTableRef = ref()

onMounted(() => {
  read().then(res => {
    console.log("res:",res.data)
    emit("getExistingData",res.data)
    tableData2.value=res.data
  });
})

const handleCurrentChange =  (val)=> {
  emit("getExistingData",val)
  childCurrentRow.value = val;
  //清除父组件的行选择
  tableRow()
  setTableRow(val)
}

const setTableRow=(row)=>{
  singleTableRef.value.setCurrentRow(row)
}

const tableRow = inject('tableRow');
defineExpose({ setTableRow })
</script>

<template>
  <el-table :data="tableData2" highlight-current-row height="500"
            @current-change="handleCurrentChange" ref="singleTableRef">
    <el-table-column label="已有脚本">
      <template #default="scope">
        <el-button type="warning" round>{{ scope.row.scriptName}}</el-button>
      </template>
    </el-table-column>
    <el-table-column align="right">
      <template #default="scope">
        <el-button
            type="primary"
            @click="handleDelete(scope.$index)"
        >编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<style scoped lang="scss">

</style>