石广澎
2024-09-12 f14805e9e9550bb11e1f79bdbdec574237e92893
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<template>
  <view class="box">
    <view class="u-text-right u-font-30 color-666 u-p-h-20 u-p-t-10" @click="close">关闭</view>
    <view class="u-p-10 u-flex u-row-between">
      <view class="u-flex u-flex-wrap">
        <view v-for="(num,index) in numList" :key="index" class="num-item" hover-class="num-hover" @click="inputStr(num)">{{num}}</view>
      </view>
      <view class="flex-1 u-flex-col">
        <view hover-class="num-hover" class="del-item u-flex u-row-center" @click="delStr">
          <image src="@/static/del-icon.png" class="del-btn"></image>
        </view>
        <view hover-class="num-hover" class="flex-1 pay-btn u-font-30 color-fff font-bold" @click="pay">付款</view>
      </view>
    </view>
  </view>
 
</template>
 
<script>
export default {
  props: {
    num: {
      type: String,
      default: ''
    }
  },
  watch: {
    num(val) {
      this.emitNum = val
    }
  },
  data() {
    return {
      emitNum: '',
      numList: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']
    }
  },
  methods: {
    // 输入框
    inputStr(num) {
      var dotinx = this.emitNum.indexOf('.');
      if (dotinx != -1) {
        if (num == '.') {
          // 小数点不能重复添加
          return;
        }
        if (dotinx == this.emitNum.length - 3) {
          //小数点后面最多两位
          return;
        }
        if (this.emitNum == '0.0' && num == '0') {
          //小数点后面最多两位
          return;
        }
      } else if (num == '0' && this.emitNum == '0') {
        // 首位的0最多1个
        return;
      } else {
        if (num != '.' && this.emitNum.length > 7) {
          //整数不能超过10位
          return;
        }
      }
      if (this.emitNum == '' && num == '.') {
        this.emitNum = '0.';
      } else if (this.emitNum == '0' && num != '.') {
        this.emitNum = num;
      } else {
        this.emitNum += num;
      }
      this.$emit('changeMoney', this.emitNum)
    },
    // 删除
    delStr() {
      this.emitNum = this.emitNum.slice(0, -1)
      this.$emit('changeMoney', this.emitNum)
    },
    // 支付
    pay() {
      this.$emit('pay')
    },
    // 关闭输入框
    close() {
      this.$emit('close')
    }
  }
}
</script>
 
<style lang="scss" scoped>
.box {
  background-color: #F5F5F5;
  transition: all 0.3s;
  padding-bottom: constant(safe-area-inset-bottom); /*兼容 IOS<11.2*/
  padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/
}
 
.show-box {
  bottom: 0rpx;
}
 
.bord-box {
}
 
.num-item {
  width: 175rpx;
  height: 90rpx;
  line-height: 90rpx;
  color: #333333;
  font-size: 36rpx;
  font-weight: bold;
  text-align: center;
  margin: 0 10rpx 10rpx 0;
  background-color: #FFFFFF;
}
 
.num-hover {
  opacity: 0.7;
}
 
.num-item:nth-child(10n) {
  width: 356rpx;
}
 
.h-100 {
  height: 100%;
}
 
.pay-btn {
  background-color: #D45159;
  border-radius: 16rpx;
  text-align: center;
  height: 290rpx;
  line-height: 290rpx;
  vertical-align: middle;
  color: white;
  margin-bottom: 10rpx;
}
 
.del-item {
  width: 175rpx;
  height: 90rpx;
  margin-bottom: 10rpx;
  background-color: #FFFFFF;
}
 
.del-btn {
  width: 40rpx;
  height: 40rpx;
}
</style>