parent
8b2291d8b4
commit
83a6955778
|
@ -520,177 +520,7 @@
|
|||
},
|
||||
// #endif
|
||||
methods: {
|
||||
kefuClick() {
|
||||
location.href = this.chatUrl;
|
||||
},
|
||||
closeChange: function() {
|
||||
this.$set(this.sharePacket, 'isState', true);
|
||||
},
|
||||
goActivity: function(e) {
|
||||
let item = e;
|
||||
if (item.type === "1") {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/goods_seckill_details/index?id=${item.id}`
|
||||
});
|
||||
} else if (item.type === "2") {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/goods_bargain_details/index?id=${item.id}&startBargainUid=${this.uid}`
|
||||
});
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/goods_combination_details/index?id=${item.id}`
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 购物车手动填写
|
||||
*
|
||||
* @param number 数量
|
||||
*/
|
||||
iptCartNum: function(number) {
|
||||
this.$set(this.attr.productSelect, 'cart_num', number ? number : 1);
|
||||
},
|
||||
/**
|
||||
* 去商品详情页
|
||||
*/
|
||||
goDetail(item) {
|
||||
if (!item.activityH5) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/goods_details/index?id=' + item.id
|
||||
})
|
||||
return
|
||||
}
|
||||
if (item.activityH5.length == 0) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/goods_details/index?id=' + item.id
|
||||
})
|
||||
return
|
||||
}
|
||||
// 砍价
|
||||
if (item.activityH5 && item.activityH5.type == 2) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/activity/goods_bargain_details/index?id=${item.activityH5.id}&bargain=${this.uid}`
|
||||
})
|
||||
return
|
||||
}
|
||||
// 拼团
|
||||
if (item.activityH5 && item.activityH5.type == 3) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/activity/goods_combination_details/index?id=${item.activityH5.id}`
|
||||
})
|
||||
return
|
||||
}
|
||||
// 秒杀
|
||||
if (item.activityH5 && item.activityH5.type == 1) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/activity/goods_seckill_details/index?id=${item.activityH5.id}`
|
||||
})
|
||||
}
|
||||
},
|
||||
// 微信登录回调
|
||||
onLoadFun: function(e) {
|
||||
this.getCouponList();
|
||||
this.getCartCount();
|
||||
},
|
||||
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);
|
||||
},
|
||||
/**
|
||||
* 领取完毕移除当前页面领取过的优惠券展示
|
||||
*/
|
||||
ChangCoupons: function(e) {
|
||||
let coupon = e;
|
||||
let couponList = this.$util.ArrayRemove(this.couponList, 'id', coupon.id);
|
||||
this.$set(this, 'couponList', couponList);
|
||||
this.getCouponList();
|
||||
},
|
||||
|
||||
/**
|
||||
* 优品推荐
|
||||
*/
|
||||
getGoods() {
|
||||
getProductGood().then(res => {
|
||||
let good_list = res.data.list || [];
|
||||
let count = Math.ceil(good_list.length / 6);
|
||||
let goodArray = new Array();
|
||||
for (let i = 0; i < count; i++) {
|
||||
let list = good_list.slice(i * 6, i * 6 + 6);
|
||||
if (list.length) goodArray.push({
|
||||
list: list
|
||||
});
|
||||
}
|
||||
this.$set(this, 'good_list', goodArray);
|
||||
|
||||
// 设置 nav bar
|
||||
let navList = ['商品', '评价', '详情'];
|
||||
if (goodArray.length) {
|
||||
navList.splice(2, 0, '推荐')
|
||||
}
|
||||
this.$set(this, 'navList', navList);
|
||||
this.$nextTick(() => {
|
||||
if (good_list.length) {
|
||||
this.setClientHeight();
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
// ========== 商品详情相关 ==========
|
||||
/**
|
||||
* 获取产品详情
|
||||
*/
|
||||
|
@ -749,44 +579,6 @@
|
|||
});
|
||||
})
|
||||
},
|
||||
getProductReplyList: function() {
|
||||
getReplyProduct(this.id).then(res => {
|
||||
this.reply = res.data.productReply ? [res.data.productReply] : [];
|
||||
})
|
||||
},
|
||||
getProductReplyCount: function() {
|
||||
let that = this;
|
||||
getReplyConfig(that.id).then(res => {
|
||||
that.$set(that, 'replyChance', res.data.replyChance * 100);
|
||||
that.$set(that, 'replyCount', res.data.sumCount);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 拨打电话
|
||||
*/
|
||||
makePhone: function() {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: this.systemStore.phone
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 打开地图
|
||||
*
|
||||
*/
|
||||
showMaoLocation: function() {
|
||||
if (!this.systemStore.latitude || !this.systemStore.longitude) return this.$util.Tips({
|
||||
title: '缺少经纬度信息无法查看地图!'
|
||||
});
|
||||
uni.openLocation({
|
||||
latitude: parseFloat(this.systemStore.latitude),
|
||||
longitude: parseFloat(this.systemStore.longitude),
|
||||
scale: 8,
|
||||
name: this.systemStore.name,
|
||||
address: this.systemStore.address + this.systemStore.detailed_address,
|
||||
success: function() {},
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 查找默认选中的 sku,设置到 attr.productSelect 中
|
||||
*
|
||||
|
@ -821,8 +613,312 @@
|
|||
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", "已选择");
|
||||
},
|
||||
/**
|
||||
* 打开 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;
|
||||
},
|
||||
closeChange: function() {
|
||||
this.$set(this.sharePacket, 'isState', true);
|
||||
},
|
||||
goActivity: function(e) {
|
||||
let item = e;
|
||||
if (item.type === "1") {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/goods_seckill_details/index?id=${item.id}`
|
||||
});
|
||||
} else if (item.type === "2") {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/goods_bargain_details/index?id=${item.id}&startBargainUid=${this.uid}`
|
||||
});
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: `/pages/activity/goods_combination_details/index?id=${item.id}`
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 去商品详情页
|
||||
*/
|
||||
goDetail(item) {
|
||||
if (!item.activityH5) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/goods_details/index?id=' + item.id
|
||||
})
|
||||
return
|
||||
}
|
||||
if (item.activityH5.length == 0) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/goods_details/index?id=' + item.id
|
||||
})
|
||||
return
|
||||
}
|
||||
// 砍价
|
||||
if (item.activityH5 && item.activityH5.type == 2) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/activity/goods_bargain_details/index?id=${item.activityH5.id}&bargain=${this.uid}`
|
||||
})
|
||||
return
|
||||
}
|
||||
// 拼团
|
||||
if (item.activityH5 && item.activityH5.type == 3) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/activity/goods_combination_details/index?id=${item.activityH5.id}`
|
||||
})
|
||||
return
|
||||
}
|
||||
// 秒杀
|
||||
if (item.activityH5 && item.activityH5.type == 1) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/activity/goods_seckill_details/index?id=${item.activityH5.id}`
|
||||
})
|
||||
}
|
||||
},
|
||||
// 微信登录回调
|
||||
onLoadFun: function(e) {
|
||||
this.getCouponList();
|
||||
this.getCartCount();
|
||||
},
|
||||
ChangCouponsClone: function() {
|
||||
this.$set(this.coupon, 'coupon', false)
|
||||
},
|
||||
/**
|
||||
* 领取完毕移除当前页面领取过的优惠券展示
|
||||
*/
|
||||
ChangCoupons: function(e) {
|
||||
let coupon = e;
|
||||
let couponList = this.$util.ArrayRemove(this.couponList, 'id', coupon.id);
|
||||
this.$set(this, 'couponList', couponList);
|
||||
this.getCouponList();
|
||||
},
|
||||
|
||||
/**
|
||||
* 优品推荐
|
||||
*/
|
||||
getGoods() {
|
||||
getProductGood().then(res => {
|
||||
let good_list = res.data.list || [];
|
||||
let count = Math.ceil(good_list.length / 6);
|
||||
let goodArray = new Array();
|
||||
for (let i = 0; i < count; i++) {
|
||||
let list = good_list.slice(i * 6, i * 6 + 6);
|
||||
if (list.length) goodArray.push({
|
||||
list: list
|
||||
});
|
||||
}
|
||||
this.$set(this, 'good_list', goodArray);
|
||||
|
||||
// 设置 nav bar
|
||||
let navList = ['商品', '评价', '详情'];
|
||||
if (goodArray.length) {
|
||||
navList.splice(2, 0, '推荐')
|
||||
}
|
||||
this.$set(this, 'navList', navList);
|
||||
this.$nextTick(() => {
|
||||
if (good_list.length) {
|
||||
this.setClientHeight();
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
getProductReplyList: function() {
|
||||
getReplyProduct(this.id).then(res => {
|
||||
this.reply = res.data.productReply ? [res.data.productReply] : [];
|
||||
})
|
||||
},
|
||||
getProductReplyCount: function() {
|
||||
let that = this;
|
||||
getReplyConfig(that.id).then(res => {
|
||||
that.$set(that, 'replyChance', res.data.replyChance * 100);
|
||||
that.$set(that, 'replyCount', res.data.sumCount);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 拨打电话
|
||||
*/
|
||||
makePhone: function() {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: this.systemStore.phone
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 打开地图
|
||||
*/
|
||||
showMaoLocation: function() {
|
||||
if (!this.systemStore.latitude || !this.systemStore.longitude) return this.$util.Tips({
|
||||
title: '缺少经纬度信息无法查看地图!'
|
||||
});
|
||||
uni.openLocation({
|
||||
latitude: parseFloat(this.systemStore.latitude),
|
||||
longitude: parseFloat(this.systemStore.longitude),
|
||||
scale: 8,
|
||||
name: this.systemStore.name,
|
||||
address: this.systemStore.address + this.systemStore.detailed_address,
|
||||
success: function() {},
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* 获取优惠券
|
||||
*/
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue