新增商品加入店铺时设置详细信息

This commit is contained in:
weipengfei 2023-11-22 18:16:45 +08:00
parent 22acdfa746
commit 9408cb41f0
3 changed files with 112 additions and 22 deletions

View File

@ -242,22 +242,22 @@
showModel: false,
showModelCode: '',
goods: [
// {
// "id": 7,
// "store_name": " 400",
// "bar_code": "6922868290895",
// {
// "id": 314,
// "store_name": "",
// "bar_code": "6974008060011",
// "manu_address": "",
// "price": "4.80",
// "price": "0.00",
// "stock": 9999999,
// "image": "http://lihai001.oss-cn-chengdu.aliyuncs.com/def/2023-11-02/202311021740247976.jpg",
// "image": "http://lihai001.oss-cn-chengdu.aliyuncs.com/def/2023-11-18/202311181017131387.jpg",
// "slider_image": [
// "https://lihai001.oss-cn-chengdu.aliyuncs.com/def/e4784202311041417185146.jpg"
// "http://lihai001.oss-cn-chengdu.aliyuncs.com/def/2023-11-18/202311181017131387.jpg"
// ],
// "spec": "****()",
// "trademark": "****()",
// "spec": "560",
// "trademark": "",
// "manu_name": null,
// "note": "login_dateJul 13 1998 12:00:00:000AMvalid_dateJul 13 2020 12:00:00:000AM"
// },
// "note": ""
// }
],
putGoods: { //
@ -288,7 +288,8 @@
},
methods: {
addGoods(item) {
addGoods(item={}) {
item = JSON.parse(JSON.stringify(item));
if(this.isNullImage(item.image)||
( this.isNullImage(item.slider_image[0]) && this.isNullImage(item.slider_image[1]) && this.isNullImage(item.slider_image[2]) )){
return Toast('请先上传商品图片后再加入店铺');
@ -308,9 +309,50 @@
this.putGoods[key] = item[key];
}
})
this.addGoodsShow = true
this.item = item
this.initShop(item);
// this.addGoodsShow = true
// this.item = item
},
initShop(item){
item.attr = [{
value: '规格',
detail: [item.spec]
}]
item.attrValue = [{
"detail": {
'规格': item.spec
},
"sku": item.spec,
"stock": 0,
"image": item.image,
"bar_code": item.bar_code,
"cost": "",
"ot_price": "",
"price": item.price,
"volume": "",
"weight": "",
}]
item.spec_type = 1;
item.import_id = item.id + '';
item.imageList = [item.image, ...item.slider_image];
item.content = {
title: '',
image: item.slider_image[0]?[item.slider_image[0]]:[]
}
delete item.id;
delete item.stock;
console.log({...item});
uni.navigateTo({
url: '/pages/product/addGood/addGood?mer_id=42&import=1',
success: (e) => {
e.eventChannel.emit('importAttrValue', item);
uni.$once('importAttrValueOK', (e)=>{
this.goods = this.goods.filter(t=>{
return t.id!=e;
})
})
}
})
},
isNullImage(src){
let flag = false;

View File

@ -204,6 +204,7 @@
bar_code_dis: false,
merId: '', //id
product_id: '', //id
import: 0, //
code: '', //
show: false, //
image: false, //
@ -255,11 +256,36 @@
onLoad(opt) {
this.merId = Number(opt.mer_id);
this.product_id = opt.product_id;
this.import = opt.import;
// if (!opt.product_id) this.showCommodity = true;
this.showCommodity = true;;
this.initData();
this.initClasiffy();
if(this.product_id){
if(this.import==1){
this.getOpenerEventChannel().once('importAttrValue', (e) => {
this.attrValue = e.attrValue;
uni.setStorageSync('attrValue', JSON.stringify(e.attrValue));
this.attr = e.attr;
uni.setStorageSync('attr', JSON.stringify(e.attr));
this.setFormData = Object.assign({}, this.setFormData, e);
this.$nextTick(()=>{
this.$refs.commodityRef?.setDatas({
addGoodsSecoundData: {
is_good: this.setFormData.is_good, //
is_gift_bag: this.setFormData.is_gift_bag,
sort: this.setFormData.sort,
once_count: this.setFormData.once_count, //
video_link: this.setFormData.video_link,
},
goodsDis: {
store_name: this.setFormData.content?.title,
imageList: this.setFormData.content?.image
}
})
})
})
}
else if(this.product_id){
this.initDataEditData();
}
},
@ -564,7 +590,25 @@
postData.attrValue = [this.$refs.priceRef.singleSpecification];
}else postData.attrValue = this.setFormData.attrValue;
postData.stock = postData.attrValue[0]?.stock||0;
// return console.log('', postData);
if(!postData.store_name||postData.store_name?.trim().length<=0)return Toast('请输入商品名称');
if(!postData.imageList||postData.imageList?.length<2)return Toast('请上传2张以上商品图片');
if(!postData.cate_name||postData.cate_name?.trim().length<=0)return Toast('请选择平台分类');
if(!postData.unit_name||postData.unit_name?.trim().length<=0)return Toast('请输入商品单位');
let userInfo = this.$store.state.app.userInfo;
if(typeof userInfo == 'string')userInfo= JSON.parse(userInfo);
let showFlag = '';
postData.attrValue.forEach(t=>{
if(userInfo?.mer_info?.type_code=="TypeSupplyChain" && (!t.procure_price||+t.procure_price<=0) ){
showFlag = '批发价不能小于0'
}
if(!t.price||+t.price<=0) showFlag = '零售价不能小于0';
if(!t.stock||+t.stock<=0) showFlag = '库存不能小于0';
if(!t.cost||+t.cost<=0) showFlag = '成本价不能小于0';
})
if(showFlag) {
if(this.setFormData.spec_type==1) showFlag+=', 请点击设置多规格设置';
return Toast(showFlag);
}
Loading();
if (this.product_id) {
productUpdate(this.merId, this.product_id, postData)
@ -589,7 +633,11 @@
Modal('提交成功', '点击确定,返回商品管理', {
showCancel: false,
}).then(() => {
uni.redirectTo({
if(this.import==1){
uni.$emit('importAttrValueOK', this.setFormData.import_id);
uni.navigateBack();
}
else uni.redirectTo({
url: '/pages/product/goodsOnSale/index?mer_id=' + this.merId
})
})

View File

@ -343,19 +343,19 @@
flag = false;
str = '规格不能为空';
}
else if (!item.price) {
else if (!item.price||+item.price<=0) {
flag = false;
str = '零售价不能小于等于0';
}
else if (!item.stock) {
else if (!item.stock||+item.stock<=0) {
flag = false;
str = '库存不能小于等于0';
}
else if (!item.cost) {
else if (!item.cost||+item.cost<=0) {
flag = false;
str = '成本价不能小于等于0';
}
else if (!item.procure_price && this.userInfo.mer_info.type_code == 'TypeSupplyChain') {
else if ((!item.procure_price||+item.procure_price<=0) && this.userInfo.mer_info.type_code == 'TypeSupplyChain') {
flag = false;
str = '批发价不能小于等于0';
}