<template>
  <view>
	  <view class="" style="background-color: #fff;">
	  	<view class="" style="height: 1200rpx;">
	  		
	  	</view>
		<input type="text" placeholder="请输入内容" ref="inputRef" />
	  </view>
	  <view class="">
	  	<wInput
	  		v-model="verCode"
	  		type="number"
	  		maxlength="4"
	  		placeholder="短信验证码"
	  		isShowCode
	  		ref="runCode"
	  		@setCode="getVerCode()"
	  	></wInput>
		<view class="">
			123
		</view>
	  </view>
  </view>
</template>

<script>
	import wInput from '../../components/watch-login/watch-input.vue' 
export default {
  mounted() {
    // 监听键盘弹出事件
    uni.$on('keyboardHeightChange', this.handleKeyboardHeightChange);
  },
  beforeDestroy() {
    // 移除键盘弹出事件监听
    uni.$off('keyboardHeightChange', this.handleKeyboardHeightChange);
  },
  components:{
  	wInput,
  },
  methods: {
	  getVerCode(){
		  this.$refs.runCode.$emit('runCode'); 
	  },
    handleKeyboardHeightChange(e) {
		console.log('监听到了')
      // e.height 是键盘高度，e.duration 是键盘弹出和收起的持续时间
      if (e.height > 0) {
        // 键盘弹出，计算输入框被遮挡的高度并滚动到视图中
        const inputTop = this.getElementTop(this.$refs.inputRef);
        const keyboardTop = uni.getSystemInfoSync().windowHeight - e.height;
        if (inputTop > keyboardTop) {
          uni.pageScrollTo({
            scrollTop: inputTop - keyboardTop + 10, // 10 是一个偏移量，根据需要调整
            duration: e.duration
          });
        }
      }
    },
    getElementTop(element) {
      // 获取元素的上边界坐标
      return element.getBoundingClientRect().top + (uni.getSystemInfoSync().windowTop || 0);
    }
  }
};
</script>