张延森 3 years ago
parent
commit
98cce1d742
2 changed files with 33 additions and 113 deletions
  1. 2
    1
      src/pages/setDogLicense/index.config.js
  2. 31
    112
      src/pages/setDogLicense/index.jsx

+ 2
- 1
src/pages/setDogLicense/index.config.js View File

11
     "mp-form": "weui-miniprogram/form/form",
11
     "mp-form": "weui-miniprogram/form/form",
12
     "mp-dialog": "weui-miniprogram/dialog/dialog",
12
     "mp-dialog": "weui-miniprogram/dialog/dialog",
13
     "mp-toptips": "weui-miniprogram/toptips/toptips",
13
     "mp-toptips": "weui-miniprogram/toptips/toptips",
14
-    "s-picker": "../../components/s-picker/index"
14
+    "s-picker": "../../components/s-picker/index",
15
+    "uploader": "../../components/uploader/index"
15
   }
16
   }
16
 
17
 
17
 }
18
 }

+ 31
- 112
src/pages/setDogLicense/index.jsx View File

2
 import Taro, { useDidShow, useRouter } from '@tarojs/taro';
2
 import Taro, { useDidShow, useRouter } from '@tarojs/taro';
3
 import { useState } from 'react';
3
 import { useState } from 'react';
4
 import Form from '@/components/Form';
4
 import Form from '@/components/Form';
5
-import FieldLabel from '@/components/Form/FieldLabel';
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 { addDogList, addlication, getDogInfo } from '@/services/dogAPI';
8
-import { uploadFile } from '@/utils/request';
8
+import { handleFile } from '@/utils/request';
9
 import { useModel } from '@/store';
9
 import { useModel } from '@/store';
10
 
10
 
11
 import './style.less'
11
 import './style.less'
15
   const [formData, setFormData] = useState()
15
   const [formData, setFormData] = useState()
16
 
16
 
17
   const [dogDate, setDogDate] = useState({ immunizationDate: '请选择日期', petBirthday: '请选择生日', petSex: [], petType: [] })
17
   const [dogDate, setDogDate] = useState({ immunizationDate: '请选择日期', petBirthday: '请选择生日', petSex: [], petType: [] })
18
-  const [imgUrl, setImgUrl] = useState({ img1: null, immunizationImg: null })
19
   const [mainDog, setMainDog] = useState([])
18
   const [mainDog, setMainDog] = useState([])
20
 
19
 
21
-
20
+  const router = useRouter()
21
+  const applyType = router.params.type || 'first'
22
 
22
 
23
   useDidShow(() => {
23
   useDidShow(() => {
24
     addDogList().then((res) => {
24
     addDogList().then((res) => {
36
       const petType = [{ value: 0, name: e?.petType }];
36
       const petType = [{ value: 0, name: e?.petType }];
37
 
37
 
38
       setDogDate({ ...dogDate, petBirthday: e?.birthday, petSex: sex, petType: petType })
38
       setDogDate({ ...dogDate, petBirthday: e?.birthday, petSex: sex, petType: petType })
39
-      setImgUrl({ ...imgUrl, img1: e.image })
40
       console.log('test', e);
39
       console.log('test', e);
41
 
40
 
42
     })
41
     })
43
   }
42
   }
44
 
43
 
45
-
46
-
47
   const onDateChange = (type, value) => {
44
   const onDateChange = (type, value) => {
48
     console.log('dogDate', dogDate);
45
     console.log('dogDate', dogDate);
49
 
46
 
74
       value: 2,
71
       value: 2,
75
       text: '自取',
72
       text: '自取',
76
     },
73
     },
77
-
78
   ]
74
   ]
79
 
75
 
80
-  const addImage = (e) => {
81
-
82
-    if (e == 'img1') {
83
-      Taro.chooseImage({
84
-        count: 1, // 默认9
85
-        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
86
-        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有,在H5浏览器端支持使用 `user` 和 `environment`分别指定为前后摄像头
87
-        success: function (res) {
88
-          // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
89
-          var tempFilePaths = res.tempFilePaths
90
-          uploadFile(tempFilePaths[0]).then((res2) => {
91
-            console.log("🚀 ~ file: index.jsx ~ line 61 ~ uploadFile ~ res2", res2)
92
-            setImgUrl({ ...imgUrl, img1: res2 })
93
-
94
-
95
-          })
96
-        },
97
-        fail () {
98
-          Taro.showToast({
99
-            title: '上传失败请重试',
100
-            icon: 'error',
101
-            duration: 1000
102
-          })
103
-        }
104
-      })
105
-
106
-    } else {
107
-      Taro.chooseImage({
108
-        count: 1, // 默认9
109
-        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
110
-        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有,在H5浏览器端支持使用 `user` 和 `environment`分别指定为前后摄像头
111
-        success: function (res) {
112
-          // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
113
-          var tempFilePaths = res.tempFilePaths
114
-          uploadFile(tempFilePaths[0]).then((res2) => {
115
-            console.log("🚀 ~ file: index.jsx ~ line 61 ~ uploadFile ~ res2", res2)
116
-            setImgUrl({ ...imgUrl, immunizationImg: res2 })
117
-
118
-
119
-          })
120
-        },
121
-        fail () {
122
-          Taro.showToast({
123
-            title: '上传失败请重试',
124
-            icon: 'error',
125
-            duration: 1000
126
-          })
127
-        }
128
-      })
129
-    }
130
-
131
-
132
-  }
133
   // ...dogDate,
76
   // ...dogDate,
134
   const formSubmit = value => {
77
   const formSubmit = value => {
135
-    addlication({ ...value, ...imgUrl, applyType: 'first' }).then((res) => {
78
+    addlication({ ...value, applyType }).then((res) => {
136
       console.log('dogInfo xinwe', res);
79
       console.log('dogInfo xinwe', res);
137
       Taro.showToast({
80
       Taro.showToast({
138
         title: '保存成功',
81
         title: '保存成功',
154
         <Form onSubmit={formSubmit} >
97
         <Form onSubmit={formSubmit} >
155
           <mp-form  >
98
           <mp-form  >
156
             <mp-cells >
99
             <mp-cells >
157
-              <mp-cell title='犬主姓名' extClass=''>
158
-                <Slot><FieldLabel></FieldLabel> </Slot>
100
+              <FormItem title='犬主姓名' required>
159
                 <View >{person?.nickName}</View>
101
                 <View >{person?.nickName}</View>
160
-              </mp-cell>
161
-              <mp-cell title='狗狗名称' extClass=''>
162
-                {/* <Input name='petName' placeholder='请输入狗狗名称' /> */}
102
+              </FormItem>
103
+              <FormItem title='狗狗名称' required>
163
                 <s-picker name='petName' rangeKey='name' rangeValue='value' range={mainDog} value={formData?.name} onChange={getMainDogChange} />
104
                 <s-picker name='petName' rangeKey='name' rangeValue='value' range={mainDog} value={formData?.name} onChange={getMainDogChange} />
164
-                <View onClick={onDateChange}>log打印</View>
165
-                {/* <Picker name='petSex' mode='selector' range={selector} onChange={(e) => { onDateChange('petSex', e.detail.value) }}>
166
-                  <View className='picker'>
167
-                    {dogDate.petSex}
168
-                  </View>
169
-                </Picker> */}
170
-              </mp-cell>
171
-              <mp-cell title='狗狗性别' extClass=''>
105
+              </FormItem>
106
+              <FormItem title='狗狗性别' required>
172
                 <s-picker name='petSex' rangeKey='text' rangeValue='value' range={dogDate.petSex} value={formData?.sex} />
107
                 <s-picker name='petSex' rangeKey='text' rangeValue='value' range={dogDate.petSex} value={formData?.sex} />
173
-              </mp-cell>
174
-              <mp-cell title='犬种' extClass=''>
108
+              </FormItem>
109
+              <FormItem title='犬种' required>
175
                 <s-picker name='petType' rangeKey='name' rangeValue='name' range={dogDate.petType} value={formData?.petType} />
110
                 <s-picker name='petType' rangeKey='name' rangeValue='name' range={dogDate.petType} value={formData?.petType} />
176
-              </mp-cell>
177
-              <mp-cell title='生日' extClass=''>
111
+              </FormItem>
112
+              <FormItem title='生日' required>
178
                 <Picker name='petBirthday' mode='date' onChange={(e) => { onDateChange('petBirthday', e.detail.value) }}>
113
                 <Picker name='petBirthday' mode='date' onChange={(e) => { onDateChange('petBirthday', e.detail.value) }}>
179
                   <View className='picker' style={!formData ? { "color": '#858585' } : {}}>
114
                   <View className='picker' style={!formData ? { "color": '#858585' } : {}}>
180
                     {dogDate.petBirthday}
115
                     {dogDate.petBirthday}
181
                   </View>
116
                   </View>
182
                 </Picker>
117
                 </Picker>
183
-              </mp-cell>
184
-              <mp-cell title='毛色' extClass=''>
118
+              </FormItem>
119
+              <FormItem title='毛色' required>
185
                 <Input name='petColor' placeholder='请输入毛色' value={formData?.color} />
120
                 <Input name='petColor' placeholder='请输入毛色' value={formData?.color} />
186
-              </mp-cell>
187
-              <mp-cell title='狗狗照片' extClass=''>
188
-                {
189
-                  !imgUrl.img1 ?
190
-                    <View className='addImage' onClick={() => addImage('img1')} >
191
-                      <Text>+</Text>
192
-                    </View>
193
-                    :
194
-                    <Image className='dogImg1' name='img1' src={imgUrl.img1} onClick={() => addImage('img1')} />
195
-                }
196
-
197
-              </mp-cell>
198
-              <mp-cell title='最近免疫日期' extClass=''>
121
+              </FormItem>
122
+              <FormItem title='狗狗照片' required>
123
+                <uploader name='dogImg1' onFile={handleFile} />
124
+              </FormItem>
125
+              <FormItem title='最近免疫日期' required>
199
                 <Picker name='immunizationDate' mode='date' onChange={(e) => { onDateChange('immunizationDate', e.detail.value) }}>
126
                 <Picker name='immunizationDate' mode='date' onChange={(e) => { onDateChange('immunizationDate', e.detail.value) }}>
200
                   <View className='picker' style={!formData ? { "color": '#858585' } : {}}>
127
                   <View className='picker' style={!formData ? { "color": '#858585' } : {}}>
201
                     {dogDate.immunizationDate}
128
                     {dogDate.immunizationDate}
202
                   </View>
129
                   </View>
203
                 </Picker>
130
                 </Picker>
204
-              </mp-cell>
205
-              <mp-cell title='免疫证号' extClass=''>
131
+              </FormItem>
132
+              <FormItem title='免疫证号' required>
206
                 <Input name='immunizationCode' placeholder='请输入免疫证号' />
133
                 <Input name='immunizationCode' placeholder='请输入免疫证号' />
207
-              </mp-cell>
208
-              <mp-cell title='免疫证明' extClass=''>
209
-                {
210
-                  !imgUrl.immunizationImg ?
211
-                    <View className='addImage' onClick={() => addImage('immunizationImg')} >
212
-                      <Text>+</Text>
213
-                    </View>
214
-                    :
215
-                    <Image className='dogImg1' name='immunizationImg' src={imgUrl.immunizationImg} onClick={() => addImage('immunizationImg')} />
216
-                }
217
-                {/* <Input name='immunizationImg' placeholder='请输入身份证号' type='idcard' /> */}
218
-              </mp-cell>
219
-              <mp-cell title='详细地址' extClass=''>
134
+              </FormItem>
135
+              <FormItem title='免疫证明' required>
136
+                <uploader name='immunizationImg' onFile={handleFile} />
137
+              </FormItem>
138
+              <FormItem title='详细地址' required>
220
                 <Input name='address' placeholder='请输入详细地址' />
139
                 <Input name='address' placeholder='请输入详细地址' />
221
-              </mp-cell>
222
-              <mp-cell title='申领方式' extClass=''>
140
+              </FormItem>
141
+              <FormItem title='申领方式' extClass=''>
223
                 <View className='radio-list'>
142
                 <View className='radio-list'>
224
                   <RadioGroup name='applyMethod'>
143
                   <RadioGroup name='applyMethod'>
225
                     {modeList.map((item, i) => {
144
                     {modeList.map((item, i) => {
231
                     })}
150
                     })}
232
                   </RadioGroup>
151
                   </RadioGroup>
233
                 </View>
152
                 </View>
234
-              </mp-cell>
153
+              </FormItem>
235
 
154
 
236
             </mp-cells>
155
             </mp-cells>
237
           </mp-form>
156
           </mp-form>