import React, { Component } from 'react'
import {
StyleSheet,
View,
Image,
StatusBar,
Dimensions,
PixelRatio,
TouchableOpacity,
Text,
FlatList,
ImageBackground,
ActivityIndicator,
} from 'react-native'
import { connect } from 'react-redux'
import Icon from '../../components/Iconfont/Iconfont'
import { NavigationActions, createAction } from '../../utils'
import Input from '../../components/input/index'
import SearchModal from './SearchResults'
import png from '../../static/images/defaultimg.jpg'
import Collapsible from 'react-native-collapsible'
import EmptyCommodity from '../../static/images/Empty-commodity.png'
import { ImageBaseUrl } from '../../utils/fetch/Fetchx'
import { ScaleUtil } from '../../utils/utils'
import dataModel from '../common/datamodel/dataModel'
import ToastView from '../../components/ToastView'
const { width, height } = Dimensions.get('window')
@connect(({ theme, search, category, shoppingcart }) => ({
...theme,
...search,
...category,
...shoppingcart,
}))
class CommodityHome extends Component {
constructor(props) {
super(props)
this.state = {
categorydata2Item:
(props.categorydata &&
props.categorydata[0] &&
props.categorydata[0].items) ||
[],
categorydata3Item:
(props.categorydata &&
props.categorydata[0] &&
props.categorydata[0].items &&
props.categorydata[0].items[0] &&
props.categorydata[0].items[0].items) ||
[],
categoryId: '',
secListIndex: 0,
thirdIndex: 0,
item1Color: 0,
secondIndex: 0,
isRefresh: true,
}
}
static navigationOptions = {
tabBarLabel: ({ tintColor }) => (
商品
),
tabBarIcon: ({ focused, tintColor }) =>
tintColor == '#333' ? (
) : (
),
}
componentDidMount() {
this.props.dispatch(
createAction('search/searchGoodsByCate')({
searchVal: {
search_customerId: CUSTOMERINFO.id,
search_customerRankCode: CUSTOMERINFO.customerRankCode,
// search_EQ_isOptional: 0,
// search_EQ_enableStrucManage: 0
},
})
)
}
gotoDetail = () => {
this.props.dispatch(NavigationActions.navigate({ routeName: 'Detail' }))
}
searchGoodsFn(item) {
this.props.dispatch(
createAction('search/searchGoodsByCate')({
searchVal: {
search_customerId: CUSTOMERINFO.id,
search_customerRankCode: CUSTOMERINFO.customerRankCode,
search_goodsCategoryIds: item.item.id,
// search_EQ_isOptional: 0,
// search_EQ_enableStrucManage: 0
},
})
)
}
// 一级菜单
leftRender(item, index) {
return (
{
this.state.categorydata2Item = []
if (this.state.secListIndex == item.index) {
this.setState({
secListIndex: 'asd',
})
} else {
if (
item.item &&
(Object.keys(item.item).indexOf('items') == -1 ||
(Object.keys(item.item).indexOf('items') !== -1 &&
item.item.items.length == 0))
) {
this.searchGoodsFn(item)
this.setState({
secListIndex: item.index,
item1Color: item.index,
// categorydata3Item: [],
secondIndex: 0,
})
} else {
this.setState({
categorydata2Item:
item.item && item.item.items && item.item.items.length > 0
? item.item.items
: [],
secListIndex: item.index,
item1Color: item.index,
// categorydata3Item: [],
secondIndex: 0,
})
}
}
}}
style={{
paddingLeft: 8,
paddingRight: 5,
paddingVertical: 14,
borderBottomColor: '#eee',
borderBottomWidth: 1 / PixelRatio.get(),
flexDirection: 'row',
borderLeftColor:
this.state.item1Color == item.index ? '#E70013' : 'transparent',
borderLeftWidth: 2,
}}
>
{item.item && item.item.name && item.item.name.length > 4
? item.item.name.slice(0, 4) + '...'
: item.item.name}
{item.item && item.item.items && item.item.items.length > 0 ? (
) : null}
this.secondMenu(item, this.state.categorydata2Item.length)
}
keyExtractor={(item, index) => index}
/>
)
}
//二级菜单
secondMenu(item, maxlength) {
return (
{
this.state.categorydata3Item = []
if (
item.item &&
(Object.keys(item.item).indexOf('items') == -1 ||
(Object.keys(item.item).indexOf('items') !== -1 &&
item.item.items.length == 0))
) {
this.searchGoodsFn(item)
} else {
this.setState({
categorydata3Item: item.item && item.item.items,
})
}
this.setState({
secondIndex: item.index,
})
}}
style={{ paddingHorizontal: 10, backgroundColor: '#F5F5F5' }}
>
{item.item.name}
)
}
// 三级菜单
thirdMenu(item) {
return (
{
this.setState({ thirdIndex: item.index })
this.searchGoodsFn(item)
}}
style={{
paddingHorizontal: 20,
paddingVertical: 5,
backgroundColor: '#FFF',
borderRadius: 100,
marginTop: 10,
borderWidth: 1 / PixelRatio.get(),
borderColor: this.state.thirdIndex == item.index ? '#E70013' : '#DDD',
marginRight: 10,
}}
>
{item.item.name}
)
}
// 商品信息
commodityInfo(item) {
let gouwucheColor = '#666'
if (this.props.shopListIds.indexOf(item.item.id) !== -1) {
gouwucheColor = '#E70013'
}
return (
this.props.dispatch(
createAction('detail/gotoDetail')({ item: item.item })
)
}
style={{ width: 120, height: 120, padding: 10 }}
>
this.props.dispatch(
createAction('detail/gotoDetail')({ item: item.item })
)
}
>
{
item.item.goodsAttrVals&&item.item.goodsAttrVals.length?(调):""
}
{item.item.displayName}
编码:{item.item.code}
{/* 型号:{item.item.model?(item.item.model.length>10?item.item.model.substr(0,10)+'...':item.item.model):""} */}
型号:{item.item.model?item.item.model:""}
规格:{item.item.specification?(item.item.specification.split("/")[0]+"/"+item.item.basicUnitName):""}
{/*
库存:{ScaleUtil(item.item.stock)}
*/}
¥{ScaleUtil(item.item.salePrice || item.item.baseDiscountPrice)}
{
if (item.item.isOptional) {
this.props.dispatch(
createAction('detail/gotoDetail')({
item: item.item,
comefrom: 'Home',
userFor: 'openModel',
})
)
} else {
if(item.item.goodsAttrVals && item.item.goodsAttrVals.length) {
this.plToast.show('该商品为调色商品,请到商品详情页面下单');
return;
}
if(!item.item.baseDiscountPrice) {
this.plToast.show('商品暂无价格,无法加入购物车');
return;
}
let postData = dataModel(
item.item,
CUSTOMERINFO.id,
CUSTOMERINFO.customerRankCode
)
this.props.dispatch(
createAction('shoppingcart/addShop')(postData)
)
}
}}
>
)
}
render() {
const {
appTheme,
categorydata,
GoodsList,
GoodsState,
GoodsFlag,
} = this.props
return (
this.mdl._openModal()}
iconSize={16}
style={{
height: 28,
width: width - 70,
borderRadius: width / 2,
alignSelf: 'flex-end',
paddingLeft: 14,
}}
placeholder={'商品名称/编码'}
textInputBacg={'#EEE'}
iconColor={'#999'}
placeholderTextColor={'#999'}
/>
this.props.dispatch(
NavigationActions.navigate({ routeName: 'Replenishment' })
)
}
style={{
paddingLeft: 6,
alignSelf: 'flex-end',
marginBottom: -6,
}}
>
{categorydata && categorydata.length > 0 ? (
this.leftRender(item)}
keyExtractor={(item, index) => index}
/>
{this.state.categorydata3Item &&
this.state.categorydata3Item.length > 0 ? (
index}
renderItem={(item, index) => this.thirdMenu(item, index)}
columnWrapperStyle={{
flexWrap: 'wrap',
}}
numColumns={3}
/>
) : null}
{GoodsState ? (
!GoodsFlag ? (
this.commodityInfo(item)}
keyExtractor={(item, index) => index}
/>
) : (
)
) : (
商品列表出现异常啦~
)}
) : (
商品分类出现异常啦~
)}
{
// this._refreshPlist(data);
// }}
ref={mdl => (this.mdl = mdl)}
dispatch={this.props.dispatch}
comFrom={'CommodityHome'}
// fuleipro={this.state.footerdata}
/>
{
//alert('toast消失了');
}}
ref={(element) => {
this.plToast = element;
}}
/>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
icon: {
width: 32,
height: 32,
},
})
export default CommodityHome