<template>
  <div class="comp-content">
    <Dialog
      v-model="dialogVisible"
      diaTitle="
        关联任务列表
      "
      width="80%"
      height="80%"
      @close="closeFun"
      show-footer
    >
      <div class="table-box">
        <TaskTable
          v-if="dialogVisible"
          :isDemandExportApi="true"
          tableName="SIMULATION_TASK_ALL_LIST"
          :params="searchParams"
          :api="getTaskListByDemandIdApi"
          hideSpecialSearch
          @show="showTaskDetailFun"
        ></TaskTable>
      </div>
      <template #footer>
        <div>
          <el-button @click="closeFun">取消</el-button>
          <el-button type="primary" @click="closeFun">确定</el-button>
        </div>
      </template>
    </Dialog>
    <taskDetail
      v-if="showTaskDetailDialog"
      :taskId="currentTaskInfo.id"
      :currentTaskInfo="currentTaskInfo"
      @closeFn="showTaskDetailDialog = false"
      :showApproval="false"
      :show-footer="false"
      :showLeftOptions="false"
    >
    </taskDetail>
  </div>
</template>
<script lang="ts" setup>
import Dialog from '@/components/common/dialog/index.vue';
// import { ElMessage } from 'element-plus';
import { computed, ref } from 'vue';
import TaskTable from './taskTable.vue';
import { getTaskListByDemandIdApi } from '@/api/project/task';
import { getIdMap } from '../../projectDetail/components/project';
import taskDetail from '@/views/task/projectDetail/components/taskDetail.vue';

const props = defineProps<{
  showDialog: boolean;
  demandUid: string;
  projectUid: string;
  phaseUid: string;
}>();

const showTaskDetailDialog = ref(false);

const searchParams = computed(() => {
  return { demandId: props.demandUid, type: 2, idMap: getIdMap(props.projectUid, props.phaseUid) };
});

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

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

const currentTaskInfo = ref({ id: '', uuid: '' });
const showTaskDetailFun = (row: any) => {
  showTaskDetailDialog.value = true;
  currentTaskInfo.value = row;
};

// const nextPageFun = () => {
//   if (hasSameValue()) return;
//   emits('update:currentProjectBaseInfo', { ...tableFormRef.value.getFormDataFun(), nodeType: NODE_TYPE.PROJECT });
//   emits('nextPageFun', 'basePage');
// };
</script>
<style lang="scss" scoped>
.table-box {
  height: 100%;
}
</style>
