<template>
    <el-dialog
      v-model="open"
      :title="title"
      width="800px"
      append-to-body
    >
    <el-descriptions
      class="margin-top"
      title=""
      :column="1"
      border
    >
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            预警等级
          </div>
        </template>
        {{form.alarmLevelName}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            预警类型
          </div>
        </template>
        {{form.alarmType}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            预警时间
          </div>
        </template>
        {{ parseTime(form.alarmTime) }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            预警图片
          </div>
        </template>
        <ImagePreview style="width: 400px;height: 225px;" :src="form.alarmImg"/>
      </el-descriptions-item>
    </el-descriptions>
      <template #footer>
        <div class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
</template>

<script setup>
 import { listAlarm, detailAlarm } from "@/api/alarmControl/index.js";
const { proxy } = getCurrentInstance();
const emit = defineEmits();
const open = ref(false);
const title = ref("");
const ids = ref([]);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    algorithmEnglish: undefined,
    algorithmName: undefined,
    status: undefined
  },
  rules: {
    algorithmName: [{ required: true, message: "算法名称不能为空", trigger: "blur" }],
    algorithmEnglish: [{ required: true, message: "算法英文不能为空", trigger: "blur" }],
    algorithmPlat: [{ required: true, message: "岗位顺序不能为空", trigger: "blur" }],
  }
});

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

function getImageUrl(url){
form.value.cardImg=url
console.log("🚀 ~ getImageUrl ~ orm.cardImg:", form)
}

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


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

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const id = row.id || ids.value;
  detailAlarm(id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "预警详情";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["algRef"].validate(valid => {
    if (valid) {
      if (form.value.id != undefined) {
        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();
}
defineExpose({ handleAdd , handleUpdate })
</script>

<style scoped lang="scss">
// .el-upload--picture-card 控制加号部分
:deep(.hide .el-upload--picture-card) {
    display: none;
}
</style>