<template>
    <!-- 对话框表单 -->
    <el-dialog
        custom-class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="baTable.form.operate ? true : false"
        @close="baTable.toggleForm"
        width="400px"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? baTable.form.operate == 'edit' ? '编辑' : '添加' : '无标题' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" >
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"

            >
                <el-form
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    label-width="100px"
                    :rules="rules"
                    v-if="!baTable.form.loading"
                >
                    <el-form-item prop="nickName" label="用户名">
                        <el-input v-model="baTable.form.items!.nickName" placeholder="请输入用户名"></el-input>
                    </el-form-item>
                    <el-form-item prop="account" label="账号">
                        <el-input v-model="baTable.form.items!.account" placeholder="请输入账号"></el-input>
                    </el-form-item>
                    <el-form-item prop="password" label="密码">
                        <el-input v-model="baTable.form.items!.password" placeholder="请输入密码"></el-input>
                    </el-form-item>
                    <el-form-item prop="status" label="状态">
                        <el-select v-model="baTable.form.items!.status" placeholder="请选择状态"
                                   style="width: 100%"
                                   >
                            <el-option label="启用" value="0"/>
                            <el-option label="停用" value="1"/>
                        </el-select>
                    </el-form-item>
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">取消</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)"
                           type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? '保存并编辑下一项' : '保存' }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import {ref, reactive, inject, onMounted, watch} from 'vue'

import type baTableClass from '/@/utils/baTable'
import {regularPassword, validatorAccount, validatorMobile} from '/@/utils/validate'
import type {ElForm, FormItemRule} from 'element-plus'
import FormItem from '/@/components/formItem/index.vue'
import {getOrgTree, getEmployees} from '/@/api/backend/auth/account'
import {authGroup, sysConfig} from '/@/api/controllerUrls'
import editor from '/@/components/editor/index.vue'
import request from "/@/api/request";
import {ElNotification} from "element-plus/es";
import {document} from '/@/api/controllerUrls'
import pictureUpload from '/@/components/pictureUpload/index.vue'

const formRef = ref<InstanceType<typeof ElForm>>()
const baTable = inject('baTable') as baTableClass


const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    account: [
        {
            required: true,
            message: '请输入',
            trigger: 'blur',
        },
    ],
    password: [
        {
            required: true,
            message: '请输入',
            trigger: 'blur',
        },
    ],
    nickName: [
        {
            required: true,
            message: '请输入',
            trigger: 'blur',
        },
    ],
    status: [
        {
            required: true,
            message: '请选择',
            trigger: 'blur',
        },
    ],

})


</script>

<style scoped lang="scss">
.avatar-uploader {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: var(--el-border-radius-small);
    box-shadow: var(--el-box-shadow-light);
    border: 1px dashed var(--color-sub-1);
    cursor: pointer;
    overflow: hidden;
    width: 110px;
    height: 110px;
}

.avatar-uploader:hover {
    border-color: var(--color-primary);
}

.avatar {
    width: 110px;
    height: 110px;
    display: block;
}

.image-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}
</style>
