<template>
  <div class="page_container">
    <bg-breadcrumb></bg-breadcrumb>
    <div class="parent_container">
      <div class="left_container bgc_white">
        <el-menu default-active="1" @select="switchMenu">
          <el-menu-item index="1">
            <span>授权信息</span>
          </el-menu-item>
          <el-menu-item index="2">
            <span>安全相关</span>
          </el-menu-item>
          <el-menu-item index="3">
            <span>登录注册配置</span>
          </el-menu-item>
        </el-menu>
      </div>
      <div class="right_container bgc_white">
        <!-- 授权信息表单 -->
        <el-form
          v-if="activeIndex == 1"
          ref="authorizeFormRef"
          :model="authorizeFormData"
          :rules="authorizeRules"
          label-width="110px"
          class="authorizeForm">
          <el-form-item label="当前版本号" prop="system_version">
            <el-input disabled v-model="authorizeFormData.system_version" maxlength="20" />
          </el-form-item>
          <el-form-item label="User" prop="system_user">
            <el-input placeholder="统一管理用户认证平台" v-model="authorizeFormData.system_user" maxlength="50" />
          </el-form-item>
          <el-form-item label="Key" prop="license">
            <el-input
              placeholder="请输入"
              rows="5"
              maxlength="300"
              v-model="authorizeFormData.license"
              show-word-limit
              type="textarea" />
            <el-tooltip placement="top-start" effect="light">
              <template #content> 支持中文、英文（区分大小写）、数字、_、/、-、.,最多不超过64个字 </template>
              <div class="tip-image"></div>
            </el-tooltip>
          </el-form-item>
          <el-form-item label="有效期至" prop="license_dead_date">
            <el-input disabled v-model="authorizeFormData.license_dead_date" maxlength="50" />
          </el-form-item>
          <el-form-item label="剩余有效期提醒" prop="license_inform_day">
            <el-input placeholder="请输入" v-model="authorizeFormData.license_inform_day" maxlength="2">
              <template #append>天</template>
            </el-input>
            <el-tooltip placement="top-start" effect="light">
              <template #content>
                范围（0~90），单位：天， 当剩余有效期在配置区间内时，系统会在用户登录系统时发出提醒，0表示不提醒
              </template>
              <div class="tip-image"></div>
            </el-tooltip>
          </el-form-item>
        </el-form>
        <!-- 安全相关表单 -->
        <el-form
          v-if="activeIndex == 2"
          ref="secureFormRef"
          :model="secureFormData"
          :rules="secureRules"
          label-width="110px"
          class="secureForm">
          <div class="passwordItem">
            <el-form-item label="最低密码强度" prop="synopsis">
              <el-select placeholder="请选择">
                <el-option label="低" value="1"> </el-option>
                <el-option label="高" value="2"> </el-option>
              </el-select>
              <el-tooltip placement="top-start" effect="light">
                <template #content> 支持中文、英文（区分大小写）、数字、_、/、-、.,最多不超过64个字 </template>
                <div class="tip-image"></div>
              </el-tooltip>
            </el-form-item>
            <el-form-item label="是否强制修改" prop="force">
              <el-switch></el-switch>
            </el-form-item>
          </div>
          <el-form-item label="密码有效期" prop="synopsis">
            <el-input placeholder="请输入" maxlength="20">
              <template #append>天</template>
            </el-input>
            <el-tooltip placement="top-start" effect="light">
              <template #content> 支持中文、英文（区分大小写）、数字、_、/、-、.,最多不超过64个字 </template>
              <div class="tip-image"></div>
            </el-tooltip>
          </el-form-item>
          <el-form-item label="会话有效期" prop="synopsis">
            <el-input placeholder="请输入" maxlength="20">
              <template #append>分钟</template>
            </el-input>
            <el-tooltip placement="top-start" effect="light">
              <template #content> 支持中文、英文（区分大小写）、数字、_、/、-、.,最多不超过64个字 </template>
              <div class="tip-image"></div>
            </el-tooltip>
          </el-form-item>
          <el-form-item label="访问规则模式" prop="synopsis">
            <el-select placeholder="请选择">
              <el-option label="关闭" value="1"> </el-option>
              <el-option label="打开" value="2"> </el-option>
            </el-select>
            <el-tooltip placement="top-start" effect="light">
              <template #content> 支持中文、英文（区分大小写）、数字、_、/、-、.,最多不超过64个字 </template>
              <div class="tip-image"></div>
            </el-tooltip>
          </el-form-item>
        </el-form>
        <!-- 登录注册配置表单 -->
        <el-form
          v-if="activeIndex == 3"
          ref="registerFormRef"
          :model="registerFormData"
          :rules="registerRules"
          label-width="125px"
          class="registerForm">
          <bg-form-gap title="登录受限配置"></bg-form-gap>
          <el-form-item label="登录受限是否启用" prop="force">
            <el-switch></el-switch>
          </el-form-item>
          <div class="input_password_config">
            <span>在</span>
            <el-form-item prop="minutes" label-width="0">
              <el-input placeholder="请输入小时数" maxlength="3"></el-input>
            </el-form-item>
            <span>小时内</span>
            <el-form-item prop="times" label-width="0">
              <el-input placeholder="请输入密码输错次数" maxlength="3"></el-input>
            </el-form-item>
            <span>次输错密码，自动锁定</span>
            <el-form-item prop="times" label-width="0">
              <el-input placeholder="请输入分钟数" maxlength="3"></el-input>
            </el-form-item>
            <span>分钟</span>
            <el-button type="primary"> 一键还原受限 </el-button>
            <el-tooltip placement="top-start" effect="light">
              <template #content> 支持中文、英文（区分大小写）、数字、_、/、-、.,最多不超过64个字 </template>
              <div class="tip-image"></div>
            </el-tooltip>
          </div>
          <bg-form-gap title="注册配置"></bg-form-gap>

          <el-form-item label="允许注册" prop="times">
            <el-radio-group>
              <el-radio label="1"> 是 </el-radio>
              <el-radio label="1"> 否 </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
        <div class="operate_btns">
          <el-button type="primary" @click="save"> 保存 </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, toRefs, onBeforeMount } from "vue";
import bgBreadcrumb from "@/components/bg-breadcrumb.vue";
import { ElMessage } from "element-plus";
import axios from "@/request/http.js";
const state = reactive({
  //授权信息表单
  authorizeFormData: {
    id: "",
    system_version: "",
    system_user: "",
    license: "",
    license_dead_date: "",
    license_inform_day: "",
  },
  //授权表单校验规则
  authorizeRules: {},

  //安全相关信息表单
  secureFormData: {},

  //安全相关表单校验规则
  secureRules: {},
  //登录注册配置表单
  registerFormData: {},
  //登录注册配置表单校验规则
  registerRules: {},
  //选中项索引
  activeIndex: 1,
  //首选项配置
  preferenceConfig: {},
});
const {
  authorizeFormData,
  authorizeRules,
  secureFormData,
  secureRules,
  registerFormData,
  registerRules,
  activeIndex,
  preferenceConfig,
} = toRefs(state);
onBeforeMount(() => {
  getPreferenceConfig();
});
//切换菜单选项
const switchMenu = (index) => {
  state.activeIndex = index;
};
//获取首选项配置
const getPreferenceConfig = () => {
  axios.get("/apaas/system/v5/sysOptions").then((res) => {
    if (res.data.code == 200) {
      state.preferenceConfig = res.data.data;
    } else {
      ElMessage.error(res.data.data);
    }
  });
};
//保存表单项
const save = () => {};
</script>

<style lang="scss" scoped>
.parent_container {
  display: flex;
  justify-content: space-between;
  height: calc(100% - 46px - 20px);
  .left_container {
    width: 240px;
    height: 100%;
    padding: 24px 16px 0;
    .el-menu {
      border: none;
      .el-menu-item {
        justify-content: center;
        height: 36px;
        color: #404a62 !important;
        &.is-active,
        &:hover {
          background-color: #f2f3f7;
          border-radius: 4px;
        }
      }
    }
  }
  .right_container {
    position: relative;
    width: calc(100% - 256px);
    height: 100%;
    padding: 32px 0 68px 24px;

    .authorizeForm,
    .secureForm,
    .registerForm {
      :deep() .el-form-item {
        margin-bottom: 24px;
        width: 750px;
        font-size: 14px;
        .el-form-item__label,
        .el-radio__label {
          color: var(--el-text-color-primary);
        }
        .el-select {
          width: 100%;
        }
        .el-input-group__append {
          width: 60px;
          color: #404a62;
          border-radius: 0 6px 6px 0;
          background: #f7f7f9;
        }
      }
    }
    .secureForm {
      .passwordItem {
        display: flex;
        align-items: center;
        .el-form-item:nth-of-type(1) {
          flex-shrink: 0;
          margin-right: 56px;
        }
      }
    }

    .registerForm {
      .input_password_config {
        position: relative;
        display: flex;
        align-items: center;
        width: 798px;
        margin-bottom: 24px;
        font-size: 14px;
        color: var(--el-text-color-primary);
        .el-form-item {
          margin: 0px 8px;
          &:nth-of-type(1),
          &:nth-of-type(3) {
            width: 120px;
          }
          &:nth-of-type(2) {
            width: 150px;
          }
        }
        .el-button {
          margin-left: 18px;
        }
      }
      .el-radio {
        margin-right: 54px;
      }
    }

    .operate_btns {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 68px;
      padding-right: 16px;
      line-height: 68px;
      text-align: right;
      border-top: solid 1px #e6e9ef;
      .el-button {
        width: 92px;
      }
    }
  }
}
</style>
