<script lang="ts">
// 声明额外的选项
export default {
  name: "Edit"
};
</script>
<script setup lang="ts">
import { inject, onMounted, reactive, ref, Uploadfile, UploadImg, Editor, useRenderIcon, ElMessage, ElMessageBox, Upload, Close, http, getGroupUrl, RegularVerification, verification } from "@/utils/importUsed"
// 接口列表实例
let UrlList = reactive(null)
// 获取当前板块接口列表
onMounted(async () => {
  UrlList = await getGroupUrl(["prizeSet"]);

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

});
// 类型选项数据
const groupKindOptionList = [
]

// 表单实例
const ruleFormRef = ref()

// 选项卡参数(默认值为列表某项的id)
const activeId = ref('1')
// 提交函数
const submit = async (formEl) => {
  // 表单校验拦截
  if (!formEl) return
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      //表单校验成功回调
      console.log('submit!')

      // 需动态生成接口
      const { status, msg }: any = await http.Request({
        method: UrlList.prizeSet.apiGroupupdate.method,
        url: UrlList.prizeSet.apiGroupupdate.url,
        params: UpdateForm.value
      });
      if (status === 1) {
        //业务成功回调
        ElMessage({
          message: "修改成功",
          type: "success"
        });
        UpdateForm.value = {
          groupName: "", //名称
          groupRemark: "", //说明
          groupVersion: "", //版本号
          groupKind: "", //类型

        };
        // 关闭修改弹窗;
        closeUpdateVisible();
      } else {
        //业务失败回调
        ElMessageBox.alert(msg, "提示", {
          confirmButtonText: "关闭",
          type: "warning"
        });
      }
    } else {
      //表单校验失败回调
      ElMessage({
        message: "请输入完整信息",
        type: "error"
      });
    }
  })
};




// 表单校验规则
const rules = reactive({
  groupName: [
    { required: true, message: '请输入名称', trigger: 'blur' },
  ],
  groupVersion: [
    { required: true, message: '请输入版本号', trigger: 'blur' },
  ],
  groupKind: [
    { required: true, message: '请输入类型', trigger: 'blur' },
  ],

})
// 关闭弹窗回调函数
const closeFn: any = inject('closeEditUpdateVisible');
const openVisible = async () => {
  //通过ID获取表格数据
  const { status, data }: any = await http.Request({ method: UrlList.prizeSet.apiGroupquery.method, url: UrlList.prizeSet.apiGroupquery.url, params: { id: props.formData.id } });
  if (status === 1) {
    UpdateForm.value = data;

  }
};
// 关闭弹窗回调函数
const closeUpdateVisible = () => {
  UpdateForm.value = {
    groupName: "", //名称
    groupRemark: "", //说明
    groupVersion: "", //版本号
    groupKind: "", //类型

  };
  closeFn();
};

// 弹窗是否全屏
const isFullscreen = ref(false)
</script>

<template lang="pug">
.main
  el-dialog(v-model='props.editVisible' draggable width="50%" :fullscreen="isFullscreen" title="修改" @close="closeUpdateVisible" @open="openVisible")
    el-form(:model='UpdateForm' label-position="right" ref="ruleFormRef" :rules="rules" label-width="100px")
      el-form-item(label='名称' prop="groupName")
        el-input(v-model='UpdateForm.groupName' autocomplete='off'
          placeholder="请输入名称")
      el-form-item(label='说明' prop="groupRemark")
        el-input(v-model='UpdateForm.groupRemark' autocomplete='off'
          placeholder="请输入说明")
      el-form-item(label='版本号' prop="groupVersion")
        el-input(v-model='UpdateForm.groupVersion' autocomplete='off'
          placeholder="请输入版本号")
      el-form-item(label="类型", prop="groupKind")
        el-select(
          v-model="UpdateForm.groupKind",
          placeholder="请选择类型",
          clearable,
        )
          el-option(:label="item.label", :value="item.id" v-for="(item,index) in groupKindOptionList")

    .flex.justify-end
      el-button(
        :icon="useRenderIcon(Close)",
        :loading="loading",
        @click="closeUpdateVisible()"
      ) 关闭
      el-button(
        type="primary",
        :icon="useRenderIcon(Upload)",
        @click="submit(ruleFormRef)"
      ) 确认提交
</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;
}

.el-select {
  width: 100%;
}
</style>
