张延森 il y a 3 ans
Parent
révision
98cce1d742
2 fichiers modifiés avec 33 ajouts et 113 suppressions
  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 Voir le fichier

@@ -11,7 +11,8 @@ export default {
11 11
     "mp-form": "weui-miniprogram/form/form",
12 12
     "mp-dialog": "weui-miniprogram/dialog/dialog",
13 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 Voir le fichier

@@ -2,10 +2,10 @@ import { View, Button, Text, RadioGroup, Picker, Image, Input, Radio, Label, Scr
2 2
 import Taro, { useDidShow, useRouter } from '@tarojs/taro';
3 3
 import { useState } from 'react';
4 4
 import Form from '@/components/Form';
5
-import FieldLabel from '@/components/Form/FieldLabel';
5
+import FormItem from '@/components/Form/FormItem';
6 6
 import AuthProfile from '@/components/Authorize/AuthProfile';
7 7
 import { addDogList, addlication, getDogInfo } from '@/services/dogAPI';
8
-import { uploadFile } from '@/utils/request';
8
+import { handleFile } from '@/utils/request';
9 9
 import { useModel } from '@/store';
10 10
 
11 11
 import './style.less'
@@ -15,10 +15,10 @@ export default (props) => {
15 15
   const [formData, setFormData] = useState()
16 16
 
17 17
   const [dogDate, setDogDate] = useState({ immunizationDate: '请选择日期', petBirthday: '请选择生日', petSex: [], petType: [] })
18
-  const [imgUrl, setImgUrl] = useState({ img1: null, immunizationImg: null })
19 18
   const [mainDog, setMainDog] = useState([])
20 19
 
21
-
20
+  const router = useRouter()
21
+  const applyType = router.params.type || 'first'
22 22
 
23 23
   useDidShow(() => {
24 24
     addDogList().then((res) => {
@@ -36,14 +36,11 @@ export default (props) => {
36 36
       const petType = [{ value: 0, name: e?.petType }];
37 37
 
38 38
       setDogDate({ ...dogDate, petBirthday: e?.birthday, petSex: sex, petType: petType })
39
-      setImgUrl({ ...imgUrl, img1: e.image })
40 39
       console.log('test', e);
41 40
 
42 41
     })
43 42
   }
44 43
 
45
-
46
-
47 44
   const onDateChange = (type, value) => {
48 45
     console.log('dogDate', dogDate);
49 46
 
@@ -74,65 +71,11 @@ export default (props) => {
74 71
       value: 2,
75 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 76
   // ...dogDate,
134 77
   const formSubmit = value => {
135
-    addlication({ ...value, ...imgUrl, applyType: 'first' }).then((res) => {
78
+    addlication({ ...value, applyType }).then((res) => {
136 79
       console.log('dogInfo xinwe', res);
137 80
       Taro.showToast({
138 81
         title: '保存成功',
@@ -154,72 +97,48 @@ export default (props) => {
154 97
         <Form onSubmit={formSubmit} >
155 98
           <mp-form  >
156 99
             <mp-cells >
157
-              <mp-cell title='犬主姓名' extClass=''>
158
-                <Slot><FieldLabel></FieldLabel> </Slot>
100
+              <FormItem title='犬主姓名' required>
159 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 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 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 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 113
                 <Picker name='petBirthday' mode='date' onChange={(e) => { onDateChange('petBirthday', e.detail.value) }}>
179 114
                   <View className='picker' style={!formData ? { "color": '#858585' } : {}}>
180 115
                     {dogDate.petBirthday}
181 116
                   </View>
182 117
                 </Picker>
183
-              </mp-cell>
184
-              <mp-cell title='毛色' extClass=''>
118
+              </FormItem>
119
+              <FormItem title='毛色' required>
185 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 126
                 <Picker name='immunizationDate' mode='date' onChange={(e) => { onDateChange('immunizationDate', e.detail.value) }}>
200 127
                   <View className='picker' style={!formData ? { "color": '#858585' } : {}}>
201 128
                     {dogDate.immunizationDate}
202 129
                   </View>
203 130
                 </Picker>
204
-              </mp-cell>
205
-              <mp-cell title='免疫证号' extClass=''>
131
+              </FormItem>
132
+              <FormItem title='免疫证号' required>
206 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 139
                 <Input name='address' placeholder='请输入详细地址' />
221
-              </mp-cell>
222
-              <mp-cell title='申领方式' extClass=''>
140
+              </FormItem>
141
+              <FormItem title='申领方式' extClass=''>
223 142
                 <View className='radio-list'>
224 143
                   <RadioGroup name='applyMethod'>
225 144
                     {modeList.map((item, i) => {
@@ -231,7 +150,7 @@ export default (props) => {
231 150
                     })}
232 151
                   </RadioGroup>
233 152
                 </View>
234
-              </mp-cell>
153
+              </FormItem>
235 154
 
236 155
             </mp-cells>
237 156
           </mp-form>