<template>
  <div>
    <div v-for="item in menuList" :key="item.id">
      <div>{{ item.menuName }}</div>
      <el-form :model="item" label-width="100">
        <el-form-item label="ip" prop="ip">
          <el-input v-model="item.ip" />
        </el-form-item>
        <el-form-item label="port" prop="port">
          <el-input v-model="item.port" />
        </el-form-item>
      </el-form>
    </div>
    <el-form-item>
      <el-button @click="cancel"> 取消</el-button>
      <el-button type="primary" @click="saveAddress">保存</el-button>
    </el-form-item>
  </div>
</template>

<script lang="ts" setup>
import { onMounted } from "vue";
import { systemMenuList, updateSystemMenuList } from "@/api/user";

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

const menuList = ref<any[]>([]);

onMounted(() => {
  systemMenuList().then((res) => {
    menuList.value = res.data ?? [];
  });
});

const cancel = () => {
  emit("finish");
};

const finish = () => {
  emit("finish");
};

const saveAddress = () => {
  updateSystemMenuList(menuList.value).then(() => {
    ElMessage.success("保存成功");
    finish();
  });
};
</script>

<style lang="scss" scoped></style>
