addRole.vue 4.1 KB
<template>
    <div>
        <el-dialog :title="$t('dialog.addRole')" :visible.sync="isShow" class="manage-dialog"
            :before-close="closeDialog">
            <el-form :model="addForm" status-icon :rules="rules" ref="addForm">
                <el-form-item :label="$t('table.roleName')" prop="name">
                    <el-input v-model.trim="addForm.name"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('table.englishName')" prop="enName">
                    <el-input v-model.trim="addForm.enName"></el-input>
                </el-form-item>
                <el-form-item :label="$t('table.state')" prop="stutas">
                    <el-select class="manage-sel" v-model="addForm.stutas" :placeholder="$t('pholder.state')"
                        :no-data-text="$t('pholder.nodata')">
                        <el-option :label="$t('table.stateA')" :value="1"></el-option>
                        <el-option :label="$t('table.stateB')" :value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item :label="$t('table.describe')" prop="position">
                    <el-input v-model.trim="addForm.position"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="closeDialog" class="dialog-btn">{{ $t('dialog.cancel') }}</el-button>
                <el-button type="primary" @click="addSubmit('addForm')" class="dialog-btn dialog-confirm-btn">
                    {{ $t('dialog.confirm') }}</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            isShow: false,
            addForm: {
                name: '',
                mallId: null,
                gender: null,
                age: null,
                position: ''
            },
            rules: {
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' }
                ],
            },
        }
    },
    created() {

    },
    methods: {
        dialogInit() {
            this.isShow = true;
        },
        bindRole(role_unid) {
            this.$api.management.bindRole(this.$cookie.get('user_unid'), {
                role_unid: role_unid
            })
                .then(res => {
                    this.$message({
                        showClose: true,
                        message: this.$t('message.bindSuccess'),
                        type: 'success'
                    })
                    this.$refs.addForm.resetFields();
                    this.$parent.getTableData();
                })
                .catch(error => {
                    this.$message({
                        showClose: true,
                        message: this.$t('message.bindFailed'),
                        type: 'error'
                    })
                })
        },
        addSubmit(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$api.management.addRole({
                        name: this.addForm.name
                    })
                        .then((res) => {
                            let result = res.data;
                            if (result) {
                                this.$message({
                                    showClose: true,
                                    message: this.$t('添加成功'),
                                    type: 'success'
                                })
                                this.$refs.addForm.resetFields();
                                this.$parent.getTableData();
                            }
                        })
                        .catch((error) => {

                        })
                } else {
                    return false;
                }
            });
            this.isShow = false
        },
        closeDialog() {
            this.$refs.addForm.resetFields();
            this.isShow = false;
        }
    }
}
</script>