<template>
  <div class="task-performance-page">
    <div class="operate-form">
      <el-form :model="filterForm">
        <el-form-item label="算例:">
          <el-select v-model="filterForm.exampleName" class="select-style">
            <el-option v-for="item in exampleList" :label="item.name" :value="item.id" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="列数：">
          <el-input-number v-model="filterForm.lineNum" :min="1" :max="5" @change="handleChangeLineFun" />
        </el-form-item>
      </el-form>
    </div>

    <div class="task-img-box">

      <div
        class="img-item"
        :style="{ width: `calc((100% / ${filterForm.lineNum}) - 20px)` }"
        v-for="item in exampleImglist"
        :key="item.id"
      >
        <img class="task-img" :src="item.url" alt="">
      </div>

    </div>

  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { getSimulationTaskFilesApi } from '@/api/data/data';

const props = defineProps(['taskId']);
const env = import.meta.env;

const filterForm = reactive<any>({
  exampleName: props.taskId,
  lineNum: 2,
});

const exampleList = ref<any>([
  {
    name: '当前任务',
    id: props.taskId,
  },
]);

const exampleImglist = ref<any>([

]);

const handleChangeLineFun = () => {
  // ElMessage.success('选择列数' + filterForm.lineNum);
};

const getTaskResultImageDataFun = async () => {

  const res: any = await getSimulationTaskFilesApi({
    taskId: props.taskId,
    fileBizType: 1,
    fileName: '',
    startTime: '',
    endTime: '',
    current: 1,
    size: 1000,
  });

  if (res && res.code === 200) {
    exampleImglist.value = res.data?.data?.map((item: any) => {
      return {
        ...item,
        url: `${env.VITE_API_IMAGE_PREVIEW_URL}/data/previewImage?fileId=${item.id}`,
      };
    });
  }

  // ElMessage.success('获取任务结果图片数据' + props.taskId);

};

onMounted(() => {
  getTaskResultImageDataFun();
});

</script>

<style lang="scss" scoped>
.task-performance-page {
  width: 100%;
  height: 100%;
  // height: 450px;

  .operate-form {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;

    .el-form {
      display: flex;

      .el-form-item {
        margin-right: 20px;
      }
    }

    .select-style {
      min-width: 180px;
    }
  }

  .task-img-box {
    width: 100%;
    height: calc(100% - 60px);
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    overflow-y: auto;

    .img-item {
      margin-right: 10px;
      margin-bottom: 10px;

      .task-img {
        width: 100%;
        border: 1px solid #ddd;

      }
    }
  }
}
</style>
