cf-wx-app/src/pages/home/home.js

284 lines
8.1 KiB
JavaScript
Raw Normal View History

2018-11-29 17:35:49 +08:00
import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Swiper, SwiperItem, Image } from '@tarojs/components'
2018-12-03 17:32:48 +08:00
import { AtActivityIndicator } from 'taro-ui'
2018-11-30 17:30:16 +08:00
import filteredShopComponent from '../../component/filteredShopComponent/filteredShopComponent'
2018-12-03 17:32:48 +08:00
import bottomNav from '../../component/bottomNav/bottomNav'
import URL from '../../serviceAPI.config'
2018-11-29 17:35:49 +08:00
import './home.scss'
class Home extends Component {
2018-11-30 17:30:16 +08:00
config = {
2018-11-29 17:35:49 +08:00
navigationBarTitleText: '首页'
}
2018-11-30 17:30:16 +08:00
constructor() {
2018-12-03 17:32:48 +08:00
super(...arguments);
2018-11-30 17:30:16 +08:00
this.state = {
shopsDetails: '',
ads: '',
categories: '',
demanding: '',
2018-12-03 17:32:48 +08:00
otherData:''
2018-11-29 17:35:49 +08:00
}
}
2018-12-03 17:32:48 +08:00
componentWillMount(){
2018-11-29 17:35:49 +08:00
2018-12-03 17:32:48 +08:00
}
2018-11-30 17:30:16 +08:00
componentDidMount() {
2018-12-03 17:32:48 +08:00
2018-11-30 17:30:16 +08:00
this.getShops()
this.getHomeCategoriesInfo()
2018-11-29 17:35:49 +08:00
}
2018-11-30 17:30:16 +08:00
componentWillReceiveProps(nextProps) {
2018-11-29 17:35:49 +08:00
//console.log(this.props, nextProps)
}
2018-11-30 17:30:16 +08:00
componentWillUnmount() { }
2018-11-29 17:35:49 +08:00
2018-11-30 17:30:16 +08:00
componentDidShow() { }
2018-11-29 17:35:49 +08:00
2018-11-30 17:30:16 +08:00
componentDidHide() { }
2018-11-29 17:35:49 +08:00
2018-12-03 17:32:48 +08:00
// 得到首页的信息
2018-11-30 17:30:16 +08:00
getHomeCategoriesInfo() {
2018-11-29 17:35:49 +08:00
Taro.request({
2018-12-03 17:32:48 +08:00
url: URL.ShopWxStore,
2018-11-29 17:35:49 +08:00
})
2018-11-30 17:30:16 +08:00
.then(res => {
console.log(res)
2018-11-29 17:35:49 +08:00
this.setState({
ads: res.data.data.adsLb,
categories: res.data.data.supplyClass,
demanding: res.data.data.demand.supplys,
2018-12-03 17:32:48 +08:00
otherData:res.data.otherData
2018-11-29 17:35:49 +08:00
}, () => {
2018-11-30 17:30:16 +08:00
//console.log(this.state.demanding)
})
})
2018-11-29 17:35:49 +08:00
}
2018-12-03 17:32:48 +08:00
// 得到所有商店的信息
2018-11-30 17:30:16 +08:00
getShops(parent_supply_class = 0, supply_class = '-1', supply_level = 1) {
2018-11-29 17:35:49 +08:00
Taro.request({
2018-12-03 17:32:48 +08:00
url: URL.ShopSupplyShops,
2018-11-29 17:35:49 +08:00
method: 'POST',
dataType: 'json',
data: {
param: JSON.stringify({
curr_page: 1,
page_count: 20,
2018-11-30 17:30:16 +08:00
parent_supply_class: parent_supply_class, //父级class id
supply_class: supply_class,// 子级class id
supply_level: supply_level,// 层级
2018-11-29 17:35:49 +08:00
action: "2"
})
},
header: {
2018-12-03 17:32:48 +08:00
'content-type': 'application/x-www-form-urlencoded',
2018-11-29 17:35:49 +08:00
}
})
.then(res => {
2018-11-30 17:30:16 +08:00
this.setState({ shopsDetails: res.data.shops }, () => {
// console.log('-----',res)
})
2018-11-29 17:35:49 +08:00
}
)
}
2018-11-30 17:30:16 +08:00
onClickParentCate(item) {
this.setState({ subCate: item.children })
this.getShops(item.parent_class_id, item.class_id)
}
onClickChildCate(item) {
this.getShops(item.parent_class_id, item.class_id, 2)
}
goToAllDemandingPage(){
Taro.navigateTo({
url: '/pages/allDemanding/allDemanding'
})
}
2018-12-03 17:32:48 +08:00
2018-11-30 17:30:16 +08:00
render() {
2018-12-03 17:32:48 +08:00
const demandingElemensArray = this.state.demanding?this.state.demanding.map((item, index) => {
2018-11-30 17:30:16 +08:00
return < SwiperItem key={index} >
<View className='demanding-item'>
<View className='item-tag'>
<Text className='item-tag-text'> {item.class_name}</Text>
</View>
<View className='item-title'>
{item.sd_title}
</View>
<View className='item-address'>
{item.user_address}
</View>
<View className='item-name'>
2018-11-29 17:35:49 +08:00
业主{item.user_name}
</View>
2018-11-30 17:30:16 +08:00
<View className='item-button-box'>
<Button className='item-button' >{item.state_name}</Button>
</View>
</View>
</SwiperItem >
2018-12-03 17:32:48 +08:00
}) :null
2018-11-29 17:35:49 +08:00
2018-12-03 17:32:48 +08:00
const adsImgElementsArray = this.state.ads?this.state.ads.map((item, index) => {
2018-11-30 17:30:16 +08:00
return <SwiperItem key={index}>
2018-12-03 17:32:48 +08:00
<Image className='banner-img' src={URL.Base + item.ads_pic} />
2018-11-29 17:35:49 +08:00
</SwiperItem>
2018-12-03 17:32:48 +08:00
}):null
2018-11-30 17:30:16 +08:00
// 这里应该代码可以优化-----
2018-12-03 17:32:48 +08:00
const categoriesElementsArray1 = this.state.categories?this.state.categories[0].map((item, index) => {
2018-11-30 17:30:16 +08:00
return <View className='category-item' key={index} onClick={this.onClickParentCate.bind(this, item)}>
2018-12-03 17:32:48 +08:00
<View> <Image style='height: 42px;width: 42px;' className='cate-img' src={URL.Base + item.icon} /></View>
2018-11-29 17:35:49 +08:00
<View>{item.class_name}</View>
</View>
2018-12-03 17:32:48 +08:00
}):null
const categoriesElementsArray2 = this.state.categories?this.state.categories[1].map((item, index) => {
2018-11-30 17:30:16 +08:00
return <View className='category-item' key={index} onClick={this.onClickParentCate.bind(this, item)}>
2018-12-03 17:32:48 +08:00
<View> <Image style='height: 42px;width: 42px;' className='cate-img' src={URL.Base + item.icon} /></View>
2018-11-29 17:35:49 +08:00
<View>{item.class_name}</View>
</View>
2018-12-03 17:32:48 +08:00
}):null
const shopCollectionElementsArray = this.state.shopsDetails?this.state.shopsDetails.map((item, index) => {
2018-11-30 17:30:16 +08:00
return <filteredShopComponent shop={item} key={index}></filteredShopComponent>
2018-12-03 17:32:48 +08:00
}):null
const subCateElementsArray = this.state.subCate?this.state.subCate.map((item, index) => {
2018-11-30 17:30:16 +08:00
return <SwiperItem key={index} onClick={this.onClickChildCate.bind(this, item)}>
<View className='text'>{item.class_name}</View>
</SwiperItem>
2018-12-03 17:32:48 +08:00
}):null
2018-11-29 17:35:49 +08:00
return (
2018-12-03 17:32:48 +08:00
2018-11-29 17:35:49 +08:00
<View className='home'>
2018-11-30 17:30:16 +08:00
{/* 第一行图片滚动条 */}
2018-12-03 17:32:48 +08:00
2018-11-30 17:30:16 +08:00
<View className='first-banner'>
2018-11-29 17:35:49 +08:00
<Swiper
2018-11-30 17:30:16 +08:00
className='swipper'
2018-11-29 17:35:49 +08:00
indicatorColor='#999'
indicatorActiveColor='#333'
hotizontal
circular
indicatorDots
autoplay>
{adsImgElementsArray}
</Swiper>
</View>
2018-11-30 17:30:16 +08:00
{/* 第二行图片滚动条 */}
<View className='second-banner'>
2018-11-29 17:35:49 +08:00
<Swiper
2018-11-30 17:30:16 +08:00
className='swipper'
2018-11-29 17:35:49 +08:00
indicatorColor='#999'
indicatorActiveColor='#333'
hotizontal
circular
indicatorDots
autoplay>
<SwiperItem>
<View className='categories'>
{categoriesElementsArray1}
</View>
</SwiperItem>
<SwiperItem>
<View className='categories'>
{categoriesElementsArray2}
</View>
</SwiperItem>
</Swiper>
</View>
2018-11-30 17:30:16 +08:00
{/* 第三行图片滚动条 */}
<View className='third-banner'>
<Swiper
className='swipper'
indicatorColor='#999'
indicatorActiveColor='#333'
horizontal
circular
indicatorDots
autoplay>
<SwiperItem>
<Image className='banner-img' src='http://192.168.1.230/Public/images/xgt.png' />
</SwiperItem>
</Swiper>
</View>
2018-12-03 17:32:48 +08:00
2018-11-30 17:30:16 +08:00
{/* 业主需求和行业推荐 */}
2018-11-29 17:35:49 +08:00
<View className='container'>
2018-11-30 17:30:16 +08:00
<View className='title'>
<Text className='title-block'></Text>
<Text className='title-text'>业主需求</Text>
<Text className='more-link' onClick={this.goToAllDemandingPage.bind(this)}>
2018-11-30 17:30:16 +08:00
更多>>
</Text>
</View>
<View className='customer-demanding'>
<Swiper
className='swipper swiper-sub'
indicatorColor='#999'
indicatorActiveColor='#333'
horizontal
circular
displayMultipleItems='2.5'
>
{demandingElemensArray}
</Swiper>
</View>
<View className='sub-cate'>
2018-12-03 17:32:48 +08:00
</View>
<View className='second-banner-level2'>
<Swiper
className='swipper swiper-sub'
indicatorColor='#999'
indicatorActiveColor='#333'
horizontal
displayMultipleItems='4.5'
>
{subCateElementsArray}
</Swiper>
2018-11-30 17:30:16 +08:00
</View>
<View className='title'>
<Text className='title-block'></Text>
<Text className='title-text'>行业推荐</Text>
</View>
2018-12-03 17:32:48 +08:00
2018-12-06 17:24:34 +08:00
2018-11-30 17:30:16 +08:00
<View className='shop-box'>
2018-11-29 17:35:49 +08:00
{shopCollectionElementsArray}
2018-12-03 17:32:48 +08:00
{this.state.shopsDetails.length !== 0 ? <View className='title'>
沒有更多了...
</View>: < View className='title' >
没有找到...
</View > }
2018-11-30 17:30:16 +08:00
</View>
2018-12-06 17:24:34 +08:00
<View className='gap'>
</View>
2018-12-03 17:32:48 +08:00
2018-11-29 17:35:49 +08:00
</View>
2018-12-06 17:24:34 +08:00
2018-12-03 17:32:48 +08:00
<View className='bottom-nav-box'>
<bottomNav otherData={this.state.otherData}/>
</View>
2018-11-29 17:35:49 +08:00
</View>
)
}
}
export default Home