|
@@ -10,6 +10,7 @@
|
|
|
:http-request="submitUpload"
|
|
:http-request="submitUpload"
|
|
|
list-type="picture"
|
|
list-type="picture"
|
|
|
:limit="1"
|
|
:limit="1"
|
|
|
|
|
+ :on-remove="removeImage"
|
|
|
:on-change="uploadChange"
|
|
:on-change="uploadChange"
|
|
|
:on-exceed="uploadExceed"
|
|
:on-exceed="uploadExceed"
|
|
|
:before-upload="beforeUpload"
|
|
:before-upload="beforeUpload"
|
|
@@ -21,8 +22,8 @@
|
|
|
</template>
|
|
</template>
|
|
|
<template #tip>
|
|
<template #tip>
|
|
|
<div class="el-upload__tip">
|
|
<div class="el-upload__tip">
|
|
|
- <p>Image files with a size less than 500kb.</p>
|
|
|
|
|
- <p>Only one image is allowed to be uploaded.</p>
|
|
|
|
|
|
|
+ <p class="text-xs">Image files with a size less than 500kb.</p>
|
|
|
|
|
+ <p class="text-xs">Only one image is allowed to be uploaded.</p>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
@@ -46,7 +47,7 @@
|
|
|
|
|
|
|
|
props: {
|
|
props: {
|
|
|
|
|
|
|
|
- variant: {
|
|
|
|
|
|
|
+ paramData: {
|
|
|
type: Object,
|
|
type: Object,
|
|
|
default: function() {
|
|
default: function() {
|
|
|
return {};
|
|
return {};
|
|
@@ -62,24 +63,20 @@
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
fileList: [],
|
|
fileList: [],
|
|
|
- form: {
|
|
|
|
|
- sku: '',
|
|
|
|
|
- name: '',
|
|
|
|
|
- price: 0,
|
|
|
|
|
- weight: 0,
|
|
|
|
|
- quantity: 0,
|
|
|
|
|
- // status: false,
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
watch: {
|
|
watch: {
|
|
|
- 'variant.images':{
|
|
|
|
|
|
|
+ 'paramData.variantImages':{
|
|
|
handler(newVal, oldVal) {
|
|
handler(newVal, oldVal) {
|
|
|
- this.fileList = [];
|
|
|
|
|
- console.log(newVal);
|
|
|
|
|
|
|
+ //console.log('paramData.variantIimages -- ',newVal, oldVal);
|
|
|
|
|
+ if(newVal.length) {
|
|
|
|
|
+ this.fileList = [{
|
|
|
|
|
+ id: newVal[0].id,
|
|
|
|
|
+ name: newVal[0].file_name,
|
|
|
|
|
+ url: newVal[0].original_url
|
|
|
|
|
+ }];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -90,23 +87,18 @@
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
|
-
|
|
|
|
|
- getVariant(id) {
|
|
|
|
|
- let loading = this.$loading({
|
|
|
|
|
- target: '.flexiblevariant-eidtdialog'
|
|
|
|
|
- });
|
|
|
|
|
- axios.get(`/admin/flexible-variant/variants/${id}`).then((result) => {
|
|
|
|
|
- console.log(result);
|
|
|
|
|
|
|
+ removeImage(file,fileList) {
|
|
|
|
|
+ console.log(file,fileList);
|
|
|
|
|
+ if(file.status === 'success' && file.id) {
|
|
|
|
|
+ axios.delete(`/admin/flexible-variant/variants/${this.variant.id}/images/${file.id}`).then((result) => {
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
+ this.$message({
|
|
|
|
|
+ message: 'Delete Success',
|
|
|
|
|
+ type: 'success'
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- this.form = result.data.data;
|
|
|
|
|
- loading.close();
|
|
|
|
|
- }).catch((error) => {
|
|
|
|
|
- this.$message({
|
|
|
|
|
- message: error.message,
|
|
|
|
|
- type: 'error'
|
|
|
|
|
- });
|
|
|
|
|
- loading.close();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
uploadExceed(files) {
|
|
uploadExceed(files) {
|
|
|
this.$refs.uploadRef.clearFiles();
|
|
this.$refs.uploadRef.clearFiles();
|
|
@@ -135,13 +127,34 @@
|
|
|
});
|
|
});
|
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
|
formData.append('file', option.file);
|
|
formData.append('file', option.file);
|
|
|
- axios.post(`/admin/flexible-variant/variants/${this.variant.id}/images/upload`, formData, {
|
|
|
|
|
|
|
+ this.paramData.variantIds.forEach((id) => {
|
|
|
|
|
+ formData.append('variant_ids[]', id);
|
|
|
|
|
+ });
|
|
|
|
|
+ axios.post(`/admin/flexible-variant/variants/images`, formData, {
|
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
|
}).then((result) => {
|
|
}).then((result) => {
|
|
|
console.log(result);
|
|
console.log(result);
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @todo
|
|
|
|
|
+ * 1.更新fileList
|
|
|
|
|
+ * 2.触发confirm事件,把新的variant数据发给父组件
|
|
|
|
|
+ * 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,
|
|
|
|
|
+ // }]
|
|
|
|
|
+ // });
|
|
|
|
|
|
|
|
loading.close();
|
|
loading.close();
|
|
|
|
|
+
|
|
|
}).catch((error) => {
|
|
}).catch((error) => {
|
|
|
this.$message({
|
|
this.$message({
|
|
|
message: error.message,
|
|
message: error.message,
|
|
@@ -151,32 +164,7 @@
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
- async saveVariant() {
|
|
|
|
|
- // /admin/flexible-variant/variants/{id}
|
|
|
|
|
- await this.$refs.variantFormRef.validate();
|
|
|
|
|
- let requestData = {
|
|
|
|
|
- sku: this.form.sku,
|
|
|
|
|
- name: this.form.name,
|
|
|
|
|
- price: this.form.price,
|
|
|
|
|
- weight: this.form.weight,
|
|
|
|
|
- quantity: this.form.quantity,
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- let res = await axios.put(`/admin/flexible-variant/variants/${this.variantId}`,requestData);
|
|
|
|
|
- this.$message({
|
|
|
|
|
- message: 'Save successfully.',
|
|
|
|
|
- type: 'success',
|
|
|
|
|
- });
|
|
|
|
|
- this.$emit('update:isShow', false);
|
|
|
|
|
- this.$emit('confirm', res.data.data);
|
|
|
|
|
- } catch(err) {
|
|
|
|
|
- this.$message({
|
|
|
|
|
- message: err.message,
|
|
|
|
|
- type: 'error',
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- },
|
|
|
|
|
|
|
+
|
|
|
confirmHandler() {
|
|
confirmHandler() {
|
|
|
this.$refs.uploadRef.submit()
|
|
this.$refs.uploadRef.submit()
|
|
|
},
|
|
},
|