<template>
  <div class="add">
    <el-dialog
      v-model="dialogVisible"
      :title="'全局数据' + (logType === 'add' ? '新增' : '修改')"
      width="500"
    >
      <el-form
        :label-position="labelPosition"
        label-width="auto"
        :model="formLabelAlign"
        style="max-width: 600px"
        ref="ruleFormRef"
      >
        <!--        <el-form-item-->
        <!--          label="数据项编码	"-->
        <!--          :label-position="itemLabelPosition"-->
        <!--          prop="dataItemCode"-->
        <!--        >-->
        <!--          <el-input v-model="formLabelAlign.dataItemCode" />-->
        <!--        </el-form-item>-->

        <el-form-item
          label="数据项名称	"
          :label-position="itemLabelPosition"
          prop="dataItemCode"
        >
          <el-input v-model="formLabelAlign.dataItemName" />
        </el-form-item>
        <!--        <el-form-item-->
        <!--          label="测试工程id	"-->
        <!--          :label-position="itemLabelPosition"-->
        <!--          type="number"-->
        <!--          prop="engineeringId"-->
        <!--        >-->
        <!--          <el-input v-model="formLabelAlign.engineeringId" />-->
        <!--        </el-form-item>-->
        <el-form-item
          label="设定值	"
          :label-position="itemLabelPosition"
          prop="setValue"
        >
          <el-input v-model="formLabelAlign.setValue" />
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="saveFun"> 保存 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref, watch } from "vue";

const dialogVisible = ref(false);

import type { FormItemProps, FormProps } from "element-plus";

const route = useRoute();

const labelPosition = ref<FormProps["labelPosition"]>("right");
const itemLabelPosition = ref<FormItemProps["labelPosition"]>("");

interface VersionItem {
  dataItemName: string;
  setValue: string;
  // dataItemCode: string;
  engineeringId: number;
}

// dataItemCode	数据项编码
// dataItemName	数据项名称
// engineeringId	测试工程id
// setValue 设定值
const formLabelAlign = ref<VersionItem>({
  dataItemName: "",
  setValue: "",
  // dataItemCode: "",
  engineeringId: 0,
});

const emit = defineEmits(["save"]);

const saveFun = () => {
  emit(
    "save",
    { ...formLabelAlign.value, engineeringId: route.params.engineerId },
    flag.value
  );
};

const ruleFormRef = ref();
const flag = ref("");
const logType = ref("");
const showDialog = (type: string, data: any) => {
  logType.value = type;
  dialogVisible.value = true;
  ruleFormRef.value && ruleFormRef.value.resetFields();
  flag.value = type;
  formLabelAlign.value = JSON.parse(JSON.stringify(data));
};
const hiddenDialog = () => {
  dialogVisible.value = false;
};
defineExpose({
  showDialog,
  hiddenDialog,
});
</script>
<style scoped lang="scss">
// .add {
//   // position: fixed;
//   // width: 100%;
//   // height: 100%;
//   // z-index: 10;
//   // background-color: #000;
// }
</style>
