<template> <el-dialog :title="dialogObj.title" :visible.sync="dialogObj.show"> <el-form> <el-form-item label="名称" label-width="100px"> <el-input v-model="form.name"></el-input> </el-form-item> <el-form-item label="英文名称" v-if="dialogObj.list == 'list2'" label-width="100px"> <el-input v-model="form.english_name"></el-input> </el-form-item> <el-form-item label="封面" label-width="100px"> <el-upload class="upload-demo" :on-remove="handleRemove" action="/api/public/upload" :http-request="uploadFile" list-type="picture-card" multiple :limit="1" :file-list="imgList"> </el-upload> </el-form-item> <el-form-item label="课时英文名称" v-if="dialogObj.list == 'list3'" label-width="100px"> <el-input v-model="form.english_name"></el-input> </el-form-item> <el-form-item label="课时封面" v-if="dialogObj.list == 'list3'" label-width="100px"> <el-upload class="upload-demo" :on-remove="handleRemove1" action="/api/public/upload" :http-request="uploadFile1" list-type="picture-card" multiple :limit="1" :file-list="imgList1"> </el-upload> </el-form-item> </el-form> <span slot="footer" class="dialog-footer"> <el-button @click="dialogObj.show = false">取 消</el-button> <el-button type="primary" @click="onSave()">确 定</el-button> </span> </el-dialog> </template> <script> import {getCategoryApi,addCategoryApi,updateMenuApi,uploadFileApi} from "../../service/api"; export default { name: "menuDialog", data(){ return { imgList:[], imgList1:[], form:{ name:'', pid:'', cover:'', type:0, english_name: '', sub_cover: '' } } }, methods:{ initDialog(){ switch (this.dialogObj.type) { case 0: this.form = { name:'', pid:this.dialogObj.pid, cover:'', type:0, english_name: '', sub_cover: '' }; this.imgList = []; this.imgList1 = []; break; case 1: this.form = { name:this.dialogObj.that.name, pid:this.dialogObj.that.pid, cover:this.dialogObj.that.cover, type:0, english_name: this.dialogObj.that.english_name, sub_cover:this.dialogObj.that.sub_cover }; this.imgList = []; this.imgList1 = []; if(this.form.cover){ this.imgList.push({name:this.dialogObj.that.cover,url:this.dialogObj.that.cover,title:'',lable:''}) } if(this.form.sub_cover){ this.imgList1.push({name:this.dialogObj.that.sub_cover,url:this.dialogObj.that.sub_cover,title:'',lable:''}) } } }, handleRemove(){ this.imgList = []; this.form.cover = ''; }, handleRemove1(){ this.imgList1 = []; this.form.sub_cover = ''; }, onSave(){ if(this.imgList[0]){ this.form.cover = this.imgList[0].url; }else{ this.form.cover = ''; } if(this.imgList1[0]){ this.form.sub_cover = this.imgList1[0].url; }else{ this.form.sub_cover = ''; } switch (this.dialogObj.type) { case 0: addCategoryApi(this.form).then(res=>{ this.$message({ type: 'success', message: '添加成功!' }); this.dialogObj.show = false; this.$emit('reflash') }); break; case 1: updateMenuApi(this.dialogObj.category_id,this.form).then(res=>{ this.$message({ type: 'success', message: '修改成功!' }); this.dialogObj.show = false; this.$emit('reflash') }) } }, uploadFile(a){ this.$store.dispatch('setProgress',{type:'new',id:a.file.uid}); uploadFileApi({file:a.file,type:'local'}).then(res=>{ this.imgList[0]= {name:res.url,url:process.env.IMAGE_URL_HEAD + res.url,title:'',lable:''} }) }, uploadFile1(a){ this.$store.dispatch('setProgress',{type:'new',id:a.file.uid}); uploadFileApi({file:a.file,type:'local'}).then(res=>{ this.imgList1[0]= {name:res.url,url:process.env.IMAGE_URL_HEAD + res.url,title:'',lable:''} }) } }, props:[ 'dialogObj' ], watch:{ 'dialogObj'(){ this.initDialog() } } } </script> <style scoped> </style>