<template>
    <!-- 对话框表单 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['add', 'edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="50%"
    >
        <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
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @submit.prevent=""
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                >
                    <FormItem :label="t('xuqiuOrder.需求订单编号')" type="string" v-model="baTable.form.items!.需求订单编号" prop="需求订单编号" :placeholder="t('Please input field', { field: t('xuqiuOrder.需求订单编号') })" />
                    <FormItem :label="t('xuqiuOrder.活动城市')" type="string" v-model="baTable.form.items!.活动城市" prop="活动城市" :placeholder="t('Please input field', { field: t('xuqiuOrder.活动城市') })" />
                    <FormItem :label="t('xuqiuOrder.需求项目')" type="string" v-model="baTable.form.items!.需求项目" prop="需求项目" :placeholder="t('Please input field', { field: t('xuqiuOrder.需求项目') })" />
                    <FormItem :label="t('xuqiuOrder.活动人数')" type="string" v-model="baTable.form.items!.活动人数" prop="活动人数" :placeholder="t('Please input field', { field: t('xuqiuOrder.活动人数') })" />
                    <FormItem :label="t('xuqiuOrder.活动需求')" type="string" v-model="baTable.form.items!.活动需求" prop="活动需求" :placeholder="t('Please input field', { field: t('xuqiuOrder.活动需求') })" />
                    <FormItem :label="t('xuqiuOrder.活动时间')" type="string" v-model="baTable.form.items!.活动时间" prop="活动时间" :placeholder="t('Please input field', { field: t('xuqiuOrder.活动时间') })" />
                    <FormItem :label="t('xuqiuOrder.活动总天数')" type="number" prop="活动总天数" :input-attr="{ step: 1 }" v-model.number="baTable.form.items!.活动总天数" :placeholder="t('Please input field', { field: t('xuqiuOrder.活动总天数') })" />
                    <FormItem :label="t('xuqiuOrder.咨询截止时间')" type="datetime" v-model="baTable.form.items!.咨询截止时间" prop="咨询截止时间" :placeholder="t('Please select field', { field: t('xuqiuOrder.咨询截止时间') })" />
                    <FormItem :label="t('xuqiuOrder.状态')" type="string" v-model="baTable.form.items!.状态" prop="状态" :placeholder="t('Please input field', { field: t('xuqiuOrder.状态') })" />
                    <FormItem :label="t('xuqiuOrder.需求公司')" type="string" v-model="baTable.form.items!.需求公司" prop="需求公司" :placeholder="t('Please input field', { field: t('xuqiuOrder.需求公司') })" />
                    <FormItem :label="t('xuqiuOrder.联系电话')" type="string" v-model="baTable.form.items!.联系电话" prop="联系电话" :placeholder="t('Please input field', { field: t('xuqiuOrder.联系电话') })" />
                    <FormItem :label="t('xuqiuOrder.创建人')" type="string" v-model="baTable.form.items!.创建人" prop="创建人" :placeholder="t('Please input field', { field: t('xuqiuOrder.创建人') })" />
                    <FormItem :label="t('xuqiuOrder.创建时间')" type="datetime" v-model="baTable.form.items!.创建时间" prop="创建时间" :placeholder="t('Please select field', { field: t('xuqiuOrder.创建时间') })" />
                    <FormItem :label="t('xuqiuOrder.更新时间')" type="datetime" v-model="baTable.form.items!.更新时间" prop="更新时间" :placeholder="t('Please select field', { field: t('xuqiuOrder.更新时间') })" />
                </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 { reactive, 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, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'

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

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    需求订单编号: [buildValidatorData({ name: 'required', title: t('xuqiuOrder.需求订单编号') })],
    活动总天数: [buildValidatorData({ name: 'number', title: t('xuqiuOrder.活动总天数') })],
    咨询截止时间: [buildValidatorData({ name: 'date', title: t('xuqiuOrder.咨询截止时间') })],
    创建时间: [buildValidatorData({ name: 'date', title: t('xuqiuOrder.创建时间') })],
    更新时间: [buildValidatorData({ name: 'date', title: t('xuqiuOrder.更新时间') })],
})
</script>

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