index.jsx 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import { useState, useEffect } from 'react'
  2. import withLayout from '@/layout'
  3. import { ScrollView, Input, Image, Block, View, Button } from '@tarojs/components'
  4. import '@/assets/css/iconfont.css'
  5. import { fetch } from '@/utils/request'
  6. import BottomMoadl from '@/components/BottomMoadl/index'
  7. import { API_USER_ADD_CUSTOMER, API_CHANNEL_REPORT } from '@/constants/api'
  8. import { ROLE_CODE } from '@/constants/user'
  9. import Taro from '@tarojs/taro'
  10. import Picker from '@/components/Picker'
  11. // import BuildingPicker from './components/BuildingPicker'
  12. import ConsultantPicker from './components/ConsultantPicker'
  13. import './index.scss'
  14. const defaultSpecialImage = 'https://yz-websit.oss-cn-hangzhou.aliyuncs.com/xlk/index-icon19.jpg'
  15. const sexDicts = [
  16. { name: '男', id: '1' },
  17. { name: '女', id: '2' },
  18. ]
  19. export default withLayout((props) => {
  20. const { router, person } = props
  21. const { personId, personType } = person
  22. const { buildingId: originBuiding } = router.params
  23. const [loading, setLoading] = useState(false)
  24. const [buildingId, setBuildingId] = useState(null)
  25. const [CardId, setCardId] = useState(null)
  26. const [SexId, setSexId] = useState(null)
  27. const [FormData, setFormData] = useState({
  28. name: '', // 姓名
  29. phone: '', // 电话
  30. sex: '', // 性别
  31. intention: '', // 意向楼盘
  32. realtyConsultant: '', // 置业顾问
  33. remark: '', // 描述
  34. })
  35. useEffect(() => {
  36. console.log('------originBuiding------>', originBuiding)
  37. if (originBuiding) {
  38. setBuildingId(originBuiding)
  39. }
  40. }, [originBuiding])
  41. const preSubmit = (payload) => {
  42. if (payload.name === '') {
  43. Taro.showToast({ title: '请填写客户姓名', icon: 'none' })
  44. return false
  45. }
  46. if (SexId === null) {
  47. Taro.showToast({ title: '请选择客户性别', icon: 'none' })
  48. return false
  49. }
  50. if (payload.phone === '') {
  51. Taro.showToast({ title: '请填写客户电话', icon: 'none' })
  52. return false
  53. }
  54. if (!(/^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(payload.phone)) || payload.phone.length != 11) {
  55. Taro.showToast({ title: '请填写正确的客户电话', icon: 'none' })
  56. return false
  57. }
  58. if (buildingId === null) {
  59. Taro.showToast({ title: '请选择客户的意向楼盘', icon: 'none' })
  60. return false
  61. }
  62. if (buildingId === null && personType !== ROLE_CODE.CUSTOMER) {
  63. Taro.showToast({ title: '请选择客户的意向楼盘', icon: 'none' })
  64. return false
  65. }
  66. return true
  67. }
  68. const onSubmit = () => {
  69. const payload = personType === ROLE_CODE.CONSULTANT ?
  70. {
  71. name: FormData.name, // 姓名
  72. phone: FormData.phone, // 电话
  73. sex: SexId, // 性别
  74. describe: FormData.describe, // 描述
  75. buildingId,
  76. } :
  77. {
  78. ...FormData,
  79. sex: SexId,
  80. buildingId,
  81. realtyConsultant: CardId
  82. };
  83. if (!preSubmit(payload)) {
  84. return;
  85. }
  86. setLoading(true)
  87. let url = null
  88. if (personType === ROLE_CODE.CONSULTANT || personType === ROLE_CODE.CUSTOMER) {
  89. // url = API_REPORT_CUETOMER
  90. url = API_USER_ADD_CUSTOMER
  91. } else if (personType === ROLE_CODE.CHANNEL_AGENT) {
  92. url = API_CHANNEL_REPORT
  93. } else if (personType === ROLE_CODE.CUSTOMER) {
  94. // url = API_USER_ADD_CUSTOMER
  95. }
  96. fetch({ url, method: 'post', payload }).then(() => {
  97. setLoading(false)
  98. Taro.showToast({ title: '操作成功', icon: 'none' })
  99. const t = setTimeout(() => {
  100. Taro.navigateBack({ delta: 1 })
  101. clearTimeout(t)
  102. }, 1500)
  103. }).catch(() => {
  104. setLoading(false)
  105. })
  106. }
  107. const FormInput = (e) => {
  108. let Data = { ...FormData }
  109. Data[e.currentTarget.dataset.type] = e.detail.value
  110. setFormData(Data)
  111. }
  112. const handleBuildingSelect = (bid, building) => {
  113. setBuildingId(bid)
  114. }
  115. return (
  116. <view className='Page addCustomer'>
  117. <ScrollView scroll-y refresher-enabled={false} refresher-background='#fff'>
  118. <view className='PageContent'>
  119. <text>客户姓名</text>
  120. <view className='FormLine flex-h'>
  121. <view className='flex-item'>
  122. <Input placeholder='请输入客户真实姓名' data-type='name' onInput={FormInput.bind(this)}></Input>
  123. </view>
  124. </view>
  125. <text>客户电话</text>
  126. <view className='FormLine flex-h'>
  127. <view className='flex-item'>
  128. <Input placeholder='请输入手机号' data-type='phone' onInput={FormInput.bind(this)}></Input>
  129. </view>
  130. </view>
  131. <text>性别</text>
  132. <view className='FormLine flex-h'>
  133. <view className='flex-item'>
  134. <Picker kv={['name', 'id']} dicts={sexDicts} onChange={setSexId} value={SexId} />
  135. </view>
  136. {/* <text className='iconfont icon-jiantoudown'></text> */}
  137. </view>
  138. <text>意向楼盘</text>
  139. <view className='FormLine flex-h'>
  140. <view className='flex-item'>
  141. {/* <BuildingPicker change={BuildingChange} value={buildingId} type={personType} /> */}
  142. {/* <View onClick={() => setShowFrame(true)} >{buildingName}</View> */}
  143. <BottomMoadl onChange={handleBuildingSelect} role={personType} />
  144. </view>
  145. </view>
  146. {
  147. personType === ROLE_CODE.CONSULTANT || ROLE_CODE.CUSTOMER ?
  148. <Block>
  149. <text>内场接待(选填)</text>
  150. <view className='FormLine flex-h'>
  151. <view className='flex-item'>
  152. <ConsultantPicker onChange={setCardId} value={CardId} buildingId={buildingId} />
  153. </view>
  154. {/* <Image mode='heightFix' src={defaultSpecialImage}></Image>
  155. <text>选择</text> */}
  156. </view>
  157. <text>备注</text>
  158. <view className='FormLine flex-h'>
  159. <view className='flex-item'>
  160. {
  161. //解决事件穿透
  162. <Input placeholder='补充说明(选填)' dataType='remark' onInput={FormInput.bind(this)}></Input>
  163. }
  164. </view>
  165. </view>
  166. </Block> : ''
  167. }
  168. <view className='Btn'>
  169. <Button loading={loading} onClick={onSubmit}>提交</Button>
  170. </view>
  171. </view>
  172. </ScrollView>
  173. </view>
  174. )
  175. })