<template>
    <Wraper :hidden="hidden" :refresh="refresh" :onOk="submit">
        <a-form-model layout="vertical" :model="form" :rules="rules" ref="form">
            <a-form-model-item :label="$t('language')" prop="paramLocale">
                <Language v-model="form.paramLocale" />
            </a-form-model-item>
            <a-form-model-item :label="$t('paramter.moduleParameters')" prop="paramModule">
                <a-input v-model="form.paramModule" :placeholder="$t('input.placeholder')" />
            </a-form-model-item>
            <a-form-model-item :label="$t('paramter.parameterCoding')" prop="paramCode">
                <a-input v-model="form.paramCode" :placeholder="$t('input.placeholder')" />
            </a-form-model-item>
            <a-form-model-item :label="$t('paramter.paramValue')" prop="paramValue">
                <a-input v-model="form.paramValue" :placeholder="$t('input.placeholder')" />
            </a-form-model-item>
            <a-form-model-item :label="$t('business.parameterName')" prop="paramName">
                <a-input v-model="form.paramName" :placeholder="$t('input.placeholder')" />
            </a-form-model-item>
            <a-form-model-item :label="$t('order')" prop="paramIndex">
                <a-input v-model="form.paramIndex" :placeholder="$t('input.placeholder')" />
            </a-form-model-item>
            <a-form-model-item :label="$t('table.remark')" prop="remark">
                <a-textarea v-model="form.remark" :rows="4" :placeholder="$t('input.placeholder')" />
            </a-form-model-item>
        </a-form-model>
    </Wraper>
</template>

<script>
import Api from '@/api/organization';
import { WraperMixins } from '@/components/table';
import Language from './components/language.vue';

export default {
    mixins: [WraperMixins],
    components: { Language },
    data() {
        return {
            form: {},
            rules: {
                paramLocale: [{ required: true, message: this.$t('languageInputError') }],
                paramModule: [{ required: true, message: this.$t('paramter.moduleParametersError') }],
                paramCode: [{ required: true, message: this.$t('paramter.parameterCodingError') }],
                paramValue: [{ required: true, message: this.$t('paramter.paramValueError') }],
                paramName: [{ required: true, message: this.$t('business.parameterNameError') }],
                paramIndex: [{ required: true, message: this.$t('orderInputError') }],
            },
        };
    },
    computed: {
        isEdit() {
            return this.type === 'eidt';
        },
    },

    mounted() {
        if (this.type) {
            this.form = { ...this.row };
        }
    },

    methods: {
        async submit() {
            await this.$refs.form.validate();
            return this.isEdit ? Api.updateBusiness({ ...this.form }) : Api.addBusiness({ ...this.form });
        },
    },
};
</script>
