<!--
 * @Author: 
 * @Date: 2023-03-01 19:20:44
 * @LastEditors: guicheng 1625811865@qq.com
 * @LastEditTime: 2024-05-14 14:53:14
 * @Description: kxs files
 * @filePath: 
-->
<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 Upload from "@iconify-icons/ri/upload-2-fill";
import Close from "@iconify-icons/ri/close-fill";
import { http } from "@/utils/http";
// 获取当前板块接口列表
import { getGroupUrl } from "@/utils/getUrl/getUrl";
// 获取URLLIST
const UserUrl = await getGroupUrl(["User"]);
const props = defineProps<{
  editVisible: {
    type: Boolean;
    default: false;
  };
  width: {
    type: Number;
    default: 50;
  };
  formData: {
    id: any;
    type: any;
    default: {};
  };
}>();
// 表单数据
const UpdateForm: any = ref({
  RealName: "",
  AdminName: "",
  PassWord: "",
  RoleId: ""
});
// 传参选项数据
const optionList = [
  { Id: "1", label: "推荐" },
  { Id: "2", label: "实物" },
  { Id: "3", label: "虚拟商品" }
];
// 选项卡参数(默认值为列表某项的id)
const activeId = ref("1");
// 提交函数
const submit = async () => {
  const { status, info }: any = http.request(
    UserUrl.User.userSearch.method,
    UserUrl.User.userSearch.url,
    UpdateForm.value
  );
  if (status === "1") {
    ElMessage({
      message: "修改成功",
      type: "success"
    });
    UpdateForm.value = {
      AdminName: "",
      RealName: "",
      RoleId: "",
      PassWord: ""
    };
  } else {
    ElMessageBox.alert(info, "提示", {
      confirmButtonText: "关闭",
      type: "warning"
    });
  }
};
// 关闭弹窗回调函数
const closeVisible = inject("closeEditVisible");
const openVisible = async () => {
  //通过ID获取表格数据
  const { data, info }: any = http.request(
    UserUrl.User.userSearch.method,
    UserUrl.User.userSearch.url,
    props.formData.id
  );
  UpdateForm.value = data;
  // 通过表格项获取数据
  UpdateForm.value = props.formData;
};
</script>

<template lang="pug">
.main
  el-dialog(v-model='props.editVisible' width="50%" title="修改" @close="closeVisible()" @open="openVisible")
    //- 有选项卡模板
    el-tabs(v-model="activeId" class="demo-tabs" @tab-click="handleClick")
      el-tab-pane(label="选项卡一" name="1")
        el-form(:model='UpdateForm' label-position="right" label-width="100px")
          el-form-item(label='账户名称' prop="RealName")
            el-input(v-model='UpdateForm.RealName' autocomplete='off' class="!w-[230px]"
              placeholder="请输入账户名称")
          el-form-item(label='用户名' prop="AdminName")
            el-input(v-model='UpdateForm.AdminName' autocomplete='off' class="!w-[230px]"
              placeholder="请输入用户名")
          el-form-item(label='密码' prop="PassWord")
            el-input(v-model='UpdateForm.PassWord' autocomplete='off' class="!w-[230px]"
              placeholder="请输入密码")
          el-form-item(label="角色:", prop="RoleId")
            el-select(
              v-model="UpdateForm.RoleId",
              placeholder="请选择用户角色",
              clearable,
              class="!w-[230px]"
            )
              el-option(:label="item.label", :value="item.Id" v-for="(item,index) in optionList")
      el-tab-pane(label="选项卡二" name="2")
        el-form(:model='UpdateForm' label-position="right" label-width="100px")
          el-form-item(label='账户名称' prop="RealName")
            el-input(v-model='UpdateForm.RealName' autocomplete='off' class="!w-[230px]"
              placeholder="请输入账户名称")
          el-form-item(label='用户名' prop="AdminName")
            el-input(v-model='UpdateForm.AdminName' autocomplete='off' class="!w-[230px]"
              placeholder="请输入用户名")
          el-form-item(label='密码' prop="PassWord")
            el-input(v-model='UpdateForm.PassWord' autocomplete='off' class="!w-[230px]"
              placeholder="请输入密码")
          el-form-item(label="角色:", prop="RoleId")
            el-select(
              v-model="UpdateForm.RoleId",
              placeholder="请选择用户角色",
              clearable,
              class="!w-[230px]"
            )
              el-option(:label="item.label", :value="item.Id" v-for="(item,index) in optionList")
    //- 无选项卡模板
    el-form(:model='UpdateForm' label-position="right" label-width="100px")
      el-form-item(label='账户名称' prop="RealName")
        el-input(v-model='UpdateForm.RealName' autocomplete='off' class="!w-[230px]" placeholder="请输入账户名称")
      el-form-item(label='用户名' prop="AdminName")
        el-input(v-model='UpdateForm.AdminName' autocomplete='off' class="!w-[230px]" placeholder="请输入用户名")
      el-form-item(label='密码' prop="PassWord")
        el-input(v-model='UpdateForm.PassWord' autocomplete='off' class="!w-[230px]" placeholder="请输入密码")
      el-form-item(label="角色:", prop="RoleId")
        el-select(
          v-model="UpdateForm.RoleId",
          placeholder="请选择用户角色",
          clearable,
          class="!w-[230px]"
        )
          el-option(:label="item.label", :value="item.Id" v-for="(item,index) in optionList")
    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>
