张延森 3 years ago
parent
commit
f3758edfed

+ 24
- 0
src/components/Spin/SpinBox.jsx View File

1
+
2
+import React, { useMemo } from 'react'
3
+import { View } from '@tarojs/components'
4
+import Spin from '.'
5
+import './style.less'
6
+
7
+export default (props) => {
8
+  const { className, style, loading, size = '64rpx', ...leftProps } = props
9
+
10
+  const cls = useMemo(() => [className, 'loading-wrapper'].filter(Boolean).join(' '), [className])
11
+
12
+  return (
13
+    <View className={cls} style={style}>
14
+      {
15
+        loading && (
16
+          <View className='loading-box'>
17
+            <Spin size={size} {...leftProps} />
18
+          </View>
19
+        )
20
+      }
21
+      {props.children}
22
+    </View>
23
+  )
24
+}

+ 19
- 0
src/components/Spin/style.less View File

130
     transform: translate(-50%, -50%);
130
     transform: translate(-50%, -50%);
131
   }
131
   }
132
 }
132
 }
133
+
134
+
135
+.loading-wrapper {
136
+  position: relative;
137
+
138
+  .loading-box {
139
+    position: absolute;
140
+    z-index: 10;
141
+    top: 0;
142
+    left: 0;
143
+    width: 100%;
144
+    height: 100%;
145
+    min-height: 72px;
146
+    padding-top: 60%;
147
+    padding-left: 50%;
148
+    background: rgba(255, 255, 255, .95);
149
+    box-sizing: border-box;
150
+  }
151
+}

+ 45
- 17
src/pages/TobeShop/index.jsx View File

7
 import { getVerifyTargetList, putVerifyTarget } from "@/services/payOrder";
7
 import { getVerifyTargetList, putVerifyTarget } from "@/services/payOrder";
8
 import formatTime from '@/utils/formatTime'
8
 import formatTime from '@/utils/formatTime'
9
 import Popup from "@/components/Popup";
9
 import Popup from "@/components/Popup";
10
+import SpinBox from "@/components/Spin/SpinBox";
10
 import formatPrice from "@/utils/formatPrice";
11
 import formatPrice from "@/utils/formatPrice";
11
 
12
 
12
 import LocationBig from "@/assets/icons/UserCenter/LocationBig.png";
13
 import LocationBig from "@/assets/icons/UserCenter/LocationBig.png";
26
   //核销
27
   //核销
27
   const [Consumption, setConsumption] = useState(false);
28
   const [Consumption, setConsumption] = useState(false);
28
 
29
 
29
-  const [checked, setChecked] = useState();
30
+  const [checked, setChecked] = useState([]);
30
   const [shopContent, setShopContent] = useState([])
31
   const [shopContent, setShopContent] = useState([])
31
 
32
 
33
+  const [loading, setLoading] = useState(false)
32
   const [list, setList] = useState([]);
34
   const [list, setList] = useState([]);
33
 
35
 
34
 
36
 
40
   }
42
   }
41
 
43
 
42
   const getList = (params) => {
44
   const getList = (params) => {
45
+    setLoading(true)
43
     getVerifyTargetList({
46
     getVerifyTargetList({
44
       shopId: id,
47
       shopId: id,
45
       isMine: true,
48
       isMine: true,
50
       if (res) {
53
       if (res) {
51
         setList(res.records)
54
         setList(res.records)
52
 
55
 
53
-        setChecked(res?.records.filter(x => x.subOrderId == subOrderId)[0]?.verifyNo)
54
-
55
-        // if(item.verifyNo==checked)
56
+        if (res.records && res.records.length > 0) {
57
+          if (res.records.length === 1) {
58
+            setChecked([res.records[0].verifyNo])
59
+          } else {
60
+            setChecked([res?.records.filter(x => x.subOrderId == subOrderId)[0]?.verifyNo].filter(Boolean))
61
+          }
62
+        } else {
63
+          Taro.navigateBack({ delta: 1 })
64
+        }
56
       }
65
       }
57
 
66
 
58
-    });
67
+      setLoading(false)
68
+    }).catch(() => setLoading(false));
59
   };
69
   };
60
 
70
 
61
   useEffect(() => {
71
   useEffect(() => {
62
-    getList();
63
-    getShop();
64
-  }, []);
72
+    if (id) {
73
+      getList();
74
+      getShop();
75
+    }
76
+  }, [id]);
77
+
78
+  const handleCheck = (verifyNo) => {
79
+    const inx = checked.indexOf(verifyNo)
80
+    if (inx === -1) {
81
+      setChecked([...checked, verifyNo])
82
+    } else {
83
+      const p1 = checked.slice(0, inx)
84
+      const p2 = checked.slice(inx + 1)
85
+      setChecked(p1.concat(p2))
86
+    }
87
+  }
65
 
88
 
66
   const ShowMoldeOn = () => {
89
   const ShowMoldeOn = () => {
67
     setShowDialog(true);
90
     setShowDialog(true);
70
     setShowDialog(false);
93
     setShowDialog(false);
71
   };
94
   };
72
   const ButtonOK = (e) => {
95
   const ButtonOK = (e) => {
73
-    if (!checked) return
96
+    if (!checked || !checked.length) return
74
     if (showDialog === true) {
97
     if (showDialog === true) {
75
       Taro.showLoading({
98
       Taro.showLoading({
76
         title: '核销中'
99
         title: '核销中'
77
       })
100
       })
78
 
101
 
79
-      putVerifyTarget(checked).then(res => {
102
+      Promise.all(checked.map(verifyNo => putVerifyTarget(verifyNo)))
103
+      .then(res => {
80
         Taro.hideLoading()
104
         Taro.hideLoading()
81
         setShowDialog(false);
105
         setShowDialog(false);
82
         setConsumption(true);
106
         setConsumption(true);
83
-      }).catch(e => {
107
+      })
108
+      .catch(e => {
84
         Taro.hideLoading()
109
         Taro.hideLoading()
85
         setShowDialog(false);
110
         setShowDialog(false);
111
+        getList();  // 刷新数据
86
         Taro.showToast({
112
         Taro.showToast({
87
           title: '核销失败',
113
           title: '核销失败',
88
           icon: 'none',
114
           icon: 'none',
101
     }
127
     }
102
   };
128
   };
103
 
129
 
130
+  const btnText = ['确认核销', checked && checked.length > 0  ? `(${checked.length})` : undefined].filter(Boolean).join(' ')
131
+
104
   return (
132
   return (
105
     <view className='shop-Eat'>      
133
     <view className='shop-Eat'>      
106
       <view className='index-navbar'>
134
       <view className='index-navbar'>
147
           />
175
           />
148
           <text className='shop-title-title'>请选择你要核销的套餐</text>
176
           <text className='shop-title-title'>请选择你要核销的套餐</text>
149
         </view>
177
         </view>
150
-        <view>
178
+        <SpinBox loading={loading}>
151
           {(list || []).map((item) => {
179
           {(list || []).map((item) => {
152
             return (
180
             return (
153
-              <view class='wrapper' key={item.verifyNo} onClick={() => setChecked(item.verifyNo)}>
181
+              <view class='wrapper' key={item.verifyNo} onClick={() => handleCheck(item.verifyNo)}>
154
                 <view class='left-complete-one'>
182
                 <view class='left-complete-one'>
155
                   <image className='left-image-1' src={ProCard_hot}></image>
183
                   <image className='left-image-1' src={ProCard_hot}></image>
156
                   <view className='left-viewText'>返现¥{(item.cashback / 100).toFixed(2)}</view>
184
                   <view className='left-viewText'>返现¥{(item.cashback / 100).toFixed(2)}</view>
182
                 <view class='right-complete-two'>
210
                 <view class='right-complete-two'>
183
                   <view className='right-content'>
211
                   <view className='right-content'>
184
                     <view className='Check_OK-box'>
212
                     <view className='Check_OK-box'>
185
-                      <image className='Check_OK-image' src={item.verifyNo == checked ? Check_OK : Check_NO} />
213
+                      <image className='Check_OK-image' src={checked.indexOf(item.verifyNo) > -1 ? Check_OK : Check_NO} />
186
                     </view>
214
                     </view>
187
                   </view>
215
                   </view>
188
                 </view>
216
                 </view>
189
               </view>
217
               </view>
190
             );
218
             );
191
           })}
219
           })}
192
-        </view>
220
+        </SpinBox>
193
 
221
 
194
         <view className='button-info'>
222
         <view className='button-info'>
195
-          <Button className='button-box' disabled={!checked} onClick={ShowMoldeOn}>
196
-            确定核销
223
+          <Button className='button-box' disabled={!checked.length} onClick={ShowMoldeOn}>
224
+            {btnText}
197
           </Button>
225
           </Button>
198
         </view>
226
         </view>
199
       </view>
227
       </view>

+ 10
- 8
src/pages/details/foodDetails/foodDetails.jsx View File

12
 import Star from "@/components/Star/Star.jsx";
12
 import Star from "@/components/Star/Star.jsx";
13
 import NoData from '@/components/NoData'
13
 import NoData from '@/components/NoData'
14
 import Cards from "@/components/foodCards/foodCards.jsx";
14
 import Cards from "@/components/foodCards/foodCards.jsx";
15
+import SpinBox from "@/components/Spin/SpinBox";
15
 import ax from "@/assets/icons/housemantj/onlove.png";
16
 import ax from "@/assets/icons/housemantj/onlove.png";
16
 import yysj from "@/assets/icons/housemantj/openTime.png";
17
 import yysj from "@/assets/icons/housemantj/openTime.png";
17
 import dw from "@/assets/icons/housemantj/loc.png";
18
 import dw from "@/assets/icons/housemantj/loc.png";
48
   }, [id, scene, subOrderId]);
49
   }, [id, scene, subOrderId]);
49
 
50
 
50
   //商铺基础信息
51
   //商铺基础信息
52
+  const [loading, setLoading] = useState(false)
51
   const [detail, setDetail] = useState({});
53
   const [detail, setDetail] = useState({});
52
   //商铺套餐
54
   //商铺套餐
53
   const [spackage, setPackage] = useState([]);
55
   const [spackage, setPackage] = useState([]);
104
 
106
 
105
   useEffect(() => {
107
   useEffect(() => {
106
     if (id) {
108
     if (id) {
109
+      setLoading(true)
107
       getShopDetail(id, { location }).then((res) => {
110
       getShopDetail(id, { location }).then((res) => {
108
         setDetail(res);
111
         setDetail(res);
109
         log.current = res.locaton.toString().split(",")[0];
112
         log.current = res.locaton.toString().split(",")[0];
110
         lat.current = res.locaton.toString().split(",")[1];
113
         lat.current = res.locaton.toString().split(",")[1];
111
         setimglist(res.imageList || []);
114
         setimglist(res.imageList || []);
112
-      });
115
+        setLoading(false)
116
+      }).catch(() => setLoading(false));
113
       getShopPackage(id).then((res) => {
117
       getShopPackage(id).then((res) => {
114
         setPackage(res.records || []);
118
         setPackage(res.records || []);
115
         setNewpgNum(res.records.length);
119
         setNewpgNum(res.records.length);
142
       <view className='index-navbar'>
146
       <view className='index-navbar'>
143
         <CustomNav title='十公里' />
147
         <CustomNav title='十公里' />
144
       </view>
148
       </view>
145
-      <view
146
-        style={{ overflow: "hidden", padding: "0 30rpx", height: '100%', background: "#F8F8F8" }}
147
-      >
149
+      <SpinBox loading={loading} className='index-container' style={{ padding: '0 30rpx' }}>
148
         <scroll-view
150
         <scroll-view
149
           scrollY
151
           scrollY
150
           style={{ height: '100%' }}
152
           style={{ height: '100%' }}
156
               current={index}
158
               current={index}
157
               onChange={handchange}
159
               onChange={handchange}
158
             >
160
             >
159
-              {imglist.map((item) => (
160
-                <SwiperItem>
161
+              {imglist.map((item, inx) => (
162
+                <SwiperItem key={inx}>
161
                   <image src={item.url} mode='aspectFit' className='storeImage'>
163
                   <image src={item.url} mode='aspectFit' className='storeImage'>
162
                     <view className='tpPage'>
164
                     <view className='tpPage'>
163
                       <text>
165
                       <text>
269
               </>
271
               </>
270
           }
272
           }
271
         </scroll-view>
273
         </scroll-view>
272
-      </view>
273
-      <view className='bottomTab'>
274
+      </SpinBox>
275
+      <view className='bottomTab custom-tabbar'>
274
         <Button openType='share' className='sharebtn'>
276
         <Button openType='share' className='sharebtn'>
275
           分享
277
           分享
276
         </Button>
278
         </Button>