<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('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('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';

export default {
    mixins: [WraperMixins],
    data() {
        return {
            form: {},
            rules: {
                paramModule: [{ required: true, message: this.$t('paramter.moduleParametersError') }],
                paramCode: [{ required: true, message: this.$t('paramter.parameterCodingError') }],
                paramValue: [{ required: true, message: this.$t('paramter.paramValueError') }],
            },
        };
    },
    computed: {
        isEdit() {
            return this.type === 'edit';
        },
    },
    mounted() {
        if (this.type) {
            this.form = { ...this.row };
        }
    },
    methods: {
        async submit() {
            await this.$refs.form.validate();
            return this.isEdit ? Api.updateOperation({ ...this.form }) : Api.addOperation({ ...this.form });
        },
    },
};
</script>
