情况描述:
在多属性规格的情况下,校验失败商品属性会被清除。在单属性或者多属性只有一条的情况下校验失败,把校验失败的字段内容修改后不能再次提交,只能重新打开上传商品并且一次性把所有商品内容按照正确的校验规则填写好才能成功。
修改后再次点击提交无反应。
可以修改如下代码:
//提交接口数据更新
getFromData() {
if (this.formValidate.specType && this.formValidate.attr.length < 1)
return this.$message.warning('请填写多规格属性!');
this.formValidate.cateId = this.formValidate.cateIds.join(',');
this.formValidate.keyword = this.labelarr.join(',');
if (this.videoLink) {
//如果有视频主图,将视频链接插入到轮播图第一的位置
this.formValidate.sliderImages.unshift(this.videoLink);
}
this.formValidate.sliderImage = JSON.stringify(this.formValidate.sliderImages);
if (!this.isShowGroup) this.formValidate.guaranteeIds = this.formValidate.guaranteeIdsList.join(',');
if (this.formValidate.specType) {
this.formValidate.attrValue = this.ManyAttrValue;
this.formValidate.attr = this.formValidate.attr.map((item) => {
return {
attrName: item.attrName,
id: item.id,
attrValue: item.attrValue,
attrValues: item.attrValue.join(','),
};
});
for (var i = 0; i < this.formValidate.attrValue.length; i++) {
this.$set(this.formValidate.attrValue[i], 'id', 0);
this.$set(this.formValidate.attrValue[i], 'productId', 0);
let attrValues = this.formValidate.attrValue[i].attrValue;
this.$set(this.formValidate.attrValue[i], 'attrValue', JSON.stringify(attrValues)); //
delete this.formValidate.attrValue[i].value0;
}
} else {
this.formValidate.attr = [
{
attrName: '规格',
attrValues: '默认',
id: parseFloat(this.$route.params.id) > 0 ? this.formValidate.attr[0].id : 0,
},
];
this.OneattrValue.map((item) => {
this.$set(item, 'attrValue', JSON.stringify({ 规格: '默认' }));
this.$set(item, 'productId', 0);
});
this.formValidate.attrValue = this.OneattrValue;
}
if (this.formValidate.type === 5 || this.formValidate.type === 6) this.formValidate.tempId = 0;
},
// 提交
handleSubmit(name) {
this.$refs[name].validate((valid) => {
if (valid) {
this.getFromData();
this.loadingBtn = true;
parseFloat(this.$route.params.id) > 0
? productUpdateApi(this.formValidate)
.then(async (res) => {
this.$message.success('编辑成功');
setTimeout(() => {
this.$router.push({ path: '/product/list' });
}, 500);
this.closeSelectedTag();
this.loadingBtn = false;
})
.catch((res) => {
this.loadingBtn = false;
for (var i = 0; i < this.formValidate.attrValue.length; i++) {
let attrValues = this.formValidate.attrValue[i].attrValue;
this.$set(this.formValidate.attrValue[i], 'attrValue', JSON.parse(attrValues));
}
if (this.formValidate.specType) this.ManyAttrValue = this.formValidate.attrValue;
})
: productCreateApi(this.formValidate)
.then(async (res) => {
this.$message.success('新增成功');
setTimeout(() => {
this.$router.push({ path: '/product/list' });
}, 500);
this.closeSelectedTag();
this.loadingBtn = false;
})
.catch((res) => {
this.loadingBtn = false;
for (var i = 0; i < this.formValidate.attrValue.length; i++) {
let attrValues = this.formValidate.attrValue[i].attrValue;
this.$set(this.formValidate.attrValue[i], 'attrValue', JSON.parse(attrValues));
}
});
} else {
if (
!this.formValidate.name ||
!this.formValidate.cateId ||
!this.formValidate.keyword ||
!this.formValidate.unitName ||
!this.formValidate.intro ||
!this.formValidate.image ||
!this.formValidate.sliderImages
) {
this.$message.warning('请填写完整商品信息!');
}
}
});
},
更新位置如下:
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}