Просмотр исходного кода

一只狗申请时默认选中

李志伟 3 лет назад
Родитель
Сommit
9bb1890d51
3 измененных файлов: 35 добавлений и 49 удалений
  1. 5
    2
      src/pages/index/index.jsx
  2. 28
    45
      src/pages/setDogLicense/index.jsx
  3. 2
    2
      src/services/dogAPI.js

+ 5
- 2
src/pages/index/index.jsx Просмотреть файл

@@ -7,7 +7,7 @@ import PageLoading from '@/components/PageLoading'
7 7
 import withBasic from '@/layouts/withBasic'
8 8
 
9 9
 import { useModel } from '@/store'
10
-import { getApplicationList, getBannerList } from '@/services/dogAPI'
10
+import { getApplicationList, getBannerList,getDogCardList } from '@/services/dogAPI'
11 11
 import MenuItem from './components/MenuItem'
12 12
 
13 13
 import './style.less'
@@ -22,7 +22,7 @@ const ml16 = {
22 22
 }
23 23
 
24 24
 const IndexPage = (props) => {
25
-  const { pets, cards } = useModel('userData')
25
+  const { pets, cards,setCards } = useModel('userData')
26 26
   const [totalApplyNum, setTotalApplyNum] = useState(0)
27 27
   const [noticeList, setNoticeList] = useState([])
28 28
   const [bannerList, setBannerList] = useState([])
@@ -42,6 +42,9 @@ const IndexPage = (props) => {
42 42
     getBannerList().then(res => {
43 43
       setBannerList(res)
44 44
     })
45
+    getDogCardList().then(res=>{
46
+      setCards(res.records)
47
+    })
45 48
   }, [])
46 49
 
47 50
   const goNoticeList = (e) => {

+ 28
- 45
src/pages/setDogLicense/index.jsx Просмотреть файл

@@ -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} />

+ 2
- 2
src/services/dogAPI.js Просмотреть файл

@@ -76,7 +76,7 @@ export const setDogInfo = (id, data) => request(`/pet/${id}`, { data, method: 'P
76 76
 
77 77
 
78 78
 /**
79
- * 狗狗证件
79
+ * 狗狗证件列表
80 80
  * @param {*} data
81 81
  * @returns
82 82
  */
@@ -91,7 +91,7 @@ export const getDogCardInfo = (id, data) => request(`/card/${id}`, { data, metho
91 91
 
92 92
 
93 93
 /**
94
- * 狗狗证件
94
+ * 申请列表
95 95
  * @param {*} data
96 96
  * @returns
97 97
  */