import React, { Component } from 'react'
import {
StyleSheet,
View,
Image,
StatusBar,
Dimensions,
TouchableOpacity,
PixelRatio,
Text,
FlatList,
ActivityIndicator,
} from 'react-native'
import { connect } from 'react-redux'
import Icon from '../../components/Iconfont/Iconfont'
import { NavigationActions, createAction, Storage } from '../../utils'
import Input from '../../components/input/index'
import Checkbox from '../../components/checkbox/index'
import Grid from '../../components/Grid'
import Collapsible from 'react-native-collapsible'
import SearchModal from './SearchResults'
import dataModel from '../common/datamodel/dataModel'
import ToastView from '../../components/ToastView'
const { width, height } = Dimensions.get('window')
const AllData = {
saleOrganizationName: '全部供应商',
saleOrganizationId: '',
}
const ProductLineData = {
productLineName: '全部产品线',
productLineId: '',
}
@connect(({ theme, search, shoppingcart, mine }) => ({
...theme,
...search,
...shoppingcart,
...mine,
}))
class CommodityShowbase extends Component {
constructor(props) {
super(props)
this.state = {
allProDatas: [],
priceCompany: false,
listRowBool: true,
filterIndex1: 0,
filterIndex2: 0,
collapsed: true,
collapsed1: false,
collapsed2: false,
gridStyle: {
viewWid: {
width: width,
height: width * 0.4 + 1,
borderBottomColor: '#F5F5F5',
borderBottomWidth: 1 / PixelRatio.get(),
},
imgWid: {
width: width * 0.4,
height: width * 0.4,
},
},
// searchCondition: {
isNew: false,
productLineId: ProductLineData.productLineId,
productLineName: ProductLineData.productLineName,
keyWord: props.navigation.state.params.searchval,
organizationId: AllData.saleOrganizationId,
organizationName: AllData.saleOrganizationName,
Loading: false,
// }
}
this.page = 0
this.size = 10
}
componentDidMount = () => {
this.props.dispatch(
createAction('mine/getCusSup')({
customerId: CUSTOMERINFO.id,
customerRankCode: CUSTOMERINFO.customerRankCode,
addDefaultData: 'productLine',
})
)
this.props.dispatch(
createAction('search/searchGoodsAll')({
comeFrom: 'Filter',
actionData: [],
pageInfo: { page: 0, size: this.size },
searchInfo: this.SearchVal(),
})
)
this.setState({ keyWord: this.props.navigation.state.params.searchval })
}
onRefresh() {
this._SearchGood()
}
gotoDetail = () => {
this.props.dispatch(NavigationActions.navigate({ routeName: 'Detail' }))
}
toggleExpanded(e) {
if (!this.state.collapsed1 && !this.state.collapsed2) {
e == '1'
? this.setState({
collapsed: !this.state.collapsed,
collapsed1: !this.state.collapsed1,
})
: this.setState({
collapsed: !this.state.collapsed,
collapsed2: !this.state.collapsed2,
})
} else {
this.state.collapsed1
? e == '1'
? this.setState({
collapsed: !this.state.collapsed,
collapsed1: !this.state.collapsed1,
})
: this.setState({
collapsed1: !this.state.collapsed1,
collapsed2: !this.state.collapsed2,
})
: e == '1'
? this.setState({
collapsed1: !this.state.collapsed1,
collapsed2: !this.state.collapsed2,
})
: this.setState({
collapsed: !this.state.collapsed,
collapsed2: !this.state.collapsed2,
})
}
}
filterIndexfun(item, selnum) {
if (selnum == '1') {
this.state.productLineId = item.item.productLineId
this.setState({
filterIndex1: item.index,
productLineName: item.item.productLineName,
productLineId: item.item.productLineId,
collapsed: !this.state.collapsed,
collapsed1: !this.state.collapsed1,
})
} else {
this.state.organizationId = item.item.saleOrganizationId
this.setState({
filterIndex2: item.index,
organizationName: item.item.saleOrganizationName,
organizationId: item.item.saleOrganizationId,
collapsed: !this.state.collapsed,
collapsed2: !this.state.collapsed2,
})
}
this.onRefresh()
}
filterRender(item) {
if (this.state.collapsed1 && !this.state.collapsed2) {
return (
this.filterIndexfun(item, '1')}
>
{this.state.filterIndex1 == item.index ? (
{item.item.productLineName}
) : (
{item.item.productLineName}
)}
)
} else {
return (
this.filterIndexfun(item, '2')}
>
{this.state.filterIndex2 == item.index ? (
{item.item.saleOrganizationName}
) : (
{item.item.saleOrganizationName}
)}
)
}
}
checkClick(bool, checkname) {
switch (checkname) {
case 'newpro':
this.state.isNew = bool
this.setState({ isNew: bool })
break
case 'inventory':
console.log('inventory>>>>' + bool)
break
case 'hotsale':
console.log('hotsale>>>>>' + bool)
break
}
// this._SearchGood();
this.onRefresh()
}
SearchVal() {
let searchVal = {}
searchVal = {
search_customerId: CUSTOMERINFO.id,
search_customerRankCode: CUSTOMERINFO.customerRankCode,
search_EQ_isEnable: 1,
// search_EQ_isOptional: 0,
// search_EQ_enableStrucManage: 0
}
if (this.state.isNew) {
searchVal.search_EQ_isNew = 1
}
if (this.state.productLineId) {
searchVal.search_EQ_productLineId = this.state.productLineId
}
if (this.state.keyWord) {
searchVal.search_keywords = this.state.keyWord
}
if (this.state.organizationId) {
searchVal.search_organizationId = this.state.organizationId
}
return searchVal
}
_SearchGood() {
this.props.dispatch(
createAction('search/searchGoodsAll')({
comeFrom: 'Filter',
actionData: [],
pageInfo: { page: 0, size: this.size },
searchInfo: this.SearchVal(),
})
)
this.page = 0
}
listRowCol() {
if (this.state.listRowBool) {
this.setState({
listRowBool: !this.state.listRowBool,
gridStyle: {
viewWid: {
borderRightColor: '#F5F5F5',
borderRightWidth: 1 / PixelRatio.get(),
borderBottomColor: '#F5F5F5',
borderBottomWidth: 1 / PixelRatio.get(),
width: width / 2,
height: width / 2 + 110,
},
imgWid: {
width: width / 2 - 1,
height: width / 2,
},
},
})
} else {
this.setState({
listRowBool: !this.state.listRowBool,
gridStyle: {
viewWid: {
width: width,
height: width * 0.4 + 1,
borderBottomColor: '#F5F5F5',
borderBottomWidth: 1 / PixelRatio.get(),
},
imgWid: {
width: width * 0.4,
height: width * 0.4,
},
},
})
}
}
_refreshPlist(data) {
this.state.keyWord = data
this.setState({ keyWord: data })
this.onRefresh()
}
render() {
let selectcolor1, selectcolor2
this.state.collapsed1 && !this.state.collapsed2
? (selectcolor1 = '#E14C46')
: (selectcolor1 = '#333')
this.state.collapsed2 && !this.state.collapsed1
? (selectcolor2 = '#E14C46')
: (selectcolor2 = '#333')
const {
appTheme,
listDatas,
totalPages,
shopListIds,
SupplierInfo,
productRefs,
searchRefresh,
} = this.props
let filterData = []
!this.state.collapsed1 && this.state.collapsed2
? (filterData = SupplierInfo)
: (filterData = productRefs)
return (
this.props.dispatch(NavigationActions.back())}
>
this.mdl._openModal(this.state.keyWord)}
style={{
height: 28,
width: width / 1.36,
borderRadius: width / 2,
alignSelf: 'flex-end',
paddingLeft: 14,
marginBottom: 4,
}}
placeholder={this.state.keyWord || '请输入商品名称或商品编码'}
textInputBacg={'#EEE'}
iconColor={'#999'}
placeholderTextColor={'#999'}
// onchangeFn={e => {
// console.log(e);
// }}
/>
this.props.dispatch(
NavigationActions.navigate({ routeName: 'Replenishment' })
)
}
style={{
alignSelf: 'flex-end',
marginLeft: 8,
}}
>
{
this.toggleExpanded('1')
}}
>
{this.state.productLineName}
{
this.toggleExpanded('2')
}}
>
{this.state.organizationName}
this.sortPrice()}
>
{/* 价格 */}
{/* */}
this.checkClick(a, 'newpro')}
/>
{/* this.checkClick(a, "newpro")}
/>
this.checkClick(a, "hotsale")}
/>
this.checkClick(a, "inventory")}
/> */}
this.listRowCol()}
style={{ alignSelf: 'center', marginTop: 5, marginLeft: 20 }}
>
{this.state.listRowBool ? (
// 列表形式
) : (
// 宫格形式
)}
(this.gridPull = gridPull)}
titleBool={false}
listRowBool={this.state.listRowBool}
// data={this.state.allProDatas}
data={listDatas}
// 名称key
nameKey="displayName"
extraData={this.state}
// 图片key
pictureKey="mainPictureFileUrl"
// 价格key
priceKey="baseDiscountPrice"
// key值 一般输入code
keyext="code"
// 编码
codeKey="code"
// 库存
invenKey="stock"
viewWid={this.state.gridStyle.viewWid}
imgWid={this.state.gridStyle.imgWid}
imageTouch={e => {
this.props.dispatch(createAction('detail/gotoDetail')({ item: e }))
// this.props.dispatch(
// createAction("home/getRecentView")({ recentView: e })
// );
}}
shoppingCart={item => {
if(item.goodsAttrVals && item.goodsAttrVals.length) {
this.plToast.show('该商品为调色商品,请到商品详情页面下单');
return;
}
if(!item.baseDiscountPrice) {
this.plToast.show('商品暂无价格,无法加入购物车');
return;
}
let postData = dataModel(
item,
CUSTOMERINFO.id,
CUSTOMERINFO.customerRankCode
)
this.props.dispatch(createAction('shoppingcart/addShop')(postData))
}}
SearchVal={this.SearchVal()}
onEndReached={() => {
if (this.props.showFoot != 0) {
return
}
if (this.page != 1 && this.page >= totalPages) {
return
} else {
this.page++
}
this.props.dispatch(
createAction('search/searchGoodsAll')({
comeFrom: 'Filter',
actionData: listDatas,
pageInfo: { page: this.page, size: this.size },
searchInfo: this.SearchVal(),
forUse: 'slipOn',
})
)
}}
onRefresh={() => this.onRefresh()}
Parentprops={this.props}
shopListIds={shopListIds}
/>
{/* 遮罩 */}
{!this.state.collapsed ? (
) : null}
{/* 产品线/供应商-折叠*/}
index}
renderItem={(item, index) => this.filterRender(item, index)}
/>
{
this._refreshPlist(data)
}}
ref={mdl => (this.mdl = mdl)}
dispatch={this.props.dispatch}
comFrom={'CommodityShowbase'}
defaultValue={this.props.defaultValue || '请输入商品名称或商品编码'}
// 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 CommodityShowbase