Yansen 2 年 前
コミット
ab6ab79054

+ 13
- 3
src/pages/check/loc/edit/components/Footer/index.jsx ファイルの表示

@@ -46,9 +46,19 @@ export default (props) => {
46 46
         {
47 47
           isPrev && <Button type="primary" block plain hairline style={{flex: 1}} onClick={onPrev}>上一题</Button>
48 48
         }
49
-        <Button type="primary" block style={{flex: 1, marginLeft: isPrev ? '1em' : 0 }} onClick={onNext}>
50
-          {isFinished ? '提交' : (value == -1 ? '开始测评' : '下一题')}
51
-        </Button>
49
+        {
50
+          value == -1 ? (
51
+            <Button type="primary" block style={{flex: 1, marginLeft: isPrev ? '1em' : 0 }} onClick={onNext}>
52
+              {readonly ? '查看测评' : '开始测评'}
53
+            </Button>
54
+          ) : (
55
+            !(readonly && isFinished) && (
56
+              <Button type="primary" block style={{flex: 1, marginLeft: isPrev ? '1em' : 0 }} onClick={onNext}>
57
+                {isFinished ? '提交' : '下一题'}
58
+              </Button>
59
+              )
60
+          )
61
+        }
52 62
       </View>
53 63
     </View>
54 64
   )

+ 4
- 1
src/pages/check/loc/edit/components/LocForm.jsx ファイルの表示

@@ -9,6 +9,8 @@ import mapIcon from '@/assets/icons/marker.png';
9 9
 export default (props) => {
10 10
   const { checkItemInfo, answer, readonly, onChange, onLoadingChange } = props;
11 11
 
12
+  const [loc, setLoc] = React.useState();
13
+
12 14
   const setLoading = (v) => {
13 15
     if (onLoadingChange) {
14 16
       onLoadingChange(v)
@@ -17,6 +19,7 @@ export default (props) => {
17 19
   
18 20
   const setFieldChange = (key, val) => {
19 21
     onChange({
22
+      location: loc,
20 23
       ...answer || {},
21 24
       [key]: val,
22 25
     })
@@ -39,7 +42,7 @@ export default (props) => {
39 42
   
40 43
   return (
41 44
     <View>
42
-      <Map location={answer?.location} onLocChange={e => !readonly && setFieldChange('location', e)} />
45
+      <Map location={answer?.location} onLocChange={setLoc} />
43 46
       <CellGroup>
44 47
         <Cell
45 48
           title="点位"

+ 3
- 1
src/pages/check/loc/edit/components/Question.jsx ファイルの表示

@@ -29,7 +29,9 @@ export default (props) => {
29 29
     if (quInfo?.quId) {
30 30
       setLoading(true);
31 31
       getTaCheckAnswerItem({ quId: quInfo.quId, isMine: true }).then(res => {
32
-        onChange(res && res.length ? res[0] : {});
32
+        if (res && res[0]) {
33
+          onChange(res[0]);
34
+        }
33 35
         setLoading(false);
34 36
       }).catch(() => {
35 37
         setLoading(false);

+ 59
- 34
src/pages/check/loc/edit/index.jsx ファイルの表示

@@ -1,9 +1,9 @@
1 1
 import React from 'react';
2 2
 import Taro from '@tarojs/taro';
3
-import { View } from '@tarojs/components';
3
+import { View, ScrollView } from '@tarojs/components';
4 4
 import { Notify } from '@antmjs/vantui';
5 5
 import Page from '@/layouts/index';
6
-import { getTaCheckItemById, preCheck, getTaCheckItemAnswer } from '@/services/tacheckitem';
6
+import { getTaCheckItemById, preCheck, getTaCheckItemAnswer, putTaCheckItemAnswer } from '@/services/tacheckitem';
7 7
 import { getTaCheckItemQu } from '@/services/tacheckitemqu';
8 8
 import VABC from '@/components/VABC';
9 9
 import { ROLE_INSPECTOR } from '@/utils/user';
@@ -47,6 +47,8 @@ export default (props) => {
47 47
   }
48 48
 
49 49
   const onAnswerItemChange = (answerItem, quInfo) => {
50
+    if (!answerItem) return;
51
+
50 52
     const an = {...(answer || {})}
51 53
     const answerItemList = an.answerItemList || []
52 54
 
@@ -86,7 +88,27 @@ export default (props) => {
86 88
 
87 89
   // 作答
88 90
   const onSubmit = () => {
91
+    if (readonly) return;
92
+
93
+    const finished = quList.filter(x => x.finished).length == quList.length;
94
+    if (!answer || !answer.answerItemList || !finished) {
95
+      Notify.show({
96
+        message: '请作答完成所有题目',
97
+        type: 'warning',
98
+      })
99
+      return;
100
+    }
89 101
 
102
+    setLoading(true);
103
+    putTaCheckItemAnswer(id, answer).then(() => {
104
+      setLoading(false);
105
+      const t = setTimeout(() => {
106
+        clearTimeout(t);
107
+        Taro.navigateBack({delta: 1});
108
+      }, 1000);      
109
+    }).catch(() => {
110
+      setLoading(false);
111
+    });
90 112
   }
91 113
 
92 114
   React.useEffect(() => {
@@ -143,39 +165,42 @@ export default (props) => {
143 165
           />
144 166
         )}
145 167
       >
146
-      {
147
-        index == -1 && (
148
-          <LocForm
149
-            readonly={readonly}
150
-            checkItemInfo={checkItemInfo}
151
-            answer={answer}
152
-            onChange={setAnswer}
153
-            onLoadingChange={setLoading}
154
-          />
155
-        )
156
-      }
157
-      {
158
-        quList.map((x, inx) => {
159
-          const answerItem = answer?.answerItemList?.filter(y => y.quId == x.quId)[0];
160
-
161
-          return (
162
-            index == inx && (
163
-              <Question
164
-                key={x.quId}
165
-                cursor={inx}
166
-                readonly={readonly}
167
-                quInfo={x}
168
-                answerItem={answerItem}
169
-                total={quList?.length}
170
-                onChange={e => onAnswerItemChange(e, x)}
171
-                onPrev={() => onIndexChange(null, -1)}
172
-                onNext={() => onIndexChange(null, 1)}
173
-                onLoadingChange={setLoading}
174
-              />
175
-            )
168
+        <ScrollView scrollY style={{height: '100%'}}>
169
+        {
170
+          index == -1 && (
171
+            <LocForm
172
+              readonly={readonly}
173
+              checkItemInfo={checkItemInfo}
174
+              answer={answer}
175
+              onChange={setAnswer}
176
+              onLoadingChange={setLoading}
177
+            />
176 178
           )
177
-        })
178
-      }
179
+        }
180
+        {
181
+          quList.map((x, inx) => {
182
+            const answerItem = answer?.answerItemList?.filter(y => y.quId == x.quId)[0];
183
+
184
+            return (
185
+              index == inx && (
186
+                <Question
187
+                  key={x.quId}
188
+                  cursor={inx}
189
+                  readonly={readonly}
190
+                  quInfo={x}
191
+                  answerItem={answerItem}
192
+                  total={quList?.length}
193
+                  onChange={e => onAnswerItemChange(e, x)}
194
+                  onPrev={() => onIndexChange(null, -1)}
195
+                  onNext={() => onIndexChange(null, 1)}
196
+                  onLoadingChange={setLoading}
197
+                />
198
+              )
199
+            )
200
+          })
201
+        }
202
+          
203
+        </ScrollView>
179 204
       </VABC>
180 205
     </Page>
181 206
   )

+ 5
- 0
src/services/tacheckitem.js ファイルの表示

@@ -34,3 +34,8 @@ export const preCheck = (id, opts = {}) => request(`/api/taCheckItem/${id}/answe
34 34
  * 获取当前答案
35 35
  */
36 36
 export const getTaCheckItemAnswer = (id) => request(`/api/taCheckItem/${id}/answer`);
37
+
38
+/*
39
+ * 获取当前答案
40
+ */
41
+export const putTaCheckItemAnswer = (id, data) => request(`/api/taCheckItem/${id}/answer`, { method: 'put', data });