index.jsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { useState, useEffect } from 'react'
  2. import '@/assets/css/iconfont.css'
  3. import { Image, Slider, Textarea, ScrollView } from '@tarojs/components'
  4. import { fetch } from '@/utils/request'
  5. import { API_HELP_FIND_HOUSE_SUBMIT } from '@/constants/api'
  6. import { useSelector } from 'react-redux'
  7. import './index.scss'
  8. import questions from './formData'
  9. import SubmitBuyHouseResult from '../helpToFindHouse/components/SubmitBuyHouseResult/index'
  10. export default function AddedValueService () {
  11. const user = useSelector(state => state.user)
  12. const [FormData, setFormData] = useState(questions)
  13. const [StepId, setStepId] = useState(1)
  14. const [StepRange, setStepRange] = useState([0, 3])
  15. const [ResultList, setResultList] = useState([])
  16. const [ShowPopup, setShowPopup] = useState(false)
  17. useEffect(() => {
  18. if (StepId === 1) {
  19. setStepRange([0, 3])
  20. } else if (StepId === 2) {
  21. setStepRange([3, 6])
  22. } else if (StepId === 3) {
  23. setStepRange([6, 8])
  24. } else if (StepId === 4) {
  25. setStepRange([8, 9])
  26. }
  27. }, [StepId])
  28. const SubmitForm = (data) => {
  29. data = data || []
  30. let params = []
  31. data.map((item) => {
  32. if(item.key === 'budget') {
  33. params.push({...item, key: 'minPrice', result: item.options[0] * 10000})
  34. params.push({...item, key: 'maxPrice', result: item.result !== '' ? item.result * 10000 : 5000000})
  35. } else {
  36. if(item.result !== '' || item.resultId !== null) {
  37. params.push(item)
  38. }
  39. }
  40. })
  41. params.push({question: '创建人小程序人员', result: user?.userInfo?.person?.personId, key: 'personId' })
  42. let payload = {}
  43. params.map((item) => {
  44. payload[item.key] = item.result || item.resultId
  45. })
  46. fetch({ url: API_HELP_FIND_HOUSE_SUBMIT, method: 'post', payload: { ...payload, questionnaire: JSON.stringify(params), type: 4 } }).then((res) => {
  47. setResultList(res.taBuildingList || [])
  48. setShowPopup(true)
  49. })
  50. }
  51. const CutCheckbox = (item, index) => {
  52. return () => {
  53. let newFormData = [...FormData]
  54. newFormData[index].resultId = item.id
  55. newFormData[index].result = item.name
  56. setFormData([...newFormData])
  57. }
  58. }
  59. const Rangehange = (e, index) => {
  60. let newFormData = [...FormData]
  61. newFormData[index].result = e.detail.value
  62. setFormData([...newFormData])
  63. }
  64. const remarkInput = (e, index) => {
  65. let newFormData = [...FormData]
  66. newFormData[index].remark = e.detail.value
  67. setFormData([...newFormData])
  68. }
  69. const textareaInput = (e, index) => {
  70. let newFormData = [...FormData]
  71. newFormData[index].result = e.detail.value
  72. setFormData([...newFormData])
  73. }
  74. const NextStep = () => {
  75. if (StepId < 4) {
  76. setStepId(StepId + 1)
  77. } else {
  78. SubmitForm(FormData)
  79. }
  80. }
  81. const PrevStep = () => {
  82. if (StepId > 1) {
  83. setStepId(StepId - 1)
  84. }
  85. }
  86. return (
  87. <view className='components AddedValueService'>
  88. {
  89. ShowPopup &&
  90. <SubmitBuyHouseResult List={ResultList.slice(0, 1)}></SubmitBuyHouseResult>
  91. }
  92. <ScrollView scroll-y>
  93. <view className='PageContent'>
  94. {
  95. FormData.map((item, index) => (
  96. <view className='Step' key={`Form-${index}`}>
  97. {
  98. index >= StepRange[0] && index < StepRange[1] &&
  99. <view>
  100. <text>{item.question}</text>
  101. {
  102. item.type === 'checkbox' &&
  103. <view className='CheckList'>
  104. {
  105. item.options.map((subItem, subIndex) => (
  106. <view key={`${item.key}-${subIndex}`} className={item.resultId === subItem.id ? 'active' : ''} onClick={CutCheckbox(subItem, index)}>
  107. {subItem.name}
  108. <Image mode='heightFix' src={require('@/assets/findHouse-icon1.png')}></Image>
  109. </view>
  110. ))
  111. }
  112. </view>
  113. }
  114. {
  115. item.type === 'checkbox' && item.remark !== undefined &&
  116. <view className='Textarea'>
  117. <Textarea placeholder='请说出您的其他需求,让我们更好的为您服务!' onInput={(e) => { remarkInput(e, index) }} />
  118. </view>
  119. }
  120. {
  121. item.type === 'range' &&
  122. <view className='RangeList flex-h'>
  123. <view className='flex-item'>
  124. <Slider activeColor='#193C83' block-color='#fff' onChange={(e) => { Rangehange(e, index) }} min={item.options[0]} max={item.options[1]} show-value />
  125. </view>
  126. <text>万</text>
  127. </view>
  128. }
  129. {
  130. item.type === 'textarea' &&
  131. <view className='Textarea'>
  132. <Textarea placeholder='请说出您的其他需求,让我们更好的为您服务!' onInput={(e) => { textareaInput(e, index) }} />
  133. </view>
  134. }
  135. </view>
  136. }
  137. </view>
  138. ))
  139. }
  140. <view className='Btn'>
  141. <text className='active' onClick={NextStep}>下一步</text>
  142. <text onClick={PrevStep}>返回</text>
  143. </view>
  144. </view>
  145. </ScrollView>
  146. </view>
  147. )
  148. }