index.jsx 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { useState, useEffect } from 'react'
  2. import '@/assets/css/iconfont.css'
  3. import { Image, Slider, Textarea } from '@tarojs/components'
  4. import './index.scss'
  5. import questions from './formData'
  6. export default function RentingHouse (props) {
  7. const { change = () => { }, toSubmit = () => {}, AreaInfo = {}, selectArea = () => {} } = props
  8. const [FormData, setFormData] = useState(questions)
  9. const [StepId, setStepId] = useState(1)
  10. const [StepRange, setStepRange] = useState([0, 4])
  11. useEffect(() => {
  12. if(StepId === 1) {
  13. setStepRange([0, 4])
  14. } else if(StepId === 2) {
  15. setStepRange([4, 6])
  16. }
  17. change(StepId)
  18. }, [StepId])
  19. const CutCheckbox = (item, index) => {
  20. return () => {
  21. let newFormData = [...FormData]
  22. newFormData[index].resultId = item.id
  23. newFormData[index].result = item.name
  24. setFormData([...newFormData])
  25. }
  26. }
  27. const Rangehange = (e, index) => {
  28. let newFormData = [...FormData]
  29. newFormData[index].result = e.detail.value
  30. setFormData([...newFormData])
  31. }
  32. const remarkInput = (e, index) => {
  33. let newFormData = [...FormData]
  34. newFormData[index].remark = e.detail.value
  35. setFormData([...newFormData])
  36. }
  37. const textareaInput = (e, index) => {
  38. let newFormData = [...FormData]
  39. newFormData[index].result = e.detail.value
  40. setFormData([...newFormData])
  41. }
  42. const NextStep = () => {
  43. if (StepId < 2) {
  44. setStepId(StepId + 1)
  45. } else {
  46. toSubmit(FormData)
  47. }
  48. }
  49. const PrevStep = () => {
  50. if (StepId > 1) {
  51. setStepId(StepId - 1)
  52. }
  53. }
  54. return (
  55. <view className='components BuyHouse'>
  56. {
  57. FormData.map((item, index) => (
  58. <view className='Step' key={`Form-${index}`}>
  59. {
  60. index >= StepRange[0] && index < StepRange[1] &&
  61. <view>
  62. <text>{item.question}</text>
  63. {
  64. item.type === 'checkbox' &&
  65. <view className='CheckList'>
  66. {
  67. item.options.map((subItem, subIndex) => (
  68. <view key={`${item.key}-${subIndex}`} className={item.resultId === subItem.id ? 'active' : ''} onClick={CutCheckbox(subItem, index)}>
  69. {subItem.name}
  70. <Image mode='heightFix' src={require('@/assets/findHouse-icon1.png')}></Image>
  71. </view>
  72. ))
  73. }
  74. </view>
  75. }
  76. {
  77. item.type === 'checkbox' && item.remark !== undefined &&
  78. <view className='Textarea'>
  79. <Textarea placeholder='请说出您的其他需求,让我们更好的为您服务!' onInput={(e) => {remarkInput(e, index)}} />
  80. </view>
  81. }
  82. {
  83. item.type === 'range' &&
  84. <view className='RangeList flex-h'>
  85. <view className='flex-item'>
  86. <Slider activeColor='#193C83' block-color='#fff' onChange={(e) => { Rangehange(e, index) }} min={item.options[0]} max={item.options[1]} show-value />
  87. </view>
  88. <text>元</text>
  89. </view>
  90. }
  91. {
  92. item.type === 'select' &&
  93. <view className='Area'>
  94. <view className='flex-h' onClick={selectArea}>
  95. {
  96. item.key === 'district' &&
  97. <text className='iconfont icon-dingwei'></text>
  98. }
  99. <text>{AreaInfo.name || '不限'}</text>
  100. <view className='flex-item'></view>
  101. <text className='iconfont icon-jiantoudown'></text>
  102. </view>
  103. </view>
  104. }
  105. {
  106. item.type === 'textarea' &&
  107. <view className='Textarea'>
  108. <Textarea placeholder='请说出您的其他需求,让我们更好的为您服务!' onInput={(e) => {textareaInput(e, index)}} />
  109. </view>
  110. }
  111. </view>
  112. }
  113. </view>
  114. ))
  115. }
  116. <view className='Btn'>
  117. <text className='active' onClick={NextStep}>下一步</text>
  118. <text onClick={PrevStep}>返回</text>
  119. </view>
  120. </view>
  121. )
  122. }