index.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import Taro, { useState } from '@tarojs/taro'
  2. import { View, OpenData } from '@tarojs/components'
  3. import { AtTextarea, AtButton } from 'taro-ui'
  4. import { suggest } from '@/service/cloud'
  5. import './index.scss'
  6. function Index() {
  7. const [value, setValue] = useState()
  8. const submit = async() => {
  9. if (value && value.length < 5) {
  10. Taro.showToast({
  11. title: '要详细点哦~',
  12. icon: 'none',
  13. duration: 2000,
  14. })
  15. return
  16. }
  17. const { status } = await suggest({ data: value })
  18. if (status === 0) {
  19. await new Promise(r => {
  20. Taro.showToast({
  21. title: '提交成功',
  22. icon: 'success',
  23. duration: 2000,
  24. success: () => {
  25. setTimeout(r, 2000)
  26. }
  27. })
  28. })
  29. Taro.redirectTo({
  30. url: '/pages/index/index'
  31. })
  32. }
  33. }
  34. return (
  35. <View className='container'>
  36. <View className='header'>
  37. <View className='user-avatar'>
  38. <OpenData type='userAvatarUrl' />
  39. </View>
  40. </View>
  41. <View className='body'>
  42. <AtTextarea
  43. value={value}
  44. className='textarea'
  45. maxLength={200}
  46. onChange={(e: any) => setValue(e.target.value)}
  47. placeholder='感谢您的反馈和建议。。。'
  48. />
  49. </View>
  50. <AtButton
  51. type='secondary'
  52. disabled={!value}
  53. onClick={submit}
  54. >提交</AtButton>
  55. </View>
  56. )
  57. }
  58. Index.config = {
  59. navigationBarTitleText: '意见反馈'
  60. }
  61. export default Index