<template>
  <!-- 我关注的 -->
  <div class="gl-page-content">
    <taskTable
      showIndex
      ref="tableRef"
      tableName="SIMULATION_TASK_ATTENTION_LIST"
      :params="{type:1}"
      :api="queryTaskListApi"
      :actionsWidth="tableActionsLength['4-4']"
      exportFileName="我关注的任务列表"
    >
      <template #tableActions="{ row }">
        <div class="gl-table-actions">
          <el-link type="primary" @click="showTaskDetailFun(row)">查看详情</el-link>
          <el-popconfirm
            title="确认取消关注吗？"
            @confirm="attentionTaskFun(row,false)"
          >
            <template #reference>
              <el-link type="danger">取消关注</el-link>
            </template>
          </el-popconfirm>
        </div>
      </template>
    </taskTable>
    <!-- <BaseTable
      tableName="SIMULATION_TASK_ATTENTION_LIST"
      :params="{type:0}"
      :api="queryTaskListApi"
      :searchLimitNum="3"
    >
      <template #tableActions="{ row }">
        <div class="actions">
          <el-link type="danger">查看详情</el-link>
          <el-popconfirm
            title="确认取消关注吗？"
            @confirm="attentionTaskFun(row,false)"
          >
            <template #reference>
              <el-link type="danger">取消关注</el-link>
            </template>
          </el-popconfirm>
        </div>
      </template>
    </BaseTable> -->
    <taskDetail v-if="showTaskDetailDialog" :taskId="currentTaskInfo.id" :currentTaskInfo="currentTaskInfo" @closeFn="showTaskDetailDialog = false" @updateFn="updateTaskInfoFun">
    </taskDetail>
  </div>
</template>

<script setup lang="ts">
import { attentionTaskApi, queryTaskListApi } from '@/api/project/task';
// import BaseTable from '@/components/common/table/baseTable.vue';
import { ElMessage } from 'element-plus';
import taskTable from '../components/taskTable.vue';
import { tableActionsLength } from '@/utils/common';
import { onMounted, ref } from 'vue';
import { disposeAttentionParams } from '../taskPage';
import taskDetail from '@/views/task/projectDetail/components/taskDetail.vue';

// enum TaskType {
//   /** 待确认任务 */
//   CONFIRM = 'confirm',
//   /** 执行的任务 */
//   EXECUTE = 'execute',
//   /** 发起的任务 */
//   SPONSOR = 'sponsor',
//   /** 关注的任务 */
//   ATTENTION = 'attention',
//   /** 所有任务 */
//   ALL = 'all',
// }

const tableRef = ref();

const showTaskDetailDialog = ref(false);

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

const updateTaskInfoFun = async (info:any) => {
  const { flag, data }:any = info;

  console.log(flag, 'flag');
  console.log(data, 'data');

  showTaskDetailDialog.value = false;
};

const attentionTaskFun = async(row:any, isAttention:boolean) => {
  const res:any = await attentionTaskApi(disposeAttentionParams(row.uuid, isAttention));
  if (res.code === 200) {
    ElMessage.success('取消关注成功');
    tableRef.value.tableRef.resetFun();
  }
};
onMounted(() => {

});
</script>
