| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <template>
- <view>
- <view class="textareabg" @click="onBlurBg" :style="{height:bgHeight + '%'}"></view>
- <view class="bottom-textarea" :style="{bottom:inputBottom +'px'}">
- <view class="textarea-container">
- <textarea
- v-model="recordInput"
- :maxlength="-1"
- :auto-height="true"
- :show-confirm-bar="false"
- :cursor-spacing="10"
- :fixed="true"
- :adjust-position="false"
- :focus="textareaFocus"
- @focus="focusTextarea"
- @blur="blurTextarea"
- ref="focusRef"
- />
- </view>
- <u-button type="success" size="small" @click="addRecord" class="u-reset-button" text="确定"></u-button>
- </view>
- </view>
- </template>
- <script>
- export default {
- name:"getInput",
- props: {
- show:{
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- recordInput:'',
- inputBottom: -60, //输入框
- bgHeight:0, //底层背景高度
- textareaFocus:false //获取焦点
- };
- },
- watch: {
- show(res){
- if(res){
- this.inputBottom = 0;
- this.bgHeight = 100;
- this.textareaFocus = true;
- }else{
- this.inputBottom = -60;
- this.bgHeight = 0;
- this.textareaFocus = false;
- }
- }
- },
- methods:{
- //聚焦文本框
- focusTextarea(e) {
- this.inputBottom = e.detail.height;
- },
- //失去焦点
- blurTextarea(e) {
- this.inputBottom = 0;
- uni.pageScrollTo({
- scrollTop: 0,
- duration: 0
- })
- },
- //点击了确定
- addRecord(){
- if(this.recordInput == ''){
- uni.showToast({
- icon:'none',
- title: '请输入信息',
- duration: 2000
- });
- return;
- }
-
- this.$emit("openInput");
- this.$emit("getInputInfo",this.recordInput);
- //重置值
- this.recordInput = "";
- },
- //点击背景层
- onBlurBg(){
- this.$emit("openInput");
- }
-
- },
- }
- </script>
- <style lang="scss" scoped>
- .textareabg{
- position: fixed;
- bottom: 0px;
- left: 0px;
- right: 0px;
- width: 100%;
- }
- .bottom-textarea {
- position: fixed;
- bottom: 0px;
- left: 0px;
- right: 0px;
- z-index: 99;
- background-color: #f2f2f2;
- border-top: 2rpx solid rgba(226, 226, 226, 1);
- padding: 10rpx 20rpx;
- display: flex;
- align-items: flex-end;
- transition: all 0.3S ease;
- .textarea-container {
- flex: 1;
- min-height: 80rpx;
- background: rgba(255, 255, 255, 1);
- border-radius: 8rpx;
- box-sizing: border-box;
- > textarea {
- max-height: 240rpx;
- font-size: 32rpx;
- color: rgba(8, 8, 8, 1);
- width: auto;
- }
- }
- > button {
- flex-shrink: 0;
- height: 80rpx;
- margin: 0;
- margin-left: 16rpx;
- font-size: 32rpx;
- }
- }
- </style>
|