<template>
  <div class="comp-content">
    <Dialog
      v-model="dialogVisible"
      diaTitle="推送报告"
      width="80%"
      height="80%"
      @close="closeFun"
      show-footer
    >
      <div class="table-box">
        <BaseTable
          ref="tableRef"
          tableName="RESULT_REPORT"
          :api="getSimulationTaskFileApi"
          showIndex
          showCheckbox
          :params="{ model: '仿真报告', fileBizType: 2, uuid: workspaceUuid }"
          :searchLimitNum="3"
          fullHeight
        >
          <template #achieveStatus="{ row }">
            <StatusDot
              :status="statusMapFun5(row.achieveStatus)"
              :title="RESULT_ACHIEVE_STATUS.O[row.achieveStatus]"
            />
          </template>
          <template #exeStatus="{ row }">
            <StatusDot
              :status="statusMapFun6(row.exeStatus)"
              :title="TASK_ACHIEVE_STATUS.O[row.exeStatus]"
            />
          </template>
        </BaseTable>
      </div>
      <template #footer>
        <div>
          <el-button @click="closeFun">取消</el-button>
          <el-button type="primary" @click="confirmFun">确定</el-button>
        </div>
      </template>
    </Dialog>
  </div>
</template>
<script lang="ts" setup>
import { getSimulationTaskFileApi } from '@/api/data/dataAnalysis';
import Dialog from '@/components/common/dialog/index.vue';
import { statusMapFun5, statusMapFun6 } from '@/components/common/statusDot/statusMap';
import { useDict } from '@/utils/useDict';
// import { ElMessage } from 'element-plus';
import { computed, onMounted, ref } from 'vue';
import StatusDot from '@/components/common/statusDot/index.vue';
import BaseTable from '@/components/common/table/baseTable.vue';
import { pushReportApi } from '@/api/project/node';
import { ElMessage } from 'element-plus';

const props = defineProps<{
  showDialog: boolean;
  projectUuid: string;
  workspaceUuid: string;
  workspaceCode: string;
  projectCode: string;
}>();

const { RESULT_ACHIEVE_STATUS, TASK_ACHIEVE_STATUS } = useDict(
  'RESULT_ACHIEVE_STATUS',
  'TASK_ACHIEVE_STATUS'
);

const dialogVisible = computed({
  get() {
    return props.showDialog;
  },
  set(val) {
    emits('update:showDialog', val);
  },
});
const emits = defineEmits(['update:showDialog', 'updateWorkspaceApproveStatus']);

const closeFun = () => {
  emits('update:showDialog', false);
};

const tableRef = ref();

const confirmFun = async () => {
  const res: any = await pushReportApi({
    fileIdList: tableRef.value.tableRef.getCheckboxRecords().map((item: any) => item.id),
    projectCode: props.projectCode,
    workspaceCode: props.workspaceCode,
  });
  if (res.code === 200) {
    ElMessage.success('报告推送成功！');
    emits('updateWorkspaceApproveStatus');
    closeFun();
  } else {
    ElMessage.error(res.message);
  }
};

onMounted(() => {});
</script>
<style lang="scss" scoped>
.table-box {
  height: 100%;
}
</style>
