import React, { useEffect, useMemo, useState } from 'react'
import Taro,{useRouter } from "@tarojs/taro";
import { useSelector } from 'react-redux'
import { View, Input, Text, Image } from '@tarojs/components'
import Layout from '../../layout/index'
import Tab from '../../compents/tab/index'
import Container from '../../compents/container/index'
import locationicon from '../../assets/locationicon.png'
import request from '../../util/request'
import './index.scss'

const index = (props) => {
    const router = useRouter()

    const { houseId } = router.params
    const page = useSelector(state => state.page)

    const user = useSelector(state => state.user)

    const [userRole, setUserRole] = useState('1')
    const [pageState, setPageState] = useState('1')
    const [list, setList] = useState([])
    const [wifiName,setWifiName] = useState('')
    const [wifiPassword,setWifiPassword] = useState('')

   useEffect(() => {
        
        if (houseId) {
            getDetail()
        }

    }, [])
    const getDetail = () => {
        request({ url: `/taHouse/${houseId}` }).then((res) => {
            console.log(res.data.data, 'getDetail')
            setWifiName(res.data.data.wifiName)
            setWifiPassword(res.data.data.wifiPassword)
        })
    }


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

    const onRegisterChange = (e) => {
        console.log(e, '111')
    }
    const onSave = () => {
        console.log(333)
        const data= {
            wifiName,
            wifiPassword
        }

        request({ url: `/taHouse/${houseId}`, method: 'put', data: { ...data, houseId } }).then((res) => {
            Taro.navigateBack({
                delta: 1
            })
        })
        
        // Taro.showModal({
        //     title: '修改成功',
        //     content: '点击确认按钮，返回上级菜单',
        //     showCancel:false,
        //     success: function (res) {
        //       if (res.confirm) {
        //         console.log('用户点击确定')

        //         Taro.navigateBack({
        //             delta: 1
        //           })
        //       } else if (res.cancel) {
        //         console.log('用户点击取消')
        //       }
        //     }
        //   })
    }


    return <View className='map'>




        <Layout>
            <View className='map-view'>
                <Text className='title'>WiFi名称</Text>
                <Container className='map-view-card'>
                <Input value={wifiName} onInput={(e)=>setWifiName(e.detail.value)}  placeholderClass='placeholderinput' className='input' type='text' placeholder='' />
                </Container>
            </View>
         

            <View className='map-view'>
                <Text className='title'>密码</Text>
                <Container className='map-view-card'>
                <Input value={wifiPassword} onInput={(e)=>setWifiPassword(e.detail.value)} placeholderClass='placeholderinput' className='input' type='text' placeholder='' />
                </Container>
            </View>
        </Layout>
         <Tab className='addhousetab' pageState='3' value={['取消', '保存修改']} onClick={[(e) =>Taro.navigateBack({
                delta: 1
            }), () => onSave()]}></Tab>





    </View>
}

export default index