import React, { useEffect, useMemo, useState } from 'react'
import Taro, { useDidShow,useRouter } from '@tarojs/taro'
import { useSelector } from 'react-redux'
import { View, ScrollView } from '@tarojs/components'
import Layout from '../../layout/index'
import Tab from '../../compents/tab/index'
import Guide from '../guide/index'
import Recommend from '../recommend/index'

// import HouseLIst from '../house/list'

import './index.scss'
import request from '../../util/request'

const house = (props) => {
    const router = useRouter()
    const { houseId } = router.params
    const user = useSelector(state => state.user)
   
    const [userRole, setUserRole] = useState('1')
    const [pageState, setPageState] = useState('2')
    const [list, setList] = useState([])
    const [dataSource, setDataSource] = useState([])
    const [imgSource, setImgSource] = useState([])
    useDidShow(() => {
        if (houseId) {
            getDetail()
        }
    })

    useEffect(() => {
        getImageList()
    }, [])

    const getImageList=()=>{
        request({url:'/taHouseSurround',params:{houseId:houseId}}).then((res)=>{
            const {records,...page} =res.data.data  
            setImgSource(records)
        })
    }
    // useEffect(() => {
    //     console.log(houseId, 'params33')
    //     if (houseId) {
    //         getDetail()
    //     }

    // }, [])
    const getDetail = () => {
        request({ url: `/taHouse/${houseId}` }).then((res) => {
            setDataSource(res.data.data)

            wx.setNavigationBarTitle({
                title: res.data.data.title
            })
        })
    }
    

    const onTabClick = (e) => {
        console.log(e, '111')
        setUserRole(e)
    }

    const onRegisterChange = (e) => {
        console.log(e, '111')
    }


    return <View className='index'>


        <View >

            <Layout>
                {pageState == '2' && <Guide houseId={houseId} dataSource={dataSource}></Guide>}
                {pageState == '3' && <Recommend houseId={houseId} dataSource={imgSource}></Recommend>}
            </Layout>
            {pageState != '1' && <Tab value={['入住指引', '房东推荐']} pageState={pageState} onClick={[(e) => setPageState('2'), (e) => setPageState('3')]}></Tab>}

        </View>


    </View>
}

export default house