张延森 3 years ago
parent
commit
f40136dd1f

+ 49
- 0
src/components/InputNumber/index.jsx View File

@@ -0,0 +1,49 @@
1
+import React from 'react';
2
+import { Input, View } from '@tarojs/components';
3
+import './style.less'
4
+
5
+// eslint-disable-next-line no-restricted-globals
6
+const isNotaNumber = x => isNaN(x)
7
+const noop = x => x
8
+
9
+export default (props) => {
10
+  const { className, style, value, step = 1, onChange = noop, ...leftProps } = props
11
+
12
+  const handleInput = (e) => {
13
+    const val = e.detail.value
14
+
15
+    if (isNotaNumber(val)) {
16
+      onChange(undefined)
17
+    } else {
18
+      onChange(val - 0)
19
+    }
20
+  }
21
+
22
+  const handleAdd = () => {
23
+    if (isNotaNumber(value)) {
24
+      onChange(step)
25
+    } else {
26
+      onChange(value + step)
27
+    }
28
+  }
29
+
30
+  const handleSub = () => {
31
+    if (isNotaNumber(value)) {
32
+      onChange(-step)
33
+    } else {
34
+      onChange(value - step)
35
+    }
36
+  }
37
+
38
+  const cls = [className, 'input-number-wrapper'].filter(Boolean).join(' ')
39
+
40
+  return (
41
+    <View className={cls} style={style}>
42
+      <View>
43
+        <View className='input-number' onClick={handleSub}>-</View>
44
+        <Input value={value} onInput={handleInput} type='number' className='input-number' {...leftProps} />
45
+        <View className='input-number' onClick={handleAdd}>+</View>
46
+      </View>
47
+    </View>
48
+  )
49
+}

+ 32
- 0
src/components/InputNumber/style.less View File

@@ -0,0 +1,32 @@
1
+
2
+.input-number-wrapper {
3
+  display: inline-block;
4
+
5
+  & > view {
6
+    box-sizing: border-box;
7
+    display: flex;
8
+    border: 1px solid #999999;
9
+    border-radius: 8px;
10
+    font-size: 34px;
11
+    font-weight: 400;
12
+    color: #202020;
13
+  }
14
+
15
+  .input-number {
16
+    box-sizing: border-box;
17
+    flex: 1;
18
+    outline: none;
19
+    height: 60px;
20
+    line-height: 60px;
21
+    width: 60px;
22
+  }
23
+
24
+  input {
25
+    &.input-number {
26
+      border-left: 1px solid #999999;
27
+      border-right: 1px solid #999999;
28
+      font-size: 28px;
29
+      width: 90px;
30
+    }
31
+  }
32
+}

+ 2
- 20
src/pages/PayOrder/index.jsx View File

@@ -4,7 +4,7 @@ import { getPackageDetail } from "@/services/home";
4 4
 import { saveOrder, getOrderSub, payOrder } from "@/services/payOrder";
5 5
 import { useState, useEffect } from "react";
6 6
 import formatPrice from "@/utils/formatPrice";
7
-
7
+import InputNumber from "@/components/InputNumber";
8 8
 import { Button, Checkbox, Input, RadioGroup, Radio } from "@tarojs/components";
9 9
 import AuthPage from '@/components/AuthPage'
10 10
 import food from "@/assets/icons/ProCard/food.png";
@@ -195,25 +195,7 @@ export default withLayout((props) => {
195 195
         <CustomNav title='订单' />
196 196
         <Popup show={showDialog} maskClosable={false}>
197 197
           <OrderMolded item={detail} />
198
-          <view className='item-center-Number'>
199
-            <view
200
-              className='buy-num-minus'
201
-              disabled={DisabledBool}
202
-              onClick={NumberCut}
203
-            >
204
-              -
205
-            </view>
206
-            <Input
207
-              className='buy-num-input'
208
-              type='number'
209
-              min='1'
210
-              onInput={onInput}
211
-              value={BuyNumber}
212
-            />
213
-            <view className='buy-num-add' onClick={NumberAdd}>
214
-              +
215
-            </view>
216
-          </view>
198
+          <InputNumber value={BuyNumber} onChange={x => setBuyNumber(x)} style={{ marginTop: '40rpx' }} />
217 199
           <view className='buy-button-box'>
218 200
             <button className='button-Cancel' onClick={ButtonCancel}>
219 201
               取消