import { useState } from "react"
import { Textarea, View } from "@tarojs/components"
import CustomNav from "@/components/CustomNav"
import ButtontWX from "@/components/ButtontWX"
import { feedback } from "@/services/mine"
import Taro from "@tarojs/taro"

import './style.less'



export default (props) => {

  const [textAreaValue, setTextAreaValue] = useState('')
  const [loading, setLoading] = useState(false)

  const onSubmitClick = () => {
    setLoading(true)
    console.log('textAreaValue', textAreaValue);
    if (textAreaValue == '') {
      Taro.showToast({
        title: '请填写内容哦',
        icon: 'none',
        duration: 2000
      })

    } else {

      feedback({ content: textAreaValue }).then(() => {
        Taro.showToast({
          title: '反馈已收到！',
          icon: 'success',
          duration: 2000
        }).then(() => {
          setTimeout(() => {
            setLoading(true)
            Taro.navigateBack({
              delta: 1
            }


            )
          }, 1000)

        })
      })
    }



  }

  return (
    <View className='page-index'>
      <View className='index-navbar'>
        <CustomNav title='意见反馈' />
      </View>
      <View>
        <View className='components-page'>

          <Textarea placeholder='请留下您宝贵的意见和建议！' className='components-page-TextareaCentent' autoHeight onInput={(e) => { setTextAreaValue(e.detail.value) }} />
        </View>
        <View className='buton-bottom-Feedback'>
          <ButtontWX disabled={loading} onClick={onSubmitClick} butText='提交' butWidth={350} butHeight={49} butFontSize={16} butBorderRadius={49} />
        </View>
      </View>
    </View>
  )
}
