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