Getinput.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view>
  3. <view class="textareabg" @click="onBlurBg" :style="{height:bgHeight + '%'}"></view>
  4. <view class="bottom-textarea" :style="{bottom:inputBottom +'px'}">
  5. <view class="textarea-container">
  6. <textarea
  7. v-model="recordInput"
  8. :maxlength="-1"
  9. :auto-height="true"
  10. :show-confirm-bar="false"
  11. :cursor-spacing="10"
  12. :fixed="true"
  13. :adjust-position="false"
  14. :focus="textareaFocus"
  15. @focus="focusTextarea"
  16. @blur="blurTextarea"
  17. ref="focusRef"
  18. />
  19. </view>
  20. <u-button type="success" size="small" @click="addRecord" class="u-reset-button" text="确定"></u-button>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. name:"getInput",
  27. props: {
  28. show:{
  29. type: Boolean,
  30. default: false
  31. }
  32. },
  33. data() {
  34. return {
  35. recordInput:'',
  36. inputBottom: -60, //输入框
  37. bgHeight:0, //底层背景高度
  38. textareaFocus:false //获取焦点
  39. };
  40. },
  41. watch: {
  42. show(res){
  43. if(res){
  44. this.inputBottom = 0;
  45. this.bgHeight = 100;
  46. this.textareaFocus = true;
  47. }else{
  48. this.inputBottom = -60;
  49. this.bgHeight = 0;
  50. this.textareaFocus = false;
  51. }
  52. }
  53. },
  54. methods:{
  55. //聚焦文本框
  56. focusTextarea(e) {
  57. this.inputBottom = e.detail.height;
  58. },
  59. //失去焦点
  60. blurTextarea(e) {
  61. this.inputBottom = 0;
  62. uni.pageScrollTo({
  63. scrollTop: 0,
  64. duration: 0
  65. })
  66. },
  67. //点击了确定
  68. addRecord(){
  69. if(this.recordInput == ''){
  70. uni.showToast({
  71. icon:'none',
  72. title: '请输入信息',
  73. duration: 2000
  74. });
  75. return;
  76. }
  77. this.$emit("openInput");
  78. this.$emit("getInputInfo",this.recordInput);
  79. //重置值
  80. this.recordInput = "";
  81. },
  82. //点击背景层
  83. onBlurBg(){
  84. this.$emit("openInput");
  85. }
  86. },
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .textareabg{
  91. position: fixed;
  92. bottom: 0px;
  93. left: 0px;
  94. right: 0px;
  95. width: 100%;
  96. }
  97. .bottom-textarea {
  98. position: fixed;
  99. bottom: 0px;
  100. left: 0px;
  101. right: 0px;
  102. z-index: 99;
  103. background-color: #f2f2f2;
  104. border-top: 2rpx solid rgba(226, 226, 226, 1);
  105. padding: 10rpx 20rpx;
  106. display: flex;
  107. align-items: flex-end;
  108. transition: all 0.3S ease;
  109. .textarea-container {
  110. flex: 1;
  111. min-height: 80rpx;
  112. background: rgba(255, 255, 255, 1);
  113. border-radius: 8rpx;
  114. box-sizing: border-box;
  115. > textarea {
  116. max-height: 240rpx;
  117. font-size: 32rpx;
  118. color: rgba(8, 8, 8, 1);
  119. width: auto;
  120. }
  121. }
  122. > button {
  123. flex-shrink: 0;
  124. height: 80rpx;
  125. margin: 0;
  126. margin-left: 16rpx;
  127. font-size: 32rpx;
  128. }
  129. }
  130. </style>