952 lines
27 KiB
JavaScript
952 lines
27 KiB
JavaScript
// import {getGoodsInfoById,getCategoryTree,addGoods,editGoods,addVirtualGoods,editVirtualGoods,addVirtualCardGoods,editVirtualCardGoods} from '@/api/goods'
|
||
// import {getOrderFormList} from '@/api/form'
|
||
// import {getSupplyList} from '@/api/supply'
|
||
export default {
|
||
data() {
|
||
return {
|
||
repeatFlag: false,
|
||
isIphoneX: false,
|
||
goodsImgHeight: 165, // 商品图片高度
|
||
isAWait: false,
|
||
albumPage: 'goodsEdit',
|
||
//店内分类
|
||
shopCategoryNumber: 1,
|
||
shopCategoryData: {
|
||
store_0: {}
|
||
},
|
||
shopCategoryIndex: '',
|
||
|
||
categoryList: [],
|
||
secondCategory: [],
|
||
thirdCategory: [],
|
||
categoryId: [0, 0, 0],
|
||
categoryName: ['', '', ''],
|
||
currentLevel: 1,
|
||
lastLevel: 1,
|
||
showFisrt: true,
|
||
showSecond: false,
|
||
showThird: false,
|
||
|
||
goodsData: {
|
||
id: 0,//商品id
|
||
goodsname:'',//商品名称
|
||
subtitle:'',//商品简介
|
||
is_show_arrive:1,//默认商品预达简介0关闭1开启
|
||
diy_arrive_switch:0,//商品自定义预达简介0关闭1开启
|
||
goods_start_count:1,//起售数量
|
||
grounding:1,//0下架1上架
|
||
is_index_show:1,//0首页不推荐1推荐
|
||
price:0,//售价
|
||
productprice:0,//原价
|
||
costprice:0,//成本价
|
||
total:0,//库存
|
||
pick_up_type:0,//提货时,0当日达1次日达2隔日达3自定义
|
||
dispatchtype:1,//1统一运费
|
||
dispatchprice:0,//统一运费金额
|
||
begin_time:'',//团购开始时间
|
||
end_time:'',//团购结束时间
|
||
oneday_limit_count:0,//每天限购
|
||
one_limit_count:0,//单次限购
|
||
total_limit_count:0,//历史限购
|
||
is_all_sale:0,//所有团长1部分团长0
|
||
goods_image:[],
|
||
begin_time:'',//团购开始时间
|
||
end_time:''//团购结束时间
|
||
},
|
||
groundingArray: ['下架', '上架'],
|
||
|
||
pickuptypeArray: ['当日达', '次日达', '隔日达'],//, '自定义'
|
||
|
||
|
||
currCategory: 0, // 当前所设置的商品分类
|
||
virtualDeliverArray: [{
|
||
name: '自动发货',
|
||
value: 'auto_deliver',
|
||
},
|
||
{
|
||
name: '手动发货',
|
||
value: 'artificial_deliver',
|
||
},
|
||
{
|
||
name: '到店核销',
|
||
value: 'verify',
|
||
}
|
||
],
|
||
virtualDeliverValue: {
|
||
'auto_deliver': '自动发货',
|
||
'artificial_deliver': '手动发货',
|
||
'verify': '到店核销'
|
||
},
|
||
virtualReceiveArray: [{
|
||
name: '自动收货',
|
||
value: 'auto_receive',
|
||
},
|
||
{
|
||
name: '买家确认收货',
|
||
value: 'artificial_receive',
|
||
},
|
||
],
|
||
virtualReceiveValue: {
|
||
'auto_receive': '自动收货',
|
||
'artificial_receive': '买家确认收货',
|
||
},
|
||
validityTypeArray: ['永久', '购买后几日有效', '指定过期日期'],
|
||
virtualIndate: 0,
|
||
minDate: '',
|
||
carmiLength: '添加卡密',
|
||
limitLength: [ //限购
|
||
{
|
||
name: '单次限购',
|
||
value: '1'
|
||
},
|
||
{
|
||
name: '长期限购',
|
||
value: '2'
|
||
}
|
||
],
|
||
current: 0,
|
||
goodsFormArray: [],
|
||
goodsForm: [],
|
||
|
||
supplyFormArray: [],
|
||
supplyForm: []
|
||
};
|
||
},
|
||
async onLoad(option) {
|
||
this.goodsData.id = option.id || 0;
|
||
|
||
// if (!this.$util.checkToken('/pages/goods/edit/index?id=' + this.goodsData.id)) return;
|
||
|
||
// this.clearStoreage();
|
||
|
||
// this.getCategoryTreeFn();
|
||
if (this.goodsData.id) {
|
||
this.isAWait = true;
|
||
uni.setNavigationBarTitle({
|
||
title: '编辑商品'
|
||
});
|
||
await this.editGetGoodsInfo();
|
||
} else {
|
||
|
||
this.isAWait = false;
|
||
uni.setNavigationBarTitle({
|
||
title: '添加商品'
|
||
});
|
||
}
|
||
|
||
let date = new Date();
|
||
this.minDate = date.getFullYear() + '-' + date.getMonth() + '-' + date.getUTCDate();
|
||
|
||
// if (this.addonIsExit.form) this.getGoodsForm();
|
||
|
||
// if (this.addonIsExit.supply) this.getSupplyList();
|
||
|
||
},
|
||
onShow() {
|
||
this.isIphoneX = this.$util.uniappIsIPhoneX();
|
||
//this.refreshData();
|
||
},
|
||
methods: {
|
||
|
||
groundingChange(e) {
|
||
this.goodsData.grounding = e.detail.value;
|
||
},
|
||
|
||
pickuptypeChange(e) {
|
||
this.goodsData.pick_up_type = e.detail.value;
|
||
},
|
||
|
||
// 获取编辑商品数据
|
||
async editGetGoodsInfo() {
|
||
this.$api.sendRequest({
|
||
url: 'app.getgoodsinfo',
|
||
data:{
|
||
id:this.goodsData.id
|
||
},
|
||
success: res => {
|
||
console.log(res)
|
||
if(res.result.detail){
|
||
this.goodsData = res.result.detail
|
||
console.log(this.goodsData.goods_image)
|
||
}else{
|
||
this.$util.showToast({
|
||
title: '商品不存在',
|
||
});
|
||
setTimeout(() => {
|
||
this.$util.redirectTo('/pages/goods/list', {}, 'redirectTo');
|
||
}, 1000);
|
||
}
|
||
// if (res.status == 0) {
|
||
// setTimeout(() => {
|
||
// this.$util.redirectTo('/pages/goods/list', {}, 'redirectTo');
|
||
// }, 1000);
|
||
// }
|
||
}
|
||
})
|
||
/*var res = await getGoodsInfoById(this.goodsData.goods_id);
|
||
if (res.code == 0 && res.data) {
|
||
var data = res.data;
|
||
|
||
data.goods_category.forEach((item, index) => {
|
||
this.shopCategoryData['store_' + index] = {
|
||
category_id: item.id,
|
||
category_name: item.category_name
|
||
}
|
||
})
|
||
this.shopCategoryNumber = data.goods_category.length;
|
||
|
||
// 商品分类
|
||
data.category_id = data.goods_category[0].id;
|
||
data.category_name = data.goods_category[0].category_name.replace(/\//g, " / ");
|
||
|
||
if (typeof data.category_id == 'string') {
|
||
this.categoryId = data.category_id.split(",");
|
||
this.categoryName = data.category_name.split(" / ");
|
||
} else {
|
||
this.categoryId = data.category_id;
|
||
this.categoryName = data.category_name;
|
||
}
|
||
|
||
delete data.category_json;
|
||
delete data.goods_category;
|
||
|
||
data.goods_image = data.goods_image.split(",");
|
||
|
||
data.goods_sku_data.forEach((item) => {
|
||
if (item.sku_spec_format) item.sku_spec_format = JSON.parse(item.sku_spec_format);
|
||
});
|
||
|
||
if (data.goods_spec_format) {
|
||
uni.setStorageSync("editGoodsSpecFormat", data.goods_spec_format);
|
||
uni.setStorageSync("editGoodsSkuData", JSON.stringify(data.goods_sku_data));
|
||
data.goods_spec_format = JSON.parse(data.goods_spec_format);
|
||
} else {
|
||
data.sku_id = data.goods_sku_data[0].sku_id;
|
||
data.price = data.goods_sku_data[0].price;
|
||
data.market_price = data.goods_sku_data[0].market_price;
|
||
data.cost_price = data.goods_sku_data[0].cost_price;
|
||
data.weight = data.goods_sku_data[0].weight;
|
||
data.volume = data.goods_sku_data[0].volume;
|
||
data.sku_no = data.goods_sku_data[0].sku_no;
|
||
}
|
||
|
||
if (data.goods_class == 1) {
|
||
// 实物商品
|
||
delete data.virtual_indate;
|
||
uni.setStorageSync("editGoodsShippingTemplateId", data.shipping_template);
|
||
uni.setStorageSync("editGoodsShippingTemplateName", data.template_name ? data.template_name : '');
|
||
} else {
|
||
// 虚拟商品
|
||
delete data.shipping_template;
|
||
delete data.is_free_shipping;
|
||
}
|
||
|
||
// 商品参数
|
||
if (data.goods_attr_format) {
|
||
uni.setStorageSync("editGoodsAttrClass", data.goods_attr_class);
|
||
uni.setStorageSync("editGoodsAttrName", data.goods_attr_name);
|
||
uni.setStorageSync("editGoodsAttrFormat", data.goods_attr_format);
|
||
data.goods_attr_format = JSON.parse(data.goods_attr_format);
|
||
}
|
||
|
||
uni.setStorageSync("editGoodsState", data.goods_state);
|
||
uni.setStorageSync("editGoodsContent", data.goods_content);
|
||
|
||
if (data.verify_validity_type == 1) {
|
||
this.virtualIndate = data.virtual_indate;
|
||
} else if (data.verify_validity_type == 2) {
|
||
this.virtualTime = this.$util.timeStampTurnTime(data.virtual_indate, 'Y-m-d');
|
||
}
|
||
data.verify_num = data.goods_sku_data[0].verify_num
|
||
|
||
this.goodsData = data;
|
||
|
||
this.goodsData.goods_form_index = 0;
|
||
|
||
this.goodsData.supply_index = 0;
|
||
|
||
this.$forceUpdate();
|
||
} else {
|
||
this.$util.showToast({
|
||
title: '商品不存在',
|
||
});
|
||
setTimeout(() => {
|
||
this.$util.redirectTo('/pages/goods/list', {}, 'redirectTo');
|
||
}, 1000);
|
||
}*/
|
||
},
|
||
// 选择商品分类
|
||
openGoodsCategoryPop(index) {
|
||
this.currCategory = index;
|
||
if (this.shopCategoryData['store_' + index].category_id) {
|
||
this.categoryId = this.shopCategoryData['store_' + index].category_id.split(',');
|
||
this.categoryName = this.shopCategoryData['store_' + index].category_name.split(' / ');
|
||
|
||
this.categoryList.forEach((item, index) => {
|
||
item.selected = this.categoryId.indexOf(item.category_id.toString()) != -1;
|
||
if (item.selected) {
|
||
this.secondCategory = item.child_list;
|
||
}
|
||
if (item.child_list) {
|
||
if (item.selected) this.lastLevel = 2;
|
||
item.child_list.forEach(secondItem => {
|
||
secondItem.selected = this.categoryId.indexOf(secondItem.category_id.toString()) != -1;
|
||
if (secondItem.selected) {
|
||
this.thirdCategory = secondItem.child_list;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
this.changeShow(this.categoryId.length);
|
||
} else {
|
||
this.categoryId = [0];
|
||
this.categoryName = [''];
|
||
this.changeShow(1);
|
||
}
|
||
this.$refs.categoryPopup.open();
|
||
},
|
||
closeGoodsCategoryPop() {
|
||
this.$refs.categoryPopup.close();
|
||
},
|
||
// 编辑规格类型
|
||
openGoodsSpec() {
|
||
this.$util.redirectTo('/pages/goods/edit/spec');
|
||
},
|
||
// 编辑多规格
|
||
openGoodsSpecEdit() {
|
||
this.$util.redirectTo('/pages/goods/edit/spec_edit', {
|
||
goods_class: this.goodsData.goods_class,
|
||
virtual_deliver_type: this.goodsData.virtual_deliver_type
|
||
});
|
||
},
|
||
//编辑卡密
|
||
openCarmichaelEdit() {
|
||
this.$util.redirectTo('/pages/goods/edit/carmichael_edit', {
|
||
goods_class: this.goodsData.goods_class
|
||
});
|
||
},
|
||
// 编辑商品状态
|
||
openGoodsState() {
|
||
this.$util.redirectTo('/pages/goods/edit/state', {
|
||
goods_state: this.goodsData.goods_state
|
||
});
|
||
},
|
||
// 编辑快递运费
|
||
openExpressFreight() {
|
||
this.$util.redirectTo('/pages/goods/edit/express_freight', {
|
||
template_id: this.goodsData.shipping_template
|
||
});
|
||
},
|
||
// 编辑商品详情
|
||
openGoodsContent() {
|
||
this.$util.redirectTo('/pages/goods/edit/content');
|
||
},
|
||
// 编辑商品参数
|
||
openAttr() {
|
||
this.$util.redirectTo('/pages/goods/edit/attr');
|
||
},
|
||
/**
|
||
* 刷新商品图片高度
|
||
* @param {Object} data
|
||
*/
|
||
refreshGoodsImgHeight(data) {
|
||
if (data.height == '') return;
|
||
var height = parseFloat(data.height.replace('px', ''));
|
||
this.goodsImgHeight = height + 80;
|
||
this.$forceUpdate();
|
||
if (data.isLoad && this.$refs.loadingCover) {
|
||
// 数据渲染留点时间
|
||
setTimeout(() => {
|
||
this.$refs.loadingCover.hide();
|
||
}, 100);
|
||
}
|
||
uni.removeStorageSync("selectedAlbumImg");
|
||
|
||
},
|
||
// 获取商品分类树状结构
|
||
getCategoryTreeFn() {
|
||
getCategoryTree().then(res=>{
|
||
if (res.data) {
|
||
this.categoryList = res.data;
|
||
this.categoryList.forEach((item, index) => {
|
||
item.selected = this.categoryId.indexOf(item.category_id.toString()) != -1;
|
||
if (item.selected) {
|
||
this.secondCategory = item.child_list;
|
||
this.currentLevel = 1;
|
||
}
|
||
if (item.child_list) {
|
||
if (item.selected) this.lastLevel = 2;
|
||
item.child_list.forEach(secondItem => {
|
||
secondItem.selected = this.categoryId.indexOf(secondItem.category_id.toString()) != -1;
|
||
if (secondItem.selected) {
|
||
this.thirdCategory = secondItem.child_list;
|
||
this.currentLevel = 2;
|
||
}
|
||
if (secondItem.child_list) {
|
||
if (secondItem.selected) this.lastLevel = 3;
|
||
secondItem.child_list.forEach(thirdItem => {
|
||
thirdItem.selected = this.categoryId.indexOf(thirdItem.category_id.toString()) != -1;
|
||
if (thirdItem.selected) this.currentLevel = 3;
|
||
});
|
||
}
|
||
});
|
||
}
|
||
});
|
||
this.changeShow(this.lastLevel);
|
||
if (this.goodsData.goods_id == 0 && this.$refs.loadingCover) {
|
||
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
|
||
}
|
||
}
|
||
});
|
||
},
|
||
changeShow(index) {
|
||
if (index == 1) {
|
||
this.showFisrt = true;
|
||
this.showSecond = false;
|
||
this.showThird = false;
|
||
} else if (index == 2) {
|
||
this.showFisrt = false;
|
||
this.showSecond = true;
|
||
this.showThird = false;
|
||
} else if (index == 3) {
|
||
this.showFisrt = false;
|
||
this.showSecond = false;
|
||
this.showThird = true;
|
||
}
|
||
this.currentLevel = index;
|
||
this.$forceUpdate();
|
||
},
|
||
selectCategory(category) {
|
||
this.currentLevel = category.level;
|
||
|
||
// 如果当前选中跟上次不一样,则 要清空下级数据
|
||
if (category.level == 1 && this.categoryId[0] > 0 && this.categoryId[0] != category.captcha_id) {
|
||
this.categoryId[1] = 0;
|
||
this.categoryName[1] = '';
|
||
this.categoryId[2] = 0;
|
||
this.categoryName[2] = '';
|
||
} else if (category.level == 2 && this.categoryId[1] > 0 && this.categoryId[1] != category.captcha_id) {
|
||
this.categoryId[2] = 0;
|
||
this.categoryName[2] = '';
|
||
}
|
||
|
||
this.categoryId[category.level - 1] = category.category_id;
|
||
this.categoryName[category.level - 1] = category.category_name;
|
||
if (category.level == 1) {
|
||
if (category.child_list) {
|
||
this.secondCategory = category.child_list;
|
||
} else {
|
||
this.categoryId[1] = 0;
|
||
this.categoryName[1] = '';
|
||
this.categoryId[2] = 0;
|
||
this.categoryName[2] = '';
|
||
}
|
||
} else if (category.level == 2) {
|
||
if (category.child_list) {
|
||
this.thirdCategory = category.child_list;
|
||
} else {
|
||
this.categoryId[2] = 0;
|
||
this.categoryName[2] = '';
|
||
}
|
||
}
|
||
|
||
this.lastLevel = 1;
|
||
this.categoryList.forEach((item, index) => {
|
||
item.selected = this.categoryId[0] == item.category_id;
|
||
if (item.child_list) {
|
||
if (item.selected) this.lastLevel = 2;
|
||
item.child_list.forEach((secondItem, secondIndex) => {
|
||
secondItem.selected = this.categoryId[1] == secondItem.category_id;
|
||
if (secondItem.child_list) {
|
||
if (secondItem.selected) this.lastLevel = 3;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
this.changeShow(this.lastLevel);
|
||
|
||
this.goodsData.category_id = [];
|
||
this.goodsData.category_name = [];
|
||
|
||
for (var i = 0; i < this.categoryId.length; i++) {
|
||
if (this.categoryId[i]) this.goodsData.category_id.push(this.categoryId[i]);
|
||
}
|
||
for (var i = 0; i < this.categoryName.length; i++) {
|
||
if (this.categoryName[i]) this.goodsData.category_name.push(this.categoryName[i]);
|
||
}
|
||
|
||
this.goodsData.category_id = this.goodsData.category_id.toString();
|
||
this.goodsData.category_name = this.goodsData.category_name.join(" / ");
|
||
|
||
if (
|
||
(this.lastLevel == 3 && this.categoryId[2]) ||
|
||
(this.lastLevel == 2 && this.categoryId[1]) ||
|
||
(this.lastLevel == 1 && this.categoryId[0])
|
||
) {
|
||
this.shopCategoryData['store_' + this.currCategory] = {
|
||
category_id: this.goodsData.category_id,
|
||
category_name: this.goodsData.category_name
|
||
};
|
||
this.closeGoodsCategoryPop();
|
||
}
|
||
|
||
this.$forceUpdate();
|
||
},
|
||
addShopCategory() {
|
||
if (this.shopCategoryNumber == 10) {
|
||
this.$util.showToast({
|
||
title: '商品可以属于多个分类,最多10个'
|
||
});
|
||
return;
|
||
}
|
||
this.shopCategoryData['store_' + this.shopCategoryNumber] = {};
|
||
++this.shopCategoryNumber;
|
||
},
|
||
deleteShopCategory(index) {
|
||
delete this.shopCategoryData['store_' + index];
|
||
--this.shopCategoryNumber;
|
||
|
||
//重置数据
|
||
let i = 0;
|
||
let obj = {};
|
||
for (let key in this.shopCategoryData) {
|
||
obj['store_' + i] = this.shopCategoryData[key];
|
||
i++;
|
||
}
|
||
this.shopCategoryData = {};
|
||
this.shopCategoryData = Object.assign(this.shopCategoryData, obj);
|
||
},
|
||
// 刷新数据
|
||
refreshData() {
|
||
var selectedAlbumImg = uni.getStorageSync('selectedAlbumImg');
|
||
if (selectedAlbumImg) {
|
||
uni.setStorageSync('selectedAlbumImgTemp', selectedAlbumImg);
|
||
selectedAlbumImg = JSON.parse(selectedAlbumImg);
|
||
this.goodsData.goods_image = selectedAlbumImg.list.split(",");
|
||
this.$refs.goodsShmilyDragImg.refresh();
|
||
}
|
||
|
||
// 规格项
|
||
this.goodsData.goods_spec_format = uni.getStorageSync('editGoodsSpecFormat') ? JSON.parse(uni.getStorageSync('editGoodsSpecFormat')) : [];
|
||
if (this.goodsData.goods_spec_format.length <= 0) {
|
||
|
||
this.goodsData.carmichael = uni.getStorageSync('editGoodsCarmichael') ? JSON.parse(uni.getStorageSync('editGoodsCarmichael')) : [];
|
||
if (this.goodsData.carmichael.length > 0) {
|
||
this.carmiLength = '添加卡密【' + this.goodsData.carmichael.length + '】'
|
||
}
|
||
}
|
||
|
||
// 多规格数据
|
||
this.goodsData.goods_sku_data = uni.getStorageSync('editGoodsSkuData') ? JSON.parse(uni.getStorageSync('editGoodsSkuData')) : [];
|
||
if (this.goodsData.goods_sku_data.length > 0) {
|
||
this.goodsData.goods_stock = 0;
|
||
this.goodsData.goods_stock_alarm = 0;
|
||
this.goodsData.goods_sku_data.forEach((item) => {
|
||
if (item.stock) this.goodsData.goods_stock += parseInt(item.stock);
|
||
if (item.stock_alarm) this.goodsData.goods_stock_alarm += parseInt(item.stock_alarm);
|
||
});
|
||
}
|
||
|
||
// 快递运费
|
||
this.goodsData.shipping_template = uni.getStorageSync('editGoodsShippingTemplateId') || 0;
|
||
this.goodsData.is_free_shipping = this.goodsData.shipping_template > 0 ? 0 : 1;
|
||
this.goodsData.template_name = uni.getStorageSync('editGoodsShippingTemplateName') || '';
|
||
|
||
if (uni.getStorageSync('editGoodsState') !== undefined && uni.getStorageSync('editGoodsState') !== '') {
|
||
this.goodsData.goods_state = uni.getStorageSync('editGoodsState');
|
||
}
|
||
|
||
if (uni.getStorageSync('editGoodsContent') != undefined && uni.getStorageSync('editGoodsContent') != '') {
|
||
this.goodsData.goods_content = uni.getStorageSync('editGoodsContent');
|
||
}
|
||
// 商品参数
|
||
this.goodsData.goods_attr_class = uni.getStorageSync('editGoodsAttrClass') || 0;
|
||
this.goodsData.goods_attr_name = uni.getStorageSync('editGoodsAttrName') || '';
|
||
this.goodsData.goods_attr_format = uni.getStorageSync('editGoodsAttrFormat') ? JSON.parse(uni.getStorageSync('editGoodsAttrFormat')) : [];
|
||
this.$forceUpdate();
|
||
},
|
||
// 验证
|
||
verify() {
|
||
|
||
if (this.goodsData.goodsname.length == 0) {
|
||
this.$util.showToast({
|
||
title: '请输入商品名称'
|
||
});
|
||
return false;
|
||
}
|
||
|
||
if (this.goodsData.subtitle.length > 100) {
|
||
this.$util.showToast({
|
||
title: '商品简介不能超过100个字符'
|
||
});
|
||
return false;
|
||
}
|
||
|
||
if (this.goodsData.goods_image.length == 0) {
|
||
this.$util.showToast({
|
||
title: '请上传商品图片'
|
||
});
|
||
return false;
|
||
}
|
||
|
||
|
||
// if (!this.shopCategoryData.store_0.category_id) {
|
||
// this.$util.showToast({
|
||
// title: `请选择商品分类`
|
||
// });
|
||
// return false;
|
||
// }
|
||
|
||
// if (this.goodsData.goods_class == 2 && this.goodsData.virtual_deliver_type == 'verify') {
|
||
// if (this.goodsData.verify_validity_type == 1) {
|
||
// if (this.virtualIndate.length == 0) {
|
||
// this.$util.showToast({
|
||
// title: '请输入有效期'
|
||
// });
|
||
// return false;
|
||
// }
|
||
// if (isNaN(this.virtualIndate) || !this.$util.data().regExp.number.test(this.virtualIndate)) {
|
||
// this.$util.showToast({
|
||
// title: '[有效期]格式输入错误'
|
||
// });
|
||
// return false;
|
||
// }
|
||
// if (this.virtualIndate < 1) {
|
||
// this.$util.showToast({
|
||
// title: '有效期不能小于1天'
|
||
// });
|
||
// return false;
|
||
// }
|
||
// }
|
||
|
||
// if (this.goodsData.verify_validity_type == 2) {
|
||
// if (this.virtualTime.length == 0) {
|
||
// this.$util.showToast({
|
||
// title: '请设置有效期'
|
||
// });
|
||
// return false;
|
||
// }
|
||
// }
|
||
|
||
// }
|
||
|
||
// 单规格
|
||
if (this.goodsData.price == 0) {
|
||
|
||
this.$util.showToast({
|
||
title: '请输入销售价'
|
||
});
|
||
return false;
|
||
}
|
||
if (isNaN(this.goodsData.price) || !this.$util.data().regExp.digit.test(this.goodsData.price)) {
|
||
this.$util.showToast({
|
||
title: '[销售价]格式输入错误'
|
||
});
|
||
return false;
|
||
}
|
||
|
||
if (this.goodsData.productprice.length > 0 && (isNaN(this.goodsData.productprice) || !this.$util.data().regExp.digit.test(this.goodsData.productprice))) {
|
||
this.$util.showToast({
|
||
title: '[原价价]格式输入错误'
|
||
});
|
||
return false;
|
||
}
|
||
|
||
|
||
|
||
// 总库存
|
||
if (this.goodsData.total == 0) {
|
||
this.$util.showToast({
|
||
title: '请输入库存'
|
||
});
|
||
return false;
|
||
}
|
||
|
||
if (isNaN(this.goodsData.total) || !this.$util.data().regExp.number.test(this.goodsData.total)) {
|
||
this.$util.showToast({
|
||
title: '[库存]格式输入错误'
|
||
});
|
||
return false;
|
||
}
|
||
if (isNaN(this.goodsData.goods_start_count) || !this.$util.data().regExp.number.test(this.goodsData.goods_start_count)) {
|
||
this.$util.showToast({
|
||
title: '[起售]格式输入错误'
|
||
});
|
||
return false;
|
||
}
|
||
if (this.goodsData.goods_start_count < 0) {
|
||
this.$util.showToast({
|
||
title: '起售数量不能小于0'
|
||
});
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
|
||
},
|
||
// 删除本地缓存
|
||
clearStoreage() {
|
||
|
||
// 临时选择的商品图片
|
||
uni.removeStorageSync("selectedAlbumImg");
|
||
uni.removeStorageSync("selectedAlbumImgTemp");
|
||
|
||
// 商品规格
|
||
uni.removeStorageSync("editGoodsSpecFormat");
|
||
uni.removeStorageSync("editGoodsSkuData");
|
||
|
||
//电子卡密
|
||
uni.removeStorageSync("editGoodsCarmichael");
|
||
uni.removeStorageSync("specName");
|
||
|
||
// 物流公司
|
||
uni.removeStorageSync("editGoodsShippingTemplateId");
|
||
uni.removeStorageSync("editGoodsShippingTemplateName");
|
||
|
||
// 商品状态
|
||
uni.removeStorageSync("editGoodsState");
|
||
|
||
// 商品详情
|
||
uni.removeStorageSync("editGoodsContent");
|
||
|
||
// 商品参数
|
||
uni.removeStorageSync("editGoodsAttrClass");
|
||
uni.removeStorageSync("editGoodsAttrName");
|
||
uni.removeStorageSync("editGoodsAttrFormat");
|
||
},
|
||
save() {
|
||
if (!this.verify()) return;
|
||
if (this.repeatFlag) return;
|
||
this.repeatFlag = true;
|
||
this.$api.sendRequest({
|
||
url: 'app.addgoods',
|
||
data:this.goodsData,
|
||
success: res => {
|
||
this.$util.showToast({
|
||
title: res.result.message
|
||
});
|
||
if (res.status == 1) {
|
||
setTimeout(() => {
|
||
this.$util.redirectTo('/pages/goods/list', {}, 'redirectTo');
|
||
}, 1000);
|
||
} else {
|
||
this.repeatFlag = false;
|
||
}
|
||
}
|
||
})
|
||
|
||
// 清空规格的图片
|
||
console.log(this.goodsData)
|
||
return false
|
||
for (var i = 0; i < this.goodsData.goods_sku_data.length; i++) {
|
||
if (this.goodsData.goods_sku_data[i].sku_images.length == 0) this.goodsData.goods_sku_data[i].sku_image = '';
|
||
}
|
||
var data = JSON.parse(JSON.stringify(this.goodsData));
|
||
delete data.category_name;
|
||
|
||
data.category_json = [];
|
||
data.category_id = '';
|
||
|
||
for (var key in this.shopCategoryData) {
|
||
if (this.shopCategoryData[key].category_id) {
|
||
data.category_id += ',' + this.shopCategoryData[key].category_id;
|
||
data.category_json.push(this.shopCategoryData[key].category_id);
|
||
}
|
||
}
|
||
data.category_id += ',';
|
||
data.category_json = JSON.stringify(data.category_json);
|
||
if (data.goods_spec_format.length == 0) {
|
||
// 单规格数据
|
||
var singData = {
|
||
sku_id: (data.goods_id ? data.sku_id : 0),
|
||
sku_name: data.goods_name,
|
||
spec_name: '',
|
||
sku_no: data.sku_no,
|
||
sku_spec_format: '',
|
||
price: data.price,
|
||
market_price: data.market_price,
|
||
cost_price: data.cost_price,
|
||
stock: data.goods_stock,
|
||
stock_alarm: data.goods_stock_alarm,
|
||
weight: data.weight,
|
||
volume: this.goodsData.volume,
|
||
sku_image: data.goods_image[0],
|
||
sku_images: data.goods_image.toString(),
|
||
// verify_num: data.goods_sku_data.length > 0 ? data.goods_sku_data[0].verify_num : this.goodsData.verify_num
|
||
verify_num: data.verify_num
|
||
}
|
||
var singleSkuData = JSON.stringify([singData]);
|
||
}
|
||
data.goods_image = data.goods_image.toString();
|
||
// 商品规格json格式
|
||
data.goods_spec_format = data.goods_spec_format.length > 0 ? JSON.stringify(data.goods_spec_format) : '';
|
||
|
||
// SKU商品数据
|
||
data.goods_sku_data = data.goods_spec_format.length > 0 ? JSON.stringify(data.goods_sku_data) :
|
||
singleSkuData;
|
||
|
||
// 商品参数json格式
|
||
data.goods_attr_format = data.goods_attr_format.length > 0 ? JSON.stringify(data.goods_attr_format) : '';
|
||
|
||
data.spec_type_status = data.goods_spec_format.length > 0 ? 1 : 0;
|
||
|
||
if (this.goodsData.verify_validity_type == 1) {
|
||
data.virtual_indate = this.virtualIndate;
|
||
} else if (this.goodsData.verify_validity_type == 2) {
|
||
data.virtual_indate = this.virtualTime;
|
||
}
|
||
|
||
// console.log(this.goodsData.goods_spec_format,'format')
|
||
// if(this.goodsData.goods_spec_format == '[]'){
|
||
// data.carmichael= data.carmichael
|
||
// }
|
||
var save = null;
|
||
if (data.goods_class == 3) {
|
||
save = addVirtualCardGoods;
|
||
if (data.goods_id) save = editVirtualCardGoods;
|
||
}else if (data.goods_class == 2){
|
||
save = addVirtualGoods;
|
||
if (data.goods_id) save = editVirtualGoods;
|
||
}else {
|
||
save = addGoods;
|
||
if (data.goods_id) save = editGoods;
|
||
}
|
||
data.goods_form = this.goodsData.goods_form_index ? this.goodsForm[this.goodsData.goods_form_index - 1].id : 0;
|
||
|
||
data.supplier_id = this.goodsData.supply_index ? this.supplyForm[this.goodsData.supply_index - 1].supplier_id : 0;
|
||
if (this.repeatFlag) return;
|
||
this.repeatFlag = true;
|
||
save(data).then(res=>{
|
||
this.$util.showToast({
|
||
title: res.message
|
||
});
|
||
if (res.code == 0) {
|
||
this.clearStoreage();
|
||
setTimeout(() => {
|
||
this.$util.redirectTo('/pages/goods/list', {}, 'tabbar');
|
||
}, 1000);
|
||
} else {
|
||
this.repeatFlag = false;
|
||
}
|
||
});
|
||
},
|
||
//是否开启限购
|
||
onLimit() {
|
||
this.goodsData.is_limit = this.goodsData.is_limit == 1 ? 0 : 1
|
||
},
|
||
|
||
//限购类型
|
||
limitChange(e) {
|
||
this.goodsData.limit_type = e
|
||
},
|
||
/**
|
||
* 是否参与会员折扣
|
||
*/
|
||
joinMemberDiscount() {
|
||
this.goodsData.is_consume_discount = this.goodsData.is_consume_discount == 1 ? 0 : 1;
|
||
},
|
||
switchBtn(type) {
|
||
this.goodsData[type] = this.goodsData[type] == 1 ? 0 : 1;
|
||
},
|
||
/**
|
||
* 推荐方式选择
|
||
* @param {Object} e
|
||
*/
|
||
recommendWayChange(e) {
|
||
this.goodsData.recommend_way = e.detail.value;
|
||
},
|
||
/**
|
||
* 发货选择
|
||
* @param {Object} e
|
||
*/
|
||
virtualDeliverTypeChange(e) {
|
||
this.goodsData.virtual_deliver_type = this.virtualDeliverArray[e.detail.value]['value'];
|
||
},
|
||
/**
|
||
* 收货选择
|
||
* @param {Object} e
|
||
*/
|
||
virtualReceiveTypeChange(e) {
|
||
this.goodsData.virtual_receive_type = this.virtualReceiveArray[e.detail.value]['value'];
|
||
},
|
||
/**
|
||
* 核销有效期类型
|
||
* @param {Object} e
|
||
*/
|
||
validityTypeChange(e) {
|
||
this.goodsData.verify_validity_type = e.detail.value;
|
||
},
|
||
/**
|
||
* 核销有效期选择
|
||
* @param {Object} e
|
||
*/
|
||
virtualTimeChange(e) {
|
||
this.virtualTime = e.detail.value;
|
||
},
|
||
|
||
/**
|
||
* 团购开始时间选择
|
||
* @param {Object} e
|
||
*/
|
||
beginChange(e) {
|
||
this.goodsData.begin_time = e.detail.value;
|
||
},
|
||
/**
|
||
* 团购结束时间选择
|
||
* @param {Object} e
|
||
*/
|
||
endChange(e) {
|
||
this.goodsData.end_time = e.detail.value;
|
||
},
|
||
|
||
/**
|
||
* 是否需要核销
|
||
*/
|
||
isNeedVerify() {
|
||
this.goodsData.is_need_verify = this.goodsData.is_need_verify == 1 ? 0 : 1;
|
||
},
|
||
/**
|
||
* 获取商品表单
|
||
*/
|
||
getGoodsForm() {
|
||
getOrderFormList().then(res=>{
|
||
if (res.data) {
|
||
let goodsForm = ['请选择商品表单'];
|
||
res.data.forEach((item, index) => {
|
||
goodsForm.push(item.form_name);
|
||
if (this.goodsData.form_id && this.goodsData.form_id == item.id) this.goodsData.goods_form_index = index + 1;
|
||
})
|
||
this.goodsForm = res.data;
|
||
this.goodsFormArray = goodsForm;
|
||
this.$forceUpdate();
|
||
}
|
||
})
|
||
},
|
||
goodsFormChange(e) {
|
||
this.goodsData.goods_form_index = e.detail.value;
|
||
this.$forceUpdate();
|
||
},
|
||
/**
|
||
* 获取供应商
|
||
*/
|
||
getSupplyList() {
|
||
getSupplyList().then(res=>{
|
||
if (res.data) {
|
||
let supplyForm = ['请选择供应商'];
|
||
res.data.forEach((item, index) => {
|
||
supplyForm.push(item.title);
|
||
if (this.goodsData.supplier_id && this.goodsData.supplier_id == item.supplier_id) this.goodsData.supply_index = index + 1;
|
||
})
|
||
this.supplyForm = res.data;
|
||
this.supplyFormArray = supplyForm;
|
||
this.$forceUpdate();
|
||
}
|
||
})
|
||
},
|
||
supplyChange(e) {
|
||
this.goodsData.supply_index = e.detail.value;
|
||
this.$forceUpdate();
|
||
}
|
||
}
|
||
}; |