瀏覽代碼

一只狗申请时默认选中

李志伟 3 年之前
父節點
當前提交
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
 import withBasic from '@/layouts/withBasic'
7
 import withBasic from '@/layouts/withBasic'
8
 
8
 
9
 import { useModel } from '@/store'
9
 import { useModel } from '@/store'
10
-import { getApplicationList, getBannerList } from '@/services/dogAPI'
10
+import { getApplicationList, getBannerList,getDogCardList } from '@/services/dogAPI'
11
 import MenuItem from './components/MenuItem'
11
 import MenuItem from './components/MenuItem'
12
 
12
 
13
 import './style.less'
13
 import './style.less'
22
 }
22
 }
23
 
23
 
24
 const IndexPage = (props) => {
24
 const IndexPage = (props) => {
25
-  const { pets, cards } = useModel('userData')
25
+  const { pets, cards,setCards } = useModel('userData')
26
   const [totalApplyNum, setTotalApplyNum] = useState(0)
26
   const [totalApplyNum, setTotalApplyNum] = useState(0)
27
   const [noticeList, setNoticeList] = useState([])
27
   const [noticeList, setNoticeList] = useState([])
28
   const [bannerList, setBannerList] = useState([])
28
   const [bannerList, setBannerList] = useState([])
42
     getBannerList().then(res => {
42
     getBannerList().then(res => {
43
       setBannerList(res)
43
       setBannerList(res)
44
     })
44
     })
45
+    getDogCardList().then(res=>{
46
+      setCards(res.records)
47
+    })
45
   }, [])
48
   }, [])
46
 
49
 
47
   const goNoticeList = (e) => {
50
   const goNoticeList = (e) => {

+ 28
- 45
src/pages/setDogLicense/index.jsx 查看文件

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

+ 2
- 2
src/services/dogAPI.js 查看文件

76
 
76
 
77
 
77
 
78
 /**
78
 /**
79
- * 狗狗证件
79
+ * 狗狗证件列表
80
  * @param {*} data
80
  * @param {*} data
81
  * @returns
81
  * @returns
82
  */
82
  */
91
 
91
 
92
 
92
 
93
 /**
93
 /**
94
- * 狗狗证件
94
+ * 申请列表
95
  * @param {*} data
95
  * @param {*} data
96
  * @returns
96
  * @returns
97
  */
97
  */