import { useState } from 'react'
import Taro from '@tarojs/taro'
import withLayout from '@/layout'
import { ScrollView, Input } from '@tarojs/components'
import { fetch } from '@/utils/request'
import { API_TOBE_MANAGER } from '@/constants/api'
import './index.scss'

export default withLayout(() => {

  const [Code, setCode] = useState('')

  const ToSubmit = () => {
    if (Code !== '') {
      fetch({ url: API_TOBE_MANAGER, method: 'post', payload: { marketingCode: Code } }).then((res) => {
        Taro.showToast({
          title: '绑定成功',
          icon: 'none'
        })
      })
    } else {
      Taro.showToast({
        title: '请输入楼盘码',
        icon: 'none'
      })
    }
  }

  const CodeChange = (e) => {
    setCode(e.detail.value)
  }

  return (
    <view className='Page toBeManager'>

      <ScrollView scroll-y>
        <view className='PageContent'>

          <view className='Input'>
            <Input placeholder='请输入楼盘码' onInput={CodeChange}></Input>
          </view>

          <view className='Btn'>
            <text onClick={ToSubmit}>提交</text>
          </view>

        </view>
      </ScrollView>

    </view>
  )
})
