|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<el-dialog
|
|
|
- title="添加分类"
|
|
|
+ :title="title"
|
|
|
:visible.sync="dialogShow"
|
|
|
width="800px"
|
|
|
:before-close="close"
|
|
@@ -25,11 +25,8 @@
|
|
|
</el-form-item>
|
|
|
<el-form-item label="分类图片" prop="picUrl">
|
|
|
<image-upload
|
|
|
+ v-model="categoryPicUrl"
|
|
|
:limit="1"
|
|
|
- :value="form.picUrl"
|
|
|
- :file-size="50"
|
|
|
- :is-public="true"
|
|
|
- @input="pictureSelect"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="是否显示" prop="isShow">
|
|
@@ -52,7 +49,7 @@
|
|
|
</template>
|
|
|
<script>
|
|
|
import CustomFieldsMixin from "@/mixins/CustomFields";
|
|
|
-import { goodsCategoryCreate } from "@/api/business/category";
|
|
|
+import { goodsCategoryCreate, goodsCategoryDetail, goodsCategoryUpdate } from "@/api/business/category";
|
|
|
export default {
|
|
|
mixins: [CustomFieldsMixin],
|
|
|
props: {
|
|
@@ -61,15 +58,16 @@ export default {
|
|
|
type: Boolean,
|
|
|
default: false,
|
|
|
},
|
|
|
- },
|
|
|
- created() {
|
|
|
-
|
|
|
+ // 分类ID
|
|
|
+ categoryId: {
|
|
|
+ type: [String, Number],
|
|
|
+ default: null
|
|
|
+ }
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
loading: false,
|
|
|
form: {
|
|
|
- picUrl: [],
|
|
|
isShow: 1,
|
|
|
sort: 0
|
|
|
},
|
|
@@ -79,7 +77,6 @@ export default {
|
|
|
],
|
|
|
picUrl: [
|
|
|
{
|
|
|
- type: "array",
|
|
|
required: true,
|
|
|
message: "请上传分类图片",
|
|
|
trigger: "change",
|
|
@@ -99,17 +96,34 @@ export default {
|
|
|
},
|
|
|
};
|
|
|
},
|
|
|
- methods: {
|
|
|
-
|
|
|
- changeType(){
|
|
|
- this.$refs["form"].clearValidate();
|
|
|
- },
|
|
|
-
|
|
|
- // 添加图片
|
|
|
- pictureSelect(data) {
|
|
|
- this.form.picUrl = data;
|
|
|
+ computed: {
|
|
|
+ title() {
|
|
|
+ return this.categoryId ? '编辑分类' : '添加分类';
|
|
|
},
|
|
|
-
|
|
|
+ categoryPicUrl: {
|
|
|
+ get() {
|
|
|
+ return this.form.picUrl ? this.form.picUrl.split(',').map(item => {
|
|
|
+ return {
|
|
|
+ fileName: item
|
|
|
+ }
|
|
|
+ }) : []
|
|
|
+ },
|
|
|
+ set(val) {
|
|
|
+ this.$set(this.form, 'picUrl', val.map(item => { return item.fileName }).toString())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ if(this.categoryId){
|
|
|
+ goodsCategoryDetail({ categoryId: this.categoryId }).then(res => {
|
|
|
+ const { name, sort, picUrl, isShow } = res && res.data
|
|
|
+ this.form = {
|
|
|
+ name, sort, picUrl, isShow
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
// 关闭弹框
|
|
|
close() {
|
|
|
this.$emit("close");
|
|
@@ -135,14 +149,14 @@ export default {
|
|
|
|
|
|
// 提交
|
|
|
submitForm(form) {
|
|
|
- let data = {
|
|
|
- ... form,
|
|
|
- picUrl: this.form.picUrl[0].fileName,
|
|
|
- };
|
|
|
- goodsCategoryCreate(data)
|
|
|
+ let request = this.categoryId ? goodsCategoryUpdate : goodsCategoryCreate
|
|
|
+ if(this.categoryId){
|
|
|
+ form.categoryId = this.categoryId
|
|
|
+ }
|
|
|
+ request(form)
|
|
|
.then((res) => {
|
|
|
if (res.code == 0) {
|
|
|
- this.msgSuccess("添加成功");
|
|
|
+ this.msgSuccess(this.categoryId ? "修改成功" : '添加成功');
|
|
|
this.close();
|
|
|
}
|
|
|
})
|