You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
6.3 KiB

3 years ago
<template>
<div class="main-content">
<div class="form-area">
<el-form size="default" :model="form" label-width="120px">
<el-form-item label="分组" style="width: 80%">
3 years ago
<el-select v-model="form.groupId" placeholder="请选择">
<el-option :value="0" label="不分组"></el-option>
3 years ago
<el-option v-for="(item) in groupData" :key="item.id" :value="item.id" :label="item.name"></el-option>
3 years ago
</el-select>
</el-form-item>
<el-form-item label="车系" style="width: 80%">
3 years ago
<div>
<el-checkbox-group v-model="form.brandList">
<el-checkbox v-for="(item,index) in brandData" :key="index" :label="item.id">
{{item.name}}
</el-checkbox>
</el-checkbox-group>
</div>
</el-form-item>
<el-form-item label="类型" style="width: 80%">
<el-select v-model="form.type" placeholder="请选择">
<el-option :value="1" label="视频"></el-option>
<el-option :value="2" label="图片"></el-option>
<el-option :value="3" label="文字"></el-option>
3 years ago
</el-select>
</el-form-item>
3 years ago
<el-form-item label="视频封面" style="width: 80%" v-if="form.type == 1">
3 years ago
<uploadFile @change="coverUpload" isCompress :config="{ limit: 1, accept: '.jpg, .jpeg, .png, .gif,'}">
3 years ago
<el-icon v-if="form.coverUrl == ''" class="img-upload"><Plus /></el-icon>
<img v-else class="img-upload" :src="$ImgUrl(form.coverUrl)" />
</uploadFile>
</el-form-item>
3 years ago
<el-form-item label="标签" style="width: 80%">
3 years ago
<el-checkbox-group v-model="form.tagList">
<el-checkbox v-for="(item,index) in tagData" :key="index" :label="item.id">
{{item.title}}
</el-checkbox>
</el-checkbox-group>
3 years ago
</el-form-item>
<el-form-item label="素材描述" style="width: 80%">
3 years ago
<el-input type="textarea" v-model="form.title" />
3 years ago
</el-form-item>
<el-form-item label="素材内容" style="width: 100%">
3 years ago
<uploadFile @change="handlerUpload" isCompress :config="{ limit: 10, accept: '.jpg, .jpeg, .png, .gif, .mp4'}">
3 years ago
<el-button>上传文件</el-button>
3 years ago
</uploadFile>
3 years ago
<el-link v-for="(item,index) in form.fileUrlList" :key="index" :href="$ImgUrl(item)" target="_blank">
3 years ago
{{item.url}}
3 years ago
</el-link>
3 years ago
</el-form-item>
<el-form-item>
<el-button type="primary" @click="confirm"></el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
3 years ago
import {defineComponent,reactive,ref,getCurrentInstance} from 'vue'
3 years ago
export default defineComponent({
name: 'v-matUpload',
setup() {
const activeId = reactive({
value: 0
});
const form = reactive({
3 years ago
groupId: 0,
title: '',
3 years ago
type: undefined,
3 years ago
tagList: [],
brandList: [],
3 years ago
coverUrl: '',
3 years ago
fileUrlList: [],
3 years ago
});
3 years ago
const tagData = ref([]);
const brandData = ref([]);
3 years ago
const groupData = ref([]);
3 years ago
const { proxy } = getCurrentInstance();
3 years ago
return {
3 years ago
form,proxy,
3 years ago
tagData,brandData,groupData,
3 years ago
activeId
}
},
3 years ago
activated() {
this.getApi();
},
3 years ago
mounted() {
this.getApi()
},
3 years ago
methods: {
3 years ago
getApi() {
this.proxy.$post("/tag/list", {}).then(res => {
this.tagData = res.data.records;
}).catch(() => {});
this.proxy.$post("/brand/list", {}).then(res => {
this.brandData = res.data.records;
}).catch(() => {});
3 years ago
this.proxy.$post("/referenceGroup/list", {}).then(res => {
this.groupData = res.data.records;
}).catch(() => {});
3 years ago
if(this.$route.params.id) {
this.proxy.$post("/reference/detail", {id: this.$route.params.id}).then(res => {
this.form.groupId = res.data.groupId;
this.form.type = res.data.type;
this.form.title = res.data.title;
3 years ago
res.data.brandList.forEach(ele => {this.form.brandList.push(ele.id)});
res.data.tagList.forEach(ele => {this.form.tagList.push(ele.id)});
3 years ago
this.form.fileUrlList = res.data.fileUrlList;
3 years ago
this.form.coverUrl = res.data.coverUrl;
3 years ago
}).catch(() => {});
}
3 years ago
},
3 years ago
confirm() {
3 years ago
if(this.$route.params.id) {
let obj = Object.assign(this.form, {id: this.$route.params.id})
this.proxy.$post("/reference/upd", obj).then(res => {
3 years ago
this.$message.success(res.data);
this.form.fileUrlList = [];
3 years ago
this.$router.go(-1);
}).catch(() => {});
} else {
this.proxy.$post("/reference/add", this.form).then(res => {
3 years ago
this.$message.success(res.data);
this.form.fileUrlList = [];
3 years ago
this.$router.go(-1);
}).catch(() => {});
}
3 years ago
},
//素材上传
3 years ago
handlerUpload(data) {
3 years ago
if(data.fileUrl != null) {
3 years ago
let obj = {
duration: data.duration,
3 years ago
url: data.fileUrl,
fileUrlSmall: data.fileUrlSmall
3 years ago
}
this.form.fileUrlList.push(obj)
3 years ago
}
3 years ago
},
coverUpload(data) {
this.form.coverUrl = data.fileUrl
3 years ago
}
}
})
</script>
<style lang="less">
.form-area {
width: 600px
}
3 years ago
.img-upload {
font-size: 28px;
color: #8c939d;
width: 135px;
height: 135px;
text-align: center;
border: 1px solid;
}
3 years ago
</style>