|
@@ -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>
|