Authored by 陈峰

Merge branch 'release/1.0' of http://git.yoho.cn/fe/yoho-shop-manage into release/1.0

... ... @@ -325,7 +325,7 @@
</Row>
<Row>
<Col span="6" offset="12" class="text-center">
<Col style="text-align: center">
<Button type="primary" @click="submit" size="large">保存</Button>
</Col>
</Row>
... ... @@ -398,8 +398,7 @@ export default {
return `<div v-if="isExist(${index})">
<i-input
v-model="row.factoryGoodsName"
:placeholder="row.goodsName.name"
@on-blur="changeFactoryGoodsName(row,${index})">
:placeholder="row.goodsName.name">
</i-input>
</div>`;
}
... ... @@ -409,7 +408,10 @@ export default {
key: 'goodsColorImage',
width: 170,
render(row, col, index) {
return `<div class="upload-item">
return `<div
:class="{'upload-item': true ,
'upload-item-error': row.goodsColorImage.showValidate && row.goodsColorImage.validate}"
>
<div class="upload-item-img">
<img v-if="row.goodsColorImage.value"
:src="row.goodsColorImage.value" alt="" width="120px" height="122px">
... ... @@ -419,6 +421,10 @@ export default {
@on-success="uploadSuccess"
@on-error="uploadError"></file-upload>
</div>
<div v-if="row.goodsColorImage.showValidate && row.goodsColorImage.validate"
class="upload-item-tip">
必须上传图片
</div>
</div>`;
}
},
... ... @@ -429,7 +435,6 @@ export default {
return `<div v-if="isExist(${index})">
<i-input
v-model="row.factoryCode"
@on-blur="changeFactoryCode(row, ${index})"
placeholder="请输入..."
>
</i-input>
... ... @@ -452,14 +457,20 @@ export default {
title: '商品条码*',
key: 'sizeCode',
render(row, col, index) {
return `<div class='size-code' v-if="table.data[${index}]">
return `<div class='size-code'>
<div v-for="size,i in row.sizeCode" class="row-span">
<i-input v-if="table.data[${index}].operator[i]"
v-model="size.name"
@on-blur="changeSizeCode(row, ${index}, i)"
:disabled="!table.data[${index}].operator[i].value"
placeholder="请输入..."
/>
<div style="position: relative">
<div :class="{'size-code-error': size.validate && !size.name}">
<i-input
v-model="size.name"
:disabled="!row.operator[i].value"
placeholder="请输入..."
/>
</div>
<div class="size-code-tip" v-if="size.validate && !size.name">
不能为空
</div>
</div>
</div>
</div>`;
}
... ... @@ -487,7 +498,7 @@ export default {
selectedSizes: [],
defaultSelectedSizes: [],
selectedColors: [],
defaultSelectedColors: []
defaultSelectedColors: [],
},
desc: '',
render: {
... ... @@ -559,8 +570,16 @@ export default {
this.table.data[index].factoryCode = row.factoryCode;
},
uploadSuccess: function(attach, files) {
this.table.data[attach.index].goodsColorImage = files[0];
this.refreshTable();
this.table.data[attach.index].goodsColorImage.value = files[0];
this.$emit('on-color-upload', attach, files[0]);
this.table.data[attach.index].goodsColorImage.validate = true;
if (this.table.data[attach.index].goodsColorImage.value) {
this.table.data[attach.index].goodsColorImage.showValidate = false;
} else {
this.table.data[attach.index].goodsColorImage.showValidate = true;
}
},
uploadError: function(attach, err) {
},
... ... @@ -577,6 +596,7 @@ export default {
this.product.goods[colorIndex].goodsImage[imageIndex].imageUrl = '';
},
clickDefault: function(index) {
this.refreshTable();
let color = this.table.data[index];
color.goodsName.isDefault = true;
... ... @@ -722,11 +742,13 @@ export default {
});
newGoods.sizeCode.push({
name: ''
name: '',
validate: false,
showValidate: false
});
newGoods.operator.push({
value: true
value: false
});
});
... ... @@ -738,8 +760,11 @@ export default {
}
newGoods.sizeId[index].productSku = s.productSku;
newGoods.sizeCode[index].name = s.factoryCode;
newGoods.operator[index].value = true;
if (s.factoryCode) {
newGoods.sizeCode[index].name = s.factoryCode;
newGoods.operator[index].value = true;
}
});
return newGoods;
... ... @@ -750,6 +775,8 @@ export default {
beforeSave: function() {
let newProduct = makeSaveProduct();
this.refreshTable();
newProduct.productSkn = this.product.productSkn;
newProduct.id = this.product.id;
newProduct.productName = this.product.productName;
... ... @@ -798,7 +825,16 @@ export default {
});
},
submit: function() {
this.validate().then(this.save).catch( () => this.$Loading.error());
this.validate()
.then(([r1, r2]) => {
if (r1 & r2) {
return Promise.resolve();
} else {
this.$Message.error('验证未通过');
return Promise.reject();
}
})
.then(this.save).catch( () => this.$Loading.error());
},
isExist: function(index) {
let row = this.table.data[index];
... ... @@ -810,6 +846,8 @@ export default {
return false;
},
addColor: function(color) {
this.refreshTable();
if (color.disabled) {
return;
}
... ... @@ -899,6 +937,7 @@ export default {
return null;
},
removeSize: function(color, sizeId) {
let index = color.sizeId.findIndex((s) => {
return s.id === sizeId;
});
... ... @@ -935,20 +974,50 @@ export default {
this.product.goods[index].factoryGoodsName = code;
},
validate: function() {
return this.validateProduct();
return Promise.all([this.validateProduct(), this.validateTable()]);
},
validateProduct: function() {
return new Promise((resolve, reject) => {
this.$refs['product'].validate((valid) => {
if (valid){
resolve();
resolve(true);
} else {
reject();
resolve(false)
}
})
});
},
validateTable: function() {
this.refreshTable();
let errors = [];
this.table.data.forEach((color) => {
if (!color.goodsColorImage.value) {
color.goodsColorImage.showValidate = true;
color.goodsColorImage.validate = true;
errors.push({message: '没有上传封面'});
} else {
color.goodsColorImage.showValidate = false;
}
color.operator.forEach((o,i) => {
if (o.value) {
if (!color.sizeCode[i].name) {
color.sizeCode[i].showValidate = true;
color.sizeCode[i].validate = true;
errors.push({message: '商品未编码'});
} else {
color.sizeCode[i].showValidate = false;
}
}
})
});
if (errors.length === 0) {
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
},
refreshTable() {
this.table.data = this.$refs.sellerGoods.rebuildData;
... ... @@ -1160,6 +1229,17 @@ export default {
.size-code {
@include row-span;
&-error {
border: 1px solid #f30;
}
&-tip {
position: absolute;
line-height: 1;
padding-top: 6px;
color: #f30;
}
}
.size-id {
... ... @@ -1185,6 +1265,27 @@ export default {
margin: 50px 0;
}
.upload-item {
display: inline-block;
height: 200px;
width: 130px;
text-align: center;
margin: 30px 0;
}
.upload-item-error {
border: 1px solid #f30;
position: relative;
}
.upload-item-tip {
position: absolute;
line-height: 1;
padding-top: 6px;
color: #f30;
top: 100%;
}
.upload-item-img {
display: inline-block;
height: 126px;
... ... @@ -1193,9 +1294,4 @@ export default {
box-sizing: border-box;
}
.upload-item-title {
display: inline-block;
margin-top: 15px;
}
</style>
... ...