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

245 lines
7.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Swiper, SwiperItem, Image } from '@tarojs/components'
import { AtButton } from 'taro-ui'
import filteredShopComponent from '../../component/filteredShopComponent/filteredShopComponent'
import { add, minus, asyncAdd } from '../../actions/counter'
import './home.scss'
class Home extends Component {
config = {
navigationBarTitleText: '首页'
}
constructor() {
this.state = {
shopsDetails: '',
ads: '',
categories: '',
demanding: '',
}
}
componentDidMount() {
this.getShops()
this.getHomeCategoriesInfo()
}
componentWillReceiveProps(nextProps) {
//console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
getHomeCategoriesInfo() {
Taro.request({
url: 'http://192.168.1.230/Shop-wxStore',
})
.then(res => {
console.log(res)
this.setState({
ads: res.data.data.adsLb,
categories: res.data.data.supplyClass,
demanding: res.data.data.demand.supplys,
}, () => {
//console.log(this.state.demanding)
})
})
}
getShops(parent_supply_class = 0, supply_class = '-1', supply_level = 1) {
Taro.request({
url: 'http://192.168.1.230/Shop-supplyShops',
method: 'POST',
dataType: 'json',
data: {
param: JSON.stringify({
curr_page: 1,
page_count: 20,
parent_supply_class: parent_supply_class, //父级class id
supply_class: supply_class,// 子级class id
supply_level: supply_level,// 层级
action: "2"
})
},
header: {
'content-type': 'application/x-www-form-urlencoded'
}
})
.then(res => {
this.setState({ shopsDetails: res.data.shops }, () => {
// console.log('-----',res)
})
}
)
}
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)
}
render() {
const demandingElemensArray = this.state.demanding.map((item, index) => {
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'>
业主{item.user_name}
</View>
<View className='item-button-box'>
<Button className='item-button' >{item.state_name}</Button>
</View>
</View>
</SwiperItem >
})
const adsImgElementsArray = this.state.ads.map((item, index) => {
return <SwiperItem key={index}>
<Image className='banner-img' src={'http://192.168.1.230/' + item.ads_pic} />
</SwiperItem>
})
// 这里应该代码可以优化-----
const categoriesElementsArray1 = this.state.categories[0].map((item, index) => {
return <View className='category-item' key={index} onClick={this.onClickParentCate.bind(this, item)}>
<View> <Image style='height: 42px;width: 42px;' className='cate-img' src={'http://192.168.1.230/' + item.icon} /></View>
<View>{item.class_name}</View>
</View>
})
const categoriesElementsArray2 = this.state.categories[1].map((item, index) => {
return <View className='category-item' key={index} onClick={this.onClickParentCate.bind(this, item)}>
<View> <Image style='height: 42px;width: 42px;' className='cate-img' src={'http://192.168.1.230/' + item.icon} /></View>
<View>{item.class_name}</View>
</View>
})
const shopCollectionElementsArray = this.state.shopsDetails.map((item, index) => {
return <filteredShopComponent shop={item} key={index}></filteredShopComponent>
})
const subCateElementsArray = this.state.subCate.map((item, index) => {
return <SwiperItem key={index} onClick={this.onClickChildCate.bind(this, item)}>
<View className='text'>{item.class_name}</View>
</SwiperItem>
})
return (
<View className='home'>
{/* 第一行图片滚动条 */}
<View className='first-banner'>
<Swiper
className='swipper'
indicatorColor='#999'
indicatorActiveColor='#333'
hotizontal
circular
indicatorDots
autoplay>
{adsImgElementsArray}
</Swiper>
</View>
{/* 第二行图片滚动条 */}
<View className='second-banner'>
<Swiper
className='swipper'
indicatorColor='#999'
indicatorActiveColor='#333'
hotizontal
circular
indicatorDots
autoplay>
<SwiperItem>
<View className='categories'>
{categoriesElementsArray1}
</View>
</SwiperItem>
<SwiperItem>
<View className='categories'>
{categoriesElementsArray2}
</View>
</SwiperItem>
</Swiper>
</View>
{/* 第三行图片滚动条 */}
<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>
<View className='second-banner-level2'>
<Swiper
className='swipper swiper-sub'
indicatorColor='#999'
indicatorActiveColor='#333'
horizontal
displayMultipleItems='4.5'
>
{subCateElementsArray}
</Swiper>
</View>
{/* 业主需求和行业推荐 */}
<View className='container'>
<View className='title'>
<Text className='title-block'></Text>
<Text className='title-text'>业主需求</Text>
<Text className='more-link'>
更多>>
</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'>
</View>
<View className='title'>
<Text className='title-block'></Text>
<Text className='title-text'>行业推荐</Text>
</View>
<View className='shop-box'>
{shopCollectionElementsArray}
</View>
</View>
</View>
)
}
}
export default Home