<template>
|
<view class="im_interface">
|
<scroll-view id="scrollview" scroll-y="true" :style="'height: '+scrollviewHigh + 'px'" :scroll-with-animation="true"
|
:scroll-top="scrollTop" @scrolltoupper='newdata'>
|
|
<view class="im_interface_content" ref='container'>
|
<view :class="item.user_id == user_id?'im_text':'im_text2'" class="m-item" v-for="(item,index) in content_list" :key="index">
|
<image class="avatar" :src="item.user_id != user_id?item.user.avatarUrl:avatarUrl"
|
mode=""></image>
|
<view>
|
<view class="my_date">{{item.create_time}}</view>
|
<view :class="item.user_id == user_id?'my_content my_text_content':'you_content you_text_content'">
|
{{item.content}}
|
</view>
|
</view>
|
</view>
|
</view>
|
<view style="width: 100%;height: 130rpx;"></view>
|
</scroll-view>
|
|
<view class="buttom" :style="'bottom:' +inputBottom+'px;'">
|
<input type="text" v-model="content" @confirm="send_content()" confirm-type="send" @focus="inputFocus" @blur="inputBlur"
|
:adjust-position="false" placeholder="请输入....." />
|
<view class="upload_box">
|
<button @click="send_content()">发送</button>
|
</view>
|
</view>
|
|
<Upload v-if="isupload" :isupload="isupload" :type="type" @getImgs="getImgsFunc">上传图片</Upload>
|
</view>
|
</template>
|
|
<script>
|
import Upload from '@/components/upload/upload';
|
export default {
|
data() {
|
return {
|
user_id: '', //我的user_id
|
you_user_id: '', //对方的suser_id
|
myavatarUrl: '',
|
avatarUrl: '',
|
phoneHeight: 0,
|
/*可滚动视图区域高度*/
|
scrollviewHigh: 0,
|
content: '', //用户输入的内容
|
content_list: [], //聊天信息数据
|
style: {
|
pageHeight: 0,
|
contentViewHeight: 0,
|
footViewHeight: 90,
|
mitemHeight: 0
|
},
|
scrollTop: 0,
|
page: 1,
|
nomore: false,
|
scrollHeight: 0,
|
nickName: '',
|
inputBottom: 0,
|
is_Ios: true,
|
}
|
},
|
components: {},
|
created() {
|
let self = this;
|
const res = uni.getSystemInfoSync(); //获取手机可使用窗口高度 api为获取系统信息同步接口
|
this.style.pageHeight = res.windowHeight;
|
this.style.contentViewHeight = res.windowHeight - uni.getSystemInfoSync().screenWidth / 750 * (100) - 70; //像素
|
},
|
onShow() {
|
this.getAvatarUrl();
|
this.init();
|
this.isuserAgent();
|
},
|
onLoad(option) {
|
let self = this;
|
self.you_user_id = option.you_user_id;
|
self.nickName = option.nickname;
|
self.avatarUrl = option.avatarurl;
|
uni.setNavigationBarTitle({
|
title: self.nickName
|
})
|
this.get_content_list();
|
},
|
methods: {
|
/*初始化*/
|
init() {
|
let self = this;
|
uni.getSystemInfo({
|
success(res) {
|
self.phoneHeight = res.windowHeight;
|
// 计算组件的高度
|
self.scrollviewHigh = self.phoneHeight;
|
}
|
});
|
},
|
initData() {
|
this.page++;
|
this.get_content_list();
|
},
|
|
|
// 发送消息
|
send_content() {
|
if (this.content == '') {
|
uni.showToast({
|
title: '发送内容不能为空!',
|
icon: 'none'
|
})
|
return false
|
}
|
let self = this;
|
let item = {
|
content: this.content,
|
user_id: this.user_id,
|
create_time: self.formatDate(),
|
user: {
|
avatarUrl: self.myavatarUrl
|
}
|
}
|
this.content_list = [...this.content_list, item];
|
this.$nextTick(function() {
|
this.scrollToBottom()
|
})
|
uni.showLoading({
|
title: '加载中'
|
})
|
self._post('plus.release.chat/add', {
|
content: self.content,
|
you_user_id: self.you_user_id,
|
}, (res) => {
|
self.content = '';
|
uni.hideLoading()
|
})
|
},
|
getAvatarUrl() {
|
let self = this;
|
self.user_id = uni.getStorageSync('user_id')
|
self._get(
|
'plus.release.chat/getInfo', {},
|
function(res) {
|
self.myavatarUrl = res.data.info.avatarUrl;
|
}
|
);
|
},
|
|
//获取聊天记录
|
get_content_list() {
|
let self = this;
|
uni.showLoading({
|
title: '加载中'
|
})
|
self._post('plus.release.chat/message', {
|
//被聊天人的user_id
|
page: self.page,
|
you_user_id: self.you_user_id,
|
}, (res) => {
|
console.log(self.content_list)
|
let list = res.data.list.data.reverse();
|
self.content_list = [...list, ...self.content_list];
|
console.log(self.content_list)
|
if (res.data.list.last_page <= self.page) {
|
self.nomore = true;
|
}
|
if (self.page == 1) {
|
self.$nextTick(() => {
|
self.scrollToBottom();
|
});
|
} else {
|
self.$nextTick(() => {
|
const newquery = uni.createSelectorQuery().in(self);
|
newquery.select('.im_interface_content').boundingClientRect(data => {
|
console.log(data)
|
self.scrollTop = data.height - self.scrollHeight;
|
}).exec();
|
});
|
}
|
uni.hideLoading()
|
})
|
},
|
scrollToBottom: function() {
|
let self = this;
|
let query = uni.createSelectorQuery();
|
query.selectAll('.m-item').boundingClientRect();
|
query.select('#scrollview').boundingClientRect();
|
query.exec((res) => {
|
self.style.mitemHeight = 0;
|
res[0].forEach((rect) => self.style.mitemHeight = self.style.mitemHeight + rect.height +
|
40)
|
setTimeout(() => {
|
if (self.style.mitemHeight > (self.style.contentViewHeight - 100)) {
|
self.scrollTop = self.style.mitemHeight - self.style.contentViewHeight +
|
150
|
}
|
}, 300)
|
})
|
},
|
|
getJSON(str) {
|
return JSON.parse(str)
|
},
|
newdata() {
|
let self = this;
|
this.page++;
|
const query = uni.createSelectorQuery().in(this);
|
query.select('.im_interface_content').boundingClientRect(data => {
|
this.scrollHeight = data.height;
|
}).exec();
|
this.get_content_list();
|
},
|
inputFocus(e) {
|
this.inputBottom = e.detail.height;
|
},
|
inputBlur() {
|
this.inputBottom = 0;
|
},
|
isuserAgent() {
|
let self = this;
|
switch (uni.getSystemInfoSync().platform) {
|
case 'android':
|
self.is_Ios = false;
|
console.log('运行Android上')
|
break;
|
case 'ios':
|
console.log('运行iOS上')
|
break;
|
default:
|
console.log('运行在开发者工具上')
|
break;
|
}
|
},
|
formatDate() {
|
let date = new Date();
|
let year = date.getFullYear(); // 年
|
let month = date.getMonth() + 1; // 月
|
let day = date.getDate(); // 日
|
let week = date.getDay(); // 星期
|
let weekArr = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
|
let hour = date.getHours(); // 时
|
hour = hour < 10 ? "0" + hour : hour; // 如果只有一位,则前面补零
|
let minute = date.getMinutes(); // 分
|
minute = minute < 10 ? "0" + minute : minute; // 如果只有一位,则前面补零
|
let second = date.getSeconds(); // 秒
|
second = second < 10 ? "0" + second : second; // 如果只有一位,则前面补零
|
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
},
|
}
|
}
|
</script>
|
|
<style>
|
page {
|
background-color: #EDEDED;
|
}
|
|
.im_interface {
|
width: 750rpx;
|
}
|
|
.im_interface_content {
|
padding: 20rpx 50rpx;
|
}
|
|
.buttom {
|
width: 750rpx;
|
height: 130rpx;
|
background-color: #F7F7F7;
|
border-top: 1px #D2D2D2 solid;
|
display: flex;
|
justify-content: flex-start;
|
align-items: flex-start;
|
position: fixed;
|
bottom: 0;
|
padding-top: 20rpx;
|
box-sizing: border-box;
|
}
|
|
.buttom input {
|
width: 605rpx;
|
height: 75rpx;
|
line-height: 75rpx;
|
background-color: white;
|
display: block;
|
padding: 5rpx;
|
box-sizing: border-box;
|
margin-left: 30rpx;
|
border-radius: 10rpx;
|
vertical-align: middle;
|
position: relative;
|
border: 1rpx solid #CCCCCC;
|
|
}
|
|
.buttom button {
|
width: 125rpx;
|
height: 50rpx;
|
line-height: 200%;
|
display: block;
|
margin: 0 15rpx;
|
vertical-align: middle;
|
position: relative;
|
background-color: #05C160;
|
color: white;
|
}
|
|
.im_text {
|
/* width: 100%; */
|
display: flex;
|
margin-top: 75rpx;
|
flex-direction: row-reverse;
|
position: relative;
|
}
|
|
.im_text2 {
|
/* width: 100%; */
|
display: flex;
|
margin-top: 75rpx;
|
position: relative;
|
}
|
|
.im_text .avatar {
|
width: 84rpx;
|
height: 84rpx;
|
margin-left: 3%;
|
border-radius: 10rpx;
|
background-color: #000000;
|
align-items: flex-start;
|
}
|
|
.im_text2 .avatar {
|
width: 84rpx;
|
height: 84rpx;
|
margin-right: 3%;
|
border-radius: 10rpx;
|
background-color: #000000;
|
align-items: flex-start;
|
}
|
|
.im_text .my_content {
|
max-width: 550rpx;
|
align-items: flex-start;
|
border-radius: 10rpx;
|
padding: 17rpx 20rpx;
|
box-sizing: border-box;
|
word-break: break-all;
|
}
|
|
.im_text2 .my_content {
|
max-width: 450rpx;
|
align-items: flex-start;
|
border-radius: 10rpx;
|
padding: 10rpx;
|
box-sizing: border-box;
|
word-break: break-all;
|
}
|
|
.im_text .you_content {
|
max-width: 450rpx;
|
align-items: flex-start;
|
border-radius: 10rpx;
|
padding: 17rpx 20rpx;
|
box-sizing: border-box;
|
}
|
|
.im_text2 .you_content {
|
max-width: 450rpx;
|
align-items: flex-start;
|
border-radius: 10rpx;
|
padding: 10rpx;
|
box-sizing: border-box;
|
}
|
|
.my_content {
|
background-color: #9EEA6A;
|
margin-top: 25rpx;
|
}
|
|
.you_content {
|
background-color: white;
|
margin-top: 25rpx;
|
}
|
|
.im_icon {
|
position: absolute;
|
bottom: -2rpx;
|
right: 41px;
|
transform: rotate(270deg);
|
|
}
|
|
.im_icon2 {
|
position: absolute;
|
bottom: 0;
|
}
|
|
.im_icon .icon-sanjiao1 {
|
color: #9EEA6A;
|
}
|
|
.im_icon2 .icon-sanjiao1 {
|
position: absolute;
|
bottom: 0;
|
}
|
|
.upload {
|
width: 50rpx;
|
height: 50rpx;
|
background-color: #007AFF;
|
border-radius: 50%;
|
line-height: 50rpx;
|
text-align: center;
|
}
|
|
.cont_img {
|
width: 200rpx;
|
height: 200rpx;
|
border-radius: 10rpx;
|
}
|
|
.top_pro {
|
/* margin-left: 85rpx; */
|
}
|
|
.top_product {
|
width: 610rpx;
|
height: 200rpx;
|
border-radius: 10rpx;
|
margin: 0 auto;
|
display: flex;
|
align-items: flex-start;
|
justify-content: flex-start;
|
background-color: #FFFFFF;
|
padding: 10rpx 20rpx;
|
position: relative;
|
}
|
|
.top_order {
|
width: 610rpx;
|
/* height: 200rpx; */
|
border-radius: 10rpx;
|
margin: 0 auto;
|
display: flex;
|
align-items: flex-start;
|
justify-content: flex-start;
|
background-color: #FFFFFF;
|
padding: 10rpx 20rpx;
|
position: relative;
|
}
|
|
.pro_img {
|
height: 150rpx;
|
width: 150rpx;
|
border-radius: 10rpx;
|
margin-right: 20rpx;
|
background-color: #FFFFFF;
|
}
|
|
.pro_name {
|
font-size: 28rpx;
|
text-overflow: -o-ellipsis-lastline;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
display: -webkit-box;
|
-webkit-line-clamp: 3;
|
line-clamp: 3;
|
-webkit-box-orient: vertical;
|
margin-bottom: 50rpx;
|
width: 400rpx;
|
}
|
|
.pro_price {
|
font-size: 24rpx;
|
color: #E2231A;
|
}
|
|
.pro_btn {
|
position: absolute;
|
bottom: 12rpx;
|
right: 15rpx;
|
width: 180rpx;
|
height: 50rpx;
|
line-height: 50rpx;
|
border-radius: 25rpx;
|
text-align: center;
|
font-size: 24rpx;
|
color: #FFFFFF;
|
background-color: #FF6633;
|
}
|
|
.orderdetail_btn {
|
width: 180rpx;
|
height: 50rpx;
|
line-height: 50rpx;
|
border-radius: 25rpx;
|
text-align: center;
|
font-size: 24rpx;
|
color: #FFFFFF;
|
background-color: #FF6633;
|
margin-left: 270rpx;
|
margin-top: 20rpx;
|
}
|
|
.ord_btn {
|
position: absolute;
|
bottom: 20rpx;
|
right: 15rpx;
|
width: 180rpx;
|
height: 50rpx;
|
line-height: 50rpx;
|
border-radius: 25rpx;
|
text-align: center;
|
font-size: 24rpx;
|
color: #FFFFFF;
|
background-color: #FF6633;
|
}
|
|
.close_pro {
|
position: absolute;
|
top: 12rpx;
|
right: 15rpx;
|
}
|
|
.product_item {
|
width: 400rpx;
|
height: 200rpx;
|
}
|
|
.product_txtitem {
|
display: flex;
|
width: 550rpx;
|
/* height: 150rpx; */
|
}
|
|
.pro_txtname {
|
font-size: 28rpx;
|
text-overflow: -o-ellipsis-lastline;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
display: -webkit-box;
|
-webkit-line-clamp: 1;
|
line-clamp: 1;
|
-webkit-box-orient: vertical;
|
margin-bottom: 50rpx;
|
}
|
|
.my_text_content {
|
/* height: 100%; */
|
max-width: 430rpx;
|
}
|
|
.you_text_content {
|
/* height: 100%; */
|
max-width: 430rpx;
|
}
|
|
.my_date {
|
color: #cccccc;
|
font-size: 24rpx;
|
position: absolute;
|
top: -10rpx;
|
}
|
|
.im_text .my_date {
|
right: 100rpx;
|
}
|
|
.sendpro_price {
|
position: absolute;
|
bottom: 25px;
|
}
|
|
.sendord_price {
|
position: absolute;
|
bottom: 40px;
|
}
|
|
.upload_box {
|
/* width: 50rpx; */
|
height: 75rpx;
|
display: flex;
|
align-items: center;
|
margin-left: 20rpx;
|
justify-content: space-around;
|
flex: 1;
|
}
|
</style>
|