【订单详情】

1. 将商品相关的方法挪到最前面
pull/1/MERGE
YunaiV 2023-06-08 21:55:18 +08:00
parent 8b2291d8b4
commit 83a6955778
1 changed files with 255 additions and 253 deletions

View File

@ -520,6 +520,261 @@
},
// #endif
methods: {
// ========== ==========
/**
* 获取产品详情
*/
getGoodsDetails: function() {
ProductSpuApi.getSpuDetail(this.id).then(res => {
let productInfo = res.data;
let spu = res.data;
let skus = res.data.skus;
this.$set(this, 'productInfo', productInfo);
this.$set(this, 'spu', spu);
this.$set(this, 'userCollect', res.data.userCollect); // TODO
this.$set(this.attr, 'properties', ProductUtil.convertProductPropertyList(skus));
this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus));
this.$set(this.sharePacket, 'priceName', res.data.priceName); // TODO share packet
this.$set(this.sharePacket, 'isState', Math.floor(res.data.priceName) === 0);
this.$set(this, 'activityH5', res.data.activityAllH5 ? res.data.activityAllH5 : []);
//
uni.setNavigationBarTitle({
title: productInfo.name.substring(0, 7) + "..."
})
// TODO
if (this.isLogin) {
this.getCartCount();
//#ifdef H5
this.make(this.uid);
this.ShareInfo();
this.getImageBase64(this.productInfo.image);
// #endif
// #ifdef MP
this.getQrcode();
// #endif
}
//
setTimeout(() => {
this.infoScroll();
}, 500);
// #ifdef MP
this.imgTop = spu.picUrl
// #endif
// #ifndef H5
this.downloadFilestoreImage();
// #endif
// sku
this.selectDefaultSku();
}).catch(err => {
return this.$util.Tips({
title: err.toString()
}, {
tab: 3,
url: 1
});
})
},
/**
* 查找默认选中的 sku设置到 attr.productSelect
*
* 先找有库存的 SKU否则找第一个 SKU
*/
selectDefaultSku: function() {
let properties = this.attr.properties;
// "," skuKey = ["", ""]
let skuKey = undefined;
for (let key in this.skuMap) {
if (this.skuMap[key].stock > 0) {
skuKey = key.split(",");
break;
}
}
if (!skuKey) { //
skuKey = Object.keys(this.skuMap)[0].split(",");
}
// 使 index
for (let i = 0; i < properties.length; i++) {
this.$set(properties[i], "index", skuKey[i]);
}
let sku = this.skuMap[skuKey.join(",")];
if (!sku) {
return
}
this.$set(this.attr.productSelect, "spuName", this.spu.name);
this.$set(this.attr.productSelect, "id", sku.id);
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
this.$set(this.attr.productSelect, "price", sku.price);
this.$set(this.attr.productSelect, "stock", sku.stock);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", skuKey.join(","));
},
/**
* 打开 SKU 属性的选择
*/
openAttr: function() {
this.$set(this.attr, 'cartAttr', true);
},
/**
* 关闭 productWindow 弹窗
*/
closeAttr: function () {
this.$set(this.attr, "cartAttr", false);
},
/**
* 属性变动赋值
*
* @param newSkuKey 新的 skuKey
* @param propertyIndex properties 的下标
* @param valueIndex values 的下标
*/
ChangeAttr: function(newSkuKey, propertyIndex, valueIndex) {
// SKU
let sku = this.skuMap[newSkuKey];
if (!sku) {
return;
}
this.$set(this.attr.productSelect, "id", sku.id);
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
this.$set(this.attr.productSelect, "price", sku.price);
this.$set(this.attr.productSelect, "stock", sku.stock);
this.$set(this.attr.productSelect, "cart_num", 1);
// SKU
this.$set(this.attr.properties[propertyIndex], 'index', this.attr.properties[propertyIndex].values[valueIndex].name);
this.$set(this, "attrValue", newSkuKey);
},
/**
* 购物车数量加和数量减
*
* @param changeValue true 增加false 减少
*/
ChangeCartNum: function(changeValue) {
// sku
let sku = this.attr.productSelect;
if (!sku) {
return;
}
//
let stock = sku.stock || 0;
if (changeValue) {
sku.cart_num++;
if (sku.cart_num > stock) {
this.$set(this.attr.productSelect, "cart_num", stock);
this.$set(this, "cart_num", stock);
}
} else {
sku.cart_num--;
if (sku.cart_num < 1) {
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "cart_num", 1);
}
}
},
/**
* 购物车手动填写
*
* @param number 数量
*/
iptCartNum: function(number) {
this.$set(this.attr.productSelect, 'cart_num', number ? number : 1);
},
/**
* 打开属性加入购物车
*/
joinCart: function() {
//
if (!this.isLogin) {
toLogin();
return;
}
// attr
if (!this.attr.cartAttr) {
this.openAttr();
return
}
//
let sku = this.attr.productSelect;
if (sku.stock === 0) {
return that.$util.Tips({
title: "产品库存不足,请选择其它"
});
}
//
TradeCartApi.addCart({
count: sku.cart_num,
skuId: sku.id,
addStatus: true // TODO addStatus
}).then(res => {
// attr
this.attr.cartAttr = false;
//
this.$util.Tips({
title: "添加购物车成功",
success: () => {
this.getCartCount(true);
}
});
}).catch(res => {
this.$util.Tips({
title: res
});
});
},
/**
* 立即购买
*/
goBuy: function() {
//
if (!this.isLogin) {
toLogin();
return;
}
// attr
if (!this.attr.cartAttr) {
this.openAttr();
return;
}
//
let sku = this.attr.productSelect;
uni.navigateTo({
url: '/pages/users/order_confirm/index?skuId=' + sku.id + '&count=' + sku.cart_num
});
},
/**
* 获取购物车数量
*
* @param isAnima 是否展示购物车动画和重置属性
*/
getCartCount: function(isAnima) {
const isLogin = this.isLogin;
if (!isLogin) {
return
}
TradeCartApi.getCartCount().then(res => {
this.cartCount = res.data;
//
if (isAnima) {
this.cartAnimated = true;
setTimeout(() => {
this.cartAnimated = false;
}, 500);
}
});
},
// === TODO ====
kefuClick() {
location.href = this.chatUrl;
},
@ -542,14 +797,6 @@
});
}
},
/**
* 购物车手动填写
*
* @param number 数量
*/
iptCartNum: function(number) {
this.$set(this.attr.productSelect, 'cart_num', number ? number : 1);
},
/**
* 去商品详情页
*/
@ -595,62 +842,6 @@
ChangCouponsClone: function() {
this.$set(this.coupon, 'coupon', false)
},
/**
* 购物车数量加和数量减
*
* @param changeValue true 增加false 减少
*/
ChangeCartNum: function(changeValue) {
// sku
let sku = this.attr.productSelect;
if (!sku) {
return;
}
//
let stock = sku.stock || 0;
if (changeValue) {
sku.cart_num++;
if (sku.cart_num > stock) {
this.$set(this.attr.productSelect, "cart_num", stock);
this.$set(this, "cart_num", stock);
}
} else {
sku.cart_num--;
if (sku.cart_num < 1) {
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "cart_num", 1);
}
}
},
/**
* 属性变动赋值
*
* @param newSkuKey 新的 skuKey
* @param propertyIndex properties 的下标
* @param valueIndex values 的下标
*/
ChangeAttr: function(newSkuKey, propertyIndex, valueIndex) {
// SKU
let sku = this.skuMap[newSkuKey];
if (!sku) {
return;
}
this.$set(this.attr.productSelect, "id", sku.id);
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
this.$set(this.attr.productSelect, "price", sku.price);
this.$set(this.attr.productSelect, "stock", sku.stock);
this.$set(this.attr.productSelect, "cart_num", 1);
// SKU
this.$set(this.attr.properties[propertyIndex], 'index', this.attr.properties[propertyIndex].values[valueIndex].name);
this.$set(this, "attrValue", newSkuKey);
},
/**
* 关闭 productWindow 弹窗
*/
closeAttr: function () {
this.$set(this.attr, "cartAttr", false);
},
/**
* 领取完毕移除当前页面领取过的优惠券展示
*/
@ -690,65 +881,6 @@
})
});
},
/**
* 获取产品详情
*/
getGoodsDetails: function() {
ProductSpuApi.getSpuDetail(this.id).then(res => {
let productInfo = res.data;
let spu = res.data;
let skus = res.data.skus;
this.$set(this, 'productInfo', productInfo);
this.$set(this, 'spu', spu);
this.$set(this, 'userCollect', res.data.userCollect); // TODO
this.$set(this.attr, 'properties', ProductUtil.convertProductPropertyList(skus));
this.$set(this, 'skuMap', ProductUtil.convertProductSkuMap(skus));
this.$set(this.sharePacket, 'priceName', res.data.priceName); // TODO share packet
this.$set(this.sharePacket, 'isState', Math.floor(res.data.priceName) === 0);
this.$set(this, 'activityH5', res.data.activityAllH5 ? res.data.activityAllH5 : []);
//
uni.setNavigationBarTitle({
title: productInfo.name.substring(0, 7) + "..."
})
// TODO
if (this.isLogin) {
this.getCartCount();
//#ifdef H5
this.make(this.uid);
this.ShareInfo();
this.getImageBase64(this.productInfo.image);
// #endif
// #ifdef MP
this.getQrcode();
// #endif
}
//
setTimeout(() => {
this.infoScroll();
}, 500);
// #ifdef MP
this.imgTop = spu.picUrl
// #endif
// #ifndef H5
this.downloadFilestoreImage();
// #endif
// sku
this.selectDefaultSku();
}).catch(err => {
return this.$util.Tips({
title: err.toString()
}, {
tab: 3,
url: 1
});
})
},
getProductReplyList: function() {
getReplyProduct(this.id).then(res => {
this.reply = res.data.productReply ? [res.data.productReply] : [];
@ -771,7 +903,6 @@
},
/**
* 打开地图
*
*/
showMaoLocation: function() {
if (!this.systemStore.latitude || !this.systemStore.longitude) return this.$util.Tips({
@ -787,42 +918,7 @@
});
},
/**
* 查找默认选中的 sku设置到 attr.productSelect
*
* 先找有库存的 SKU否则找第一个 SKU
*/
selectDefaultSku: function() {
let properties = this.attr.properties;
// "," skuKey = ["", ""]
let skuKey = undefined;
for (let key in this.skuMap) {
if (this.skuMap[key].stock > 0) {
skuKey = key.split(",");
break;
}
}
if (!skuKey) { //
skuKey = Object.keys(this.skuMap)[0].split(",");
}
// 使 index
for (let i = 0; i < properties.length; i++) {
this.$set(properties[i], "index", skuKey[i]);
}
let sku = this.skuMap[skuKey.join(",")];
if (!sku) {
return
}
this.$set(this.attr.productSelect, "spuName", this.spu.name);
this.$set(this.attr.productSelect, "id", sku.id);
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
this.$set(this.attr.productSelect, "price", sku.price);
this.$set(this.attr.productSelect, "stock", sku.stock);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", skuKey.join(","));
this.$set(this, "attrTxt", "已选择");
},
/**
* 获取优惠券
*/
@ -873,12 +969,6 @@
}
}
},
/**
* 打开 SKU 属性的选择
*/
openAttr: function() {
this.$set(this.attr, 'cartAttr', true);
},
/**
* 打开优惠券插件
*/
@ -891,94 +981,6 @@
that.$set(that.coupon, 'coupon', true);
}
},
/**
* 打开属性加入购物车
*/
joinCart: function() {
//
if (!this.isLogin) {
toLogin();
return;
}
// attr
if (!this.attr.cartAttr) {
this.openAttr();
return
}
//
let sku = this.attr.productSelect;
if (sku.stock === 0) {
return that.$util.Tips({
title: "产品库存不足,请选择其它"
});
}
//
TradeCartApi.addCart({
count: sku.cart_num,
skuId: sku.id,
addStatus: true // TODO addStatus
}).then(res => {
// attr
this.attr.cartAttr = false;
//
this.$util.Tips({
title: "添加购物车成功",
success: () => {
this.getCartCount(true);
}
});
}).catch(res => {
this.$util.Tips({
title: res
});
});
},
/**
* 获取购物车数量
*
* @param isAnima 是否展示购物车动画和重置属性
*/
getCartCount: function(isAnima) {
const isLogin = this.isLogin;
if (!isLogin) {
return
}
TradeCartApi.getCartCount().then(res => {
this.cartCount = res.data;
//
if (isAnima) {
this.cartAnimated = true;
setTimeout(() => {
this.cartAnimated = false;
}, 500);
}
});
},
/**
* 立即购买
*/
goBuy: function() {
//
if (!this.isLogin) {
toLogin();
return;
}
// attr
if (!this.attr.cartAttr) {
this.openAttr();
return;
}
//
let sku = this.attr.productSelect;
uni.navigateTo({
url: '/pages/users/order_confirm/index?skuId=' + sku.id + '&count=' + sku.cart_num
});
},
//
authColse: function(e) {
this.isShowAuth = e