Browse Source

feat(api): 添加销售端聊天功能相关接口和页面

- 新增获取好友关系详情、聊天消息列表和发送聊天消息的 API 接口
- 实现聊天页面的初始化、获取聊天记录、发送消息等功能
- 优化聊天消息的展示逻辑,根据用户类型区分发送和接收消息
- 修改市场线索页面,增加跳转到聊天页面的功能
master
liutong 10 months ago
parent
commit
cd7220c488
  1. 22
      api/apiRoute.js
  2. 139
      pages/common/im_chat_info.vue
  3. 5
      pages/market/clue/index.vue

22
api/apiRoute.js

@ -227,6 +227,28 @@ export default {
})
},
//销售端-获取好友关系绑定详情
xs_chatGetChatFriendsInfo(data = {}) {
let url = '/chat/getChatFriendsInfo'
return http.get(url, data).then(res => {
return res;
})
},
//销售端-获取聊天消息列表
xs_chatGetChatMessagesList(data = {}) {
let url = '/chat/getChatMessagesList'
return http.get(url, data).then(res => {
return res;
})
},
//销售端-发送聊天消息
xs_chatSendChatMessages(data = {}) {
let url = '/chat/sendChatMessages'
return http.post(url, data).then(res => {
return res;
})
},

139
pages/common/im_chat_info.vue

@ -7,12 +7,11 @@
class="section_1"
scroll-y="true"
:lower-threshold="lowerThreshold"
@scrolltolower="loadMoreData"
style="height: 80vh;"
>
<view class="ul">
<view class="item_box" v-for="(v,k) in tableList" :key="k">
<view class="time_section" v-if="v.create_time">{{v.create_time}}</view>
<view class="item_box" v-for="(v,k) in tableList" :key="k" :id="'item_' + v.id">
<view class="time_section" v-if="v.created_at">{{v.created_at}}</view>
<view class="li" v-if="v.direction == `left`">
<view class="item left_item">
@ -43,6 +42,7 @@
</template>
<script>
import apiRoute from '@/api/apiRoute.js';
import memberApi from '@/api/member.js';
import commonApi from '@/api/common.js';
import AQUplodeImgMulti from '@/components/AQ/AQUplodeImgMulti';
@ -65,17 +65,37 @@ export default {
page:1,//
limit:10,//
total:10,//
hair_staff_id: '',//id
friend_id: '',//chat_friendsid
},
tableList:[],//
from_id:'',//ID
to_id:'',//ID
from_type:'',//|personnel=,customer=()
//
chatFriendsInfoParams:{
personnel_id:'',
customer_resources_id:'',
},
chatFriendsInfo:{},//
//
formData: {
content: '',
from_type:'',//|personnel=,customer=()
from_id:'',//ID
to_id:'',//ID
friend_id:'',//chat_friendsid
message_type: 'text',//|text=,img=
content: '',//JSON ,=,=
},
lastItemId: null,
}
},
onLoad(options) {
this.filteredData.hair_staff_id = options.hair_staff_id//id
this.from_id = options.from_id//id
this.to_id = options.to_id//id
},
onShow(){
this.init()
@ -89,7 +109,66 @@ export default {
//
async init(){
//
let userType = uni.getStorageSync('userType')
//1=,2=,3=
if (['1', '2'].includes(String(userType))) {
//
this.from_type = 'personnel'//
this.chatFriendsInfoParams.personnel_id = this.from_id//id
this.chatFriendsInfoParams.customer_resources_id = this.to_id//id
this.formData.from_type = 'personnel'//
this.formData.from_id = this.from_id//id()
this.formData.to_id = this.to_id//id()
} else {
//
this.from_type = 'customer'//
this.chatFriendsInfoParams.personnel_id = this.to_id//id
this.chatFriendsInfoParams.customer_resources_id = this.from_id//id
this.formData.from_type = 'customer'//
this.formData.from_id = this.to_id//id()
this.formData.to_id = this.from_id//id()
}
//
await this.getChatFriendsInfo()
//
await this.getList();
// item ID
this.lastItemId = 'item_' + (this.tableList.length - 1);
//
this.$nextTick(() => {
this.$refs.scrollView.scrollTo({ top: this.scrollViewHeight });
});
// 使 scroll-into-view
this.scrollIntoView = this.lastItemId;
},
//
async getChatFriendsInfo(){
let params = {
personnel_id: this.chatFriendsInfoParams.personnel_id,//ID
customer_resources_id: this.chatFriendsInfoParams.customer_resources_id,//ID
}
let res = await apiRoute.xs_chatGetChatFriendsInfo(params)
if (res.code != 1){
uni.showToast({
title: res.msg,
icon: 'none'
})
return
}
this.chatFriendsInfo = res.data
this.filteredData.friend_id = res.data.id
this.formData.friend_id = res.data.id
},
//()
@ -109,27 +188,27 @@ export default {
this.filteredData.total = 10//
},
//
//
async getList(){
this.loading = true
let data = {...this.filteredData}
//
if(this.filteredData.page * this.filteredData.limit > this.filteredData.total){
this.loading = false
//
if ((this.filteredData.page - 1) * this.filteredData.limit >= this.filteredData.total) {
this.loading = false;
uni.showToast({
title: '暂无更多',
icon: 'none'
})
return
});
return;
}
if(data.page == 1){
this.tableList = []
}
let res = await commonApi.getContactMessage(data)//
let res = await apiRoute.xs_chatGetChatMessagesList(data)//
this.loading = false
this.isReachedBottom = false;
if (res.code != 1){
@ -141,9 +220,32 @@ export default {
}
// this.tableList = this.tableList.concat(res.data.data); // 使 concat
this.tableList.unshift(...res.data.data); //
console.log('列表',this.tableList)
let list = res.data.data
list.forEach((v, k) => {
if (this.from_type == 'personnel') {
//
if (v.from_type == 'personnel') {
v.direction = 'right'//
} else {
v.direction = 'left'//
}
} else if (this.from_type == 'customer') {
//
if (v.from_type == 'customer') {
v.direction = 'right'//
} else {
v.direction = 'left'//
}
}
})
list.reverse()
this.tableList.unshift(...list); //
console.log('列表',res.data.total)
this.filteredData.total = res.data.total
this.filteredData.page++
},
@ -165,10 +267,7 @@ export default {
//
async submitForm() {
let data = {
hair_staff_id: this.filteredData.hair_staff_id,
content: this.formData.content,
}
let data = {...this.formData}
if (!data.content) {
//
uni.showToast({
@ -177,7 +276,7 @@ export default {
})
return
}
let res = await commonApi.sendMessage(data)
let res = await apiRoute.xs_chatSendChatMessages(data)
if (res.code != 1) {
uni.showToast({
title: res.msg,

5
pages/market/clue/index.vue

@ -450,9 +450,10 @@ export default {
//-
openViewMyMessage(item) {
let hair_staff_id = item.hair_staff_id
let from_id = this.userInfo.id//id
let to_id = item.customerResource.id//ID
uni.navigateTo({
url: `/pages/common/im_chat_info?hair_staff_id=${hair_staff_id}`
url: `/pages/common/im_chat_info?from_id=${from_id}&to_id=${to_id}`
})
},

Loading…
Cancel
Save