<template>
	<view>
		<view class="submit">
			<view class="submit-chat">
				<!-- 文本框 -->
				<textarea auto-height="true" fixed="true" class="chat-send btn" @confirm="inputs" @focus="focus"
					v-model="msg"></textarea>
				<view class="bt-img" @tap="more">
					<text class="iconfont icon-gengduoneirong"></text>
				</view>
			</view>
			<!-- 更多 -->
			<view class="more" :class="{displaynone:!ismore}">
				<view class="more-list" @tap="sendImg('album')">
					<text class="iconfont icon-tupian"></text>
					<view class="more-list-title">图片</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ismore: false,
				msg: "",
			};
		},
		methods: {
			//获取高度方法
			getElementHeight() {
				const query = uni.createSelectorQuery().in(this);
				query.select('.submit').boundingClientRect(data => {
					this.$emit('heights', data.height);
				}).exec();
			},
			//文字发送
			inputs(e) {
				var chatm = e.detail.value;
				if (chatm.length > 1) {
					// 0为表情和文字
					this.send(this.msg, 0)
				}
			},
			// 输入框聚焦
			focus() {
				//关闭其他项
				this.ismore = false;
				setTimeout(() => {
					this.getElementHeight()
				}, 10)
			},
			//更多功能
			more() {
				this.ismore = !this.ismore;
				setTimeout(() => {
					this.getElementHeight();
				}, 10)
			},
			//图片发送
			sendImg(e) {
				const that = this;
				let serverUrl = that.$config.serverUrl;
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: async function(res) {
						let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
						const arr = await that.$apifile(`/point/upload`, 'file', tempFile[0], 'file');
						if (arr.errcode == '0') {
							let filePaths = {
								name: arr.name,
								uri: arr.uri,
								url: serverUrl + arr.uri
							}
							that.send([filePaths], 1)
						} else {
							uni.showToast({
								title: arr.errmsg,
								icon: 'none'
							})
						}
					}
				});
			},
			//发送
			send(msg, type) {
				let date = {
					message: msg,
					type: type
				}
				this.$emit('inputs', date);
				setTimeout(() => {
					this.msg = '';
				}, 0)
			}
		}
	};
</script>

<style lang="scss" scoped>

	.displaynone {
		display: none;
	}

	.submit-chat {
		width: 100%;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 14rpx 14rpx;

		.bt-img {
			.iconfont {
				font-size: 65rpx;
			}
		}

		.btn {
			background-color: #fff;
			border-radius: 10rpx;
			padding: 20rpx;
			margin: 0 10rpx;
		}

		.chat-send {
			line-height: 44rpx;
		}
	}

	.more {
		width: 100%;
		height: 436rpx;
		background: rgba(236, 237, 238, 1);
		box-shadow: 0px 11rpx 0px 0px rgba(0, 0, 0, 0.1);
		bottom: env(safe-area-inset-bottom);
		padding: 8rpx 20rpx;
		box-sizing: border-box;

		.more-list {
			width: 25%;
			text-align: center;
			float: left;
			padding-top: 32rpx;
			background-color: #ffffff;
			border-radius: 20rpx;

			.iconfont {
				font-size: 65rpx;
			}

			.more-list-title {
				margin: 10rpx 0;
				font-size: 30rpx;
				color: rgba(39, 40, 50, 0.5);
				line-height: 34rpx;
			}
		}
	}
</style>
