2026-03-24 11:45:13 +08:00
|
|
|
|
<template>
|
2026-06-05 15:27:42 +08:00
|
|
|
|
<view class="service-code-modal" v-if="show" :style="{ bottom: `${popBotom}px` }">
|
2026-03-24 11:45:13 +08:00
|
|
|
|
<view class="modal-mask" @touchmove.stop.prevent></view>
|
|
|
|
|
|
<view class="modal-content">
|
|
|
|
|
|
<view class="modal-title">开始服务</view>
|
|
|
|
|
|
<view class="modal-subtitle">请输入服务码</view>
|
|
|
|
|
|
<view class="code-box">
|
2026-06-05 15:27:42 +08:00
|
|
|
|
<view v-for="(item, idx) in codeLength" :key="idx"
|
2026-03-24 11:45:13 +08:00
|
|
|
|
:class="['code-cell', idx === currentIndex ? 'active' : '', code[idx] ? 'filled' : '']">
|
|
|
|
|
|
<text v-if="code[idx]">{{ code[idx] }}</text>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<!-- 隐藏真实输入框 -->
|
2026-06-05 15:27:42 +08:00
|
|
|
|
<input :adjust-position="false" class="real-input" type="number" :maxlength="codeLength"
|
|
|
|
|
|
v-model="inputValue" :focus="true" @input="onInput" @focus="onFocus"
|
|
|
|
|
|
@keyboardheightchange="onkeyboardheightchange" @blur="onBlur" cursor-spacing="100"
|
2026-06-08 17:53:00 +08:00
|
|
|
|
cursor-color="transparent" ref="realInput" />
|
2026-03-24 11:45:13 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<button class="confirm-btn" :disabled="code.length < codeLength" @click="onConfirm">确定</button>
|
|
|
|
|
|
<view class="close-btn" @click="close">×</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2026-06-05 15:27:42 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
name: 'serviceCodeInput',
|
|
|
|
|
|
props: {
|
|
|
|
|
|
show: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: false
|
2026-03-24 11:45:13 +08:00
|
|
|
|
},
|
2026-06-05 15:27:42 +08:00
|
|
|
|
codeLength: {
|
|
|
|
|
|
type: Number,
|
|
|
|
|
|
default: 6
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
inputValue: '',
|
|
|
|
|
|
isFocus: true,
|
|
|
|
|
|
keyboardHeight: 0,
|
|
|
|
|
|
popBotom: 0,
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
code() {
|
|
|
|
|
|
return this.inputValue.split('').slice(0, this.codeLength)
|
2026-03-24 11:45:13 +08:00
|
|
|
|
},
|
2026-06-05 15:27:42 +08:00
|
|
|
|
currentIndex() {
|
|
|
|
|
|
return this.inputValue.length
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
// show(val) {
|
|
|
|
|
|
// if (val) {
|
|
|
|
|
|
// this.$refs.realInput && this.$refs.realInput.focus
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// this.inputValue = ''
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted() {
|
|
|
|
|
|
// uni.onKeyboardHeightChange((res)=>{
|
|
|
|
|
|
// this.keyboardHeight = res.height;
|
|
|
|
|
|
// })
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
onInput(e) {
|
|
|
|
|
|
let val = e.detail.value.replace(/[^0-9]/g, '').slice(0, this.codeLength)
|
|
|
|
|
|
this.inputValue = val
|
|
|
|
|
|
this.$emit('input', val)
|
|
|
|
|
|
if (val.length === this.codeLength) {
|
|
|
|
|
|
this.$emit('finish', val)
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2026-06-05 15:27:42 +08:00
|
|
|
|
onFocus(e) {
|
|
|
|
|
|
this.isFocus = true
|
|
|
|
|
|
this.inputValue = ''
|
|
|
|
|
|
},
|
|
|
|
|
|
onkeyboardheightchange(e) {
|
|
|
|
|
|
this.popBotom = e.target.height || 0
|
2026-03-24 11:45:13 +08:00
|
|
|
|
},
|
2026-06-05 15:27:42 +08:00
|
|
|
|
onBlur() {
|
|
|
|
|
|
this.isFocus = false
|
2026-03-24 11:45:13 +08:00
|
|
|
|
},
|
2026-06-05 15:27:42 +08:00
|
|
|
|
onConfirm() {
|
|
|
|
|
|
if (this.inputValue.length === this.codeLength) {
|
|
|
|
|
|
this.$emit('confirm', this.inputValue);
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
2026-06-05 15:27:42 +08:00
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
close() {
|
|
|
|
|
|
this.$emit('close')
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-05 15:27:42 +08:00
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.service-code-modal {
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
z-index: 999999;
|
|
|
|
|
|
|
|
|
|
|
|
.modal-mask {
|
2026-03-24 11:45:13 +08:00
|
|
|
|
position: fixed;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
bottom: 0;
|
2026-06-05 15:27:42 +08:00
|
|
|
|
background: rgba(0, 0, 0, 0.5);
|
|
|
|
|
|
z-index: -1;
|
|
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.modal-content {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
border-radius: 32rpx 32rpx 0 0;
|
|
|
|
|
|
padding: 56rpx 40rpx 40rpx 40rpx;
|
|
|
|
|
|
box-shadow: 0 -8rpx 32rpx rgba(0, 0, 0, 0.08);
|
|
|
|
|
|
min-height: 340rpx;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
animation: modalUp 0.25s;
|
|
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.modal-title {
|
|
|
|
|
|
font-size: 36rpx;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
color: #222;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.modal-subtitle {
|
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
|
color: #888;
|
|
|
|
|
|
margin: 24rpx 0 40rpx 0;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.code-box {
|
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
margin-bottom: 48rpx;
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
|
|
|
|
.code-cell {
|
|
|
|
|
|
width: 72rpx;
|
|
|
|
|
|
height: 72rpx;
|
|
|
|
|
|
border: 2rpx solid #eee;
|
|
|
|
|
|
border-radius: 16rpx;
|
|
|
|
|
|
margin-right: 24rpx;
|
|
|
|
|
|
font-size: 40rpx;
|
|
|
|
|
|
color: #ff4d8d;
|
|
|
|
|
|
background: #fff;
|
2026-03-24 11:45:13 +08:00
|
|
|
|
text-align: center;
|
2026-06-05 15:27:42 +08:00
|
|
|
|
line-height: 72rpx;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
transition: border-color 0.2s;
|
2026-03-24 11:45:13 +08:00
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
&.active {
|
|
|
|
|
|
border-color: #ff4d8d;
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
&.filled {
|
|
|
|
|
|
border-color: #ff4d8d;
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
&:last-child {
|
|
|
|
|
|
margin-right: 0;
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.real-input {
|
2026-03-24 11:45:13 +08:00
|
|
|
|
position: absolute;
|
2026-06-05 15:27:42 +08:00
|
|
|
|
left: 0;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
opacity: 0;
|
|
|
|
|
|
z-index: 2;
|
2026-06-08 17:53:00 +08:00
|
|
|
|
caret-color: transparent;
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.confirm-btn {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 88rpx;
|
|
|
|
|
|
background: #ff4d8d;
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
font-size: 32rpx;
|
|
|
|
|
|
border-radius: 16rpx;
|
|
|
|
|
|
margin-top: 16rpx;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
line-height: 88rpx;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
|
|
background: #ffd1e3;
|
|
|
|
|
|
color: #fff;
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
2026-06-05 15:27:42 +08:00
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
|
|
2026-06-05 15:27:42 +08:00
|
|
|
|
.close-btn {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
right: 32rpx;
|
|
|
|
|
|
top: 32rpx;
|
|
|
|
|
|
font-size: 48rpx;
|
|
|
|
|
|
color: #bbb;
|
|
|
|
|
|
z-index: 10;
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
line-height: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@keyframes modalUp {
|
|
|
|
|
|
from {
|
|
|
|
|
|
transform: translateY(100%);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
to {
|
|
|
|
|
|
transform: translateY(0);
|
2026-03-24 11:45:13 +08:00
|
|
|
|
}
|
2026-06-05 15:27:42 +08:00
|
|
|
|
}
|
2026-03-24 11:45:13 +08:00
|
|
|
|
</style>
|