<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :model-value="baTable.form.operate ? true : false"
        @close="baTable.toggleForm"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    ref="formRef"
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                    v-if="!baTable.form.loading"
                >
                    <el-form-item prop="username" :label="t('user.identity.User name')">
                        <el-input
                            v-model="baTable.form.items!.username"
                            type="string"
                            disabled
                        ></el-input>
                    </el-form-item>

                    <el-form-item prop="real_name" :label="t('user.identity.real_name')">
                        <el-input
                            v-model="baTable.form.items!.real_name"
                            type="string"
                            disabled
                        ></el-input>
                    </el-form-item>
                    <el-form-item prop="identity" :label="t('user.identity.Identity No')">
                        <el-input
                            v-model="baTable.form.items!.identity"
                            type="string"
                            disabled
                        ></el-input>
                    </el-form-item>
                    <!--<FormItem-->
                    <!--    :label="t('user.identity.identity_img')" v-model="baTable.form.items!.identity_img"-->
                    <!--    type="image" prop="identity_img"-->
                    <!--/>-->
                    <FormItem
                        :label="t('user.identity.Real name authentication')"
                        v-model="baTable.form.items!.real_name_status"
                        type="select"
                        :data="{
                            content: { 0: t('user.identity.unchecked'), 1: t('user.identity.verified'), 2: t('user.identity.identity_refuse') },
                            childrenAttr: { border: true },
                        }"
                    />

                    <FormItem
                        type="remoteSelect"
                        :label="t('user.identity.grouping')"
                        v-model="baTable.form.items!.group_id"
                        :placeholder="t('user.identity.grouping')"
                        :input-attr="{
                            params: { isTree: true, search: [{ field: 'status', val: '1', operator: '=' }] },
                            field: 'name',
                            'remote-url': userGroup + 'index',
                        }"
                    />
                    <FormItem
                        :label="t('user.identity.certification')"
                        v-model="baTable.form.items!.certified"
                        type="select"
                        :data="{
                            content: { 0: t('user.identity.unchecked'), 1: t('user.identity.verified'), 2: t('user.identity.refuse') },
                            childrenAttr: { border: true },
                        }"
                    />
                    <el-form-item prop="mobile" :label="t('user.identity.mobile')">
                        <el-input
                            v-model="baTable.form.items!.mobile"
                            type="string"
                            disabled

                        ></el-input>
                    </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('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)"
                           type="primary">
                    {{
                        baTable.form.operateIds && baTable.form.operateIds.length > 1
                            ? t('Save and edit next item')
                            : t('Save')
                    }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { ElForm } from 'element-plus'
import { userGroup } from '/@/api/controllerUrls'

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

const { t } = useI18n()

</script>

<style scoped lang="scss"></style>
