123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- <template>
- <view class="">
- <view v-if="msgList.length" class="margin-topW">
- <view class="flex padding-tb radius padding-lr-sm bg" @click="goMsg" v-for="(item,index) in msgList"
- :key='index'>
- <view>
- <image style="width: 80rpx;height: 80rpx;border-radius: 80rpx;"
- src="../../static/images/msg/msg.png"></image>
- </view>
- <view class="flex-sub margin-left-sm">
- <view class="flex justify-between">
- <view class="text-white">{{item.title?item.title: '系统消息'}}</view>
- <view v-if="messageCount>0"
- style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
- {{messageCount}}
- </view>
- </view>
- <view>
- <view class="text-grey">{{item.content}}</view>
- </view>
- </view>
- </view>
- </view>
- <view class="margin-topW">
- <view class="flex padding-tb radius padding-lr-sm bg" @click="goChat">
- <view>
- <image style="width: 80rpx;height: 80rpx;border-radius: 80rpx;"
- src="../../static/images/msg/msgs.png"></image>
- </view>
- <view class="flex-sub margin-left-sm">
- <view class="flex justify-between">
- <view class="text-white">在线客服</view>
- <view v-if="userCount>0"
- style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
- {{userCount}}
- </view>
- </view>
- <view>
- <view class="text-grey">联系在线客服</view>
- </view>
- </view>
- </view>
- </view>
- <view v-if="chatList.length" class="margin-top-sm content ">
- <view class="radius padding-lr-sm bg" style="margin-top: 4rpx;" @click="goIM(item)"
- v-for="(item,index) in chatList" :key='index'>
- <view class="flex padding-tb ">
- <view>
- <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
- </view>
- <view class="flex-sub margin-left-sm">
- <view class="flex justify-between align-center">
- <view class="text-white flex align-center userNameleng">
- <view class="">
- {{item.userName}}
- </view>
- <text class="text-grey"
- style="font-size: 26rpx;margin-left: 20rpx;">{{item.stationName}}</text>
- </view>
- <view class="text-grey">{{item.messageTime?getMonthOrDay(item.messageTime):''}}</view>
- </view>
- <view class="flex justify-between" style="margin-top: 10rpx;">
- <view class="text-grey" v-if="item.messageType == 1">{{item.content}}</view>
- <view class="text-grey" v-else-if="item.messageType == 18">位置</view>
- <view class="text-grey" v-else-if="item.messageType == 9">简历请求</view>
- <view class="text-grey" v-else-if="item.messageType == 6">微信请求</view>
- <view class="text-grey" v-else-if="item.messageType == 5">手机号请求</view>
- <view class="text-grey" v-else-if="item.messageType == 2">[图片]</view>
- <view class="text-grey" v-else-if="item.messageType == 4">[表情]</view>
- <view class="text-grey" v-else-if="item.messageType == 20">[视频通话]</view>
- <view class="text-grey" v-else-if="item.messageType == 21">[语音通话]</view>
- <view v-if="item.contentCount"
- style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
- {{item.contentCount}}
- </view>
- </view>
- </view>
- </view>
- <!-- <view class="flex padding-tb" v-else>
- <view>
- <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
- </view>
- <view class="flex-sub margin-left-sm">
- <view class="flex justify-between">
- <view class="text-white">{{item.userName}}</view>
- <view class="text-grey">{{item.messageTime?item.messageTime:''}}</view>
- </view>
- <view class="flex justify-between">
- <view class="text-grey" v-if="item.messageType == 1">{{item.content}}</view>
- <view class="text-grey" v-else-if="item.messageType == 18">位置</view>
- <view class="text-grey" v-else-if="item.messageType == 9">简历请求</view>
- <view class="text-grey" v-else-if="item.messageType == 6">微信请求</view>
- <view class="text-grey" v-else-if="item.messageType == 5">手机号请求</view>
- <view class="text-grey" v-else>[图片]</view>
- <view v-if="item.contentCount"
- style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
- {{item.contentCount}}
- </view>
- </view>
- </view>
- </view> -->
- </view>
- </view>
- <empty v-if="!chatList.length" content='暂无消息'></empty>
- </view>
- </template>
- <script>
- import empty from '../../components/empty.vue'
- export default {
- components: {
- empty
- },
- data() {
- return {
- page: 1,
- limit: 100,
- chatList: [],
- userId: '',
- msgList: [],
- time: '',
- messageCount: 0,
- userCount: 0,
- arr: [],
- showModal: true,
- }
- },
- onLoad() {
- if (uni.getStorageSync('userId')) {
- this.getChatList()
- }
- },
- //下拉刷新
- onPullDownRefresh() {
- let that = this
- if (uni.getStorageSync('token')) {
- that.getweiduMsg();
- that.getChatList()
- that.getMsgList()
- that.$nextTick(function() {
- that.messageCount = uni.getStorageSync('messageCount')
- })
- }
- },
- onShow() {
- let that = this
- that.userId = uni.getStorageSync('userId')
- if (that.userId) {
- that.time = setInterval(function() {
- that.getweiduMsg();
- that.getChatList()
- that.getMsgList()
- that.$nextTick(function() {
- that.messageCount = uni.getStorageSync('messageCount')
- })
- }, 3000)
- this.$Request.getT('/app/common/type/310').then(res => { //消息未读提醒
- if (res.code == 0) {
- if (res.data && res.data.value) {
- this.arr.push(res.data.value)
- }
- }
- })
- this.$Request.getT('/app/common/type/337').then(res => { //预约成功通知(通用)
- if (res.code == 0) {
- if (res.data && res.data.value) {
- this.arr.push(res.data.value)
- }
- }
- })
- this.$Request.getT('/app/common/type/338').then(res => { //订单状态通知
- if (res.code == 0) {
- if (res.data && res.data.value) {
- this.arr.push(res.data.value)
- }
- }
- })
- // #ifdef MP-WEIXIN
- if (this.showModal) {
- this.openMsg()
- }
- // #endif
- } else {
- that.chatList = []
- that.msgList = []
- }
- },
- onHide() {
- clearInterval(this.time)
- },
- methods: {
- //把时间转换为月日
- getMonthOrDay(time) {
- let date = new Date(time) // 获取时间
- // var year = date.getFullYear() // 获取年
- let month = date.getMonth() + 1 // 获取月
- let strDate = date.getDate() // 获取日
- return month + '月' + strDate + '日'
- },
- // 开启订阅消息
- openMsg() {
- console.log('订阅消息')
- var that = this
- uni.getSetting({
- withSubscriptions: true, //是否获取用户订阅消息的订阅状态,默认false不返回
- success(ret) {
- console.log(ret.subscriptionsSetting.itemSettings, '*************************************')
- // if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
- if (ret.subscriptionsSetting.itemSettings) {
- uni.setStorageSync('sendMsg', true)
- uni.openSetting({ // 打开设置页
- success(rea) {
- console.log(rea.authSetting)
- }
- });
- } else { // 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
- uni.setStorageSync('sendMsg', false)
- uni.showModal({
- title: '提示',
- content: '为了更好的体验,请绑定消息推送',
- confirmText: '确定',
- cancelText: '取消',
- confirmColor: '#00B88F',
- success: function(res) {
- if (res.confirm) {
- wx.requestSubscribeMessage({
- tmplIds: that.arr,
- success(re) {
- console.log(JSON.stringify(re),
- '++++++++++++++')
- var datas = JSON.stringify(re);
- if (datas.indexOf("accept") != -1) {
- console.log(re)
- // uni.setStorageSync('sendMsg', true)
- }
- },
- fail: (res) => {
- console.log(res)
- }
- })
- // uni.setStorageSync('sendMsg', true)
- console.log('确认')
- that.showModal = false
- } else if (res.cancel) {
- console.log('取消')
- // uni.setStorageSync('sendMsg', false)
- that.showModal = true
- }
- }
- })
- }
- }
- })
- },
- getweiduMsg() {
- this.$Request.get("/app/chats/userCount").then(res => {
- uni.stopPullDownRefresh()
- if (res.code == 0) {
- this.userCount = res.data
- }
- });
- },
- //在线客服
- goChat() {
- // uni.navigateTo({
- // url:'/my/setting/chat'
- // })
- // #ifdef MP-WEIXIN
- if (uni.getStorageSync('sendMsg')) {
- // console.log('授权+1')
- wx.requestSubscribeMessage({
- tmplIds: this.arr,
- success(re) {
- // console.log(JSON.stringify(re), 111111111111)
- var datas = JSON.stringify(re);
- if (datas.indexOf("accept") != -1) {
- // console.log(re)
- }
- },
- fail: (res) => {
- // console.log(res)
- }
- })
- }
- // #endif
- let that = this
- if (uni.getStorageSync('userType') == 1) { //用户端
- // #ifdef MP-WEIXIN
- wx.openCustomerServiceChat({
- extInfo: {
- url: that.$queue.getData('kefu')
- },
- corpId: that.$queue.getData('kefuAppid'),
- success(res) {
- console.log(res)
- },
- })
- // #endif
- // #ifdef H5
- window.location.href = that.$queue.getData('kefu');
- // #endif
- // #ifdef APP
- let kefu = that.$queue.getData('kefu')
- console.log(kefu)
- plus.runtime.openURL(kefu, function(res) {});
- // #endif
- } else { //企业端
- // #ifdef MP-WEIXIN
- wx.openCustomerServiceChat({
- extInfo: {
- url: that.$queue.getData('kefuq')
- },
- corpId: that.$queue.getData('kefuAppidq'),
- success(res) {
- console.log(res)
- },
- })
- // #endif
- // #ifdef H5
- window.location.href = that.$queue.getData('kefuq');
- // #endif
- // #ifdef APP
- let kefu = that.$queue.getData('kefuq')
- console.log(kefu)
- plus.runtime.openURL(kefu, function(res) {});
- // #endif
- }
- },
- getChatList() {
- this.$Request.get("/app/chat/selectChatConversationPage", {
- page: this.page,
- limit: this.limit
- }).then(res => {
- uni.stopPullDownRefresh()
- if (res.code == 0) {
- this.chatList = res.data.list
- }
- });
- },
- getMsgList() {
- this.$Request.get("/app/message/selectMessageByUserIdLimit1").then(res => {
- uni.stopPullDownRefresh()
- if (res.code == 0) {
- this.msgList = res.data.list
- }
- });
- },
- goIM(e) {
- // #ifdef MP-WEIXIN
- if (uni.getStorageSync('sendMsg')) {
- // console.log('授权+1')
- wx.requestSubscribeMessage({
- tmplIds: this.arr,
- success(re) {
- // console.log(JSON.stringify(re), 111111111111)
- var datas = JSON.stringify(re);
- if (datas.indexOf("accept") != -1) {
- // console.log(re)
- }
- },
- fail: (res) => {
- // console.log(res)
- }
- })
- }
- // #endif
- let userId = '';
- let userType = uni.getStorageSync('userType')
- console.log(e, 'aaaaaaaaa')
- if (userType == 2) { //当前登录用户为企业
- userId = e.userId
- } else { //当前登录用户为用户
- userId = e.focusedUserId
- }
- if (uni.getStorageSync('userType') == 1) {
- uni.navigateTo({
- url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
- '&postPushId=' + e.postPushId + '&resumesId=' + e.resumesId
- })
- } else {
- uni.navigateTo({
- url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
- '&resumesId=' + e.resumesId + '&postPushId=' + e.postPushId
- })
- }
- },
- goMsg() {
- // #ifdef MP-WEIXIN
- if (uni.getStorageSync('sendMsg')) {
- // console.log('授权+1')
- wx.requestSubscribeMessage({
- tmplIds: this.arr,
- success(re) {
- // console.log(JSON.stringify(re), 111111111111)
- var datas = JSON.stringify(re);
- if (datas.indexOf("accept") != -1) {
- // console.log(re)
- }
- },
- fail: (res) => {
- // console.log(res)
- }
- })
- }
- // #endif
- uni.navigateTo({
- url: '/pages/msg/message'
- })
- }
- }
- }
- </script>
- <style>
- page {
- background-color: #F7F7F7;
- }
- .bg {
- background: #FFFFFF;
- }
- .userNameleng {
- width: 80%;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- -o-text-overflow: ellipsis;
- }
- </style>
|