import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Swiper, SwiperItem, Image } from '@tarojs/components'
import { AtActivityIndicator } from 'taro-ui'
import filteredShopComponent from '../../component/filteredShopComponent/filteredShopComponent'
import bottomNav from '../../component/bottomNav/bottomNav'
import URL from '../../serviceAPI.config'
import './home.scss'
class Home extends Component {
config = {
navigationBarTitleText: '首页'
}
constructor() {
super(...arguments);
this.state = {
shopsDetails: '',
ads: '',
categories: '',
demanding: '',
otherData:''
}
}
componentWillMount(){
}
componentDidMount() {
this.getShops()
this.getHomeCategoriesInfo()
}
componentWillReceiveProps(nextProps) {
//console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
// 得到首页的信息
getHomeCategoriesInfo() {
Taro.request({
url: URL.ShopWxStore,
})
.then(res => {
console.log(res)
this.setState({
ads: res.data.data.adsLb,
categories: res.data.data.supplyClass,
demanding: res.data.data.demand.supplys,
otherData:res.data.otherData
}, () => {
//console.log(this.state.demanding)
})
})
}
// 得到所有商店的信息
getShops(parent_supply_class = 0, supply_class = '-1', supply_level = 1) {
Taro.request({
url: URL.ShopSupplyShops,
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)
}
goToAllDemandingPage(){
Taro.navigateTo({
url: '/pages/allDemanding/allDemanding'
})
}
render() {
const demandingElemensArray = this.state.demanding?this.state.demanding.map((item, index) => {
return < SwiperItem key={index} >
{item.class_name}
{item.sd_title}
{item.user_address}
业主:{item.user_name}
}) :null
const adsImgElementsArray = this.state.ads?this.state.ads.map((item, index) => {
return
}):null
// 这里应该代码可以优化-----
const categoriesElementsArray1 = this.state.categories?this.state.categories[0].map((item, index) => {
return
{item.class_name}
}):null
const categoriesElementsArray2 = this.state.categories?this.state.categories[1].map((item, index) => {
return
{item.class_name}
}):null
const shopCollectionElementsArray = this.state.shopsDetails?this.state.shopsDetails.map((item, index) => {
return
}):null
const subCateElementsArray = this.state.subCate?this.state.subCate.map((item, index) => {
return
{item.class_name}
}):null
return (
{/* 第一行图片滚动条 */}
{adsImgElementsArray}
{/* 第二行图片滚动条 */}
{categoriesElementsArray1}
{categoriesElementsArray2}
{/* 第三行图片滚动条 */}
{/* 业主需求和行业推荐 */}
业主需求
更多>>
{demandingElemensArray}
{subCateElementsArray}
行业推荐
{shopCollectionElementsArray}
{this.state.shopsDetails.length !== 0 ?
沒有更多了...
: < View className='title' >
没有找到...
}
)
}
}
export default Home