import React, { useEffect, useMemo, useState } from 'react'
import Taro, { useDidShow } from "@tarojs/taro";
import { useSelector } from 'react-redux'
import { View, ScrollView, Button } from '@tarojs/components'
import Layout from '../../layout/index'
import Tab from '../../compents/tab/index'
// import Register from './register/index'
import Guide from '../guide/index'
import Recommend from '../recommend/index'
import HouseLIst from '../house/list/index'
import { AtFloatLayout } from "taro-ui"
import request from '@/util/request'
import './index.scss'

const index = (props) => {


  const user = useSelector(state => state.user)
  const [isOpened, setIsOpened] = useState(false)
  const [userRole, setUserRole] = useState('1')
  const [pageState, setPageState] = useState('1')
  const [list, setList] = useState([])
  const [radioHouseData, setRadioHouseData] = useState()
  const [radioHouseState, setRadioHouseState] = useState(false)
  console.log(user,'99999999')
  useEffect(() => {

   

    setList([
      {
        name: 'zhou',
        phone: '177'
      },
      {
        name: 'zhou',
        phone: '177'
      },
      {
        name: 'zhou',
        phone: '177'
      }
    ])

    getHouseList()
  }, [])

  // useDidShow(()=>{
  //   getHouseList()
  // })

  const getHouseList=()=>{
    request({
      url:'/taHouse',
      method: 'get',
    })
  }



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

  const onRegisterChange = (e) => {
    console.log(e, '111')
  }
  const onCopy = (e) => {
    
    console.log(radioHouseData, '111')
    if(radioHouseData.id){
      Taro.navigateTo({ url: '/pages/house/addnewhouse/index?id=radioHouseData.id'})
      // Taro.showModal({
      //   title: '修改成功',
      //   content: '点击确认按钮，返回上级菜单',
      //   showCancel:false,
      //   success: function (res) {
      //     if (res.confirm) {
      //       console.log('用户点击确定')

      //       Taro.navigateTo({ url: '/pages/house/addnewhouse/index?id=radioHouseData.id'})
      //     } else if (res.cancel) {
      //       console.log('用户点击取消')
      //     }
      //   }
      // })
     
    } 
 
  }

  
  return <View className='index'>


    <View>

      <Layout>
        {pageState == '1' && <HouseLIst  radioHouseState={radioHouseState} onChange={(e) => setRadioHouseData(e)}></HouseLIst>}
      </Layout>
      {!isOpened && <Tab className='addhousetab' value={['+添加房源']} onClick={(e) => setIsOpened(true)}></Tab>}
      {/* {pageState!='1' &&<Tab value={['入住指引','房东推荐']} pageState={pageState} onClick={(e)=>setPageState(e)}></Tab>} */}
      {radioHouseState && <Tab pageState='3' value={['取消', '确认复制']} onClick={[(e) => { setRadioHouseState(false), setIsOpened(false) },()=>onCopy()]}></Tab>}
    </View>



    <AtFloatLayout isOpened={isOpened} onClose={() => handleClose()} style={{ zIndex: '1000' }}>
      <View className='floatmodel' >
        <View onClick={() => Taro.navigateTo({ url: '/pages/house/addnewhouse/index' })}>新增房源</View>
        <View onClick={() => { setIsOpened(false); setRadioHouseState(true) }}>复制房源</View>
        <View style={{ color: '#d2d2d2' }} onClick={()=>setIsOpened(false)}>取消</View>
      </View>

    </AtFloatLayout>
  </View>
}

export default index