<template>
  <div>
    <el-dialog
      v-model="open"
      :title="title"
      width="1000px"
      append-to-body
    >
      <template v-slot:header>
        <div class="cleartitle" style="display: flex;justify-content: flex-start;align-items: center;">
          <img src="@/assets/images/logo_video.png" width="25px" alt=""> <span>{{title}}</span>
        </div>
      </template>
        <div v-if="isAdd">
              <el-row :gutter="10" class="mb8">
            <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                  <span>基础信息</span>
              </div>
          </el-row>
          <el-form ref="algRef" :model="form" :rules="rules" label-width="80px">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="算法名称" prop="algorithmName">
                      <el-input v-model="form.algorithmName" placeholder="请输入岗位名称" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="算法英文" prop="algorithmEnglish">
                      <el-input v-model="form.algorithmEnglish" placeholder="请输入编码名称" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="硬件平台" prop="algorithmPlat">
                      <el-select v-model="form.algorithmPlat" placeholder="请选择硬件平台" clearable >
                        <el-option :label="'英伟达'" :value="'英伟达'"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="算法场景" prop="applicationScenarios">
                      <el-select v-model="form.applicationScenarios" multiple placeholder="请选择算法场景" clearable >
                        <el-option 
                        v-for="disc in algorithm_scen"
                        :key="disc.value"
                        :label="disc.label"
                          :value="disc.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="预警等级" prop="alarmLevel">
                      <el-select v-model="form.alarmLevel" placeholder="请选择预警等级" clearable >
                        <el-option 
                        v-for="disc in levelList"
                        :key="disc.id"
                        :label="disc.alarmName"
                        :value="disc.id"
                        >
                        <span>
                            <el-tag type="success" :style="{backgroundColor: disc.alarmColor,width:'40px'}">{{ }}</el-tag>
                          </span>
                          {{ disc.alarmName }}
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="卡片文案" prop="cardCopywriting">
                      <el-input v-model="form.cardCopywriting" type="textarea"  :rows="4" placeholder="请输入卡片文案" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="卡片图片" prop="cardImg">
                      <ImageUpload :modelValue="form.cardImg" :limit='1' :fileSize="5" @update:modelValue="getImageUrl"/>
                    </el-form-item>
                  </el-col>
                </el-row>
          </el-form>
          <!-- <el-row :gutter="10" class="mb8" style="justify-content: space-between;">
            <el-col :span="1.5">
              <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                <span>算法维护</span>
              </div>
          </el-col>
          <el-col :span="6.8" style="display: flex;">
              <el-button
                type="primary"
                plain
                icon="Search"
                @click="handleAdd"
              >搜索</el-button>
              <el-button
                type="success"
                plain
                icon="Refresh"
                @click="handleUpdate"
              >版本更新</el-button>
              <el-button
                type="success"
                plain
                icon="UploadFilled"
                @click="handleUpdate"
              >算法上传</el-button>
          </el-col>
          </el-row>
          <el-card class="left-list">
            <el-table  :data="wrapList" >
              <el-table-column label="文件名称" align="center" prop="postId" />
              <el-table-column label="状态" align="center" prop="postCode" />
              <el-table-column label="MD5核对结果" align="center" prop="postName" />
              <el-table-column label="文件大小" align="center" prop="postSort" />
              <el-table-column label="进度" align="center" prop="postSort" />
              <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
                  <template #default="scope">
                    <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:post:edit']">修改</el-button>
                    <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:post:remove']">删除</el-button>
                  </template>
              </el-table-column>
            </el-table>
            </el-card> -->
        </div>
        <el-form ref="algRef" :model="form" :rules="rules" label-width="80px" v-else>

        <el-tabs v-model="activeName" class="demo-tabs" >
            <el-tab-pane label="基础信息" name="基础信息">
              <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>基础信息</span>
                  </div>
              </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="算法名称" prop="algorithmName">
                          <el-input v-model="form.algorithmName" placeholder="请输入岗位名称" />
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="算法英文" prop="algorithmEnglish">
                          <el-input v-model="form.algorithmEnglish" placeholder="请输入编码名称" />
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="12">
                        <el-form-item label="硬件平台" prop="algorithmPlat">
                          <el-select v-model="form.algorithmPlat" placeholder="请选择硬件平台" clearable >
                            <el-option :label="'英伟达'" :value="'英伟达'"
                            />
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="算法场景" prop="applicationScenarios">
                          <el-select v-model="form.applicationScenarios" multiple placeholder="请选择算法场景" clearable >
                            <el-option 
                            v-for="disc in algorithm_scen"
                            :key="disc.value"
                            :label="disc.label"
                             :value="disc.value"
                            />
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row>
                  <el-col :span="12">
                    <el-form-item label="预警等级" prop="alarmLevel">
                      <el-select v-model="form.alarmLevel" placeholder="请选择预警等级" clearable >
                        <el-option 
                        v-for="disc in levelList"
                        :key="disc.id"
                        :label="disc.alarmName"
                        :value="disc.id"
                        > <span>
                      <el-tag type="success" :style="{backgroundColor: disc.alarmColor,width:'40px'}">{{ }}</el-tag>
                    </span>
                    {{ disc.alarmName }}
                  </el-option>
                        
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="卡片文案" prop="cardCopywriting">
                      <el-input v-model="form.cardCopywriting" type="textarea"  :rows="4" placeholder="请输入内容" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="卡片图片" prop="cardImg">
                      <ImageUpload :modelValue="form.cardImg" :limit='1' :fileSize="5" @update:modelValue="getImageUrl"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <AlgorithmFile :algId="form.id" ref="AlgorithmFileRef" />
            </el-tab-pane>
            <el-tab-pane label="算法详情" name="算法详情">
              <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>算法详情页Banner</span>
                  </div>
              </el-row>
              <el-row :gutter="10" class="mb8">
                <el-col :span="12">
                  <el-form-item label-width="130px" label="算法Banner" prop="algorithmBanner">
                    <ImageUpload :modelValue="form.algorithmBanner" :limit='1' :fileSize="5" @update:modelValue="getAlgorithmBanner"/>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>算法详情页banner卡片信息</span>
                  </div>
              </el-row>
              <el-row :gutter="10" class="mb8">
                <el-col :span="12">
                  <el-form-item label-width="130px" label="基础准确率" prop="basicAccuracy">
                    <el-input v-model="form.basicAccuracy" placeholder="请输入基础准确率" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10" class="mb8">
                <el-col :span="12">
                  <el-form-item label-width="130px" label="场景优化准确率" prop="sceneOptimizationAccuracy">
                    <el-input v-model="form.sceneOptimizationAccuracy" placeholder="请输入场景优化准确率" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10" class="mb8">
                <el-col :span="12">
                  <el-form-item label-width="130px" label="算法介绍" prop="algorithmIntroduce">
                    <el-input v-model="form.algorithmIntroduce" placeholder="请输入算法介绍" />
                  </el-form-item>
                </el-col>
              </el-row> -->
              <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>算法详情页视频</span>
                  </div>
              </el-row>
              <el-row :gutter="10" class="mb8">
                <el-col :span="12">
                  <el-form-item label-width="130px" label="banner上算法视频" prop="algorithmBannerVideo">
                    <ImgVideoUpload :modelValue="form.algorithmBannerVideo" :fileType="['rmvb', 'avi', 'mp4']"  :limit='1' :fileSize="100" :isShowTip="true" @update:modelValue="getAlgorithmBannerVideo"/>
                  </el-form-item>
                </el-col>
              </el-row> 
              <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>在线体验案例图片/视频（内置）</span>
                  </div>
              </el-row>
              <el-row :gutter="10" class="mb8">
                <el-col :span="24">
                  <el-form-item label-width="130px" label="在线体验案例图片/视频" prop="imgVideoData">
                    <ImgVideoUpload 
                    :modelValue="imgVideoData"
                     :fileType="['png', 'jpg', 'mp4']"
                      :limit='4'
                     :fileSize="20"
                     :isShowTip="true"
                     @update:modelValue="getImgVideoData"/>
                    <!-- <ImageUpload :modelValue="form.algorithmBannerVideo" :limit='1' :fileSize="30" @update:modelValue="getImageUrl"/> -->
                  </el-form-item>
                </el-col>
              </el-row> 
              <!-- <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>在线体验案例图片/视频（内置）</span>
                  </div>
              </el-row>
              <el-row :gutter="10" class="mb8">
                <el-col :span="12">
                  <el-form-item label-width="130px" label="banner上算法视频" prop="algorithmBannerVideo">
                    <ImageUpload :modelValue="form.algorithmBannerVideo" :limit='1' :fileSize="30" @update:modelValue="getImageUrl"/>
                  </el-form-item>
                </el-col>
              </el-row>  -->
            </el-tab-pane>
            <el-tab-pane label="算法边界" name="算法边界">
              <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>算法边界</span>
                  </div>
              </el-row>
              <el-row :gutter="10" class="mb8" style="justify-content: space-between;">
              <el-col :span="6.8" style="display: flex;">
                  <el-button
                    type="primary"
                    plain
                    icon="Plus"
                    @click="handleBoundaryAdd"
                  >新建边界</el-button>
              </el-col>
              </el-row>
              <el-card class="left-list">
                <el-table :data="boundaryList" >
                  <el-table-column label="边界类型" align="center" prop="caseType" >
                    <template #default="scope">
                      <dict-tag :options="algorithm_case" :value="scope.row.caseType" />
                    </template>
                  </el-table-column>
                  <el-table-column label="边界内容" align="center" prop="remark" />
                  <el-table-column label="边界案例图" align="center" prop="caseFile" >
                    <template #default="scope">
                      <ImagePreview :src="scope.row.caseFile"/>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
                      <template #default="scope">
                        <el-button link type="primary" icon="Edit" @click="handleBoundaryUpdate(scope.row)" >修改</el-button>
                        <el-button link type="primary" icon="Delete" @click="handleBoundaryDelete(scope.row)" >删除</el-button>
                      </template>
                  </el-table-column>
                </el-table>
              </el-card>
            </el-tab-pane>
            <el-tab-pane label="算法场景" name="算法场景">
              <el-row :gutter="10" class="mb8">
                <div class="form-title" style="display: flex;justify-content: flex-start;align-items: center;">
                      <span>应用场景信息</span>
                  </div>
              </el-row>
              <el-row :gutter="10" class="mb8" style="justify-content: space-between;">
              <el-col :span="6.8" style="display: flex;">
                  <el-button
                    type="primary"
                    plain
                    icon="Plus"
                    @click="handleSceneAdd"
                  >新建场景</el-button>
              </el-col>
              </el-row>
              <el-card class="left-list">
                <el-table :data="sceneList">
                  <el-table-column label="场景名称" align="center" prop="sceneName" />
                  <el-table-column label="场景详情" align="center" prop="sceneDetail" />
                  <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
                      <template #default="scope">
                        <el-button link type="primary" icon="Edit" @click="handleSceneUpdate(scope.row)" >修改</el-button>
                        <el-button link type="primary" icon="Delete" @click="handleSceneDelete(scope.row)" >删除</el-button>
                      </template>
                  </el-table-column>
                </el-table>
              </el-card>
            </el-tab-pane>
         </el-tabs>
        </el-form> 
      <template #footer>
        <div class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog
      v-model="openScene"
      :title="titleScene"
      width="500px"
      append-to-body
    >
      <template v-slot:header>
        <div class="cleartitle" style="display: flex;justify-content: flex-start;align-items: center;">
          <img src="@/assets/images/logo_video.png" width="25px" alt=""> <span>{{titleScene}}</span>
        </div>
      </template>
      <el-form ref="sceneRef" :model="formScene" :rules="rules" label-width="80px">
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="场景名称" prop="sceneName">
                      <el-input v-model="formScene.sceneName" placeholder="请输入场景名称" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="场景详情" prop="sceneDetail">
                      <el-input v-model="formScene.sceneDetail" type="textarea"  :rows="4"  placeholder="请输入场景详情" />
                    </el-form-item>
                  </el-col>
                </el-row>
          </el-form>
      <template #footer>  
        <div class="dialog-footer">
            <el-button type="primary" @click="submitSceneRefForm">确 定</el-button>
            <el-button @click="cancelScene">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog
      v-model="openBoundary"
      :title="titleBoundary"
      width="500px"
      append-to-body
    >
      <template v-slot:header>
        <div class="cleartitle" style="display: flex;justify-content: flex-start;align-items: center;">
          <img src="@/assets/images/logo_video.png" width="25px" alt=""> <span>{{titleBoundary}}</span>
        </div>
      </template>
      <el-form ref="BoundaryRef" :model="formBoundary" :rules="rules" label-width="90px">
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="边界类型" prop="caseType">
                      <el-select v-model="formBoundary.caseType" placeholder="请选择边界类型" clearable >
                            <el-option 
                            v-for="disc in algorithm_case"
                            :key="disc.value"
                            :label="disc.label"
                             :value="disc.value"
                            />
                          </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="边界内容" prop="remark">
                      <el-input v-model="formBoundary.remark"  type="textarea"  :rows="4"  placeholder="请输入边界内容" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="边界案例图" prop="caseFile">
                      <ImageUpload :modelValue="formBoundary.caseFile" :limit='1' :fileSize="5" @update:modelValue="getBoundaryImageUrl"/>
                    </el-form-item>
                  </el-col>
                </el-row>
          </el-form>
      <template #footer>  
        <div class="dialog-footer">
            <el-button type="primary" @click="submitBoundaryRefForm">确 定</el-button>
            <el-button @click="cancelBoundary">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
  
</template>

<script setup>
import { addAlg, updateAlg , detailAlg , listAlgFile, addListAlgorithmCase , listCase} from "@/api/algorithmList/index.js";
import { listScene, detailScene , addScene, updateScene, deleteScene} from "@/api/algorithmList/scene.js";
import { listBoundary, detailBoundary , addBoundary, updateBoundary, deleteBoundary} from "@/api/algorithmList/boundary.js";
import { listAlgLevel} from "@/api/algorithmList/algorithmDown.js";
import AlgorithmFile from './algorithmFile.vue'
const { proxy } = getCurrentInstance();
const { algorithm_scen, algorithm_case } = proxy.useDict("algorithm_scen", "algorithm_case");
const emit = defineEmits();
const open = ref(false);
const openScene = ref(false);
const openBoundary = ref(false);
const isAdd = ref(true);
const title = ref("");
const imgVideoData = ref("");
const AlgorithmFileRef = ref(null);
const titleScene = ref("");
const titleBoundary = ref("");
const activeName = ref("基础信息");

const sceneList = ref([]);
const boundaryList = ref([]);
const levelList = ref([]);
const ids = ref([]);
const data = reactive({
  form: {},
  formScene: {},
  formBoundary: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    algorithmEnglish: undefined,
    algorithmName: undefined,
    status: undefined
  },
  rules: {
    algorithmName: [{ required: true, message: "算法名称不能为空", trigger: "blur" }],
    applicationScenarios: [{ required: true, message: "算法场景不能为空", trigger: "blur" }],
    cardCopywriting: [{ required: true, message: "卡片文案不能为空", trigger: "blur" }],
    cardImg: [{ required: true, message: "卡片图片不能为空", trigger: "blur" }],
  }
});

const { queryParams, form, formScene,formBoundary, rules } = toRefs(data);

/** 查询预警等级列表 */
function getLevelList() {
  listAlgLevel().then(response => {
    levelList.value = response.rows;
  });
}
getLevelList()

function getImageUrl(url){
    form.value.cardImg=url
}
function getAlgorithmBannerVideo(url){
  console.log("🚀 ~ getAlgorithmBanner ~ url:", url)
    form.value.algorithmBannerVideo=url
}
function getAlgorithmBanner(url){
    form.value.algorithmBanner=url
}
function getBoundaryImageUrl(url){
    formBoundary.value.caseFile=url
}
function getImgVideoData(url){
    imgVideoData.value=url
}

/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    algorithmEnglish: undefined,
    algorithmName: undefined,
    algorithmPlat: '',
    status: "0",
    remark: undefined
  };
  proxy.resetForm("algRef");
}


/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  isAdd.value = true;
  title.value = "添加算法";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const id = row.id || ids.value;
  ids.value = id;
  getSceneList();
  getListCase();
  getBoundaryList()
  detailAlg(id).then(response => {
    form.value = response.data;
    form.value.applicationScenarios=form.value.applicationScenarios&&form.value.applicationScenarios.split(',')
    open.value = true;
    isAdd.value = false;
    title.value = "修改算法";
    setTimeout(()=>{
      AlgorithmFileRef.value.getList()
    })
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["algRef"].validate(valid => {
    if (valid) {
      form.value.applicationScenarios=form.value.applicationScenarios.join()
      if (form.value.id != undefined) {
        addCaseFile()
        updateAlg(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          emit("getList");
        });
      } else {
        addAlg(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          emit("getList");
        });
      }
    }
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 算法场景 */

/** 查询场景列表 */
function getSceneList() {
  listScene({ algorithmId: ids.value,}).then(response => {
    sceneList.value = response.rows;
  });
}

/** 表单重置 */
function resetScene() {
  formScene.value = {
    algorithmId: form.value.id,
    sceneName: undefined,
    sceneDetail: undefined,
    remark: undefined
  };
  proxy.resetForm("sceneRef");
}

/** 场景新增按钮操作 */
function handleSceneAdd() {
  resetScene();
  openScene.value = true;
  titleScene.value = "添加场景";
}

/** 删除按钮操作 */
function handleSceneDelete(row) {
  const id = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除场景名称为"' + row.sceneName + '"的数据项?').then(function () {
    return deleteScene(id);
  }).then(() => {
    getSceneList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 修改按钮操作 */
function handleSceneUpdate(row) {
  resetScene();
  const id = row.id || ids.value;
  detailScene(id).then(response => {
    formScene.value = response.data;
    openScene.value = true;
    titleScene.value = "修改场景";
  });
}

/** 提交按钮 */
function submitSceneRefForm() {
  proxy.$refs["sceneRef"].validate(valid => {
    if (valid) {
      if (formScene.value.id != undefined) {
        updateScene(formScene.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          openScene.value = false;
          getSceneList()
        });
      } else {
        addScene(formScene.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          openScene.value = false;
          getSceneList()
        });
      }
    }
  });
}
/** 取消按钮 */
function cancelScene() {
  openScene.value = false;
  resetScene();
}

/** 算法边界 */

/** 查询场景列表 */
function getBoundaryList() {
  listBoundary({ algorithmId: ids.value,}).then(response => {
    boundaryList.value = response.rows;
  });
}

/** 表单重置 */
function resetBoundary() {
  formBoundary.value = {
    algorithmId: form.value.id,
    sceneName: undefined,
    sceneDetail: undefined,
    remark: undefined
  };
  proxy.resetForm("BoundaryRef");
}

/** 场景新增按钮操作 */
function handleBoundaryAdd() {
  resetBoundary();
  openBoundary.value = true;
  titleBoundary.value = "添加场景";
}

/** 删除按钮操作 */
function handleBoundaryDelete(row) {
  const id = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除该算法边界?').then(function () {
    return deleteBoundary(id);
  }).then(() => {
    getBoundaryList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 修改按钮操作 */
function handleBoundaryUpdate(row) {
  resetBoundary();
  const id = row.id || ids.value;
  detailBoundary(id).then(response => {
    formBoundary.value = response.data;
    openBoundary.value = true;
    titleBoundary.value = "修改场景";
  });
}

/** 提交按钮 */
function submitBoundaryRefForm() {
  proxy.$refs["BoundaryRef"].validate(valid => {
    if (valid) {
      if (formBoundary.value.id != undefined) {
        updateBoundary(formBoundary.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          openBoundary.value = false;
          getBoundaryList()
        });
      } else {
        addBoundary(formBoundary.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          openBoundary.value = false;
          getBoundaryList()
        }); 
      }
    }
  });
}

/** 取消按钮 */
function cancelBoundary() {
  openBoundary.value = false;
  resetBoundary();
}


/** 查询案例文件列表 */
function getListCase() {
  listCase({ algorithmId: ids.value,caseType:2}).then(response => {
    imgVideoData.value = response.rows.map(item=>{
      return item.caseFile
    }).join(",");

  });
}

//新增案例文件
function addCaseFile(){
  if(proxy.isNotEmpty(imgVideoData.value) && imgVideoData.value.length>0){
    const params={
      algorithmId:form.value.id,
      list:[]
    }
    imgVideoData.value.split(",").forEach(item => {
      params.list.push({
        algorithmId:form.value.id,
        caseFile:item,
        caseType:2,
        fileType:getFileType(item),
      })

    });
    addListAlgorithmCase(params).then(res=>{
      console.log(res)
    })
  }
}

// 判断当前文件类型
function getFileType(fileName) {
    const videoType =['mp4','avi','mov','wmv','flv','mkv','rmvb','3gp','mpg','mpeg','webm']
    const ImgType = ['jpg','jpeg','png','gif','bmp','tiff','webp',]
    let fileType = fileName.split(".").pop();
    if (videoType.includes(fileType)) {
      return "1";

    }
    if (ImgType.includes(fileType)) {
      return "0";
    }
}

defineExpose({ handleAdd , handleUpdate })
</script>
<style scoped lang="scss">
    .form-title{
      display: flex;
      align-items:center;/*for vertical align*/
      font-size: 16px;
      font-weight: 600;
      border-radius: 5px;
      padding: 0;
    }
    .form-title::before{
      content:"";
      display: inline-block;
      width: 10px; /* 矩形的宽度 */
      height: 30px; /* 矩形的高度 */
      background-color: #1890FF; /* 矩形的背景颜色 */
      margin-right: 10px;
      border-radius: 8px;
    }
</style>