import React, { useEffect, useMemo, useState } from 'react'
// import { useEffect, useLayoutEffect, useReducer, useState, useContext, useRef, useCallback, useMemo } from '@tarojs/taro'
import Taro, { useShareAppMessage, useRouter } from "@tarojs/taro";
import { useSelector, } from 'react-redux'
import { View, Input, Text, Image, Picker } 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 './index.scss'
import request from '../../util/request';

// Page({
//     data: {
//         text: 'init data',
//         array: [{ msg: '1' }, { msg: '2' }]
//     }
// })

const index = (props) => {



    const router = useRouter()

    const { houseId } = router.params

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

    const [userRole, setUserRole] = useState('1')
    const [pageState, setPageState] = useState('1')
    const [list, setList] = useState([])
    const [personNum, setPersonNum] = useState()
    const [startTime, setStartTime] = useState('')
    const [endTime, setEndTime] = useState('')
    useEffect(() => {

        // console.log(page, 'page')
        setList([
            {
                name: 'zhou',
                phone: '177'
            },
            {
                name: 'zhou',
                phone: '177'
            },
            {
                name: 'zhou',
                phone: '177'
            }
        ])
    }, [])
    useShareAppMessage(res => {
        console.log('3333')
        if (res.from === 'button') {
            // 来自页面内转发按钮
            console.log(res.target)
        }

        const data = {
            houseId,
            personNum,
            startDate: startTime,
            endDate: endTime
        }
        return request({ url: '/taHouseSetting', method: 'post', data }).then(res => {
            const { data } = res.data
            if (res.data.data) {
                console.log(data.taHouseOrder.orderId)
                const { orderId } = data.taHouseOrder
                return request({ url: `/taHouse/${houseId}/share` }).then(res => {
                    return {
                        title: '分享到微信',
                        path: `/pages/index/index?houseId=${houseId}&personNum=${personNum}&startTime=${startTime}&endTime=${endTime}&orderId=${orderId}`
                    }
                })
            } else {
                Taro.showModal({
                    title: '输入信息有误',
                    content: '请重新输入',
                    showCancel: false,
                    success: function (res) {
                        if (res.confirm) {
                            console.log('用户点击确定')
                        } else if (res.cancel) {
                            console.log('用户点击取消')
                        }
                    }
                })
            }

        })



    })

    async function syncAddOrder() {


    }

    const onTimeChange = (e) => {
        console.log(e, '111')
        setStartTime(e.detail.value)
    }


    return <View className='share'>
        <Layout>
            <View className='inputstyle-view'>
                <Text className='title'>入住人数</Text>
                <Container className='inputstyle-view-card ' style={{ borderRadius: '20rpx', padding: '0 40rpx' }} >
                    <Input type='number' value={personNum} onInput={(e) => setPersonNum(e.detail.value)} placeholderClass='placeholderinput' className='input' type='text' placeholder='' />
                </Container>
            </View>
            <View className='inputstyle-view'>
                <Text className='title'>入住日期</Text>
                <Container className='inputstyle-view-card ' style={{ borderRadius: '20rpx', padding: '0 40rpx' }} >

                    <Picker mode='date' onChange={onTimeChange}>
                        <View className='input' style={{ height: '44rpx', lineHeight: '44rpx', fontsize: '28rpx' }}>
                            {startTime}
                        </View>
                    </Picker>
                    {/* <Input placeholderClass='placeholderinput' className='input' type='text' placeholder='' /> */}
                </Container>
            </View>

            <View className='inputstyle-view'>
                <Text className='title'>离店日期</Text>
                <Container className='inputstyle-view-card ' style={{ borderRadius: '20rpx', padding: '0 40rpx' }} >
                    <Picker mode='date' onChange={(e) => { setEndTime(e.detail.value) }}>
                        <View className='input' style={{ height: '44rpx', lineHeight: '44rpx', fontsize: '28rpx' }}>
                            {endTime}
                        </View>
                    </Picker>
                </Container>
            </View>
        </Layout>
        <Tab openType="share" className='addhousetab' color='#ffffff' pageState='3' onClick={(e) => console.log(33)} value={['分享到微信']} ></Tab>


    </View>
}

export default index