123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <template>
- <view class="num-input">
- <view class="i l" @tap.stop="red">-</view>
- <view class="i c" @tap.stop="inputNum = value ? value : ''; showInput = true">{{ value }}</view>
- <view class="i r basecolor" @tap.stop="add">+</view>
- <view v-if="showInput" class="inputModelWrapper">
- <view class="inputModel">
- <view class="t">请输入数量</view>
- <view class="m">
- <input ref="input" focus type="number" maxlength="4" v-model="inputNum" />
- </view>
- <view class="b">
- <text class="l" @tap.stop="showInput = false">取消</text>
- <text class="r basecolor" @tap.stop="comfirmNum">确定</text>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- props: {
- value: { type: Number, default: 0 },
- args: { type: Array, default: () => [] },
- max: { type: Number, default: 9999 }
- },
- data() {
- return {
- showInput: false,
- inputNum: 0
- }
- },
- methods: {
- red() {
- if (this.value > 0) {
- this.$emit('change', this.value - 1, ...this.args)
- this.$emit('input', this.value - 1, ...this.args)
- }
- },
- add() {
- if (this.value + 1 > this.max) {
- uni.toast('数量不能再多了')
- } else {
- this.$emit('change', this.value + 1, ...this.args)
- this.$emit('input', this.value + 1, ...this.args)
- }
- },
- comfirmNum() {
- if (this.inputNum) {
- if (+this.inputNum > this.max) {
- this.$emit('change', this.max, ...this.args)
- this.$emit('input', this.max, ...this.args)
- } else {
- this.$emit('change', +this.inputNum, ...this.args)
- this.$emit('input', +this.inputNum, ...this.args)
- }
- } else {
- this.$emit('change', 0, ...this.args)
- this.$emit('input', 0, ...this.args)
- }
- this.showInput = false
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .num-input {
- @include flex();
- width: 200rpx;
- height: 64rpx;
- overflow: hidden;
- font-size: 32rpx;
- background: #F2F2F2;
- border-radius: 64rpx;
- .i {
- flex: 1;
- height: 100%;
- @include flex();
- &.c {
- border-left: 4rpx solid #FFFFFF;
- border-right: 4rpx solid #FFFFFF;
- }
- }
- .inputModelWrapper {
- @include flex();
- top: 0;
- left: 0;
- z-index: 2;
- width: 100vw;
- height: 100vh;
- position: fixed;
- background: rgba(0, 0, 0, 0.3);
- .inputModel {
- width: 600rpx;
- height: 400rpx;
- background: #FFFFFF;
- border-radius: 8rpx;
- @include flex(column);
- .t {
- @include flex();
- width: 100%;
- height: 100rpx;
- border-bottom: 1rpx solid #CCCCCC;
- }
- .m {
- width: 100%;
- flex: 1;
- @include flex();
- input {
- width: 240rpx;
- height: 120rpx;
- text-align: center;
- font-size: 88rpx;
- border-radius: 8rpx;
- border: 1rpx solid #CCCCCC;
- }
- }
- .b {
- @include flex();
- width: 100%;
- height: 100rpx;
- border-top: 1rpx solid #CCCCCC;
- text {
- height: 100%;
- flex: 1;
- @include flex();
- &.basecolor {
- border-left: 1rpx solid #CCCCCC;
- }
- }
- }
- }
- }
- }
- </style>
|