张延森 3 年 前
コミット
f3758edfed
共有4 個のファイルを変更した98 個の追加25 個の削除を含む
  1. 24
    0
      src/components/Spin/SpinBox.jsx
  2. 19
    0
      src/components/Spin/style.less
  3. 45
    17
      src/pages/TobeShop/index.jsx
  4. 10
    8
      src/pages/details/foodDetails/foodDetails.jsx

+ 24
- 0
src/components/Spin/SpinBox.jsx ファイルの表示

@@ -0,0 +1,24 @@
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 ファイルの表示

@@ -130,3 +130,22 @@
130 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 ファイルの表示

@@ -7,6 +7,7 @@ import { getShopDetail, getShopPackage, getExtendContent } from '@/services/home
7 7
 import { getVerifyTargetList, putVerifyTarget } from "@/services/payOrder";
8 8
 import formatTime from '@/utils/formatTime'
9 9
 import Popup from "@/components/Popup";
10
+import SpinBox from "@/components/Spin/SpinBox";
10 11
 import formatPrice from "@/utils/formatPrice";
11 12
 
12 13
 import LocationBig from "@/assets/icons/UserCenter/LocationBig.png";
@@ -26,9 +27,10 @@ export default withLayout((props) => {
26 27
   //核销
27 28
   const [Consumption, setConsumption] = useState(false);
28 29
 
29
-  const [checked, setChecked] = useState();
30
+  const [checked, setChecked] = useState([]);
30 31
   const [shopContent, setShopContent] = useState([])
31 32
 
33
+  const [loading, setLoading] = useState(false)
32 34
   const [list, setList] = useState([]);
33 35
 
34 36
 
@@ -40,6 +42,7 @@ export default withLayout((props) => {
40 42
   }
41 43
 
42 44
   const getList = (params) => {
45
+    setLoading(true)
43 46
     getVerifyTargetList({
44 47
       shopId: id,
45 48
       isMine: true,
@@ -50,18 +53,38 @@ export default withLayout((props) => {
50 53
       if (res) {
51 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 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 89
   const ShowMoldeOn = () => {
67 90
     setShowDialog(true);
@@ -70,19 +93,22 @@ export default withLayout((props) => {
70 93
     setShowDialog(false);
71 94
   };
72 95
   const ButtonOK = (e) => {
73
-    if (!checked) return
96
+    if (!checked || !checked.length) return
74 97
     if (showDialog === true) {
75 98
       Taro.showLoading({
76 99
         title: '核销中'
77 100
       })
78 101
 
79
-      putVerifyTarget(checked).then(res => {
102
+      Promise.all(checked.map(verifyNo => putVerifyTarget(verifyNo)))
103
+      .then(res => {
80 104
         Taro.hideLoading()
81 105
         setShowDialog(false);
82 106
         setConsumption(true);
83
-      }).catch(e => {
107
+      })
108
+      .catch(e => {
84 109
         Taro.hideLoading()
85 110
         setShowDialog(false);
111
+        getList();  // 刷新数据
86 112
         Taro.showToast({
87 113
           title: '核销失败',
88 114
           icon: 'none',
@@ -101,6 +127,8 @@ export default withLayout((props) => {
101 127
     }
102 128
   };
103 129
 
130
+  const btnText = ['确认核销', checked && checked.length > 0  ? `(${checked.length})` : undefined].filter(Boolean).join(' ')
131
+
104 132
   return (
105 133
     <view className='shop-Eat'>      
106 134
       <view className='index-navbar'>
@@ -147,10 +175,10 @@ export default withLayout((props) => {
147 175
           />
148 176
           <text className='shop-title-title'>请选择你要核销的套餐</text>
149 177
         </view>
150
-        <view>
178
+        <SpinBox loading={loading}>
151 179
           {(list || []).map((item) => {
152 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 182
                 <view class='left-complete-one'>
155 183
                   <image className='left-image-1' src={ProCard_hot}></image>
156 184
                   <view className='left-viewText'>返现¥{(item.cashback / 100).toFixed(2)}</view>
@@ -182,18 +210,18 @@ export default withLayout((props) => {
182 210
                 <view class='right-complete-two'>
183 211
                   <view className='right-content'>
184 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 214
                     </view>
187 215
                   </view>
188 216
                 </view>
189 217
               </view>
190 218
             );
191 219
           })}
192
-        </view>
220
+        </SpinBox>
193 221
 
194 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 225
           </Button>
198 226
         </view>
199 227
       </view>

+ 10
- 8
src/pages/details/foodDetails/foodDetails.jsx ファイルの表示

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