购物车下单

This commit is contained in:
bentz
2019-03-11 18:27:06 +08:00
parent d52c963eef
commit 2b7d7b4dec
8 changed files with 86 additions and 28 deletions

View File

@@ -46,6 +46,7 @@ class App extends Component {
'pages/member/recommend',
'pages/member/recommend-member',
'pages/member/coupon',
'pages/member/address',
'pages/trade/list',
'pages/trade/detail',

View File

@@ -7,7 +7,9 @@ import './index.scss'
export default class GoodsItem extends Component {
static defaultProps = {
onClickImg: () => {}
onClickImg: () => {},
showMarketPrice: true,
noCurSymbol: false
}
static options = {
@@ -15,7 +17,7 @@ export default class GoodsItem extends Component {
}
render () {
const { info, onClickImg, className } = this.props
const { info, showMarketPrice, noCurSymbol, onClickImg, className } = this.props
if (!info) {
return null
}
@@ -45,14 +47,18 @@ export default class GoodsItem extends Component {
classes='goods-item__price'
className='goods-item__price'
symbol={info.curSymbol}
noSymbol={noCurSymbol}
value={price}
/>
<Price
symbol={info.curSymbol}
classes='goods-item__price-market'
className='goods-item__price-market'
value={info.market_price}
/>
{showMarketPrice && (
<Price
symbol={info.curSymbol}
noSymbol={noCurSymbol}
classes='goods-item__price-market'
className='goods-item__price-market'
value={info.market_price}
/>
)}
</View>
</View>
</View>

View File

@@ -7,13 +7,16 @@ import api from '@/api'
import S from '@/spx'
import { pickBy } from '@/utils'
import { lockScreen } from '@/utils/dom'
import { getSelectedCart } from '@/store/cart'
import CheckoutItems from './checkout-items'
import './espier-checkout.scss'
@connect(({ cart }) => ({
coupon: cart.coupon,
fastbuy: cart.fastbuy
fastbuy: cart.fastbuy,
list: getSelectedCart(cart)
}), (dispatch) => ({
onClearFastbuy: () => dispatch({ type: 'cart/clearFastbuy' }),
onClearCart: () => dispatch({ type: 'cart/clear' })
@@ -51,17 +54,24 @@ export default class CartCheckout extends Component {
info = {
cart: [{
list: [fastBuyItem],
cart_total_num: fastBuyItem.num,
cart_total_price: (fastBuyItem.price * fastBuyItem.num / 100).toFixed(2)
cart_total_num: fastBuyItem.num
}]
}
this.setState({
info
})
} else {
this.props.onClearFastbuy()
const { list } = this.props
info = {
cart: [{
list,
cart_total_num: list.reduce((acc, item) => (+item.num) + acc, 0)
}]
}
}
this.setState({
info
})
let total_fee = 0
let items_count = 0
const items = info.cart[0].list.map((item) => {

View File

@@ -10,10 +10,12 @@ import { withLogin } from '@/hocs'
import './index.scss'
@connect(({ cart }) => ({
list: cart.list
list: cart.list,
defaultAllSelect: true
}), (dispatch) => ({
onCartUpdate: (item, num) => dispatch({ type: 'cart/update', payload: { item, num } }),
onCartDel: (item) => dispatch({ type: 'cart/delete', payload: item })
onCartDel: (item) => dispatch({ type: 'cart/delete', payload: item }),
onCartSelection: (selection) => dispatch({ type: 'cart/selection', payload: selection })
}))
@withLogin()
export default class CartIndex extends Component {
@@ -23,12 +25,14 @@ export default class CartIndex extends Component {
this.state = {
selection: new Set(),
totalPrice: '0.00',
items: null,
cartMode: 'default'
}
}
componentDidMount () {
if (this.props.defaultAllSelect) {
this.handleAllSelect(true)
}
}
componentDidShow () {
@@ -67,6 +71,7 @@ export default class CartIndex extends Component {
this.setState({
selection
})
this.props.onCartSelection([...selection])
log.debug(`[cart change] item: ${item_id}, selection: ${selection}`)
}
@@ -77,18 +82,21 @@ export default class CartIndex extends Component {
}
handleAllSelect = (checked) => {
const { items, selection } = this.state
const { selection } = this.state
const { list } = this.props
if (checked) {
for (let item of items.values()) {
list.forEach((item) => {
selection.add(item.item_id)
}
})
} else {
selection.clear()
}
this.setState({
selection
selection: new Set(selection)
})
this.props.onCartSelection([...selection])
}
handleDelect = () => {
@@ -96,15 +104,16 @@ export default class CartIndex extends Component {
selection.forEach(item_id => {
this.props.onCartDel({ item_id })
})
this.setState({
selection: new Set(selection)
})
this.props.onCartSelection(selection)
}
handleCheckout = () => {
Taro.navigateTo({
url: '/pages/cart/checkout'
})
this.setState({
selection: new Set()
url: '/pages/cart/espier-checkout'
})
}

View File

@@ -10,7 +10,7 @@ export default class Index extends Component {
componentWillMount () {
if (process.env.NODE_ENV === 'development') {
Taro.redirectTo({
url: '/pages/member/point'
url: '/pages/member/index'
})
}
}

View File

@@ -0,0 +1,18 @@
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import AddressPicker from '@/components/address/picker'
export default class AddressIndex extends Component {
handleClickBack () {
return Taro.navigateBack()
}
render () {
return (
<AddressPicker
isOpened
onClickBack={this.handleClickBack.bind(this)}
/>
)
}
}

View File

@@ -128,6 +128,7 @@ export default class MemberIndex extends Component {
<SpIconMenu
icon='location'
title='收货地址'
to='/pages/member/address'
/>
</View>
<View class='member-tools__item'>

View File

@@ -4,7 +4,8 @@ import dotProp from 'dot-prop-immutable'
const initState = {
list: [],
fastbuy: null,
coupon: null
coupon: null,
selection: []
}
const cart = createReducer(initState, {
@@ -77,6 +78,13 @@ const cart = createReducer(initState, {
...initState
}
},
['cart/selection'](state, action) {
const selection = action.payload
return {
...state,
selection
}
},
['cart/changeCoupon'](state, action) {
const coupon = action.payload
@@ -92,3 +100,8 @@ export default cart
export function getTotalCount (state) {
return state.list.reduce((acc, item) => (+item.num) + acc, 0)
}
export function getSelectedCart (state) {
console.log(state.selection)
return state.list.filter(item => state.selection.includes(item.item_id))
}