<script lang="ts">
// 声明额外的选项
export default {
  name: "Add"
};
</script>
<script setup lang="ts">
import { inject, ref } from "vue";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { ElMessage, ElMessageBox } from "element-plus";
import { http } from "@/utils/http";
// 获取当前板块接口列表
import Upload from "@iconify-icons/ri/upload-2-fill";
import Close from "@iconify-icons/ri/close-fill";
// 获取URLLIST
import { getGroupUrl } from "@/utils/getUrl/getUrl";

const props = defineProps<{
  submit: {
    type: Function;
    default: () => {};
  };
  addVisible: {
    type: Boolean;
    default: false;
  };
  width: {
    type: Number;
    default: 50;
  };
}>();
// 表单数据
let UpdateForm = ref({
  groupName: "", //名称
  groupRemark: "", //说明
  groupVersion: "", //版本号
  groupKind: "", //类型

});
// 类型选项数据
const groupKindOptionList = [
  { id: 0, label: '客户端' },
  { id: 1, label: '后台' },
]

// 选项卡参数(默认值为列表某项的id)
const activeId = ref('1')
// 提交函数
const submit = async () => {
  const UrlList = await getGroupUrl(['kxsConfigServer']);
  const { status, msg }: any = await http.Request({ method: UrlList.kxsConfigServer.apiGroupadd.method, url: UrlList.kxsConfigServer.apiGroupadd.url, params: UpdateForm.value });
  if (status === 1) {
    ElMessage({
      message: "新增成功",
      type: "success"
    });
    UpdateForm.value = {
      groupName: "", //名称
      groupRemark: "", //说明
      groupVersion: "", //版本号
      groupKind: "", //类型

    };
    closeVisible();
  } else {
    ElMessageBox.alert(msg, "提示", {
      confirmButtonText: "关闭",
      type: "warning"
    });
  };
};
const closeFn: any = inject('closeAddVisible');
// 关闭弹窗回调函数
const closeVisible = () => {
  UpdateForm.value = {
    groupName: "", //名称
    groupRemark: "", //说明
    groupVersion: "", //版本号
    groupKind: "", //类型

  };
  closeFn();
};
</script>

<template lang="pug">
.main
  el-dialog(v-model='props.addVisible' width="50%" title="新增" @close="closeVisible()")
    el-form(:model='UpdateForm' label-position="right" label-width="100px")
      el-form-item(label='名称' prop="groupName")
        el-input(v-model='UpdateForm.groupName' autocomplete='off' class="!w-[230px]"
          placeholder="请输入名称")
      el-form-item(label='说明' prop="groupRemark")
        el-input(v-model='UpdateForm.groupRemark' autocomplete='off' class="!w-[230px]"
          placeholder="请输入说明")
      el-form-item(label='版本号' prop="groupVersion")
        el-input(v-model='UpdateForm.groupVersion' autocomplete='off' class="!w-[230px]"
          placeholder="请输入版本号")
      el-form-item(label="类型", prop="groupKind")
        el-select(
          v-model="UpdateForm.groupKind",
          placeholder="请选择类型",
          clearable,
          class="!w-[230px]"
        )
          el-option(:label="item.label", :value="item.id" v-for="(item,index) in groupKindOptionList")

    el-button(
      :icon="useRenderIcon(Close)",
      :loading="loading",
      @click="closeVisible()"
    ) 关闭
    el-button(
      type="primary",
      :icon="useRenderIcon(Upload)",
      :loading="loading",
      @click="submit"
    ) 确认提交
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}

:deep(.el-form-item__label) {
  font-weight: 700;
}

:deep(.el-pagination) {
  flex-flow: wrap;
}

:deep(.is-draggable) {
  max-height: 80vh;
  overflow: auto;
}

:deep(.el-dialog__header) {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
}

.collapsedom {
  padding: 0 20px;
  background-color: #fff;
}

.ovh-x {
  height: 40vh;
  overflow-y: auto;
}

:deep(.el-descriptions__header) {
  margin: 16px 0 !important;
}
</style>
