import React, { Component } from 'react'
import {
StyleSheet,
ScrollView,
View,
Image,
ActivityIndicator,
ImageBackground,
Text,
Dimensions,
StatusBar,
TouchableOpacity,
RefreshControl,
Alert,
} from 'react-native'
import { connect } from 'react-redux'
import Icon from '../../components/Iconfont/Iconfont'
import { NavigationActions, createAction, Storage, delay } from '../../utils'
import {
CarouselHorizontal,
CarouselVertical,
} from '../../components/carousel/index'
import Input from '../../components/input/index'
import Bubble from '../../components/Bubble'
// import png from "../../static/images/banner.png";
import mask from '../../static/images/home-mask.png'
import announcePng from '../../static/images/home-announce.png'
import inputdef from '../../static/images/home-topInput.png'
import inputred from '../../static/images/home-topred.png'
import homeAllGoods from '../../static/images/home-AllGoods.png'
import homeHotSale from '../../static/images/home-hotSale.png'
import Grid from '../../components/Grid'
import SearchModal from '../commodity/SearchResults'
import { ImageBaseUrl } from '../../utils/fetch/Fetchx'
import { accMul } from '../../utils/utils'
import dataModel from '../common/datamodel/dataModel'
import pendingImg from '../../static/images/home-pending.png'
import temporaryImg from '../../static/images/home-temporary.png'
import dispatchImg from '../../static/images/home-dispatched.png'
import unShipedImg from '../../static/images/home-unshiped.png'
import { isIphoneX } from '../common/theme/config'
import ToastView from '../../components/ToastView'
import moment from 'moment'
const { width, height } = Dimensions.get('window')
@connect(({ theme, home, shoppingcart, announce }) => ({
...theme,
...home,
...shoppingcart,
...announce,
}))
class Home extends Component {
constructor(props) {
super(props)
this.state = {
header: {
headercol: 'transparent',
inputtx: '#CCC',
inputbacg: '#FFF',
messcol: '#FFF',
inputWidth: width - 20,
// barStyle: "light-content"
barStyle: 'dark-content',
// barStyle: this.props.appTheme.barStyle,
},
headerView: true,
isRefreshing: false,
shopListIds: [],
isRefreshAdd: true,
}
// console.disableYellowBox = true;
}
static navigationOptions = {
tabBarLabel: ({ tintColor }) => (
首页
),
tabBarIcon: ({ focused, tintColor }) =>
tintColor == '#333' ? (
) : (
),
}
gotoDetail(e) {
this.props.dispatch(
createAction('detail/gotoDetail')({ item: e, comefrom: 'Home' })
)
}
onRefresh() {
//
this.props.dispatch(
createAction('announce/getAnnounce')({ page: 0, pageSize: 10 })
)
//
this.props.dispatch(createAction('announce/getBanner')())
//
this.props.dispatch(createAction('home/getAllPro')())
this.props.dispatch(createAction('home/getHotSale')())
}
touchItemFn = val => {
// this.props.dispatch(
// NavigationActions.reset({
// index: 0, // 注意不要越界
// actions: [NavigationActions.navigate({ routeName: "OrderHome" })]
// })
// );
switch (val) {
case '待审核':
this.props.dispatch(
NavigationActions.navigate({
routeName: 'OrderHome',
action: NavigationActions.navigate({ routeName: 'OrderHome' }),
params: { StateFilter: 'HomeToOrder/shenhe',orderListType:'1' },
})
)
this.props.dispatch(
createAction('orderlist/setRouterParamsReducer')({
routerParams: 'HomeToOrder/shenhe'
})
)
break
case '待发货':
this.props.dispatch(
NavigationActions.navigate({
routeName: 'OrderHome',
action: NavigationActions.navigate({ routeName: 'OrderHome' }),
params: { StateFilter: 'HomeToOrder/fahuo',orderListType:'1' },
})
)
this.props.dispatch(
createAction('orderlist/setRouterParamsReducer')({
routerParams: 'HomeToOrder/fahuo'
})
)
break
case '待签收':
this.props.dispatch(
NavigationActions.navigate({
routeName: 'OrderHome',
action: NavigationActions.navigate({ routeName: 'OrderHome' }),
params: { StateFilter: 'HomeToOrder/shouhuo',orderListType:'1' },
})
)
this.props.dispatch(
createAction('orderlist/setRouterParamsReducer')({
routerParams: 'HomeToOrder/shouhuo'
})
)
break
case '暂存':
this.props.dispatch(
NavigationActions.navigate({
routeName: 'OrderHome',
action: NavigationActions.navigate({ routeName: 'OrderHome' }),
params: { StateFilter: 'HomeToOrder/zancun' },
})
)
this.props.dispatch(
createAction('orderlist/setRouterParamsReducer')({
routerParams: 'HomeToOrder/zancun'
})
)
break
}
}
//待审核、待发货等按钮部分
touchItem(ReqNumData) {
let numDataObj = []
if (ReqNumData && ReqNumData.length > 0) {
ReqNumData.map(data => (numDataObj[data[0]] = data[1]))
}
let _items = [],
right,
itemdatas = [
{
text: '待审核',
fn: this.touchItemFn,
iconName: pendingImg,
// iconName: "icon-daishenhe",
bubbleval: numDataObj['02'] || 0,
},
{
text: '待发货',
fn: this.touchItemFn,
iconName: unShipedImg,
// iconName: "icon-daifahuo",
bubbleval: numDataObj['03'] || 0,
},
{
text: '待签收',
fn: this.touchItemFn,
iconName: dispatchImg,
// iconName: "icon-daishouhuo",
bubbleval: numDataObj['04'] || 0,
},
{
text: '暂存',
fn: this.touchItemFn,
iconName: temporaryImg,
// iconName: "icon-buhuo",
bubbleval: numDataObj['01'] || 0,
},
]
for (let i = 0; i < itemdatas.length; i++) {
let items = itemdatas[i]
if (items.bubbleval < 10 && items.bubbleval > 0) {
right = 20
} else if (items.bubbleval >= 100) {
right = 5
} else {
right = 7
}
_items.push(
items.fn(items.text)}
>
{/* */}
{items.text}
)
}
return _items
}
_onScroll(event) {
let offsetY = event.nativeEvent.contentOffset.y
if (offsetY > 35) {
this.setState({
// 下拉样式
header: {
headercol: '#FFF',
inputtx: '#CCC',
inputbacg: '#FFF',
messcol: '#FFF',
inputWidth: width - 50,
barStyle: 'dark-content',
// barStyle: "light-content"
},
})
} else if (offsetY < -20) {
this.setState({ headerView: false })
} else {
this.setState({
// 初始状态样式
header: {
headercol: 'transparent',
inputtx: '#CCC',
inputbacg: '#FFF',
messcol: '#FFF',
inputWidth: width - 20,
barStyle: 'light-content',
},
})
}
}
_addShopCart(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))
this.setState({ isRefreshAdd: this.state.isRefreshAdd })
}
render() {
const {
fetching,
hotSaleDatas,
allProDatas,
shopListIds,
announceDatas,
bannerData,
bannerTime,
ReqNumData,
} = this.props
let bannerImg = [],
announceArr = [],
bannerDate =
bannerTime && bannerTime.length > 0
? accMul(1000, bannerTime[0].autoPlaySpeed || 0.5)
: 5000
bannerData.map((item, index) => {
bannerImg.push(
)
})
if (announceDatas && announceDatas.length > 0) {
announceDatas.slice(1, announceDatas.length).map(data => {
announceArr = announceArr.concat(data.noticeInfoMap)
})
}
return (
{
//alert('toast消失了');
}}
ref={(element) => {
this.plToast = element;
}}
/>
{this.state.headerView ? (
this.mdl._openModal()}
textInputBacg={this.state.header.inputbacg}
placeholderTextColor={this.state.header.inputtx}
iconColor={this.state.header.inputtx}
iconSize={16}
style={{
height: 28,
width: this.state.header.inputWidth,
marginTop: 18,
borderRadius: width / 2,
alignSelf: 'center',
paddingLeft: 14,
}}
/>
{this.state.header.headercol == 'transparent' ? null : (
{
this.props.dispatch(
NavigationActions.navigate({
routeName: 'Replenishment',
})
)
// this.props.dispatch(createAction("home/recentViewClear")());
}}
/>
)}
) : null}
{
this._onScroll(event)
}}
refreshControl={
this.onRefresh)或者通过bind来绑定this引用来调用方法
tintColor="red"
title={this.state.isRefreshing ? '刷新中....' : '下拉刷新'}
/>
}
onMomentumScrollEnd={eve => {
if (eve.nativeEvent.contentOffset.y == 0) {
this.setState({ headerView: true })
}
}}
>
{
console.log(a)
}}
>
{bannerImg}
{this.touchItem(ReqNumData)}
{
this.props.dispatch(
NavigationActions.navigate({ routeName: 'Announcement' })
)
}}
activeOpacity={1}
style={{
flexDirection: 'row',
justifyContent: 'space-between',
}}
>
更多>
{hotSaleDatas && hotSaleDatas.length > 0 ? (
2
? hotSaleDatas.slice(0, 2)
: hotSaleDatas
}
titleName="热卖促销"
imageSource={homeHotSale}
nameKey="displayName"
pictureKey="mainPictureFileUrl"
priceKey="baseDiscountPrice"
keyext="id"
imageTouch={e => {
this.gotoDetail(e)
}}
shoppingCart={item => {
if (item.isOptional) {
this.gotoDetail(item)
} else {
this._addShopCart(item)
}
}}
titleIcon=""
shopListIds={shopListIds}
/>
) : null}
0
? allProDatas.content.length > 8
? allProDatas.content.slice(0, 8)
: allProDatas.content
: []
}
nameKey="displayName"
pictureKey="mainPictureFileUrl"
priceKey="baseDiscountPrice"
keyext="id"
imageTouch={e => {
// this.props.dispatch(
// createAction("home/getRecentView")({ recentView: e })
// );
this.gotoDetail(e)
}}
moreTouch={() =>
// this.props.dispatch(
// createAction("search/searchGoodsAll")({
// comeFrom: "Home",
// searchVal: {
// search_customerId: CUSTOMERINFO.id,
// search_customerRankCode: CUSTOMERINFO.customerRankCode,
// // search_EQ_isOptional: 0,
// // search_EQ_enableStrucManage: 0
// }
// })
// )
this.props.dispatch(
NavigationActions.navigate({
routeName: 'CommodityShowbase',
params: { searchval: '' },
})
)
}
shoppingCart={item => {
if (item.isOptional) {
this.gotoDetail(item)
} else {
this._addShopCart(item)
}
}}
shopListIds={shopListIds}
/>
{/* {
this.gotoDetail(e);
}}
moreTouch={() =>
this.props.dispatch(
NavigationActions.navigate({ routeName: "RecentViewMore" })
)
}
/> */}
{
// this._refreshPlist(data);
// }}
ref={mdl => (this.mdl = mdl)}
dispatch={this.props.dispatch}
comFrom={'Home'}
/>
{/* {fetching ? (
) : null} */}
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
pngstyle: {
width: width,
height: 240,
},
buttonStyle: {
backgroundColor: 'transparent',
flexDirection: 'column',
alignItems: 'center',
},
buttonText: {
fontSize: 12,
color: '#333',
},
})
export default Home