Browse Source

【重构】 多规格选择下单逻辑重新梳理

master
邓平艺 4 years ago
parent
commit
95c080b7ab
  1. 119
      pages/shop/goodsdetail.vue

119
pages/shop/goodsdetail.vue

@ -15,7 +15,7 @@
:hour="seckill.seckill.end_left_time[1]"
:minute="seckill.seckill.end_left_time[2]"
:second="seckill.seckill.end_left_time[3]"
color="white"
color="white"
splitorColor="white"
>
</countdown-time>
@ -331,21 +331,34 @@
let stores = this.goods_stock.stores;
let specs = this.goods_stock.specs;
if(!this.$isRight(specs[1])){
return `${goods_detail.min_price} - ¥${goods_detail.max_price}`;
}
let spec_current_1 = specs[1].spec_current;
let spec_current_2 = specs[2].spec_current;
if(specs[1].spec_current != null && specs[2].spec_current != null){
let id_1 = specs[1].list[spec_current_1].id;
let id_2 = specs[2].list[spec_current_2].id;
if(id_1 < id_2){
let id_3 = id_2;
id_2 = id_1;
id_1 = id_3;
if(this.$isRight(specs)){ //
let selectEnd = true; //
let specs_list = []; //
for(let i in specs){
specs_list.push(specs[i]);
if(specs[i].spec_current == null){
selectEnd = false;
}
}
return "¥"+ stores[id_2 +'-'+ id_1].price;
}else{
if(!selectEnd){ //
return `${goods_detail.min_price} - ¥${goods_detail.max_price}`;
}
let ids = []; // id
specs_list.map((item, index) => {
console.log("item.list[item.spec_current]", item.list[item.spec_current])
ids.push(item.list[item.spec_current].id);
})
ids.sort(function(a, b){ // id
return a - b;
})
let idPath = ids.join('-'); // ids
return stores[idPath].price; //
}else{ //
return `${goods_detail.min_price} - ¥${goods_detail.max_price}`;
}
},
@ -481,7 +494,7 @@
}
}
},
// TODO
//
confirm(){
if(this.is_date_finish){
return this.$msg('活动已结束');
@ -490,48 +503,42 @@
let specs = this.goods_stock.specs;
let stores = this.goods_stock.stores;
let par = {};
let have_specs = '';
let no_specs = '';
let have_specs = ''; // id
let no_specs = ''; // id
if(this.$isRight(specs)){
let s_id_1 = 1;
let s_id_2 = 2;
for(let i in specs){
if(specs[i].label_key == 'size'){
s_id_1 = 1;
}
if(specs[i].label_key == 'color'){
s_id_2 = 2;
}
if(this.$isRight(specs)){ //
let attributes = {
com_id: goods_detail.id,
img: goods_detail.img
}
let spec_current_1 = specs[s_id_1].spec_current;
let spec_current_2 = specs[s_id_2].spec_current;
let id_1 = specs[s_id_1].list[spec_current_1].id;
let id_2 = specs[s_id_2].list[spec_current_2].id;
if(id_1 > id_2){
let id_3 = id_2;
id_2 = id_1;
id_1 = id_3;
let specs_list = []; //
let ids = []; // id
for(let i in specs){
specs_list.push(specs[i]);
ids.push(specs[i].list[specs[i].spec_current].id);
attributes[specs[i].label_key] = specs[i].list[specs[i].spec_current].value; // label_keyvalue
}
ids.sort(function(a, b){ // id
return a - b;
})
let idPath = ids.join('-'); // ids
let specsValue = specs_list[0].list[specs_list[0].spec_current].value; // value
attributes['sku'] = goods_detail.goods_no +'-'+ specsValue;
par = {
attributes: {
color: specs[s_id_2].list[specs[s_id_2].spec_current].value,
com_id: goods_detail.id,
img: goods_detail.img,
size: specs[s_id_1].list[specs[s_id_1].spec_current].value,
sku: goods_detail.goods_no +'-'+ specs[s_id_1].list[specs[s_id_1].spec_current].value
},
id: stores[id_1 +'-'+ id_2].id,
product_id: stores[id_1 +'-'+ id_2].id,
price: stores[id_1 +'-'+ id_2].price,
store_count: stores[id_1 +'-'+ id_2].store,
attributes: attributes,
id: stores[idPath].id,
product_id: stores[idPath].id,
price: stores[idPath].price,
store_count: stores[idPath].store,
market_price: goods_detail.market_price,
name: goods_detail.name,
qty: this.goods_num
}
have_specs = stores[id_1 +'-'+ id_2].id;
}else{
have_specs = stores[idPath].id; //
}else{ //
par = {
attributes: {
com_id: goods_detail.id,
@ -547,8 +554,8 @@
}
no_specs = goods_detail.id;
}
//
if(this.$isRight(this.seckill)){
if(this.$isRight(this.seckill)){ //
delete par.product_id;
par.seckill_goods_id = this.seckill.item_id;
par.seckill_item_id = this.seckill.id;
@ -556,13 +563,11 @@
par.total = new Bigc(this.goods_num).times(this.seckill.seckill_price).round(2, 0);
}
uni.showLoading({
title: '正在提交'
})
this.show_popup = false;
if(this.click_type == 1){
//
if(this.click_type == 1){ //
this.$http.post({
api: 'api/shopping/cart',
data: {"0": par},
@ -578,8 +583,7 @@
}
uni.hideLoading()
}).catch(err => uni.hideLoading())
}else if(this.click_type == 2){
//
}else if(this.click_type == 2){ //
this.$cookieStorage.set('order_confirm', par);
uni.hideLoading();
this.$url('/pages/order/confirm/confirm');
@ -597,8 +601,7 @@
// }
// uni.hideLoading()
// }).catch(err => uni.hideLoading())
}else if(this.click_type == 3) {
let params = {};
}else if(this.click_type == 3) { //
if(have_specs) {
uni.hideLoading()
this.$url('/pages/order/pointconfirm/confirm?quantity='+this.goods_num+'&product_id='+have_specs+'&goods_type=0')

Loading…
Cancel
Save