diff --git a/components/diy/carousel.vue b/components/diy/carousel.vue index 392bd46c..04f8cb7e 100644 --- a/components/diy/carousel.vue +++ b/components/diy/carousel.vue @@ -2,7 +2,7 @@ - + @@ -244,9 +244,7 @@ this.$refs.popup.close(); }, url_open(link) { - if (!isEmpty(link)) { - app.globalData.url_open(link.page); - } + app.globalData.url_event(link); }, }, }; diff --git a/components/diy/custom.vue b/components/diy/custom.vue index 5dd9f1ce..48faa736 100644 --- a/components/diy/custom.vue +++ b/components/diy/custom.vue @@ -78,9 +78,7 @@ }); }, url_open(link) { - if (!isEmpty(link)) { - app.globalData.url_open(link); - } + app.globalData.url_event(link); }, }, }; diff --git a/components/diy/diy.vue b/components/diy/diy.vue index 0207f9b2..cde413c1 100644 --- a/components/diy/diy.vue +++ b/components/diy/diy.vue @@ -6,7 +6,7 @@ - + @@ -152,9 +157,13 @@ const app = getApp(); import { isEmpty, common_styles_computer, get_math, gradient_handle, padding_computer, radius_computer } from '@/common/js/common/common.js'; import imageEmpty from '@/components/diy/modules/image-empty.vue'; + import componentGoodsBuy from '@/components/goods-buy/goods-buy'; + import componentCartParaCurve from '@/components/cart-para-curve/cart-para-curve'; export default { components: { imageEmpty, + componentGoodsBuy, + componentCartParaCurve }, props: { value: { @@ -172,6 +181,8 @@ return { form: {}, new_style: {}, + is_show_cart: false, + propIsCartParaCurve: true, default_list: { title: '测试商品标题', min_original_price: '41.2', @@ -414,10 +425,88 @@ } return style; }, - url_open_event(link) { - if (!isEmpty(link)) { - app.globalData.url_open(link.page); + url_event(link) { + app.globalData.url_event(link); + }, + goods_button_event(e) { + let index = e.currentTarget.dataset.index || 0; + let goods = this.list[index]; + if (this.theme == '5') { + index = e.currentTarget.dataset.index || 0; + split_index = e.currentTarget.dataset.split_index || 0; + goods = this.shop_content_list[index][split_index]; } + if (this.form.shop_button_effect == '0') { + app.globalData.url_event(goods.goods_url); + } else { + this.goods_cart_event(goods); + } + }, + // 加入购物车 + goods_cart_event(e) { + if ((this.$refs.goods_buy || null) != null) { + // 开启购物车抛物线效果则展示提示操作 + let is_success_tips = this.propIsCartParaCurve ? 0 : 1; + this.$refs.goods_buy.init( + goods, + { + buy_event_type: 'cart', + is_direct_cart: 1, + is_success_tips: is_success_tips, + }, + { + index: index, + pos: e, + } + ); + } + }, + // 加入购物车成功回调 + goods_cart_back_event(e) { + // 增加数量 + var back = e.back_data; + var new_data = this.data; + var goods = new_data['goods_list'][back.index]; + goods['user_cart_count'] = parseInt(goods['user_cart_count'] || 0) + parseInt(e.stock); + if (goods['user_cart_count'] > 99) { + goods['user_cart_count'] = '99+'; + } + new_data['goods_list'][back.index] = goods; + this.setData({ + data: new_data, + }); + + // 抛物线 + if (this.propIsCartParaCurve && (this.$refs.cart_para_curve || null) != null) { + this.$refs.cart_para_curve.init(null, back.pos, goods.images); + } + + // 导航购物车处理 + if (this.propIsCartNumberTabBarBadgeSync) { + var cart_total = e.cart_number || 0; + if (cart_total <= 0) { + app.globalData.set_tab_bar_badge(2, 0); + } else { + app.globalData.set_tab_bar_badge(2, 1, cart_total); + } + } + + // 当前页面 + var page = app.globalData.current_page().split('?'); + switch (page[0]) { + // 商品详情页面 + case 'pages/goods-detail/goods-detail': + // 商品搜索 + case 'pages/goods-search/goods-search': + var res = app.globalData.get_page_object(page[0]); + if (res.length > 0) { + for (var i in res) { + res[i].$vm.goods_cart_count_handle(cart_total); + } + } + break; + } + this.$emit('CartSuccessEvent', { ...e, ...{ goods_list: new_data.goods_list, goods: goods } }); }, }, }; diff --git a/components/diy/modules/data-magic/magic-carousel.vue b/components/diy/modules/data-magic/magic-carousel.vue index 2b588ac0..7c270823 100644 --- a/components/diy/modules/data-magic/magic-carousel.vue +++ b/components/diy/modules/data-magic/magic-carousel.vue @@ -2,7 +2,7 @@ @@ -47,9 +47,7 @@ }, // 跳转链接 url_event(link) { - if (!isEmpty(link)) { - app.globalData.url_open(link); - } + app.globalData.url_event(link); }, }, }; diff --git a/components/diy/modules/data-magic/product-list-show.vue b/components/diy/modules/data-magic/product-list-show.vue index 888f30ff..e8356775 100644 --- a/components/diy/modules/data-magic/product-list-show.vue +++ b/components/diy/modules/data-magic/product-list-show.vue @@ -2,7 +2,7 @@