<script lang="ts">
// 声明额外的选项
export default {
  name: "Edit"
};
</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";
// 获取URLLIST
import { getGroupUrl } from "@/utils/getUrl/getUrl";

const props = defineProps<{
  editVisible: {
    type: Boolean;
    default: false;
  };
  width: {
    type: Number;
    default: 50;
  };
  formData: {
    type: Object;
    default: {};
  };
}>();
// 表单数据
let UpdateForm: any = ref({
  terminalKind: "", //终端类型
  versionNum: "", //版本号
  title: "", //标题
  info: "", //更新信息
  confirmText: "", //确定按钮文字
  cancelText: "", //取消按钮文字
  downloadUrl: "", //更新地址
  id: "", //ID

});
// 终端类型选项数据
const terminalKindOptionList = [
  { Id: 'ios', label: 'ios' },
  { Id: 'android', label: 'android' },
]

// 选项卡参数(默认值为列表某项的id)
const activeId = ref('1')
// 提交函数
const submit = async () => {
  const UrlList = await getGroupUrl(['kxsConfigServer']);
  const { status, msg }: any = await http.Request({ method: UrlList.kxsConfigServer.appVersionupdate.method, url: UrlList.kxsConfigServer.appVersionupdate.url, params: UpdateForm.value});
  if (status === 1) {
    ElMessage({
      message: "修改成功",
      type: "success"
    });
    UpdateForm.value = {
      terminalKind: "", //终端类型
      versionNum: "", //版本号
      title: "", //标题
      info: "", //更新信息
      confirmText: "", //确定按钮文字
      cancelText: "", //取消按钮文字
      downloadUrl: "", //更新地址
      id: "", //ID

    };
    closeVisible();
  } else {
    ElMessageBox.alert(msg, "提示", {
      confirmButtonText: "关闭",
      type: "warning"
    });
  };
};
// 关闭弹窗回调函数
const closeFn: any = inject('closeEditUpdateVisible');
const openVisible = async () => {
  //通过ID获取表格数据
  const UrlList = await getGroupUrl(['kxsConfigServer']);
  const { status, data }: any = await http.Request({method: UrlList.kxsConfigServer.appVersionquery.method, url: UrlList.kxsConfigServer.appVersionquery.url, params: props.formData});
  if (status === 1) {
    UpdateForm.value = data;
  }
};
// 关闭弹窗回调函数
const closeVisible = () => {
  UpdateForm.value = {
    groupName: "", //名称
    groupRemark: "", //说明
    groupVersion: "", //版本号

  };
  closeFn();
};
</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="terminalKind")
            el-select(
              v-model="UpdateForm.terminalKind",
              placeholder="请选择终端类型",
              clearable,
              class="!w-[230px]"
            )
              el-option(:label="item.label", :value="item.Id" v-for="(item,index) in terminalKindOptionList")
          el-form-item(label='版本号' prop="versionNum")
            el-input(v-model='UpdateForm.versionNum' autocomplete='off' class="!w-[230px]"
              placeholder="请输入版本号")
          el-form-item(label='标题' prop="title")
            el-input(v-model='UpdateForm.title' autocomplete='off' class="!w-[230px]"
              placeholder="请输入标题")
          el-form-item(label='确定按钮文字' prop="confirmText")
            el-input(v-model='UpdateForm.confirmText' autocomplete='off' class="!w-[230px]"
              placeholder="请输入确定按钮文字")
          el-form-item(label='取消按钮文字' prop="cancelText")
            el-input(v-model='UpdateForm.cancelText' autocomplete='off' class="!w-[230px]"
              placeholder="请输入取消按钮文字")
          el-form-item(label='更新地址' prop="downloadUrl")
            el-input(v-model='UpdateForm.downloadUrl' autocomplete='off' class="!w-[230px]"
              placeholder="请输入更新地址")
      el-tab-pane(label="基本信息" name="2")
        el-form(:model='UpdateForm' label-position="right" label-width="100px")
          el-form-item(label='ID' prop="id")
            el-input-number(v-model='UpdateForm.id' :min="1" :max="1000"
              placeholder="请输入ID")

    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>
