<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({
  title: "", //标题
  selectIcon: "", //选中图标
  normalIcon: "", //未选中图标
  selectTextColor: "", //选中文字颜色
  normalTextColor: "", //未选中文字颜色
  pageName: "", //关联页面文件
  noPageHint: "", //空页面提示信息
  backgroudColor: "", //背景色
  style: "", //按钮样式
  scrollerAnimationImages: "", //滚动图片
  pagPath: "", //PAG文件
  showTitle: "", //是否显示标题
  pagLocalPath: "", //pag文件路径
  pagDefaultIcon: "", //pag默认图标
  iconSize: "", //图标尺寸
  statusBarColor: "", //状态栏底色

});
// 按钮样式选项数据
const styleOptionList = [
  { Id: 'default', label: '默认' },
  { Id: 'pag', label: 'PAG' },
  { Id: 'scrollerAnimatio', label: '滚动变化' },
  { Id: 'irregularity', label: '不规则图形外凸' },
  { Id: 'concavity', label: '不规则内凹' },
]

// 选项卡参数(默认值为列表某项的id)
const activeId = ref('1')
// 提交函数
const submit = async () => {
  const UrlList = await getGroupUrl(['kxsConfigServer']);
  const { status, msg }: any = await http.Request({ method: UrlList.kxsConfigServer.appBottomNavsadd.method, url: UrlList.kxsConfigServer.appBottomNavsadd.url, params: UpdateForm.value});
  if (status === 1) {
    ElMessage({
      message: "新增成功",
      type: "success"
    });
    UpdateForm.value = {
      title: "", //标题
      selectIcon: "", //选中图标
      normalIcon: "", //未选中图标
      selectTextColor: "", //选中文字颜色
      normalTextColor: "", //未选中文字颜色
      pageName: "", //关联页面文件
      noPageHint: "", //空页面提示信息
      backgroudColor: "", //背景色
      style: "", //按钮样式
      scrollerAnimationImages: "", //滚动图片
      pagPath: "", //PAG文件
      showTitle: "", //是否显示标题
      pagLocalPath: "", //pag文件路径
      pagDefaultIcon: "", //pag默认图标
      iconSize: "", //图标尺寸
      statusBarColor: "", //状态栏底色

    };
    closeVisible();
  } else {
    ElMessageBox.alert(msg, "提示", {
      confirmButtonText: "关闭",
      type: "warning"
    });
  };
};
const closeFn: any = inject('closeAddVisible');
// 关闭弹窗回调函数
const closeVisible = () => {
  UpdateForm.value = {
    title: "", //标题
    selectIcon: "", //选中图标
    normalIcon: "", //未选中图标
    selectTextColor: "", //选中文字颜色
    normalTextColor: "", //未选中文字颜色
    pageName: "", //关联页面文件
    noPageHint: "", //空页面提示信息
    backgroudColor: "", //背景色
    style: "", //按钮样式
    scrollerAnimationImages: "", //滚动图片
    pagPath: "", //PAG文件
    showTitle: "", //是否显示标题
    pagLocalPath: "", //pag文件路径
    pagDefaultIcon: "", //pag默认图标
    iconSize: "", //图标尺寸
    statusBarColor: "", //状态栏底色

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

<template lang="pug">
.main
  el-dialog(v-model='props.addVisible' width="50%" title="新增" @close="closeVisible()")
    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="title")
            el-input(v-model='UpdateForm.title' autocomplete='off' class="!w-[230px]"
              placeholder="请输入标题")
          el-form-item(label='选中文字颜色' prop="selectTextColor")
            el-input(v-model='UpdateForm.selectTextColor' autocomplete='off' class="!w-[230px]"
              placeholder="请输入选中文字颜色")
          el-form-item(label='未选中文字颜色' prop="normalTextColor")
            el-input(v-model='UpdateForm.normalTextColor' autocomplete='off' class="!w-[230px]"
              placeholder="请输入未选中文字颜色")
          el-form-item(label='关联页面文件' prop="pageName")
            el-input(v-model='UpdateForm.pageName' autocomplete='off' class="!w-[230px]"
              placeholder="请输入关联页面文件")
          el-form-item(label='空页面提示信息' prop="noPageHint")
            el-input(v-model='UpdateForm.noPageHint' autocomplete='off' class="!w-[230px]"
              placeholder="请输入空页面提示信息")
          el-form-item(label='背景色' prop="backgroudColor")
            el-input(v-model='UpdateForm.backgroudColor' autocomplete='off' class="!w-[230px]"
              placeholder="请输入背景色")
          el-form-item(label="按钮样式", prop="style")
            el-select(
              v-model="UpdateForm.style",
              placeholder="请选择按钮样式",
              clearable,
              class="!w-[230px]"
            )
              el-option(:label="item.label", :value="item.Id" v-for="(item,index) in styleOptionList")
      el-tab-pane(label="基本信息" name="2")
        el-form(:model='UpdateForm' label-position="right" label-width="100px")
          el-form-item(label='图标尺寸' prop="iconSize")
            el-input-number(v-model='UpdateForm.iconSize' :min="1" :max="1000"
              placeholder="请输入图标尺寸")
          el-form-item(label='状态栏底色' prop="statusBarColor")
            el-input(v-model='UpdateForm.statusBarColor' autocomplete='off' class="!w-[230px]"
              placeholder="请输入状态栏底色")
    el-tabs(v-model="activeId" class="demo-tabs" @tab-click="handleClick")

    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>
