addDesk.vue 3.12 KB
<template>
    <div>
        <el-dialog :title="isEdit?'编辑货架':'新增货架'" class="manage-dialog" :visible.sync="addDialogVisible"
            :close-on-click-modal="false" @close="addDialogClose()">
            <el-form :model="addForm" status-icon :rules="rules" ref="addForm">
                <!-- 区域名称 -->
                <el-form-item :label="$t('货架名称')" prop="name">
                    <el-input v-model.trim="addForm.name"></el-input>
                    <i class="error-tip">*</i>
                </el-form-item>
                <el-form-item :label="$t('出入口')" prop="name">
                    <el-switch v-model="addForm.doorway"></el-switch>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addDialogVisible = false" 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() {
        var checkName = (rule, value, callback) => {
            //var flag = new RegExp("[`’\"·_ ~!%\\-@#$^&*=|{}':;',\\[\\].<>《》/?~!@#¥……&*——|{}【】‘;:”“'。,、? ]");
            var flag = new RegExp("'");
            if (flag.test(value) || /\\/.test(value)) {
                callback(new Error("名称包含特殊字符,请重新输入!"));
            } else {
                callback();
            }
        }
        return {
            addDialogVisible: false,
            addForm: {
                name: '',
                doorway:0
            },
            isEdit:false,
            rules: {
                name: [{
                    required: true,
                    message: '请输入货架名称',
                    trigger: 'blur'
                },{
                    validator: checkName,
                    trigger: "blur"
                }]
            }
        }
    },
    created() {
        // zoneTypeList
    },
    methods: {
        dialogInit(data) {
            this.addForm = {};
            if(data){
                this.isEdit = true;
                this.addForm = Object.assign({},data,{doorway:data.doorway==1?true:false});
                this.deskObj = data;
            }else{
                this.isEdit = false
            }
            this.addDialogVisible = true;
        },
        addSubmit(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                     this.$emit('submit',this.addForm)
                } else {
                    return false;
                }
            });
        },
        addDialogClose() {
            this.addDialogVisible = false;
            this.$refs.addForm.resetFields();
        },
    }
}
</script>

<style scoped>
.bdmap-btn {
    margin-left: 17px;
    padding: 0 8px;
    height: 30px;
    box-sizing: border-box;
    border-radius: 2px;
    font-size: 13px;
}

.unit-input {
    width: 100%;
}
</style>