diff --git a/project.config.json b/project.config.json index 4d490378f..8d19c3e28 100644 --- a/project.config.json +++ b/project.config.json @@ -29,7 +29,7 @@ "list": [] }, "miniprogram": { - "current": 10, + "current": 11, "list": [ { "id": 0, @@ -105,6 +105,14 @@ "id": -1, "name": "pages/recommend/list", "pathName": "pages/recommend/list", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/item/espier-detail", + "pathName": "pages/item/espier-detail", + "query": "id=118", "scene": null } ] diff --git a/src/components/tab-bar/index.js b/src/components/tab-bar/index.js index 014e78226..477a07603 100644 --- a/src/components/tab-bar/index.js +++ b/src/components/tab-bar/index.js @@ -2,8 +2,6 @@ import Taro, { Component } from '@tarojs/taro' import { View } from '@tarojs/components' import { connect } from '@tarojs/redux' import { AtTabBar } from 'taro-ui' -import req from '@/api/req' -import api from '@/api' import { navigateTo, getCurrentRoute } from '@/utils' import S from '@/spx' import { getTotalCount } from '@/store/cart' @@ -11,8 +9,6 @@ import { getTotalCount } from '@/store/cart' @connect(({ tabBar,cart }) => ({ tabBar: tabBar.current, cartCount: cart.cartCount -}),(dispatch) => ({ - onUpdateCartCount: (count) => dispatch({ type: 'cart/updateCount', payload: count }) })) export default class TabBar extends Component { static options = { @@ -124,13 +120,6 @@ export default class TabBar extends Component { return } - try { - const { item_count } = await api.cart.count({shop_type: 'distributor'}) - updateCartCount(item_count) - this.props.onUpdateCartCount(item_count) - } catch (e) { - console.error(e) - } } handleClick = (current) => { diff --git a/src/pages/home/wgts/goods.js b/src/pages/home/wgts/goods.js index f15f3d7a5..938d72ed4 100644 --- a/src/pages/home/wgts/goods.js +++ b/src/pages/home/wgts/goods.js @@ -14,7 +14,8 @@ import './goods.scss' onFastbuy: (item) => dispatch({ type: 'cart/fastbuy', payload: { item } }), onAddCart: (item) => dispatch({ type: 'cart/add', payload: { item } }), onAddFav: ({ item_id }) => dispatch({ type: 'member/addFav', payload: { item_id } }), - onDelFav: ({ item_id }) => dispatch({ type: 'member/delFav', payload: { item_id } }) + onDelFav: ({ item_id }) => dispatch({ type: 'member/delFav', payload: { item_id } }), + onUpdateCartCount: (count) => dispatch({ type: 'cart/updateCount', payload: count }) })) export default class WgtGoods extends Component { static options = { @@ -146,13 +147,22 @@ export default class WgtGoods extends Component { Taro.showToast({ title: '成功加入购物车', icon: 'success' - }) + }) + this.fetchCartcount() } catch (error) { console.log(error) } } } + async fetchCartcount() { + try { + const { item_count } = await api.cart.count({shop_type: 'distributor'}) + this.props.onUpdateCartCount(item_count) + } catch (e) { + console.error(e) + } + } render () { const { info } = this.props diff --git a/src/pages/index.js b/src/pages/index.js index 38f104df5..e02782f99 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -16,9 +16,11 @@ import { resolveFavsList } from './item/helper' import './home/index.scss' @connect(({ cart }) => ({ list: cart.list, - cartIds: cart.cartIds + cartIds: cart.cartIds, + cartCount: cart.cartCount }), (dispatch) => ({ - onUpdateLikeList: (show_likelist) => dispatch({ type: 'cart/updateLikeList', payload: show_likelist }), + onUpdateLikeList: (show_likelist) => dispatch({ type: 'cart/updateLikeList', payload: show_likelist }), + onUpdateCartCount: (count) => dispatch({ type: 'cart/updateCount', payload: count }) })) @connect(store => ({ store @@ -89,7 +91,8 @@ export default class HomeIndex extends Component { }, () => { this.fetchInfo() }) - } + } + this.fetchCartcount() } onShareAppMessage (res) { @@ -101,7 +104,14 @@ export default class HomeIndex extends Component { path: '/pages/index' } } - + async fetchCartcount() { + try { + const { item_count } = await api.cart.count({shop_type: 'distributor'}) + this.props.onUpdateCartCount(item_count) + } catch (e) { + console.error(e) + } + } async fetchInfo () { const url = '/pageparams/setting?template_name=yykweishop&version=v1.0.1&page_name=index' const info = await req.get(url) diff --git a/src/pages/item/comps/package-item.js b/src/pages/item/comps/package-item.js index fcd1e7418..29a3504a4 100644 --- a/src/pages/item/comps/package-item.js +++ b/src/pages/item/comps/package-item.js @@ -5,9 +5,14 @@ import { GoodsItem, SpCheckbox, GoodsBuyPanel } from '@/components' import { classNames, formatTime, pickBy } from '@/utils' import S from '@/spx' import api from '@/api' +import { connect } from '@tarojs/redux' import './package-item.scss'; - +@connect(({ cart }) => ({ + cart, +}), (dispatch) => ({ + onUpdateCartCount: (count) => dispatch({ type: 'cart/updateCount', payload: count }) +})) export default class PackageItem extends Component { static options = { addGlobalClass: true @@ -169,15 +174,27 @@ export default class PackageItem extends Component { activity_id: packageId, activity_type: 'package', distributor_id - } - const res = await api.cart.add(query) + } + const res = await api.cart.add(query) + if (res) { Taro.showToast({ title: '成功加入购物车', icon: 'success' - }) + }) + this.fetchCartcount() } } + + async fetchCartcount() { + try { + const { item_count } = await api.cart.count({shop_type: 'distributor'}) + this.props.onUpdateCartCount(item_count) + } catch (e) { + console.error(e) + } + } + countPackageTotal () { const { selection, packagePrices, mainItem } = this.state