|
@@ -1,196 +1,318 @@
|
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 BuildingSelect from '@/components/BuildingSelect'
|
7
|
|
-
|
8
|
|
-import { API_USER_ADD_CUSTOMER, API_CHANNEL_REPORT } from '@/constants/api'
|
9
|
|
-import { ROLE_CODE } from '@/constants/user'
|
10
|
|
-import Taro from '@tarojs/taro'
|
11
|
|
-import Picker from '@/components/Picker'
|
|
1
|
+import { useState, useEffect } from "react";
|
|
2
|
+import withLayout from "@/layout";
|
|
3
|
+import {
|
|
4
|
+ ScrollView,
|
|
5
|
+ Input,
|
|
6
|
+ Image,
|
|
7
|
+ Block,
|
|
8
|
+ View,
|
|
9
|
+ Button,
|
|
10
|
+} from "@tarojs/components";
|
|
11
|
+import "@/assets/css/iconfont.css";
|
|
12
|
+import { fetch } from "@/utils/request";
|
|
13
|
+import BuildingSelect from "@/components/BuildingSelect";
|
|
14
|
+import BuildingMultipleSelect from "@/components/BuildingMultipleSelect";
|
|
15
|
+import { API_USER_ADD_CUSTOMER, API_CHANNEL_REPORT } from "@/constants/api";
|
|
16
|
+import { ROLE_CODE } from "@/constants/user";
|
|
17
|
+import Taro from "@tarojs/taro";
|
|
18
|
+import Picker from "@/components/Picker";
|
12
|
19
|
// import BuildingPicker from './components/BuildingPicker'
|
13
|
|
-import ConsultantPicker from './components/ConsultantPicker'
|
|
20
|
+import ConsultantPicker from "./components/ConsultantPicker";
|
14
|
21
|
|
15
|
|
-import './index.scss'
|
|
22
|
+import "./index.scss";
|
16
|
23
|
|
17
|
|
-
|
18
|
|
-const defaultSpecialImage = 'https://yz-websit.oss-cn-hangzhou.aliyuncs.com/xlk/index-icon19.jpg'
|
|
24
|
+const defaultSpecialImage =
|
|
25
|
+ "https://yz-websit.oss-cn-hangzhou.aliyuncs.com/xlk/index-icon19.jpg";
|
19
|
26
|
|
20
|
27
|
const sexDicts = [
|
21
|
|
- { name: '男', id: '1' },
|
22
|
|
- { name: '女', id: '2' },
|
23
|
|
-]
|
|
28
|
+ { name: "男", id: "1" },
|
|
29
|
+ { name: "女", id: "2" },
|
|
30
|
+];
|
24
|
31
|
|
25
|
32
|
export default withLayout((props) => {
|
26
|
|
- const { router, person } = props
|
27
|
|
- const { personId, personType } = person
|
28
|
|
- const { buildingId: originBuiding } = router.params
|
29
|
|
-
|
30
|
|
- const [loading, setLoading] = useState(false)
|
31
|
|
- const [buildingId, setBuildingId] = useState(null)
|
32
|
|
- const [CardId, setCardId] = useState(null)
|
33
|
|
- const [SexId, setSexId] = useState(null)
|
|
33
|
+ const { router, person } = props;
|
|
34
|
+ const { personId, personType } = person;
|
|
35
|
+ const { buildingId: originBuiding } = router.params;
|
|
36
|
+
|
|
37
|
+ const [loading, setLoading] = useState(false);
|
|
38
|
+ const [buildingId, setBuildingId] = useState(null);
|
|
39
|
+ const [buildingIdList, setBuildingIdList] = useState([]);
|
|
40
|
+ const [CardId, setCardId] = useState(null);
|
|
41
|
+ const [SexId, setSexId] = useState(null);
|
34
|
42
|
const [FormData, setFormData] = useState({
|
35
|
|
- name: '', // 姓名
|
36
|
|
- phone: '', // 电话
|
37
|
|
- sex: '', // 性别
|
38
|
|
- intention: '', // 意向楼盘
|
39
|
|
- realtyConsultant: '', // 置业顾问
|
40
|
|
- remark: '', // 描述
|
41
|
|
- })
|
|
43
|
+ name: "", // 姓名
|
|
44
|
+ phone: "", // 电话
|
|
45
|
+ sex: "", // 性别
|
|
46
|
+ intention: "", // 意向楼盘
|
|
47
|
+ realtyConsultant: "", // 置业顾问
|
|
48
|
+ remark: "", // 描述
|
|
49
|
+ });
|
42
|
50
|
|
43
|
51
|
useEffect(() => {
|
44
|
|
- console.log('------originBuiding------>', originBuiding)
|
|
52
|
+ console.log("------originBuiding------>", originBuiding);
|
45
|
53
|
if (originBuiding) {
|
46
|
|
- setBuildingId(originBuiding)
|
|
54
|
+ if (personType === ROLE_CODE.BROKER) {
|
|
55
|
+ setBuildingIdList([originBuiding]);
|
|
56
|
+ } else {
|
|
57
|
+ setBuildingId(originBuiding);
|
|
58
|
+ }
|
47
|
59
|
}
|
48
|
|
- }, [originBuiding])
|
|
60
|
+ }, [originBuiding]);
|
49
|
61
|
|
50
|
62
|
const preSubmit = (payload) => {
|
51
|
|
- if (payload.name === '') {
|
52
|
|
- Taro.showToast({ title: '请填写客户姓名', icon: 'none' })
|
53
|
|
- return false
|
|
63
|
+ if (payload.name === "") {
|
|
64
|
+ Taro.showToast({ title: "请填写客户姓名", icon: "none" });
|
|
65
|
+ return false;
|
54
|
66
|
}
|
55
|
67
|
if (SexId === null) {
|
56
|
|
- Taro.showToast({ title: '请选择客户性别', icon: 'none' })
|
57
|
|
- return false
|
58
|
|
- }
|
59
|
|
- if (payload.phone === '') {
|
60
|
|
- Taro.showToast({ title: '请填写客户电话', icon: 'none' })
|
61
|
|
- return false
|
|
68
|
+ Taro.showToast({ title: "请选择客户性别", icon: "none" });
|
|
69
|
+ return false;
|
62
|
70
|
}
|
63
|
|
- if (!(/^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(payload.phone)) || payload.phone.length != 11) {
|
64
|
|
- Taro.showToast({ title: '请填写正确的客户电话', icon: 'none' })
|
65
|
|
- return false
|
|
71
|
+ if (payload.phone === "") {
|
|
72
|
+ Taro.showToast({ title: "请填写客户电话", icon: "none" });
|
|
73
|
+ return false;
|
66
|
74
|
}
|
67
|
|
- if (buildingId === null) {
|
68
|
|
- Taro.showToast({ title: '请选择客户的意向楼盘', icon: 'none' })
|
69
|
|
- return false
|
|
75
|
+ if (
|
|
76
|
+ !/^1[3|4|5|6|7|8|9][0-9]\d{4,8}$/.test(payload.phone) ||
|
|
77
|
+ payload.phone.length != 11
|
|
78
|
+ ) {
|
|
79
|
+ Taro.showToast({ title: "请填写正确的客户电话", icon: "none" });
|
|
80
|
+ return false;
|
70
|
81
|
}
|
71
|
|
- if (buildingId === null && personType !== ROLE_CODE.CUSTOMER) {
|
72
|
|
- Taro.showToast({ title: '请选择客户的意向楼盘', icon: 'none' })
|
73
|
|
- return false
|
|
82
|
+ if (personType === ROLE_CODE.BROKER) {
|
|
83
|
+ if (buildingIdList?.length == 0) {
|
|
84
|
+ Taro.showToast({ title: "请选择客户的意向楼盘", icon: "none" });
|
|
85
|
+ return false;
|
|
86
|
+ }
|
|
87
|
+ } else {
|
|
88
|
+ if (buildingId === null) {
|
|
89
|
+ Taro.showToast({ title: "请选择客户的意向楼盘", icon: "none" });
|
|
90
|
+ return false;
|
|
91
|
+ }
|
|
92
|
+ if (buildingId === null && personType !== ROLE_CODE.CUSTOMER) {
|
|
93
|
+ Taro.showToast({ title: "请选择客户的意向楼盘", icon: "none" });
|
|
94
|
+ return false;
|
|
95
|
+ }
|
74
|
96
|
}
|
75
|
97
|
|
76
|
|
- return true
|
77
|
|
- }
|
|
98
|
+ return true;
|
|
99
|
+ };
|
|
100
|
+ // return new Promise((resovle, reject) => {
|
|
101
|
+ // Taro.showLoading()
|
|
102
|
+ // queryChatHistory({
|
|
103
|
+ // chatWith: friend,
|
|
104
|
+ // pageSize: 20,
|
|
105
|
+ // ...params || {},
|
|
106
|
+ // }).then((res) => {
|
|
107
|
+ // const { records } = res;
|
|
108
|
+ // Taro.hideLoading()
|
|
109
|
+
|
|
110
|
+ // const lst = (records || []).reverse()
|
|
111
|
+ // resovle(lst)
|
|
112
|
+ // }).catch(() => {
|
|
113
|
+ // Taro.hideLoading()
|
|
114
|
+ // })
|
|
115
|
+ // })
|
|
116
|
+ const submitFetch = (url, payload) => {
|
|
117
|
+
|
|
118
|
+ return new Promise((resovle, reject) => {
|
78
|
119
|
|
79
|
|
- const onSubmit = () => {
|
|
120
|
+ fetch({ url, method: "post", payload })
|
|
121
|
+ .then(() => {
|
|
122
|
+ console.log("success");
|
|
123
|
+ resovle("success");
|
|
124
|
+
|
|
125
|
+ })
|
|
126
|
+ .catch(() => {
|
|
127
|
+
|
|
128
|
+ reject("fail");
|
|
129
|
+
|
|
130
|
+ });
|
|
131
|
+ });
|
|
132
|
+ };
|
|
133
|
+ const onSubmit = async () => {
|
80
|
134
|
const payload = {
|
81
|
135
|
...FormData,
|
82
|
136
|
sex: SexId,
|
83
|
|
- buildingId,
|
84
|
|
- realtyConsultant: CardId
|
|
137
|
+ realtyConsultant: CardId,
|
85
|
138
|
};
|
86
|
139
|
|
87
|
140
|
if (!preSubmit(payload)) {
|
88
|
141
|
return;
|
89
|
142
|
}
|
90
|
143
|
|
91
|
|
- setLoading(true)
|
92
|
|
- let url = null
|
93
|
|
- if (personType === ROLE_CODE.CONSULTANT || personType === ROLE_CODE.CUSTOMER || personType === ROLE_CODE.BROKER) {
|
|
144
|
+ setLoading(true);
|
|
145
|
+ let url = null;
|
|
146
|
+ if (
|
|
147
|
+ personType === ROLE_CODE.CONSULTANT ||
|
|
148
|
+ personType === ROLE_CODE.CUSTOMER ||
|
|
149
|
+ personType === ROLE_CODE.BROKER
|
|
150
|
+ ) {
|
94
|
151
|
// url = API_REPORT_CUETOMER
|
95
|
|
- url = API_USER_ADD_CUSTOMER
|
|
152
|
+ url = API_USER_ADD_CUSTOMER;
|
96
|
153
|
} else if (personType === ROLE_CODE.CHANNEL_AGENT) {
|
97
|
|
- url = API_CHANNEL_REPORT
|
|
154
|
+ url = API_CHANNEL_REPORT;
|
98
|
155
|
} else if (personType === ROLE_CODE.CUSTOMER) {
|
99
|
156
|
// url = API_USER_ADD_CUSTOMER
|
100
|
157
|
}
|
101
|
|
- fetch({ url, method: 'post', payload }).then(() => {
|
102
|
|
- setLoading(false)
|
103
|
|
- Taro.showToast({ title: '操作成功', icon: 'none' })
|
104
|
|
-
|
105
|
|
- const t = setTimeout(() => {
|
106
|
|
- Taro.navigateBack({ delta: 1 })
|
107
|
|
- clearTimeout(t)
|
108
|
|
- }, 1500)
|
109
|
|
- }).catch(() => {
|
110
|
|
- setLoading(false)
|
111
|
|
- })
|
112
|
|
- }
|
113
|
158
|
|
114
|
|
- const FormInput = (e) => {
|
115
|
|
- let Data = { ...FormData }
|
116
|
|
- Data[e.currentTarget.dataset.type] = e.detail.value
|
117
|
|
- setFormData(Data)
|
118
|
|
- }
|
|
159
|
+ if (personType === ROLE_CODE.BROKER) {
|
|
160
|
+ Promise.all(
|
|
161
|
+ buildingIdList.map((x) => {
|
|
162
|
+ return submitFetch(url, { ...payload, buildingId: x });
|
|
163
|
+ })
|
|
164
|
+ )
|
|
165
|
+ .then((res) => {
|
|
166
|
+ setLoading(false);
|
|
167
|
+ Taro.showToast({ title: "操作成功", icon: "none" });
|
119
|
168
|
|
120
|
|
- const handleBuildingSelect = (bid, building) => {
|
121
|
|
- console.log("🚀 ~ file: index.jsx ~ line 121 ~ handleBuildingSelect ~ building", building)
|
122
|
|
- setBuildingId(bid)
|
123
|
|
- // setBuildingId(building.buildingId)
|
124
|
|
- }
|
125
|
|
-console.log(personType === ROLE_CODE.CONSULTANT || ROLE_CODE.CUSTOMER,'===')
|
126
|
|
- return (
|
127
|
|
- <view className='Page addCustomer'>
|
|
169
|
+ const t = setTimeout(() => {
|
|
170
|
+ Taro.navigateBack({ delta: 1 });
|
|
171
|
+ clearTimeout(t);
|
|
172
|
+ }, 1500);
|
|
173
|
+ })
|
|
174
|
+ .catch(() => {
|
|
175
|
+ setLoading(false);
|
|
176
|
+ });
|
|
177
|
+ } else {
|
|
178
|
+ try {
|
|
179
|
+ const res = await submitFetch(url, { ...payload, buildingId });
|
|
180
|
+ setLoading(false);
|
|
181
|
+ Taro.showToast({ title: "操作成功", icon: "none" });
|
128
|
182
|
|
|
183
|
+ const t = setTimeout(() => {
|
|
184
|
+ Taro.navigateBack({ delta: 1 });
|
|
185
|
+ clearTimeout(t);
|
|
186
|
+ }, 1500);
|
|
187
|
+ } catch (error) {
|
|
188
|
+ setLoading(false);
|
|
189
|
+ }
|
|
190
|
+ }
|
|
191
|
+ };
|
|
192
|
+
|
|
193
|
+ const FormInput = (e) => {
|
|
194
|
+ let Data = { ...FormData };
|
|
195
|
+ Data[e.currentTarget.dataset.type] = e.detail.value;
|
|
196
|
+ setFormData(Data);
|
|
197
|
+ };
|
129
|
198
|
|
130
|
|
- <ScrollView scroll-y refresher-enabled={false} refresher-background='#fff'>
|
131
|
|
- <view className='PageContent'>
|
|
199
|
+ const handleBuildingSelect = (bid, building) => {
|
|
200
|
+ console.log(
|
|
201
|
+ "🚀 ~ file: index.jsx ~ line 121 ~ handleBuildingSelect ~ building",
|
|
202
|
+ building
|
|
203
|
+ );
|
|
204
|
+ if (personType === ROLE_CODE.BROKER) {
|
|
205
|
+ setBuildingIdList(bid);
|
|
206
|
+ } else {
|
|
207
|
+ setBuildingId(bid);
|
|
208
|
+ }
|
|
209
|
+ };
|
132
|
210
|
|
|
211
|
+ return (
|
|
212
|
+ <view className="Page addCustomer">
|
|
213
|
+ <ScrollView
|
|
214
|
+ scroll-y
|
|
215
|
+ refresher-enabled={false}
|
|
216
|
+ refresher-background="#fff"
|
|
217
|
+ >
|
|
218
|
+ <view className="PageContent">
|
133
|
219
|
<text>客户姓名</text>
|
134
|
|
- <view className='FormLine flex-h'>
|
135
|
|
- <view className='flex-item'>
|
136
|
|
- <Input placeholder='请输入客户真实姓名' data-type='name' onInput={FormInput.bind(this)}></Input>
|
|
220
|
+ <view className="FormLine flex-h">
|
|
221
|
+ <view className="flex-item">
|
|
222
|
+ <Input
|
|
223
|
+ placeholder="请输入客户真实姓名"
|
|
224
|
+ data-type="name"
|
|
225
|
+ onInput={FormInput.bind(this)}
|
|
226
|
+ ></Input>
|
137
|
227
|
</view>
|
138
|
228
|
</view>
|
139
|
229
|
|
140
|
230
|
<text>客户电话</text>
|
141
|
|
- <view className='FormLine flex-h'>
|
142
|
|
- <view className='flex-item'>
|
143
|
|
- <Input placeholder='请输入手机号' data-type='phone' onInput={FormInput.bind(this)}></Input>
|
|
231
|
+ <view className="FormLine flex-h">
|
|
232
|
+ <view className="flex-item">
|
|
233
|
+ <Input
|
|
234
|
+ placeholder="请输入手机号"
|
|
235
|
+ data-type="phone"
|
|
236
|
+ onInput={FormInput.bind(this)}
|
|
237
|
+ ></Input>
|
144
|
238
|
</view>
|
145
|
239
|
</view>
|
146
|
240
|
|
147
|
241
|
<text>性别</text>
|
148
|
|
- <view className='FormLine flex-h'>
|
149
|
|
- <view className='flex-item'>
|
150
|
|
- <Picker kv={['name', 'id']} dicts={sexDicts} onChange={setSexId} value={SexId} />
|
|
242
|
+ <view className="FormLine flex-h">
|
|
243
|
+ <view className="flex-item">
|
|
244
|
+ <Picker
|
|
245
|
+ kv={["name", "id"]}
|
|
246
|
+ dicts={sexDicts}
|
|
247
|
+ onChange={setSexId}
|
|
248
|
+ value={SexId}
|
|
249
|
+ />
|
151
|
250
|
</view>
|
152
|
251
|
{/* <text className='iconfont icon-jiantoudown'></text> */}
|
153
|
252
|
</view>
|
154
|
253
|
|
155
|
254
|
<text>意向楼盘</text>
|
156
|
|
- <view className='FormLine flex-h'>
|
157
|
|
- <view className='flex-item'>
|
|
255
|
+ <view className="FormLine flex-h">
|
|
256
|
+ <view className="flex-item">
|
158
|
257
|
{/* <BuildingPicker change={BuildingChange} value={buildingId} type={personType} /> */}
|
159
|
258
|
{/* <View onClick={() => setShowFrame(true)} >{buildingName}</View> */}
|
160
|
|
- <BuildingSelect value={buildingId} onChange={handleBuildingSelect} role={personType} />
|
|
259
|
+ {personType === ROLE_CODE.BROKER ? (
|
|
260
|
+ <BuildingMultipleSelect
|
|
261
|
+ value={buildingIdList}
|
|
262
|
+ onChange={handleBuildingSelect}
|
|
263
|
+ role={personType}
|
|
264
|
+ />
|
|
265
|
+ ) : (
|
|
266
|
+ <BuildingSelect
|
|
267
|
+ value={buildingId}
|
|
268
|
+ onChange={handleBuildingSelect}
|
|
269
|
+ role={personType}
|
|
270
|
+ />
|
|
271
|
+ )}
|
161
|
272
|
</view>
|
162
|
273
|
</view>
|
163
|
274
|
|
164
|
|
- {
|
165
|
|
- personType === ROLE_CODE.CONSULTANT || ROLE_CODE.CUSTOMER ?
|
166
|
|
- <Block>
|
167
|
|
- <text>内场接待(选填)</text>
|
168
|
|
- <view className='FormLine flex-h'>
|
169
|
|
- <view className='flex-item'>
|
170
|
|
- <ConsultantPicker onChange={setCardId} value={CardId} buildingId={buildingId} />
|
|
275
|
+ {personType === ROLE_CODE.CONSULTANT || ROLE_CODE.CUSTOMER ? (
|
|
276
|
+ <Block>
|
|
277
|
+ {
|
|
278
|
+ personType !== ROLE_CODE.BROKER&& <>
|
|
279
|
+ <text>内场接待(选填)</text>
|
|
280
|
+ <view className="FormLine flex-h">
|
|
281
|
+ <view className="flex-item">
|
|
282
|
+ <ConsultantPicker
|
|
283
|
+ onChange={setCardId}
|
|
284
|
+ value={CardId}
|
|
285
|
+ buildingId={buildingId}
|
|
286
|
+ />
|
|
287
|
+ </view>
|
171
|
288
|
</view>
|
172
|
|
- {/* <Image mode='heightFix' src={defaultSpecialImage}></Image>
|
173
|
|
- <text>选择</text> */}
|
174
|
|
- </view>
|
|
289
|
+ </>
|
|
290
|
+ }
|
175
|
291
|
|
176
|
|
- <text>备注</text>
|
177
|
|
- <view className='FormLine flex-h'>
|
178
|
|
- <view className='flex-item'>
|
179
|
|
- {
|
180
|
|
- //解决事件穿透
|
181
|
|
- <Input placeholder='补充说明(选填)' dataType='remark' onInput={FormInput.bind(this)}></Input>
|
182
|
|
- }
|
183
|
|
- </view>
|
|
292
|
+ <text>备注</text>
|
|
293
|
+ <view className="FormLine flex-h">
|
|
294
|
+ <view className="flex-item">
|
|
295
|
+ {
|
|
296
|
+ //解决事件穿透
|
|
297
|
+ <Input
|
|
298
|
+ placeholder="补充说明(选填)"
|
|
299
|
+ dataType="remark"
|
|
300
|
+ onInput={FormInput.bind(this)}
|
|
301
|
+ ></Input>
|
|
302
|
+ }
|
184
|
303
|
</view>
|
185
|
|
- </Block> : ''
|
186
|
|
- }
|
187
|
|
- <view className='Btn'>
|
188
|
|
- <Button loading={loading} onClick={onSubmit}>提交</Button>
|
|
304
|
+ </view>
|
|
305
|
+ </Block>
|
|
306
|
+ ) : (
|
|
307
|
+ ""
|
|
308
|
+ )}
|
|
309
|
+ <view className="Btn">
|
|
310
|
+ <Button loading={loading} onClick={onSubmit}>
|
|
311
|
+ 提交
|
|
312
|
+ </Button>
|
189
|
313
|
</view>
|
190
|
|
-
|
191
|
314
|
</view>
|
192
|
315
|
</ScrollView>
|
193
|
|
-
|
194
|
316
|
</view>
|
195
|
|
- )
|
196
|
|
-})
|
|
317
|
+ );
|
|
318
|
+});
|