|
@@ -1,34 +1,27 @@
|
1
|
|
-import { View, Text, RadioGroup, Picker, Image, Input, Radio, Label, ScrollView, Slot } from '@tarojs/components'
|
2
|
|
-import Taro, { useDidShow, useRouter } from '@tarojs/taro';
|
3
|
1
|
import { useEffect, useState } from 'react';
|
|
2
|
+import { View, RadioGroup, Picker, Input, Radio, Label } from '@tarojs/components'
|
|
3
|
+import Taro, { useDidShow, useRouter } from '@tarojs/taro';
|
4
|
4
|
import Form from '@/components/Form';
|
5
|
5
|
import FormItem from '@/components/Form/FormItem';
|
6
|
6
|
import AuthProfile from '@/components/Authorize/AuthProfile';
|
7
|
|
-import { addDogList, addlication, getDogInfo } from '@/services/dogAPI';
|
|
7
|
+import Button from '@/components/Button';
|
|
8
|
+import { addDogList, addlication, getDogInfo, getCardLicenseInfo } from '@/services/dogAPI';
|
8
|
9
|
import { handleFile } from '@/utils/request';
|
9
|
10
|
import { useModel } from '@/store';
|
10
|
|
-import Button from '../../components/Button';
|
11
|
|
-
|
12
|
11
|
import './style.less'
|
13
|
|
-import { getCardLicenseInfo } from '../../services/dogAPI';
|
14
|
12
|
|
15
|
13
|
export default (props) => {
|
16
|
|
- const { dogs, person } = useModel('userData')
|
|
14
|
+ const { dogs, setDogs, person } = useModel('userData')
|
17
|
15
|
const [formData, setFormData] = useState()
|
18
|
|
- const values = useRouter();
|
19
|
|
- // const { petId } = value.params
|
20
|
16
|
|
21
|
17
|
const [dogDate, setDogDate] = useState({ immunizationDate: null, petBirthday: null, petSex: [], petType: [] })
|
22
|
|
- const [mainDog, setMainDog] = useState([])
|
23
|
|
- const [dogStatus, setDogStatus] = useState(true)
|
|
18
|
+ //狗证详情
|
24
|
19
|
const [renewalAndReissue, setRenewalAndReissue] = useState()
|
25
|
20
|
|
26
|
21
|
const router = useRouter()
|
27
|
22
|
const applyType = router.params.type || 'first'
|
28
|
23
|
useEffect(() => {
|
29
|
24
|
switch (applyType) {
|
30
|
|
- // case 'first':
|
31
|
|
- // break;
|
32
|
25
|
case 'renewal':
|
33
|
26
|
Taro.setNavigationBarTitle({
|
34
|
27
|
title: '证件续期'
|
|
@@ -39,53 +32,48 @@ export default (props) => {
|
39
|
32
|
title: '证件补办'
|
40
|
33
|
})
|
41
|
34
|
break;
|
42
|
|
-
|
43
|
|
-
|
44
|
35
|
default:
|
45
|
36
|
break;
|
46
|
37
|
}
|
47
|
|
-
|
48
|
38
|
}, [applyType])
|
49
|
39
|
useDidShow(() => {
|
50
|
|
- addDogList().then((res) => {
|
51
|
|
- setMainDog(res.records)
|
52
|
|
- })
|
53
|
|
- }, [])
|
|
40
|
+ if (dogs) {
|
|
41
|
+ if (dogs.length == 1) {
|
|
42
|
+ getDetail(dogs[0])
|
|
43
|
+ }
|
|
44
|
+ } else {
|
|
45
|
+ addDogList().then((res) => {
|
|
46
|
+ setDogs(res.records)
|
|
47
|
+ if (res.records && res.records.length == 1) {
|
|
48
|
+ getDetail(res.records[0])
|
|
49
|
+ }
|
|
50
|
+ })
|
|
51
|
+ }
|
|
52
|
+ }, [dogs])
|
54
|
53
|
|
55
|
54
|
|
56
|
55
|
const getDogInfoFunction = (petId) => {
|
57
|
|
-
|
58
|
56
|
getDogInfo(petId).then((e) => {
|
59
|
57
|
setFormData(e)
|
60
|
58
|
const sex = [{ value: e?.sex, text: e?.sex == 1 ? '雄' : '雌' }];
|
61
|
59
|
const petType = [{ value: 0, name: e?.petType }];
|
62
|
|
-
|
63
|
60
|
setDogDate({ ...dogDate, petBirthday: e?.birthday, petSex: sex, petType: petType, })
|
64
|
|
- console.log('test', e);
|
65
|
|
-
|
66
|
61
|
})
|
67
|
62
|
}
|
68
|
|
- const getMainDogChange = (value) => {
|
69
|
|
- console.log("🚀 ~ file: index.jsx ~ line 34 ~ getMainDogChange ~ value", value)
|
70
|
|
- const valuess = value.detail.data
|
71
|
|
- const { petId } = valuess
|
72
|
|
- setRenewalAndReissue({ ...renewalAndReissue, ...valuess })
|
73
|
|
-
|
|
63
|
+ const getDetail = (val) => {
|
|
64
|
+ const { petId } = val
|
|
65
|
+ setRenewalAndReissue({ ...renewalAndReissue, ...val })
|
74
|
66
|
if (applyType == 'renewal' || applyType == 'reissue') {
|
75
|
|
- setDogStatus(false)
|
76
|
67
|
getDogInfoFunction(petId)
|
77
|
68
|
getCardLicenseInfo(petId).then((res) => {
|
78
|
|
- console.log('狗子证件有效期', res);
|
79
|
69
|
setRenewalAndReissue({ ...renewalAndReissue, ...res })
|
80
|
70
|
})
|
81
|
71
|
}
|
82
|
72
|
if (applyType == 'first') {
|
83
|
73
|
getCardLicenseInfo(petId).then((res) => {
|
84
|
74
|
if (!res) {
|
85
|
|
- setDogStatus(false)
|
86
|
75
|
getDogInfoFunction(petId)
|
87
|
76
|
} else {
|
88
|
|
- setDogStatus(true)
|
89
|
77
|
Taro.showModal({
|
90
|
78
|
title: '提示',
|
91
|
79
|
content: '当前狗狗已有证件,请勿重复申请!',
|
|
@@ -99,17 +87,16 @@ export default (props) => {
|
99
|
87
|
}
|
100
|
88
|
}
|
101
|
89
|
})
|
102
|
|
-
|
103
|
|
-
|
104
|
90
|
}
|
105
|
91
|
})
|
106
|
92
|
}
|
107
|
|
-
|
|
93
|
+ }
|
|
94
|
+ const getMainDogChange = (value) => {
|
|
95
|
+ const valuess = value.detail.data
|
|
96
|
+ getDetail(valuess);
|
108
|
97
|
}
|
109
|
98
|
|
110
|
99
|
const onDateChange = (type, value) => {
|
111
|
|
- console.log('dogDate', dogDate);
|
112
|
|
-
|
113
|
100
|
switch (type) {
|
114
|
101
|
case 'petSex':
|
115
|
102
|
setDogDate({ ...dogDate, petSex: value })
|
|
@@ -199,17 +186,13 @@ export default (props) => {
|
199
|
186
|
}
|
200
|
187
|
}
|
201
|
188
|
})
|
202
|
|
-
|
203
|
|
-
|
204
|
189
|
}
|
205
|
190
|
})
|
206
|
|
-
|
207
|
191
|
}
|
208
|
|
-
|
209
|
192
|
}
|
210
|
193
|
|
211
|
194
|
const rules = {
|
212
|
|
- petName: [{ required: true, message: '请填写狗狗名称' }],
|
|
195
|
+ petId: [{ required: true, message: '请填写狗狗名称' }],
|
213
|
196
|
petSex: [{ type: 'number', required: true, message: '请填写狗狗性别' }],
|
214
|
197
|
petBirthday: [{ required: true, message: '请选择狗狗生日' }],
|
215
|
198
|
petColor: [{ required: true, message: '请选择狗狗毛色' }],
|
|
@@ -254,7 +237,7 @@ export default (props) => {
|
254
|
237
|
}
|
255
|
238
|
|
256
|
239
|
<FormItem title='狗狗名称' required>
|
257
|
|
- <s-picker name='petName' rangeKey='name' rangeValue='value' range={mainDog} value={formData?.name} onChange={getMainDogChange} />
|
|
240
|
+ <s-picker name='petId' rangeKey='name' rangeValue='petId' range={dogs} value={formData?.petId} onChange={getMainDogChange} />
|
258
|
241
|
</FormItem>
|
259
|
242
|
<FormItem title='狗狗性别' required>
|
260
|
243
|
<s-picker name='petSex' rangeKey='text' rangeValue='value' range={dogDate.petSex} value={formData?.sex} />
|