|
@@ -1,6 +1,7 @@
|
|
|
<script type="text/x-template" id="flexiblevariant-uploaddialog-template">
|
|
<script type="text/x-template" id="flexiblevariant-uploaddialog-template">
|
|
|
<el-dialog title="Image Upload" width="660" class="flexiblevariant-uploaddialog"
|
|
<el-dialog title="Image Upload" width="660" class="flexiblevariant-uploaddialog"
|
|
|
:model-value="isShow" @update:model-value="$emit('update:isShow', $event)"
|
|
:model-value="isShow" @update:model-value="$emit('update:isShow', $event)"
|
|
|
|
|
+ @closed="closeHandler"
|
|
|
>
|
|
>
|
|
|
<div>
|
|
<div>
|
|
|
<el-upload
|
|
<el-upload
|
|
@@ -14,7 +15,7 @@
|
|
|
:on-change="uploadChange"
|
|
:on-change="uploadChange"
|
|
|
:on-exceed="uploadExceed"
|
|
:on-exceed="uploadExceed"
|
|
|
:before-upload="beforeUpload"
|
|
:before-upload="beforeUpload"
|
|
|
- action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d1"
|
|
|
|
|
|
|
+ :before-remove="beforeRemove"
|
|
|
>
|
|
>
|
|
|
|
|
|
|
|
<template #trigger>
|
|
<template #trigger>
|
|
@@ -34,7 +35,7 @@
|
|
|
<template #footer>
|
|
<template #footer>
|
|
|
<div class="dialog-footer">
|
|
<div class="dialog-footer">
|
|
|
<el-button @click="cancelHandler">Cancel</el-button>
|
|
<el-button @click="cancelHandler">Cancel</el-button>
|
|
|
- <el-button type="primary" @click="confirmHandler">Confirm</el-button>
|
|
|
|
|
|
|
+ <el-button type="primary" @click="confirmHandler">Upload</el-button>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
@@ -59,7 +60,7 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
- emits: ['update:isShow','confirm'], // 显式声明事件(推荐)
|
|
|
|
|
|
|
+ emits: ['update:isShow','confirm','cancel'], // 显式声明事件(推荐)
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
fileList: [],
|
|
fileList: [],
|
|
@@ -68,13 +69,15 @@
|
|
|
watch: {
|
|
watch: {
|
|
|
'paramData.variantImages':{
|
|
'paramData.variantImages':{
|
|
|
handler(newVal, oldVal) {
|
|
handler(newVal, oldVal) {
|
|
|
- //console.log('paramData.variantIimages -- ',newVal, oldVal);
|
|
|
|
|
|
|
+ console.log('paramData.variantIimages -- ',newVal, oldVal);
|
|
|
if(newVal.length) {
|
|
if(newVal.length) {
|
|
|
this.fileList = [{
|
|
this.fileList = [{
|
|
|
id: newVal[0].id,
|
|
id: newVal[0].id,
|
|
|
name: newVal[0].file_name,
|
|
name: newVal[0].file_name,
|
|
|
url: newVal[0].original_url
|
|
url: newVal[0].original_url
|
|
|
}];
|
|
}];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.fileList = [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
},
|
|
},
|
|
@@ -87,10 +90,28 @@
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ async beforeRemove() {
|
|
|
|
|
+ let res = await this.$confirm('This operation cannot be undone.',{
|
|
|
|
|
+ title: 'Are you sure to delete?',
|
|
|
|
|
+ showClose: false,
|
|
|
|
|
+ confirmButtonText: 'Delete',
|
|
|
|
|
+ cancelButtonText: 'Cancel',
|
|
|
|
|
+ type: 'warning',
|
|
|
|
|
+ }).then(() => true).catch(() => false);
|
|
|
|
|
+
|
|
|
|
|
+ return res;
|
|
|
|
|
+ },
|
|
|
removeImage(file,fileList) {
|
|
removeImage(file,fileList) {
|
|
|
console.log(file,fileList);
|
|
console.log(file,fileList);
|
|
|
if(file.status === 'success' && file.id) {
|
|
if(file.status === 'success' && file.id) {
|
|
|
- axios.delete(`/admin/flexible-variant/variants/${this.variant.id}/images/${file.id}`).then((result) => {
|
|
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+
|
|
|
|
|
+ this.paramData.variantIds.forEach((id) => {
|
|
|
|
|
+ formData.append('variant_ids[]', id);
|
|
|
|
|
+ });
|
|
|
|
|
+ axios.delete(`/admin/flexible-variant/images/${file.id}`,formData, {
|
|
|
|
|
+ headers: { 'Content-Type': 'multipart/form-data' }
|
|
|
|
|
+ }).then((result) => {
|
|
|
console.log(result);
|
|
console.log(result);
|
|
|
this.$message({
|
|
this.$message({
|
|
|
message: 'Delete Success',
|
|
message: 'Delete Success',
|
|
@@ -101,6 +122,7 @@
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
uploadExceed(files) {
|
|
uploadExceed(files) {
|
|
|
|
|
+ console.log('uploadExceed ---- ',files);
|
|
|
this.$refs.uploadRef.clearFiles();
|
|
this.$refs.uploadRef.clearFiles();
|
|
|
const file = files[0];
|
|
const file = files[0];
|
|
|
file.uid = this.$genFileId();
|
|
file.uid = this.$genFileId();
|
|
@@ -110,6 +132,7 @@
|
|
|
console.log(addFile.size,addFile,fileList);
|
|
console.log(addFile.size,addFile,fileList);
|
|
|
},
|
|
},
|
|
|
beforeUpload(rawFile) {
|
|
beforeUpload(rawFile) {
|
|
|
|
|
+ console.log('beforeUpload ---- ',rawFile);
|
|
|
let res = true;
|
|
let res = true;
|
|
|
if(rawFile.size > 5000000) {
|
|
if(rawFile.size > 5000000) {
|
|
|
this.$message({
|
|
this.$message({
|
|
@@ -135,24 +158,23 @@
|
|
|
}).then((result) => {
|
|
}).then((result) => {
|
|
|
console.log(result);
|
|
console.log(result);
|
|
|
/**
|
|
/**
|
|
|
- * @todo
|
|
|
|
|
* 1.更新fileList
|
|
* 1.更新fileList
|
|
|
* 2.触发confirm事件,把新的variant数据发给父组件
|
|
* 2.触发confirm事件,把新的variant数据发给父组件
|
|
|
* 3.关闭dialog
|
|
* 3.关闭dialog
|
|
|
*/
|
|
*/
|
|
|
- // this.fileList = [{
|
|
|
|
|
- // name: result.data.data.file_name,
|
|
|
|
|
- // url: result.data.data.thumb_url
|
|
|
|
|
- // }];
|
|
|
|
|
- // this.$emit('cancel', {
|
|
|
|
|
- // ...this.variant,
|
|
|
|
|
- // variant_images:[{
|
|
|
|
|
- // file_name: result.data.data.file_name,
|
|
|
|
|
- // original_url: result.data.data.url,
|
|
|
|
|
- // id: result.data.data.id,
|
|
|
|
|
- // }]
|
|
|
|
|
- // });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ this.fileList = [{
|
|
|
|
|
+ name: result.data.data.file_name,
|
|
|
|
|
+ url: result.data.data.thumb_url
|
|
|
|
|
+ }];
|
|
|
|
|
+ this.$emit('confirm', {
|
|
|
|
|
+ variantIds: this.paramData.variantIds,
|
|
|
|
|
+ variant_images:[{
|
|
|
|
|
+ file_name: result.data.data.file_name,
|
|
|
|
|
+ original_url: result.data.data.url,
|
|
|
|
|
+ id: result.data.data.id,
|
|
|
|
|
+ }]
|
|
|
|
|
+ });
|
|
|
|
|
+ this.$emit('update:isShow', false);
|
|
|
loading.close();
|
|
loading.close();
|
|
|
|
|
|
|
|
}).catch((error) => {
|
|
}).catch((error) => {
|
|
@@ -171,6 +193,9 @@
|
|
|
cancelHandler() {
|
|
cancelHandler() {
|
|
|
this.$emit('update:isShow', false);
|
|
this.$emit('update:isShow', false);
|
|
|
this.$emit('cancel', {});
|
|
this.$emit('cancel', {});
|
|
|
|
|
+ },
|
|
|
|
|
+ closeHandler() {
|
|
|
|
|
+ this.fileList = [];
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|