towMobile.vue 4.47 KB
<template>
    <el-dialog :title="title" :visible.sync="open" v-if="open" width="600px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="130px">
            <el-form-item label="二级分类代码" prop="twoClass">
                <el-input v-model="form.twoClass" placeholder="请输入二级分类代码" :disabled='disabled' />
            </el-form-item>
            <el-form-item label="二级分类名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入二级分类名称" :disabled='disabled' />
            </el-form-item>
            <el-form-item label="所属一级分类名称" prop="targetOneId">
                <el-select v-model="form.targetOneId" placeholder="所属一级分类名称" clearable size="small">
                    <el-option v-for="(item,index) in targetOneList" :key="index" :label="item.name" :value="item.id" />
                </el-select>
            </el-form-item>
            <el-form-item label="备注" prop="note">
                <el-input v-model="form.note" type="textarea" placeholder="请输入备注" :disabled='disabled' />
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { targetTwoSave, targetTwoEdit, targetOneList } from "@/api/postList/list";
export default {
    name: 'indexMobile',
    dicts: ['index_mobile_type', 'index_type_list'],
    data() {
        return {
            imageUrl: '',
            disabled: true,
            open: false,
            // 弹出层标题
            title: "",
            // 表单参数
            form: {
            },
            checkList: [],
            targetOneList:[],
            // 表单校验
            rules: {
                twoClass: [
                    { required: true, message: "二级分类代码不能为空", trigger: "blur" }
                ],
                name: [
                    { required: true, message: "二级分类名称不能为空", trigger: "blur" }
                ],
                targetOneId:[
                    { required: true, message: "一级分类名称不能为空", trigger: "blur" }
                ]
            },
            id: ''
        }
    },
    methods: {
        // 取消按钮
        cancel() {
            this.open = false;
            this.form = {}
        },
        add() {
            this.open = true;
            this.form = {}
            this.id = ''
            this.getTargetOneList()
        },
        edit(res) {
            this.open = true;
            this.form = res
            this.id = res.id
            this.getTargetOneList()
        },
        getTargetOneList() {
            targetOneList().then(response => {
                if (response.code == 200) {
                    this.targetOneList = response.data
                } else {
                   
                }
            });
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                this.form.id = this.id
                if (valid) {
                    if (this.id) {
                        targetTwoEdit(this.form).then(response => {
                            if (response.code == 200) {
                                this.$modal.msgSuccess(response.msg);
                                this.open = false;
                                this.$emit("getList")
                            } else {
                                this.$modal.msgSuccess(response.msg);
                                this.open = false;
                            }
                        });
                    } else {
                        targetTwoSave(this.form).then(response => {
                            if (response.code == 200) {
                                this.$modal.msgSuccess(response.msg);
                                this.open = false;
                                this.$emit("getList")
                            } else {
                                this.$modal.msgSuccess(response.msg);
                                this.open = false;
                            }
                        });
                    }
                }
            });
        },
    }
}
</script>

<style>
.new_dialog {
    height: 80%;
    overflow: hidden;
    overflow-y: scroll;
}
</style>