2020-09-16 09:25:13 +08:00
|
|
|
|
<template>
|
2020-09-17 20:01:50 +08:00
|
|
|
|
<view class="page">
|
2020-10-10 10:44:32 +08:00
|
|
|
|
<view class="noData" v-if="noData === true">
|
|
|
|
|
<noData :custom="true"><view class="title">暂无消息,打开他人主页可私信</view></noData>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="cu-list menu-avatar" v-if="noData === false">
|
2020-09-17 20:01:50 +08:00
|
|
|
|
<view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
|
|
|
|
|
v-for="(item,index) in message"
|
|
|
|
|
:key="index"
|
|
|
|
|
@touchstart="ListTouchStart"
|
|
|
|
|
@touchmove="ListTouchMove"
|
|
|
|
|
@touchend="ListTouchEnd"
|
|
|
|
|
:data-target="'move-box-' + index"
|
|
|
|
|
@tap="goToMessage(item)">
|
|
|
|
|
<view class="header-photo">
|
2020-09-27 15:39:35 +08:00
|
|
|
|
<avatar :userName="item.userInfo.real_name" size="50"></avatar>
|
2020-09-17 20:01:50 +08:00
|
|
|
|
</view>
|
|
|
|
|
<view class="content">
|
|
|
|
|
<view class="text-grey">{{item.userInfo.real_name}}</view>
|
|
|
|
|
<view class="text-gray text-sm width">
|
|
|
|
|
{{item.letterList[item.letterList.length-1].content}}
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="action">
|
|
|
|
|
<view class="text-grey text-xs">{{item.letterList[item.letterList.length-1].letter_create_time}}</view>
|
2020-10-10 10:44:32 +08:00
|
|
|
|
<view class="cu-tag round bg-grey sm" v-if="item.unreadNumber === 0">{{item.unreadNumber}}</view>
|
|
|
|
|
<view class="cu-tag round bg-red sm" v-if="item.unreadNumber > 0">{{item.unreadNumber}}</view>
|
2020-09-17 20:01:50 +08:00
|
|
|
|
</view>
|
|
|
|
|
<view class="move">
|
|
|
|
|
<view class="bg-red" @tap="deleteMessage">删除</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2020-09-16 09:25:13 +08:00
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2020-09-17 20:01:50 +08:00
|
|
|
|
import request from '@/util/request.js';
|
2020-09-27 15:39:35 +08:00
|
|
|
|
import avatar from "@/pages/components/avatar/avatar.vue";
|
2020-10-10 10:44:32 +08:00
|
|
|
|
import noData from '@/components/noData/noData.vue';
|
2020-12-19 12:13:27 +08:00
|
|
|
|
import { sortBy } from '@/static/js/public.js';
|
2020-09-16 09:25:13 +08:00
|
|
|
|
export default {
|
2020-09-27 15:39:35 +08:00
|
|
|
|
components: {
|
2020-10-10 10:44:32 +08:00
|
|
|
|
avatar,
|
|
|
|
|
noData
|
2020-09-27 15:39:35 +08:00
|
|
|
|
},
|
2020-09-16 09:25:13 +08:00
|
|
|
|
data() {
|
|
|
|
|
return {
|
2020-09-17 20:01:50 +08:00
|
|
|
|
modalName: null,
|
|
|
|
|
message: [],
|
2020-10-10 10:44:32 +08:00
|
|
|
|
//无数据
|
|
|
|
|
noData: false,
|
2020-09-16 09:25:13 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2020-09-17 20:01:50 +08:00
|
|
|
|
onShow() {
|
|
|
|
|
this.getPersonalPrivateLetter();
|
2020-10-10 10:44:32 +08:00
|
|
|
|
this.getTabBarNumber();
|
2020-09-16 09:25:13 +08:00
|
|
|
|
},
|
2020-09-18 08:52:05 +08:00
|
|
|
|
onPullDownRefresh () {
|
|
|
|
|
this.getPersonalPrivateLetter();
|
2020-10-10 10:44:32 +08:00
|
|
|
|
this.getTabBarNumber();
|
2020-09-23 18:53:25 +08:00
|
|
|
|
uni.startPullDownRefresh();
|
2020-09-18 08:52:05 +08:00
|
|
|
|
},
|
2020-09-16 09:25:13 +08:00
|
|
|
|
methods: {
|
2020-10-10 10:44:32 +08:00
|
|
|
|
/**
|
|
|
|
|
* 获取tabBar数字
|
|
|
|
|
*/
|
|
|
|
|
getTabBarNumber() {
|
|
|
|
|
request.post("/hs/getTabBarNumber",{
|
|
|
|
|
userId: uni.getStorageSync("userInfo").user_id
|
|
|
|
|
}).then(res => {
|
|
|
|
|
console.log("获取tabBar数字",res);
|
|
|
|
|
if (res.data.unreadNumber > 0) {
|
|
|
|
|
uni.setTabBarBadge({
|
|
|
|
|
index: 3,
|
|
|
|
|
text: res.data.unreadNumber.toString()
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
uni.removeTabBarBadge({
|
|
|
|
|
index: 3
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},err => {
|
|
|
|
|
console.log("err",err)
|
|
|
|
|
})
|
|
|
|
|
},
|
2020-09-17 20:01:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* 跳转到消息页面
|
|
|
|
|
* @param {Object} item
|
|
|
|
|
*/
|
|
|
|
|
goToMessage(item) {
|
2020-09-23 18:53:25 +08:00
|
|
|
|
uni.setStorageSync("otherInfo",item.userInfo);
|
2020-09-17 20:01:50 +08:00
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url: "/pages/tabbar/message/chat-page"
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 删除私信
|
|
|
|
|
*/
|
|
|
|
|
deleteMessage() {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: 'loading',
|
|
|
|
|
title: '不能删除哦'
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 获取私信
|
|
|
|
|
*/
|
|
|
|
|
getPersonalPrivateLetter() {
|
|
|
|
|
request.post('/hs/getPersonalPrivateLetterApp',{
|
|
|
|
|
userId: uni.getStorageSync("userInfo").user_id,
|
|
|
|
|
}).then(res => {
|
|
|
|
|
this.message = res.data;
|
2020-10-10 10:44:32 +08:00
|
|
|
|
this.noData = res.data.length > 0 ? false : true;
|
2020-09-17 20:01:50 +08:00
|
|
|
|
this.message.forEach((item,index) => {
|
|
|
|
|
let unreadNumber = 0;
|
|
|
|
|
item.letterList.forEach(i => {
|
|
|
|
|
if (i.already_read === '0' && i.receive_id === uni.getStorageSync("userInfo").user_id) {
|
|
|
|
|
unreadNumber++;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
item.unreadNumber = unreadNumber;
|
2020-12-19 12:13:27 +08:00
|
|
|
|
item.lastTime = item.letterList.length === 0 ? '' : item.letterList[item.letterList.length-1].letter_create_time
|
2020-09-17 20:01:50 +08:00
|
|
|
|
});
|
|
|
|
|
this.message.forEach((item,index) => {
|
|
|
|
|
if (item.userInfo.user_id === uni.getStorageSync("userInfo").user_id) {
|
|
|
|
|
this.message.splice(index,1);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-12-19 12:13:27 +08:00
|
|
|
|
this.message = this.message.sort(sortBy("lastTime",false))
|
2020-09-17 20:01:50 +08:00
|
|
|
|
console.log("私信",res);
|
|
|
|
|
},err=>{
|
|
|
|
|
console.log("err",err);
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* ListTouch触摸开始
|
|
|
|
|
* @param {Object} e
|
|
|
|
|
*/
|
|
|
|
|
ListTouchStart(e) {
|
|
|
|
|
this.listTouchStart = e.touches[0].pageX
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ListTouch计算方向
|
|
|
|
|
* @param {Object} e
|
|
|
|
|
*/
|
|
|
|
|
ListTouchMove(e) {
|
|
|
|
|
this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
|
|
|
|
|
},
|
2020-09-16 09:25:13 +08:00
|
|
|
|
|
2020-09-17 20:01:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* ListTouch计算滚动
|
|
|
|
|
* @param {Object} e
|
|
|
|
|
*/
|
|
|
|
|
ListTouchEnd(e) {
|
|
|
|
|
if (this.listTouchDirection == 'left') {
|
|
|
|
|
this.modalName = e.currentTarget.dataset.target
|
|
|
|
|
} else {
|
|
|
|
|
this.modalName = null
|
|
|
|
|
}
|
|
|
|
|
this.listTouchDirection = null
|
|
|
|
|
}
|
2020-09-16 09:25:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2020-09-17 20:01:50 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
.width{
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
.cu-list.menu-avatar>.cu-item{
|
|
|
|
|
margin: 20rpx 0;
|
|
|
|
|
border-radius: 10rpx;
|
|
|
|
|
}
|
|
|
|
|
.cu-list.menu-avatar>.cu-item .action{
|
|
|
|
|
width: 160rpx;
|
|
|
|
|
}
|
|
|
|
|
.header-photo{
|
|
|
|
|
position: absolute;
|
2020-09-27 15:39:35 +08:00
|
|
|
|
left: 0rpx;
|
2020-09-16 09:25:13 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|