index.jsx 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import { useState, useEffect } from 'react'
  2. import withLayout from '@/layout'
  3. import { ScrollView, Input, Image, Picker, Block } from '@tarojs/components'
  4. import '@/assets/css/iconfont.css'
  5. import { useSelector } from 'react-redux'
  6. import { fetch } from '@/utils/request'
  7. import { API_ITEMS_LIST, API_CARDS_LIST, API_REPORT_CUETOMER, API_USER_ADD_CUSTOMER, API_CHANNEL_REPORT } from '@/constants/api'
  8. import Taro from '@tarojs/taro'
  9. import './index.scss'
  10. const defaultSpecialImage = 'https://yz-websit.oss-cn-hangzhou.aliyuncs.com/xlk/index-icon19.jpg'
  11. export default withLayout((props) => {
  12. const { router } = props
  13. const { type } = router.params
  14. const user = useSelector(state => state.user)
  15. const [PersonId, setPersonId] = useState(null)
  16. const [BuildingName, setBuildingName] = useState(null)
  17. const [CanSubmit, setCanSubmit] = useState(false)
  18. const [BuildingId, setBuildingId] = useState(null)
  19. const [CardName, setCardName] = useState(null)
  20. const [CardId, setCardId] = useState(null)
  21. const [BuildingList, setBuildingList] = useState([])
  22. const [CardList, setCardList] = useState([])
  23. const [SexList] = useState([
  24. { name: '男', id: '1' },
  25. { name: '女', id: '2' }
  26. ])
  27. const [SexName, setSexName] = useState(null)
  28. const [SexId, setSexId] = useState(null)
  29. const [FormData, setFormData] = useState({
  30. name: '', // 姓名
  31. phone: '', // 电话
  32. sex: '', // 性别
  33. intention: '', // 意向楼盘
  34. realtyConsultant: '', // 置业顾问
  35. describe: '', // 描述
  36. })
  37. useEffect(() => {
  38. if (PersonId !== user.userInfo.person.personId) {
  39. setPersonId(user.userInfo.person.personId)
  40. }
  41. }, [user])
  42. useEffect(() => {
  43. if (CanSubmit) {
  44. let url = null
  45. if (type === 'consultant') { // 置业顾问
  46. url = API_REPORT_CUETOMER
  47. } else if (type === 'customer') { // 普通客户
  48. url = API_USER_ADD_CUSTOMER
  49. } else { // 经纪人
  50. url = API_CHANNEL_REPORT
  51. }
  52. let params = {}
  53. if (type === 'consultant') {
  54. params = { name: FormData.name, phone: FormData.phone, sex: SexId }
  55. } else {
  56. params = { ...FormData, sex: SexId, buildingId: BuildingId, realtyConsultant: CardId }
  57. }
  58. if (type === 'estateAgent') {
  59. params.channelCustomerId = PersonId
  60. params.channelId = user.userInfo.person.channelId
  61. params.buildingId = BuildingId
  62. params.orgId = `${user.userInfo.person.orgId}`
  63. params.personId = PersonId
  64. }
  65. fetch({ url, method: 'post', payload: params }).then(() => {
  66. Taro.showToast({ title: '添加成功', icon: 'none', duration: 2000 })
  67. setTimeout(() => {
  68. Taro.navigateBack({ delta: 1 })
  69. setCanSubmit(false)
  70. }, 2000)
  71. }).catch(() => {
  72. setCanSubmit(false)
  73. })
  74. }
  75. }, [CanSubmit])
  76. useEffect(() => {
  77. if (PersonId) {
  78. GetBuildingList()
  79. }
  80. }, [PersonId])
  81. useEffect(() => {
  82. if (BuildingId) {
  83. GetCardList()
  84. }
  85. }, [BuildingId])
  86. const GetBuildingList = () => {
  87. fetch({ url: API_ITEMS_LIST, method: 'get', params: { pageNumber: 1, pageSize: 1000, buildingId: BuildingId } }).then((res) => {
  88. setBuildingList((res.records || [].map((item) => { return { id: item.buildingId, name: item.name } })))
  89. })
  90. }
  91. const GetCardList = () => {
  92. fetch({ url: API_CARDS_LIST, method: 'get', params: { pageNumber: 1, pageSize: 1000 } }).then((res) => {
  93. setCardList((res.records || [].map((item) => { return { id: item.buildingId, name: item.name } })))
  94. })
  95. }
  96. const PickerChange = (e) => {
  97. setBuildingId(BuildingList[e.detail.value - 0].buildingId)
  98. setBuildingName(BuildingList[e.detail.value - 0].name)
  99. setCardId(null)
  100. setCardName(null)
  101. }
  102. const CardPickerChange = (e) => {
  103. setCardId(CardList[e.detail.value - 0].id)
  104. setCardName(CardList[e.detail.value - 0].name)
  105. }
  106. const SexPickerChange = (e) => {
  107. setSexId(SexList[e.detail.value - 0].id)
  108. setSexName(SexList[e.detail.value - 0].name)
  109. }
  110. const FormInput = (e) => {
  111. let Data = { ...FormData }
  112. Data[e.currentTarget.dataset.type] = e.detail.value
  113. setFormData(Data)
  114. }
  115. const ToSubmit = () => {
  116. if (FormData.name === '') {
  117. Taro.showToast({ title: '请填写客户姓名', icon: 'none' })
  118. return false
  119. }
  120. if (SexId === null) {
  121. Taro.showToast({ title: '请选择客户性别', icon: 'none' })
  122. return false
  123. }
  124. if (FormData.phone === '') {
  125. Taro.showToast({ title: '请填写客户电话', icon: 'none' })
  126. return false
  127. }
  128. if (!(/^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(FormData.phone)) || FormData.phone.length != 11) {
  129. Taro.showToast({ title: '请填写正确的客户电话', icon: 'none' })
  130. return false
  131. }
  132. if (BuildingId === null) {
  133. Taro.showToast({ title: '请选择客户的意向楼盘', icon: 'none' })
  134. return false
  135. }
  136. if (CardId === null) {
  137. Taro.showToast({ title: '请选择内场接待', icon: 'none' })
  138. return false
  139. }
  140. if (!CanSubmit) {
  141. setCanSubmit(true)
  142. }
  143. }
  144. return (
  145. <view className='Page addCustomer'>
  146. <ScrollView scroll-y refresher-enabled={false} refresher-background='#fff'>
  147. <view className='PageContent'>
  148. <text>客户姓名</text>
  149. <view className='FormLine flex-h'>
  150. <view className='flex-item'>
  151. <Input placeholder='请输入客户真实姓名' data-type='name' onInput={FormInput.bind(this)}></Input>
  152. </view>
  153. </view>
  154. <text>客户电话</text>
  155. <view className='FormLine flex-h'>
  156. <view className='flex-item'>
  157. <Input placeholder='请输入手机号' data-type='phone' onInput={FormInput.bind(this)}></Input>
  158. </view>
  159. </view>
  160. <text>性别</text>
  161. <view className='FormLine flex-h'>
  162. <view className='flex-item'>
  163. <Picker range-key='name' onChange={SexPickerChange} value={0} range={SexList}>
  164. <text>{SexName || '请选择'}</text>
  165. </Picker>
  166. </view>
  167. <text className='iconfont icon-jiantoudown'></text>
  168. </view>
  169. <text>意向楼盘</text>
  170. <view className='FormLine flex-h'>
  171. <view className='flex-item'>
  172. <Picker range-key='name' onChange={PickerChange} value={0} range={BuildingList}>
  173. <text>{BuildingName || '请选择'}</text>
  174. </Picker>
  175. </view>
  176. </view>
  177. <text>内场接待(选填)</text>
  178. <view className='FormLine flex-h'>
  179. <view className='flex-item'>
  180. <Picker range-key='name' onChange={CardPickerChange} value={0} range={CardList}>
  181. <text>{CardName || '请选择'}</text>
  182. </Picker>
  183. </view>
  184. <Image mode='heightFix' src={defaultSpecialImage}></Image>
  185. <text>选择</text>
  186. </view>
  187. {
  188. type !== 'consultant' &&
  189. <Block>
  190. <text>备注</text>
  191. <view className='FormLine flex-h'>
  192. <view className='flex-item'>
  193. <Input placeholder='补充说明(选填)' data-type='describe' onInput={FormInput.bind(this)}></Input>
  194. </view>
  195. </view>
  196. </Block>
  197. }
  198. <view className='Btn'>
  199. <text onClick={ToSubmit}>提交</text>
  200. </view>
  201. </view>
  202. </ScrollView>
  203. </view>
  204. )
  205. })