|
@@ -1,73 +1,291 @@
|
1
|
|
-import Taro from '@tarojs/taro'
|
2
|
|
-import Star from '@/components/Star/Star.jsx'
|
3
|
|
-import pay from '@/assets/icons/housemantj/pay.png'
|
4
|
|
-import msTip from '@/assets/icons/housemantj/foodtip.png'
|
5
|
|
-import wz from '@/assets/icons/housemantj/location.png'
|
6
|
|
-import hongxin from '@/assets/icons/housemantj/已收藏.png'
|
7
|
|
-import baixin from '@/assets/icons/housemantj/收藏.png'
|
8
|
|
-import './style.less'
|
9
|
|
-import useSave from "@/utils/hooks/useSave"
|
10
|
|
-import {getShopDetail,getShopcity} from '@/services/home'
|
11
|
|
-import { useState, useEffect } from 'react'
|
12
|
|
-
|
13
|
|
-
|
14
|
|
-
|
15
|
|
-//套餐卡片
|
16
|
|
-export default (props) => {
|
17
|
|
- const { item } = props
|
18
|
|
- const [isSaved, toggleSave] = useSave(item.isSaved,'shop_package', item.packageId)
|
19
|
|
- const [city,setCity]=useState({})
|
20
|
|
- const [detail,setDetail]=useState({})
|
|
1
|
+import withLayout from "@/layouts";
|
|
2
|
+import image from "@/assets/icons/ProCard/8kb.jpg";
|
|
3
|
+import { useState, useEffect } from "react";
|
|
4
|
+import { Button, Checkbox, Input } from "@tarojs/components";
|
|
5
|
+
|
|
6
|
+import food from "@/assets/icons/ProCard/food.png";
|
|
7
|
+import ProCard_hot from "@/assets/icons/ProCard/ProCard_hot.png";
|
|
8
|
+import CustomNav from "@/components/CustomNav";
|
|
9
|
+import OrderMolded from "@/components/OrderMolded";
|
|
10
|
+import Popup from "@/components/Popup";
|
|
11
|
+
|
|
12
|
+import "./style.less";
|
|
13
|
+import Taro, { useDidShow } from "@tarojs/taro";
|
|
14
|
+import { getShopPackageDetail } from "@/services/home";
|
|
15
|
+import { saveOrder, getOrderSub, payOrder } from "@/services/payOrder";
|
|
16
|
+import formatTime from "@/utils/formatTime";
|
|
17
|
+
|
|
18
|
+export default withLayout((props) => {
|
|
19
|
+ const { router, person } = props;
|
|
20
|
+ const { packageId, orderId } = props.router.params;
|
|
21
|
+
|
|
22
|
+ const [payInfo,setPayInfo] = useState()
|
|
23
|
+
|
|
24
|
+ const [showDialog, setShowDialog] = useState(false);
|
|
25
|
+ // 是否已阅读协议
|
|
26
|
+ const [agreement, setAgreement] = useState(false);
|
|
27
|
+ // 总价 totalPrice
|
|
28
|
+ const [totalPrice, setTotalPrice] = useState({});
|
|
29
|
+ const [list, setList] = useState([]);
|
|
30
|
+
|
|
31
|
+ const [BuyNumber, setBuyNumber] = useState(1);
|
|
32
|
+ const [detail, setDetail] = useState({});
|
|
33
|
+
|
|
34
|
+ const [DisabledBool, setDisabledBool] = useState(false);
|
|
35
|
+
|
|
36
|
+ const ShowMoldeOn = (e) => {
|
|
37
|
+ if (packageId) {
|
|
38
|
+ setBuyNumber(e.amount || 1);
|
|
39
|
+ setDetail(e);
|
|
40
|
+ setShowDialog(true);
|
|
41
|
+ }
|
|
42
|
+ };
|
|
43
|
+ const ButtonCancel = () => {
|
|
44
|
+ setShowDialog(false);
|
|
45
|
+ };
|
|
46
|
+ const ButtonOK = (e) => {
|
|
47
|
+ setList(
|
|
48
|
+ list.map((x) =>
|
|
49
|
+ x.packageId == detail.packageId ? { ...x, amount: BuyNumber } : x
|
|
50
|
+ )
|
|
51
|
+ );
|
|
52
|
+ setShowDialog(false);
|
|
53
|
+ };
|
|
54
|
+
|
|
55
|
+ const NumberAdd = () => {
|
|
56
|
+ setBuyNumber(BuyNumber + 1);
|
|
57
|
+ console.log(BuyNumber);
|
|
58
|
+ };
|
|
59
|
+
|
|
60
|
+ const NumberCut = () => {
|
|
61
|
+ if (DisabledBool) return;
|
|
62
|
+ setBuyNumber(BuyNumber - 1);
|
|
63
|
+ console.log(BuyNumber);
|
|
64
|
+ };
|
|
65
|
+
|
|
66
|
+ const onInput = (e) => {
|
|
67
|
+ let values = e.detail.value;
|
|
68
|
+ setBuyNumber(values - 0);
|
|
69
|
+ };
|
|
70
|
+
|
|
71
|
+ const requestPayment = (params) =>{
|
|
72
|
+ console.log(params,'requestPayment')
|
|
73
|
+ Taro.requestPayment({
|
|
74
|
+ ...params,
|
|
75
|
+ package: params.packageValue,
|
|
76
|
+ success: () => {
|
|
77
|
+ console.log("success");
|
|
78
|
+ setPayInfo()
|
|
79
|
+ Taro.showToast({
|
|
80
|
+ title: "支付成功",
|
|
81
|
+ icon: "none",
|
|
82
|
+ duration: 2000,
|
|
83
|
+ });
|
|
84
|
+ },
|
|
85
|
+ fail: (e) => {
|
|
86
|
+ console.log(e, "fail");
|
|
87
|
+ Taro.showToast({
|
|
88
|
+ title: "支付失败",
|
|
89
|
+ icon: "none",
|
|
90
|
+ duration: 2000,
|
|
91
|
+ });
|
|
92
|
+ },
|
|
93
|
+ });
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ const onShowPay = (e) => {
|
|
97
|
+ if (agreement) {
|
|
98
|
+ if(payInfo){
|
|
99
|
+ requestPayment(payInfo)
|
|
100
|
+ return
|
|
101
|
+ }
|
|
102
|
+ if (packageId) {
|
|
103
|
+ saveOrder(
|
|
104
|
+ list.map((x) => {
|
|
105
|
+ return {
|
|
106
|
+ amount: x.amount || 1,
|
|
107
|
+ itemId: x.packageId,
|
|
108
|
+ price: x.actualPrice,
|
|
109
|
+ };
|
|
110
|
+ })
|
|
111
|
+ ).then((res) => {
|
|
112
|
+ setPayInfo(res)
|
|
113
|
+ requestPayment(res)
|
|
114
|
+ });
|
|
115
|
+ }
|
|
116
|
+ if (orderId) {
|
|
117
|
+ payOrder(orderId).then((res) => {
|
|
118
|
+ setPayInfo(res)
|
|
119
|
+ requestPayment(res)
|
|
120
|
+ });
|
|
121
|
+ }
|
|
122
|
+ } else {
|
|
123
|
+ Taro.showToast({
|
|
124
|
+ title: "请勾选《平台用户服务协议》",
|
|
125
|
+ icon: "none",
|
|
126
|
+ duration: 2000,
|
|
127
|
+ });
|
|
128
|
+ }
|
|
129
|
+ };
|
21
|
130
|
|
22
|
131
|
useEffect(() => {
|
23
|
|
- getShopDetail(item.shopId).then((res)=>{
|
24
|
|
- setDetail(res)
|
25
|
|
- getShopcity(res.cityId).then((res2)=>{
|
26
|
|
- setCity(res2)
|
27
|
|
- })
|
28
|
|
- })
|
29
|
|
-}, [])
|
30
|
|
-const star=parseFloat(((detail.sweetScore+detail.environmentScore+detail.serviceScore)/3).toFixed(1));
|
|
132
|
+ if (packageId) {
|
|
133
|
+ getShopPackageDetail(packageId).then((res) => {
|
|
134
|
+ setList([res]);
|
|
135
|
+ });
|
|
136
|
+ }
|
|
137
|
+ if (orderId) {
|
|
138
|
+ getOrderSub({ pageNum: 1, pageSize: 999, orderId }).then((res) => {
|
|
139
|
+ setList(res.records);
|
|
140
|
+ });
|
|
141
|
+ }
|
|
142
|
+ }, [packageId, orderId]);
|
|
143
|
+
|
|
144
|
+ useEffect(() => {
|
|
145
|
+ if (BuyNumber < 2) {
|
|
146
|
+ setDisabledBool(true);
|
|
147
|
+ } else {
|
|
148
|
+ setDisabledBool(false);
|
|
149
|
+ }
|
|
150
|
+ }, [BuyNumber]);
|
|
151
|
+
|
|
152
|
+ useEffect(() => {
|
|
153
|
+ let total = {
|
|
154
|
+ cashback: 0,
|
|
155
|
+ actualPrice: 0,
|
|
156
|
+ standardPrice: 0,
|
|
157
|
+ };
|
|
158
|
+ list.map((x) => {
|
|
159
|
+ total.cashback += x.cashback * (x.amount || 1);
|
|
160
|
+ total.actualPrice += (x.actualPrice || x.unitPrice) * (x.amount || 1);
|
|
161
|
+ total.standardPrice += x.standardPrice * (x.amount || 1);
|
|
162
|
+ });
|
|
163
|
+ setTotalPrice(total);
|
|
164
|
+ }, [list]);
|
31
|
165
|
|
32
|
166
|
return (
|
33
|
|
- <view className='foodCard'>
|
34
|
|
- <view className='fCleft'>
|
35
|
|
- <view className='backMoney'>
|
36
|
|
- 返现¥{item.cashback/100}
|
|
167
|
+ <view class="container">
|
|
168
|
+ <CustomNav title="订单" />
|
|
169
|
+ <Popup show={showDialog} maskClosable={false}>
|
|
170
|
+ <OrderMolded />
|
|
171
|
+ <view className="item-center-Number">
|
|
172
|
+ <view
|
|
173
|
+ className="buy-num-minus"
|
|
174
|
+ disabled={DisabledBool}
|
|
175
|
+ onClick={NumberCut}
|
|
176
|
+ >
|
|
177
|
+ -
|
37
|
178
|
</view>
|
38
|
|
- <view className='appraise'>
|
39
|
|
- <Star star={star} />
|
40
|
|
- <text className='storezf'>{star}</text>
|
|
179
|
+ <Input
|
|
180
|
+ className="buy-num-input"
|
|
181
|
+ type="number"
|
|
182
|
+ min="1"
|
|
183
|
+ onInput={onInput}
|
|
184
|
+ value={BuyNumber}
|
|
185
|
+ />
|
|
186
|
+ <view className="buy-num-add" onClick={NumberAdd}>
|
|
187
|
+ +
|
41
|
188
|
</view>
|
42
|
|
- <view>
|
43
|
|
- <view className='contentImg'>
|
44
|
|
- <image src={item.poster} className='img1'></image>
|
45
|
|
- <image src={msTip} className='mstip'></image>
|
46
|
|
- </view>
|
47
|
|
- <view className='neirong'>
|
48
|
|
- <view className='textword'>{(item.description).toString().length>25?(item.description).substring(0, 25)+'...':(item.description)}</view>
|
49
|
|
- <view className='jiage'>
|
50
|
|
- <text className='rmb' >¥ </text>
|
51
|
|
- <text className='p1'><text className='price' >{item.actualPrice/100}</text>元 </text>
|
52
|
|
- <text className='p2'>门市价<text className='oldprice' >{item.standardPrice/100}</text>元</text>
|
53
|
|
- </view>
|
54
|
|
- <view className='address'>
|
55
|
|
- <image className='dw' src={wz} />
|
56
|
|
- <text className='wz'>{city.areaPName}/{city.areaName}</text>
|
57
|
|
- <view style={{display:'inline-block'}} onClick={toggleSave}>
|
58
|
|
- <image className='star' src={isSaved>0?hongxin:baixin}></image>
|
59
|
|
- <text className='collection'>{isSaved>0?'已收藏':'加入收藏'}</text>
|
|
189
|
+ </view>
|
|
190
|
+ <view className="buy-button-box">
|
|
191
|
+ <button className="button-Cancel" onClick={ButtonCancel}>
|
|
192
|
+ 取消
|
|
193
|
+ </button>
|
|
194
|
+ <button className="button-OK" onClick={ButtonOK}>
|
|
195
|
+ 确定
|
|
196
|
+ </button>
|
|
197
|
+ </view>
|
|
198
|
+ </Popup>
|
|
199
|
+ <view class="coupon-list">
|
|
200
|
+ {list?.map((item) => {
|
|
201
|
+ return (
|
|
202
|
+ <view class="wrapper">
|
|
203
|
+ <view class="left-complete-one">
|
|
204
|
+ <image className="left-image-1" src={ProCard_hot}></image>
|
|
205
|
+ <view className="left-viewText">
|
|
206
|
+ 返现¥{(item.cashback || 0) / 100}
|
|
207
|
+ </view>
|
|
208
|
+ <view className="title-image">
|
|
209
|
+ <image
|
|
210
|
+ className="image-1"
|
|
211
|
+ mode="scaleToFill"
|
|
212
|
+ src={item.poster}
|
|
213
|
+ ></image>
|
|
214
|
+ <image className="image-2" src={food}></image>
|
|
215
|
+ </view>
|
|
216
|
+ <view className="title-content">
|
|
217
|
+ <view className="Pro-title">
|
|
218
|
+ <view className="title-text">{item.description}</view>
|
|
219
|
+ </view>
|
|
220
|
+ <text className="title-money">
|
|
221
|
+ ¥{(item.actualPrice || item.unitPrice || 0) / 100}元
|
|
222
|
+ <text className="title-money-2">
|
|
223
|
+ 门市价{(item.standardPrice || 0) / 100}元
|
|
224
|
+ </text>
|
|
225
|
+ </text>
|
|
226
|
+ <view className="title-time">
|
|
227
|
+ 有效期:{formatTime(item.startTime, "yyyy/MM/dd")}-
|
|
228
|
+ {formatTime(item.endTime, "yyyy/MM/dd")}
|
|
229
|
+ </view>
|
|
230
|
+ </view>
|
60
|
231
|
</view>
|
|
232
|
+ <view
|
|
233
|
+ class="right-complete-two"
|
|
234
|
+ onClick={() => ShowMoldeOn(item)}
|
|
235
|
+ >
|
|
236
|
+ <view className="right-content">
|
|
237
|
+ <view className="right-number">×{item.amount || 1}</view>
|
|
238
|
+ <view className="right-title">数量</view>
|
|
239
|
+ </view>
|
61
|
240
|
</view>
|
62
|
241
|
</view>
|
|
242
|
+ );
|
|
243
|
+ })}
|
|
244
|
+ </view>
|
|
245
|
+ <view className="view-button">
|
|
246
|
+ <view className="Card-number-box">
|
|
247
|
+ <view className="Card-number">
|
|
248
|
+ <text style="left:29px;position: absolute; padding-top:20px">
|
|
249
|
+ 手机号码:
|
|
250
|
+ </text>
|
|
251
|
+ <text style="right:29px;position: absolute;padding-top:20px">
|
|
252
|
+ {person.phone}
|
|
253
|
+ </text>
|
|
254
|
+ </view>
|
|
255
|
+ <view className="Card-user">
|
|
256
|
+ <Checkbox
|
|
257
|
+ style="padding-left:20px; position: relative; top:24px;"
|
|
258
|
+ value="agreement"
|
|
259
|
+ checked={agreement}
|
|
260
|
+ onClick={() => {
|
|
261
|
+ setAgreement(!agreement);
|
|
262
|
+ }}
|
|
263
|
+ >
|
|
264
|
+ 我已阅读知晓并同意
|
|
265
|
+ <text style="color:#274190;text-decoration:underline;font-weight:400">
|
|
266
|
+ 《平台用户服务协议》
|
|
267
|
+ </text>
|
|
268
|
+ </Checkbox>
|
63
|
269
|
</view>
|
64
|
270
|
</view>
|
65
|
|
- <view className='fCright' onClick={()=>{Taro.navigateTo({ url: `/pages/PayOrder/index?packageId=${item.packageId}` });}}>
|
66
|
|
- <image src={pay} />
|
67
|
|
- <view>支付</view>
|
|
271
|
+ <view className="button-box-button-box">
|
|
272
|
+ <view className="button-text-image">
|
|
273
|
+ <text className="button-text-money-hot">
|
|
274
|
+ 返现¥{(totalPrice?.cashback || 0) / 100}
|
|
275
|
+ </text>
|
|
276
|
+ <image className="button-image" src={ProCard_hot}>
|
|
277
|
+ 123123
|
|
278
|
+ </image>
|
|
279
|
+ <view className="button-text-money">
|
|
280
|
+ 门店市面价:{(totalPrice?.standardPrice || 0) / 100}元
|
|
281
|
+ </view>
|
|
282
|
+ </view>
|
|
283
|
+ <Button className="button-box-one" onClick={() => onShowPay()}>
|
|
284
|
+ ¥{(totalPrice?.actualPrice || 0) / 100}元
|
|
285
|
+ <text className="button-text-one">支付订单</text>
|
|
286
|
+ </Button>
|
68
|
287
|
</view>
|
69
|
|
- <view className='columnLine'></view>
|
70
|
288
|
</view>
|
71
|
|
-
|
72
|
|
- )
|
73
|
|
-}
|
|
289
|
+ </view>
|
|
290
|
+ );
|
|
291
|
+});
|