This commit is contained in:
2025-10-27 15:55:29 +08:00
commit 6632080b83
513 changed files with 117442 additions and 0 deletions

View File

@@ -0,0 +1,599 @@
export default {
data() {
return {
cartData: [], // 购物车
checkAll: true,
totalPrice: '0.00',
totalCount: 0,
isSub: false,
invalidGoods: [], // 失效商品集合
isIphoneX: false, //判断手机是否是iphoneX以上,
isAction: false, // 是否操作删除
goodsSkuDetail: null,
discount: {},
manjian: {},
receiveSub: false,
discountPopupShow: false,
startX: '', // 触摸开始位置
endX: '', // 触摸结束位置
refresherTriggered: false, // 设置当前下拉刷新状态true 表示下拉刷新已经被触发false 表示下拉刷新未被触发
timeout: {}
};
},
onLoad() {
uni.hideTabBar();
this.isIphoneX = this.$util.uniappIsIPhoneX();
},
onShow() {
if (this.storeToken) {
this.getCartData();
} else {
this.cartData = [];
this.invalidGoods = [];
this.calculationTotalPrice();
}
},
onHide() {
this.isAction = false;
},
onUnload() {
if (!this.storeToken && this.$refs.login) this.$refs.login.cancelCompleteInfo();
},
onReady() {
if (!this.storeToken) {
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
}
},
computed: {
hasData() {
return this.cartData.length > 0 || this.invalidGoods.length > 0;
}
},
methods: {
initNum(item) {
let max_buy = item.max_buy > 0 && item.max_buy < item.stock ? item.max_buy : item.stock;
max_buy = max_buy == 0 ? 1 : max_buy;
if (item.num > max_buy) return max_buy;
return item.num;
},
/**
* 获取购物车数据
*/
getCartData() {
this.$api.sendRequest({
url: '/api/cart/goodslists',
success: res => {
if (res.code >= 0) {
if (res.data.length) this.handleCartData(res.data);
else this.cartData = [];
}
this.refresherTriggered = false;
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
},
fail: res => {
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
}
});
},
/**
* 处理购物车数据结构
*/
handleCartData(data) {
this.invalidGoods = [];
this.cartData = [];
var temp = {};
data.forEach((item, index) => {
if (item.goods_state == 1) {
if (item.store_goods_status != undefined && item.store_goods_status != 1) {
this.invalidGoods.push(item);
} else if (item.min_buy > 0 && item.min_buy > item.stock) {
// 如果最小限购超出库存则该商品失效
this.invalidGoods.push(item);
} else {
item.checked = true;
item.edit = false;
if (temp['site_' + item.site_id] != undefined) {
temp['site_' + item.site_id].cartList.push(item);
} else {
temp['site_' + item.site_id] = {
siteId: item.site_id,
siteName: item.site_name,
edit: false,
checked: true,
cartList: [item]
};
}
}
} else {
this.invalidGoods.push(item);
}
});
this.cartData = [];
Object.keys(temp).forEach(key => {
this.cartData.push(temp[key]);
});
this.calculationTotalPrice();
if (this.cartData.length) {
this.cartData[0].cartList.forEach(v => {
if (v.sku_spec_format) {
v.sku_spec_format = JSON.parse(v.sku_spec_format);
} else {
v.sku_spec_format = [];
}
});
}
if (this.invalidGoods.length) {
this.invalidGoods.forEach(v => {
if (v.sku_spec_format) {
v.sku_spec_format = JSON.parse(v.sku_spec_format);
} else {
v.sku_spec_format = [];
}
});
}
},
/**
* 单选
* @param siteIndex
* @param index
*/
singleElection(siteIndex, index) {
this.cartData[siteIndex].cartList[index].checked = !this.cartData[siteIndex].cartList[index].checked;
this.calculationTotalPrice();
},
/**
* 店铺全选
* @param checked
* @param index
*/
siteAllElection(checked, index) {
this.cartData[index].checked = checked;
this.cartData[index].cartList.forEach(item => {
item.checked = checked;
});
this.calculationTotalPrice();
},
/**
* 全选
*/
allElection(checked) {
if (typeof checked == 'boolean') {
this.checkAll = checked;
} else {
this.checkAll = !this.checkAll;
}
if (this.cartData.length) {
this.cartData.forEach(siteItem => {
siteItem.checked = this.checkAll;
siteItem.cartList.forEach(item => {
item.checked = this.checkAll;
});
});
}
this.calculationTotalPrice();
},
/**
* 计算购物车总价
*/
calculationTotalPrice() {
if (this.cartData.length) {
let totalPrice = 0,
totalCount = 0,
siteAllElectionCount = 0;
this.cartData.forEach(siteItem => {
let siteGoodsCount = 0;
siteItem.cartList.forEach(item => {
if (item.checked) {
siteGoodsCount += 1;
totalCount += parseInt(item.num);
if (Number(item.member_price) > 0 && Number(item.member_price) < Number(item.discount_price)) {
totalPrice += item.member_price * item.num;
} else {
totalPrice += item.discount_price * item.num;
}
}
});
if (siteItem.cartList.length == siteGoodsCount) {
siteItem.checked = true;
siteAllElectionCount += 1;
} else {
siteItem.checked = false;
}
});
this.totalPrice = totalPrice.toFixed(2);
this.totalCount = totalCount;
this.checkAll = this.cartData.length == siteAllElectionCount;
} else {
this.totalPrice = '0.00';
this.totalCount = 0;
}
this.discountCalculate();
},
/**
* 删除购物车
* @param tag
* @param siteIndex
* @param cartIndex
*/
deleteCart(tag, siteIndex, cartIndex) {
var cart_id = [];
if (tag == 'all') {
for (let i = 0; i < this.cartData.length; i++) {
for (let j = 0; j < this.cartData[i].cartList.length; j++) {
if (this.cartData[i].cartList[j].checked) cart_id.push(this.cartData[i].cartList[j].cart_id);
}
}
} else {
cart_id.push(this.cartData[siteIndex].cartList[cartIndex].cart_id);
}
if (cart_id.length == 0) {
this.$util.showToast({
title: '请选择要删除的商品'
});
return;
}
uni.showModal({
title: '提示',
content: cart_id.length > 1 ? '确定要删除这些商品吗?' : '确定要删除该商品吗?',
success: res => {
if (res.confirm) {
cart_id = cart_id.toString();
this.$api.sendRequest({
url: '/api/cart/delete',
data: {
cart_id
},
success: res => {
if (res.code >= 0) {
if (tag == 'all') {
// 全选
for (var i = 0; i < this.cartData.length; i++) {
for (var j = 0; j < this.cartData[i].cartList.length; j++) {
var item = this.cartData[i].cartList[j];
if (item.checked) {
this.cartData[i].cartList.splice(j, 1);
j = -1;
}
}
if (this.cartData[i].cartList.length == 0) {
this.cartData.splice(i, 1);
i = -1;
}
}
this.$store.dispatch('emptyCart');
} else {
let item = this.cartData[siteIndex].cartList;
let goods_id = item[cartIndex].goods_id;
let sku_id = item[cartIndex].sku_id;
delete this.cartList['goods_' + goods_id]['sku_' + sku_id];
if (Object.keys(this.cartList['goods_' + goods_id]).length == 2) {
delete this.cartList['goods_' + goods_id];
}
this.$store.dispatch('cartCalculate');
item.splice(cartIndex, 1);
if (item.length == 0) this.cartData.splice(siteIndex, 1);
}
this.resetEditStatus();
this.calculationTotalPrice();
} else {
this.$util.showToast({
title: res.message
});
}
}
});
}
}
});
},
/**
* 变更购物车数量
* @param {Object} params
*/
cartNumChange(num, params) {
if (isNaN(num)) return;
let data = this.cartData[params.siteIndex].cartList[params.cartIndex],
max_buy = data.is_limit && data.max_buy > 0 && data.max_buy < data.stock ? data.max_buy : data.stock,
min_buy = data.min_buy > 0 ? data.min_buy : 1;
if (num > max_buy) num = max_buy;
if (num < min_buy) num = min_buy;
let cartId = this.cartData[params.siteIndex].cartList[params.cartIndex].cart_id
if (this.timeout[cartId]) clearTimeout(this.timeout[cartId])
this.timeout[cartId] = setTimeout(() => {
this.$api.sendRequest({
url: '/api/cart/edit',
data: {
num,
cart_id: cartId
},
success: res => {
if (res.code >= 0) {
let item = this.cartData[params.siteIndex].cartList[params.cartIndex];
let goods_id = item.goods_id;
let sku_id = item.sku_id;
item.num = num;
this.cartList['goods_' + goods_id]['sku_' + sku_id].num = num;
this.$store.dispatch('cartCalculate');
this.resetEditStatus();
this.calculationTotalPrice();
} else {
this.$util.showToast({
title: res.message
});
}
}
});
}, 800)
},
/**
* 结算
*/
settlement() {
if (this.totalCount > 0) {
let cart_ids = [];
this.cartData.forEach(siteItem => {
siteItem.cartList.forEach(item => {
if (item.checked) {
cart_ids.push(item.cart_id);
}
});
});
if (this.discount.coupon_info && this.discount.coupon_info.receive_type == 'wait') this.receiveCoupon(
this.discount.coupon_info.coupon_type_id, false);
if (this.isSub) return;
this.isSub = true;
uni.removeStorageSync('delivery');
uni.setStorage({
key: 'orderCreateData',
data: {
cart_ids: cart_ids.toString()
},
success: () => {
this.$util.redirectTo('/pages/order/payment');
this.isSub = false;
}
});
}
},
/**
* 清空失效商品
*/
clearInvalidGoods() {
uni.showModal({
title: '提示',
content: '确定要清空这些商品吗?',
success: res => {
if (res.confirm) {
var cart_ids = [];
this.invalidGoods.forEach(goodsItem => {
cart_ids.push(goodsItem.cart_id);
});
if (cart_ids.length) {
this.$api.sendRequest({
url: '/api/cart/delete',
data: {
cart_id: cart_ids.toString()
},
success: res => {
if (res.code >= 0) {
this.invalidGoods = [];
this.refreshCartNumber();
} else {
this.$util.showToast({
title: res.message
});
}
}
});
}
}
}
});
},
imageError(siteIndex, cartIndex) {
this.cartData[siteIndex].cartList[cartIndex].sku_image = this.$util.getDefaultImage().goods;
this.$forceUpdate();
},
toGoodsDetail(item) {
this.$util.redirectTo('/pages/goods/detail', {
sku_id: item.sku_id
});
},
// 购物车数量
refreshCartNumber() {
if (this.storeToken) {
this.$store.dispatch('getCartNumber');
this.resetEditStatus();
}
},
goodsLimit(event, params) {
let data = this.cartData[params.siteIndex].cartList[params.cartIndex];
if (event.type == 'plus') {
if (data.max_buy > 0 && data.max_buy < data.stock) {
this.$util.showToast({
title: '该商品每人限购' + data.max_buy + '件'
});
} else {
this.$util.showToast({
title: '库存不足'
});
}
} else {
// 数量减至最少时,则删除商品
this.deleteCart('single', params.siteIndex, params.cartIndex);
// this.$util.showToast({
// title: '最少购买' + event.value + '件'
// });
}
},
toLogin() {
this.$refs.login.open();
},
// 重置编辑状态
resetEditStatus() {
if (this.cartData.length) {
for (var i = 0; i < this.cartData[0].cartList.length; i++) {
this.cartData[0].cartList[i].edit = false;
}
this.$forceUpdate();
}
},
changeAction() {
this.isAction = !this.isAction;
this.resetEditStatus();
},
selectSku(data) {
let goodsSkuDetail = this.$util.deepClone(data);
if (goodsSkuDetail.goods_spec_format) goodsSkuDetail.goods_spec_format = JSON.parse(goodsSkuDetail.goods_spec_format);
this.goodsSkuDetail = goodsSkuDetail;
this.$nextTick(() => {
this.$refs.selectSku.show('confirm', (sku_id, num) => {
this.$api.sendRequest({
url: '/api/cart/editcartsku',
data: {
cart_id: data.cart_id,
sku_id: sku_id,
num: num
},
success: res => {
if (res.code >= 0) {
this.invalidGoods = [];
this.getCartData();
this.refreshCartNumber();
} else {
this.$util.showToast({
title: res.message
});
}
}
});
}, this.goodsSkuDetail);
})
},
toggleDiscountPopup() {
if (this.$refs.discountPopup.showPopup) this.$refs.discountPopup.close();
else this.$refs.discountPopup.open();
this.discountPopupShow = !this.discountPopupShow;
},
/**
* 优惠信息计算
*/
discountCalculate() {
if (this.cartData.length == 0) return;
let skuIds = [];
this.cartData.forEach(siteItem => {
siteItem.cartList.forEach(item => {
if (item.checked) {
skuIds.push({
sku_id: item.sku_id,
num: item.num
});
}
});
});
if (skuIds.length == 0) {
this.discount = {};
return;
}
this.$api.sendRequest({
url: '/api/cartcalculate/calculate',
data: {
sku_ids: JSON.stringify(skuIds)
},
success: res => {
if (res.code >= 0 && res.data && (res.data.coupon_money > 0 || res.data.promotion_money > 0)) {
this.discount = res.data;
let manjian = {};
res.data.goods_list.forEach(item => {
if (item.promotion && item.promotion.manjian) {
manjian['sku_' + item.sku_id] = JSON.parse(item.promotion.manjian.rule_json);
}
})
Object.assign(this.manjian, manjian);
this.refresherTriggered = false;
} else {
this.discount = {};
}
}
})
},
/**
* 领取优惠券
* tips 失败时是否提示
* @param {Object} couponTypeId
*/
receiveCoupon(couponTypeId, tips = true) {
if (this.receiveSub) return;
this.receiveSub = true;
this.$api.sendRequest({
url: '/coupon/api/coupon/receive',
data: {
coupon_type_id: couponTypeId,
get_type: 2 //获取方式:1订单2.直接领取3.活动领取
},
success: res => {
if (res.code == 0) {
this.$set(this.discount.coupon_info, 'receive_type', '');
} else {
if (tips) this.$util.showToast({
title: res.message
});
this.receiveSub = false;
}
}
});
},
// 手指触摸事件 用于菜单左滑
touchS(e) {
this.startX = e.touches[0].clientX;
// console.log('开始' + e.touches[0].clientX);
},
touchE(e, cartIndex) {
this.endX = e.changedTouches[0].clientX;
// 触摸开始到停止的差值小于0左滑大于0右滑
var disX = this.startX - this.endX;
// cartIndex.edit = disX > 50;
if (disX > 50) cartIndex.edit = true;
else if (disX < 0) cartIndex.edit = false;
this.$forceUpdate();
},
moneyFormat(money) {
if (isNaN(parseFloat(money))) return money;
return parseFloat(money).toFixed(2);
},
refreshSkuDetail(goodsSkuDetail) {
this.goodsSkuDetail = goodsSkuDetail;
},
onRefresh(e) {
this.refresherTriggered = true;
if (this.storeToken) {
this.getCartData();
this.refreshCartNumber();
} else {
this.cartData = [];
this.invalidGoods = [];
this.calculationTotalPrice();
}
}
},
}

View File

@@ -0,0 +1,525 @@
export default {
data() {
return {
goodsRoute: '/pages/goods/detail',
couponList: [], //优惠券列表
couponBtnSwitch: false, //获取优惠券防止重复提交
posterApi: '/api/goods/poster',
//满减活动
manjian: {
type: 0,
manjian_name: "",
rule_json: null
},
//组合套餐
bundlingType: false,
bundling: [{
bundling_goods: {
bl_name: '',
sku_image: ''
}
}],
membercard: null, // 会员卡信息
hackReset: true,
cardOff: false,
informationform:[]//留言表单
}
},
computed: {
showDiscount() {
var flag = false;
if (
this.preview == 0 &&
this.addonIsExist.discount &&
this.goodsSkuDetail.promotion_type == 1 &&
this.goodsSkuDetail.discountTimeMachine &&
(!this.goodsSkuDetail.member_price || (this.goodsSkuDetail.member_price > 0 && Number(this.goodsSkuDetail.member_price) > Number(this.goodsSkuDetail.discount_price))
)
) {
flag = true;
}
return flag;
},
memberCardDiscount() {
let discount = 0,
showPrice = this.goodsSkuDetail.member_price > 0 && Number(this.goodsSkuDetail.member_price) < Number(this.goodsSkuDetail.discount_price) ? this.goodsSkuDetail.member_price : this.goodsSkuDetail.discount_price;
if (this.membercard && this.membercard.member_price > 0 && (parseFloat(showPrice) > parseFloat(this.membercard.member_price))) {
discount = parseFloat(showPrice) - parseFloat(this.membercard.member_price);
}
return discount.toFixed(2);
},
//表单高度
FormHeight(){
let height = 48;
if (this.goodsForm && this.goodsForm.length) {
height += this.goodsForm.length * 5;
}
height += 'vh';
return height;
}
},
onLoad(data) {
// #ifdef MP-ALIPAY
let options = my.getLaunchOptionsSync();
options.query && Object.assign(data, options.query)
// #endif
this.skuId = data.sku_id || 0;
this.goodsId = data.goods_id || 0;
// 小程序扫码进入
if (data.scene) {
var sceneParams = decodeURIComponent(data.scene);
sceneParams = sceneParams.split('&');
if (sceneParams.length) {
sceneParams.forEach(item => {
if (item.indexOf('goods_id') != -1) this.goodsId = item.split('-')[1];
});
}
}
// #ifdef MP-WEIXIN
this.getShareImg();
// #endif
},
async onShow() {
//同步获取商品详情
await this.getGoodsSkuDetail();
},
onHide() {
this.couponBtnSwitch = false;
},
methods: {
//拨打电话
phoneClick(mobile){
uni.makePhoneCall({
phoneNumber: mobile+'',
success(){},
fail(){}
})
},
setSkuId(val) {
if (val) {
this.skuId = val;
this.getBundling();
}
},
// 获取商品详情
async getGoodsSkuDetail() {
let res = await this.$api.sendRequest({
url: '/api/goodssku/detail',
async: false,
data: {
sku_id: this.skuId,
goods_id: this.goodsId,
}
});
let data = res.data;
if (data.goods_sku_detail != null) {
if (data.goods_sku_detail.promotion_type == 'presale' && data.goods_sku_detail.presale_id) {
this.$util.redirectTo('/pages_promotion/presale/detail', {
id: data.goods_sku_detail.presale_id,
sku_id: this.skuId
}, 'reLaunch');
return;
}
if(uni.getStorageSync('lang') == 'en-us') data.goods_sku_detail.goods_name = data.goods_sku_detail.en_goods_name
this.goodsSkuDetail = data.goods_sku_detail;
if (!this.skuId) this.skuId = this.goodsSkuDetail.sku_id;
if (!this.goodsId) this.goodsId = this.goodsSkuDetail.goods_id;
// 分享参数、链接
this.shareQuery = 'goods_id=' + this.goodsSkuDetail.goods_id;
this.shareUrl = this.goodsRoute + '?' + this.shareQuery;
// 在线客服聊天参数
this.chatRoomParams = {
sku_id: this.goodsSkuDetail.sku_id
};
let typeId = this.goodsSkuDetail.goods_promotion[0];
if (typeId) {
// 限时折扣
if (typeId.discount_id) {
this.chatRoomParams.type = 'discount'
this.chatRoomParams.type_id = typeId.discount_id
}
}
// 海报参数
this.posterParams = {
goods_id: this.goodsId
};
// 处理商品数据
this.handleGoodsSkuData();
// 限时折扣
if (this.goodsSkuDetail.promotion_type == 1 && this.addonIsExist.discount) {
//检测倒计时
if ((this.goodsSkuDetail.end_time - res.timestamp) > 0) {
this.goodsSkuDetail.discountTimeMachine = this.$util.countDown(this.goodsSkuDetail.end_time - res.timestamp);
} else {
this.goodsSkuDetail.promotion_type = 0;
}
}
if (this.goodsSkuDetail.promotion_type == 1 && this.goodsSkuDetail.discountTimeMachine) {
if (this.goodsSkuDetail.member_price > 0 && Number(this.goodsSkuDetail.member_price) <= Number(this.goodsSkuDetail.discount_price)) {
this.goodsSkuDetail.show_price = this.goodsSkuDetail.member_price;
} else {
this.goodsSkuDetail.show_price = this.goodsSkuDetail.discount_price;
}
} else {
if (this.goodsSkuDetail.member_price > 0) {
this.goodsSkuDetail.show_price = this.goodsSkuDetail.member_price;
} else {
this.goodsSkuDetail.show_price = this.goodsSkuDetail.price;
}
}
// 满减
if (this.goodsSkuDetail.manjian) {
this.getManjian(this.goodsSkuDetail.manjian);
}
// 会员卡
if (this.goodsSkuDetail.membercard) {
this.membercard = this.goodsSkuDetail.membercard;
}
// 优惠券
if (this.goodsSkuDetail.coupon_list) {
this.couponList = this.goodsSkuDetail.coupon_list;
this.couponList.forEach(v => {
if (v.count == v.lead_count) v.useState = 2;
else if (v.max_fetch != 0 && v.member_coupon_num && v.member_coupon_num >= v.max_fetch) v.useState = 1;
else v.useState = 0;
});
this.couponList = this.couponList.sort(this.sortBy('useState'))
}
// 组合套餐
// if (this.goodsSkuDetail.bundling_list) {
// this.handleBundlingData(this.goodsSkuDetail.bundling_list);
// }
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
} else {
this.$util.redirectTo('/pages_tool/goods/not_exist', {}, 'redirectTo');
}
},
choiceSku() {
this.$refs.goodsSku.show("buy_now", () => {
this.$store.dispatch('getCartNumber');
});
},
//商品留言打开
showinformation(){
this.informationform = this.goodsSkuDetail.goods_form
this.$refs.informationPopup.open();
},
//商品留言关闭
closeinformationPopup(){
this.$refs.informationPopup.close();
},
//保存商品留言
saveubfirnation(){
//缺少
if (!this.$refs.form.verify()) return;
// uni.setStorageSync('goodFormData', {
// goods_id: this.goodsSkuDetail.goods_id,
// form_data: this.$refs.form.formData
// });
this.$api.sendRequest({
url: '/api/goods/information',
data: {
goods_id: this.goodsSkuDetail.goods_id,
form_data: JSON.stringify(this.$refs.form.formData)
},
success: res => {
var data = res.data;
if (res.code == 0) {
}else{
this.$util.showToast({
title: res.msg
});
}
},
});
},
// 加入购物车
joinCart() {
if (!this.storeToken && this.preview == 0) {
this.$refs.login.open(this.shareUrl);
return;
}
if (this.goodsSkuDetail.is_virtual == 1) {
this.$refs.goodsSku.show("buy_now", () => {
this.$store.dispatch('getCartNumber');
});
} else {
this.$refs.goodsSku.show("join_cart", () => {
this.$store.dispatch('getCartNumber');
});
}
},
// 立即购买
buyNow() {
if (!this.storeToken && this.preview == 0) {
this.$refs.login.open(this.shareUrl);
return;
}
this.$refs.goodsSku.show("buy_now", () => {
});
},
sortBy(field) {
//根据传过来的字段进行排序,y-x 得分从高到低x-y 从低到高
return (y, x) => {
return y[field] - x[field]
}
},
// 打开优惠券弹出层
openCouponPopup() {
this.$refs.couponPopup.open();
},
// 关闭优惠券弹出层
closeCouponPopup() {
this.$refs.couponPopup.close();
},
// 领取优惠券
receiveCoupon(item) {
let that = this;
if (this.preview) return; // 开启预览,禁止任何操作和跳转
if (this.couponBtnSwitch) return;
this.couponBtnSwitch = true;
if (this.storeToken) {
this.$api.sendRequest({
url: '/coupon/api/coupon/receive',
data: {
coupon_type_id: item.coupon_type_id,
get_type: 2 //获取方式:1订单2.直接领取3.活动领取
},
success: res => {
var data = res.data;
let msg = '';
let list = this.couponList;
if (res.data.is_exist == 1 && res.code < 0) {
msg = '您已领取过该优惠券,快去使用吧';
} else if (res.code == 0) {
msg = '领取成功,快去使用吧';
} else {
msg = res.message;
}
if (res.data.is_exist == 1) {
for (let i = 0; i < list.length; i++) {
if (list[i].coupon_type_id == item.coupon_type_id) {
that.$set(that.couponList[i], 'useState', 1);
}
}
} else {
for (let i = 0; i < list.length; i++) {
if (list[i].coupon_type_id == item.coupon_type_id) {
that.$set(that.couponList[i], 'useState', 2);
}
}
}
this.$util.showToast({
title: msg
});
that.$forceUpdate()
this.hackReset = false;
this.$nextTick(() => {
this.hackReset = true;
})
this.couponBtnSwitch = false;
},
});
} else {
this.$refs.login.open(this.shareUrl);
this.couponBtnSwitch = false;
}
},
//-------------------------------------满减-------------------------------------
//获取满减信息
getManjian(data) {
this.manjian = data;
let limit = data.type == 0 ? '元' : '件';
Object.keys(data.rule_json).forEach((key) => {
var item = data.rule_json[key];
if (item.coupon_data) {
for (var i = 0; i < item.coupon_data.length; i++) {
item.coupon_data[i].coupon_num = item.coupon_num[i]
}
}
item.limit = data.type == 0 ? parseFloat(item.limit).toFixed(2) : parseInt(item.limit);
// 满减
if (item.discount_money != undefined) {
if (this.manjian.manjian == undefined) {
this.manjian.manjian = '满' + item.limit + limit + '减' + item.discount_money + '元';
} else {
this.manjian.manjian += ';满' + item.limit + limit + '减' + item.discount_money + '元';
}
}
// 满送
if (item.point != undefined || item.coupon != undefined) {
let text = '';
if (item.point != undefined) {
text = '送' + item.point + '积分';
}
if (item.coupon != undefined && item.coupon_data != undefined) {
item.coupon_data.forEach((couponItem, couponIndex) => {
if (couponItem.type == 'discount') {
if (text == '') text = '送' + item.coupon_num[couponIndex] + '张' + parseFloat(couponItem.discount) + '折优惠券';
else text += '、送' + item.coupon_num[couponIndex] + '张' + parseFloat(couponItem.discount) + '折优惠券';
} else {
if (text == '') text = '送' + item.coupon_num[couponIndex] + '张' + parseFloat(couponItem.money) + '元优惠券';
else text += '、送' + item.coupon_num[couponIndex] + '张' + parseFloat(couponItem.money) + '元优惠券';
}
})
}
if (this.manjian.mansong == undefined) {
this.manjian.mansong = '满' + item.limit + limit + text;
} else {
this.manjian.mansong += '' + '满' + item.limit + limit + text;
}
}
// 包邮
if (item.free_shipping != undefined) {
if (this.manjian.free_shipping == undefined) {
this.manjian.free_shipping = '满' + item.limit + limit + '包邮';
} else {
this.manjian.free_shipping += ';满' + item.limit + limit + '包邮';
}
}
});
},
openManjianPopup() {
this.$refs.manjianPopup.open();
},
closeManjianPopup() {
this.$refs.manjianPopup.close();
},
//-------------------------------------组合套餐-------------------------------------
//获取当前商品关联的组合套餐
getBundling() {
// 连锁门店没有营销活动
if (this.globalStoreConfig && this.globalStoreConfig.store_business == 'store') return;
this.$api.sendRequest({
url: "/bundling/api/bundling/lists",
data: {
sku_id: this.skuId
},
success: res => {
// this.handleBundlingData(res.data);
}
});
},
handleBundlingData(data) {
this.bundling = data;
if (this.bundling.length) {
for (var i = 0; i < this.bundling[0].bundling_goods.length; i++) {
if (this.bundling[0].bundling_goods[i].sku_id == this.skuId) {
this.bundlingType = true;
break;
} else {
this.bundlingType = false;
}
}
for (var i = 0; i < this.bundling.length; i++) {
for (var j = 0; j < this.bundling[i].bundling_goods.length; j++) {
if (this.bundling[i].bundling_goods[j].sku_id == this.skuId) {
this.bundling[i].bundling_goods.splice(j, 1);
}
}
}
}
},
// 打开组合套餐弹出层
openBundlingPopup() {
this.$refs.bundlingPopup.open();
},
// 关闭组合套餐弹出层
closeBundlingPopup() {
this.$refs.bundlingPopup.close();
},
imageError() {
this.goodsSkuDetail.sku_image = this.$util.getDefaultImage().goods;
this.$forceUpdate();
},
bundlingImageError(index, goods_index) {
this.bundling[index].bundling_goods[goods_index].sku_image = this.$util.getDefaultImage().goods;
this.$forceUpdate();
},
fenxiao() {
this.$refs.fenxiaoPopup.show()
},
toGoodsDetail(item) {
this.$util.redirectTo(this.goodsRoute, {
sku_id: item
});
},
toComoDetail(id) {
this.$util.redirectTo('/pages_promotion/bundling/detail', {
bl_id: id
});
},
/**
* 获取分享图
*/
getShareImg() {
let posterParams = {
goods_id: this.goodsId
};
this.$api.sendRequest({
url: '/api/goods/shareimg',
data: {
qrcode_param: JSON.stringify(posterParams)
},
success: res => {
if (res.code == 0) this.shareImg = res.data.path + '?no=' + parseInt((new Date()).getTime() / 1000);
}
})
},
/**
* 金额格式化输出
* @param {Object} money
*/
decimalPointFormat(money) {
if (isNaN(parseFloat(money))) return money;
let arr = money.toString().split(".");
let arr1 = arr[1].split("").reverse();
let arr2 = [];
arr1.forEach((item, index) => {
if (item > 1) {
arr2 = arr1.splice(index);
}
});
let str = arr2.length ? (arr[0] + "." + arr2.reverse().join("")) : arr[0];
return str;
}
}
}

View File

@@ -0,0 +1,467 @@
export default {
data() {
return {
listStyle: '',
loadingType: 'loading', //加载更多状态
orderType: '',
priceOrder: 'desc', //1 价格从低到高 2价格从高到低
categoryList: [], //排序类型
goodsList: [],
order: '',
sort: 'desc',
showScreen: false,
keyword: '',
categoryId: 0,
minPrice: '',
maxPrice: '',
isFreeShipping: false, //是否免邮
isIphoneX: false,
coupon: 0,
emptyShow: false,
isList: true, //列表样式
//分享所需标题
share_title: '',
//搜索到多少件商品
count: 0,
//当前分类名称
category_title: '',
//优惠券数据
coupon_name: '',
//列表瀑布流数据
listHeight: [],
listPosition: [],
debounce: null,
brandId: 0,
brandList: [], //品牌筛选项
config: {
fontWeight: false,
padding: 0,
cartEvent: "detail",
text: "购买",
textColor: "#FFFFFF",
theme: "default",
aroundRadius: 25,
control: true,
bgColor: "#FF6A00",
style: "button",
iconDiy: {
iconType: "icon",
icon: "",
style: {
fontSize: "60",
iconBgColor: [],
iconBgColorDeg: 0,
iconBgImg: "",
bgRadius: 0,
iconColor: [
"#000000"
],
iconColorDeg: 0
}
}
},
langstatus:0,
lang:uni.getStorageSync('lang')
}
},
onLoad(options) {
this.$api.sendRequest({
url: '/api/lucky/status',
data: {},
success: res => {
console.log(res)
this.langstatus = res.status
if(this.langstatus == 1){
// this.$langConfig.refresh();
uni.setNavigationBarTitle({
title:uni.getStorageSync('lang') == 'en-us'?'Goods List':'商品列表'
})
}
}
});
this.categoryId = options.category_id || 0;
this.keyword = options.keyword || '';
this.coupon = options.coupon || 0;
this.goods_id_arr = options.goods_id_arr || 0;
this.brandId = options.brand_id || 0;
this.loadCategoryList(this.categoryId);
this.getBrandList();
this.isIphoneX = this.$util.uniappIsIPhoneX();
//小程序分享接收source_member
if (options.source_member) {
uni.setStorageSync('source_member', options.source_member);
}
// 小程序扫码进入接收source_member
if (options.scene) {
var sceneParams = decodeURIComponent(options.scene);
sceneParams = sceneParams.split('&');
if (sceneParams.length) {
sceneParams.forEach(item => {
if (item.indexOf('sku_id') != -1) this.skuId = item.split('-')[1];
if (item.indexOf('m') != -1) uni.setStorageSync('source_member', item.split('-')[1]);
if (item.indexOf('is_test') != -1) uni.setStorageSync('is_test', 1);
});
}
}
uni.onWindowResize(res => {
if (this.debounce) clearTimeout(this.debounce);
this.waterfallflow(0);
})
},
onShow() {
//记录分享关系
if (this.storeToken && uni.getStorageSync('source_member')) {
this.$util.onSourceMember(uni.getStorageSync('source_member'));
}
},
/**
* 转发分享
*/
onShareAppMessage(res) {
var title = '搜索到' + this.count + '件“' + this.keyword + this.category_title + this.coupon_name + '”相关的优质商品';
let route = this.$util.getCurrentShareRoute(this.memberInfo ? this.memberInfo.member_id : 0);
var path = route.path;
return {
title: title,
path: path,
success: res => {
},
fail: res => {
}
};
},
// 分享到微信朋友圈
onShareTimeline() {
var title = '搜索到' + this.count + '件“' + this.keyword + this.category_title + this.coupon_name + '”相关的优质商品';
let route = this.$util.getCurrentShareRoute(this.memberInfo ? this.memberInfo.member_id : 0);
var query = route.query;
return {
title: title,
query: query,
imageUrl: ''
};
},
methods: {
/**
* 获取优惠券数据
*/
couponInfo(id) {
return new Promise(resolve => {
this.$api.sendRequest({
url: '/coupon/api/coupon/typeinfo',
data: {
coupon_type_id: id
},
success: res => {
if (res.code >= 0) {
resolve(res.data.coupon_name);
}
}
});
})
},
/**
* 获取分类名称
*/
share_select(data, id) {
return new Promise((resolve) => {
data.forEach((item) => {
if (item.category_id == id) {
resolve(item.category_name)
}
if (item.child_list && item.child_list.length > 0) {
item.child_list.forEach((v) => {
if (v.category_id == id) {
resolve(v.category_name)
}
if (v.child_list && v.child_list.length > 0) {
v.forEach((m) => {
if (m.category_id == id) {
resolve(m.category_name)
}
})
}
})
}
})
})
},
//加载分类
loadCategoryList(fid, sid) {
this.$api.sendRequest({
url: '/api/goodscategory/tree',
data: {},
success: res => {
if (res.data != null) {
this.categoryList = res.data
}
}
});
},
getGoodsList(mescroll) {
this.$api.sendRequest({
url: '/api/goodssku/page',
data: {
page: mescroll.num,
page_size: mescroll.size,
keyword: this.keyword,
category_id: this.categoryId,
brand_id: this.brandId,
min_price: this.minPrice,
max_price: this.maxPrice,
is_free_shipping: (this.isFreeShipping ? 1 : 0),
order: this.order,
sort: this.sort,
coupon: this.coupon,
goods_id_arr: this.goods_id_arr
},
success: res => {
let newArr = []
let msg = res.message;
if (res.code == 0 && res.data) {
this.count = res.data.count;
if (res.data.page_count == 0) {
this.emptyShow = true
}
newArr = res.data.list;
newArr = newArr.map(item => {
item.id = this.genNonDuplicate();
return item;
});
} else {
this.$util.showToast({
title: msg
})
}
this.category_title = '';
this.coupon_name = '';
if (res.data.config) this.config = res.data.config;
if (this.categoryId) {
this.share_select(this.categoryList, this.categoryId).then(resolve => {
this.category_title = resolve
});
}
if (this.coupon) {
this.couponInfo(this.coupon).then(resolve => {
this.coupon_name = resolve
});
}
mescroll.endSuccess(newArr.length);
//设置列表数据
if (mescroll.num == 1) this.goodsList = []; //如果是第一页需手动制空列表
this.goodsList = this.goodsList.concat(newArr); //追加新数据
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
this.waterfallflow((mescroll.num - 1) * 10);
},
fail: res => {
//联网失败的回调
mescroll.endErr();
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
}
});
},
changeListStyle() {
this.isList = !this.isList;
this.waterfallflow(0);
},
//筛选点击
sortTabClick(tag) {
if (tag == 'sale_num') {
this.order = 'sale_num';
this.sort = 'desc';
} else if (tag == 'discount_price') {
this.order = 'discount_price';
this.sort = 'desc';
} else if (tag == 'screen') {
//筛选
this.showScreen = true;
return;
} else {
this.order = '';
this.sort = '';
}
if (this.orderType === tag && tag !== 'discount_price') return;
this.orderType = tag;
if (tag === 'discount_price') {
this.priceOrder = this.priceOrder === 'asc' ? 'desc' : 'asc';
this.sort = this.priceOrder;
} else {
this.priceOrder = '';
}
this.emptyShow = false;
this.goodsList = [];
this.$refs.mescroll.refresh();
},
//商品详情
toDetail(item) {
this.$util.redirectTo('/pages/goods/detail', {
goods_id: item.goods_id
});
},
search() {
this.emptyShow = false;
this.goodsList = [];
this.$refs.mescroll.refresh();
},
selectedCategory(categoryId) {
this.categoryId = categoryId;
},
screenData() {
if (this.minPrice != '' || this.maxPrice != '') {
// if (!Number(this.minPrice) && this.minPrice) {
// this.$util.showToast({
// title: '请输入最低价'
// });
// return;
// }
if (!Number(this.maxPrice) && this.maxPrice) {
this.$util.showToast({
title: '请输入最高价'
});
return;
}
if (Number(this.minPrice) < 0 || Number(this.maxPrice) < 0) {
this.$util.showToast({
title: '筛选价格不能小于0'
});
return;
}
if (this.minPrice != '' && Number(this.minPrice) > Number(this.maxPrice) && this.maxPrice) {
this.$util.showToast({
title: '最低价不能大于最高价'
});
return;
}
if (this.maxPrice != '' && Number(this.maxPrice) < Number(this.minPrice)) {
this.$util.showToast({
title: '最高价不能小于最低价'
});
return;
}
}
this.emptyShow = false;
this.goodsList = [];
this.$refs.mescroll.refresh();
this.showScreen = false;
},
//重置数据
resetData() {
this.categoryId = 0
this.minPrice = ''
this.maxPrice = ''
this.isFreeShipping = false
},
goodsImg(imgStr) {
let imgs = imgStr.split(',');
return imgs[0] ? this.$util.img(imgs[0], {
size: 'mid'
}) : this.$util.getDefaultImage().goods;
},
imgError(index) {
this.goodsList[index].goods_image = this.$util.getDefaultImage().goods;
},
showPrice(data) {
let price = data.discount_price;
if (data.member_price && parseFloat(data.member_price) < parseFloat(price)) price = data.member_price;
return price;
},
showMarketPrice(item) {
if (item.market_price_show) {
let price = this.showPrice(item);
if (item.market_price > 0) {
return item.market_price;
} else if (parseFloat(item.price) > parseFloat(price)) {
return item.price;
}
}
return '';
},
goodsTag(data) {
return data.label_name || '';
},
/**
* 瀑布流
*/
waterfallflow(start = 0) {
if (!this.isList) {
//页面渲染完成后的事件
this.$nextTick(() => {
setTimeout(() => {
let listHeight = [];
let listPosition = [];
if (start != 0) {
listHeight = this.listHeight;
listPosition = this.listPosition;
}
let column = 2;
const query = uni.createSelectorQuery().in(this);
query.selectAll('.double-column .goods-item').boundingClientRect(data => {
for (let i = start; i < data.length; i++) {
if (i < column) {
let position = {};
position.top = uni.upx2px(20) + 'px';
if (i % column == 0) {
position.left = data[i].width * i + "px";
} else {
position.left = data[i].width * i + (i % column * uni
.upx2px(30)) + "px";
}
listPosition[i] = position;
listHeight[i] = data[i].height + uni.upx2px(20);
} else {
let minHeight = Math.min(...listHeight); // 找到第一列的最小高度
let minIndex = listHeight.findIndex(item => item === minHeight) // 找到最小高度的索引
//设置当前子元素项的位置
let position = {};
position.top = minHeight + uni.upx2px(20) + "px";
position.left = listPosition[minIndex].left;
listPosition[i] = position;
//重新定义数组最小项的高度 进行累加
listHeight[minIndex] += data[i].height + uni.upx2px(20);
}
}
this.listHeight = listHeight;
this.listPosition = listPosition;
}).exec();
}, 50)
})
}
},
getBrandList() {
var data = {
page: 1,
page_size: 0
};
this.$api.sendRequest({
url: '/api/goodsbrand/page',
data: data,
success: res => {
if (res.code == 0 && res.data) {
let data = res.data;
this.brandList = data.list;
}
}
});
},
/**
* 添加购物车回调
*/
addCart(id) {
},
genNonDuplicate(len = 6) {
return Number(Math.random().toString().substr(3, len) + Date.now()).toString(36);
}
}
}