diff --git a/api/im.js b/api/im.js index 45be304..5c74091 100644 --- a/api/im.js +++ b/api/im.js @@ -64,7 +64,7 @@ export function getTalk(talkId) { params }); } -// 从商品页点击 客服 跳转 获取聊天记录 +// 从商品页点击 客服 跳转 获取商品详情 export function jumpObtain(skuId, goodsId) { return http.request({ url: `${api.im}/goods/goods/sku/${goodsId}/${skuId}`, diff --git a/pages/mine/im/index.vue b/pages/mine/im/index.vue index f267b7c..f9d9894 100644 --- a/pages/mine/im/index.vue +++ b/pages/mine/im/index.vue @@ -17,12 +17,31 @@ - {{ user.nickName }} - {{ item.text }} + {{ item.text }} + + + + + + + + + {{ + JSON.parse(item.text).goodsName +}} + + ¥{{ + JSON.parse(item.text).price +}} + + + + @@ -46,13 +65,55 @@ {{ toUser.name }} - {{ item.text }} + {{ item.text }} + + + + + + + + {{ + JSON.parse(item.text).goodsName +}} + + ¥{{ + JSON.parse(item.text).price +}} + + + + + + + + + + + + + {{ + goodLiistData.goodsName +}} + + ¥{{ + goodLiistData.price +}} + + + X + + 发送商品 + + + @@ -109,7 +170,20 @@ import SocketService from "@/utils/socket_service.js"; import storage from "@/utils/storage.js"; import { beautifyTime } from "@/utils/filters.js" export default { + // 页面卸载后清除imGoodId + onUnload () { + storage.setImGoodsLink('') + }, onLoad (options) { + // 没有goodsid则不显示 发送商品弹窗 + this.showHideModel = options.goodsid + // 发送后刷新页面不显示 发送商品弹窗 local里面imGoodId不为空显示 + this.localImGoodsId = storage.getImGoodsLink() + this.rosolve = options + // 请求商品信息 + if (this.rosolve.goodsid) { + this.commodityDetails() + } // 如果需要缓存消息缓存msgList即可 // 监听键盘拉起 // 因为无法控制键盘拉起的速度,所以这里尽量以慢速处理 @@ -118,7 +192,6 @@ export default { query.select('#msgList').boundingClientRect(data => { // 若消息体没有超过2倍的键盘则向下移动差值,防止遮住消息体 var up = res.height * 2 - data.height - l * 110 - console.log(up) if (up > 0) { // 动态改变空盒子高度 this.msgMove(up, 300) @@ -144,6 +217,7 @@ export default { this.getTalkMessage() } else { this.getTalk(options.userId) + } this.ws.connect(); @@ -151,7 +225,6 @@ export default { onPullDownRefresh () { this.params.pageNumber = this.params.pageNumber + 1 this.getTalkMessage() - console.log('下拉事件'); setTimeout(function () { uni.stopPullDownRefresh(); }, 1000); @@ -161,6 +234,9 @@ export default { }, data () { return { + showHideModel: undefined, + localImGoodsId: '', + showHide: true, msgLoad: false, anData: {}, animationData: {}, @@ -179,6 +255,8 @@ export default { toUser: {}, srcollHeight: 0, ws: new SocketService(), + rosolve: {}, + goodLiistData: {} } }, watch: { @@ -189,7 +267,6 @@ export default { this.msgList.push(val.result) } this.newMessageNum++; - console.log(this.msgList) //接收到消息后发送已读 let msg = val msg.operation_type = 'READ' @@ -198,6 +275,37 @@ export default { } }, methods: { + // 跳转商品详情页 + jumpGoodDelic () { + uni.navigateTo({ + url: `/pages/product/goods?id=${this.rosolve.skuid}&goodsId=${this.rosolve.goodsid}`, + }); + }, + //发送商品 + gotoCards () { + let msg = { + operation_type: "MESSAGE", + to: this.toUser.userId, + from: this.user.id, + message_type: "GOODS", + context: this.goodLiistData, + talk_id: this.params.talkId, + } + this.ws.send(JSON.stringify(msg)) + this.msgList.push({ "text": JSON.stringify(this.goodLiistData), "my": true }) + this.showHide = false + storage.setImGoodsLink(this.params.talkId) + }, + //取消发送 + cancenModel () { + this.showHide = false + }, + // 请求商品详情 + commodityDetails () { + jumpObtain(this.rosolve.skuid, this.rosolve.goodsid).then((res) => { + this.goodLiistData = res.data.result.data + }) + }, beautifyTime, // 切换输入法时移动输入框(按照官方的上推页面的原理应该会自动适应不同的键盘高度-->官方bug) goPag (kh) { @@ -265,11 +373,9 @@ export default { // 回答问题的业务逻辑 answer (id) { // 这里应该传入问题的id,模拟就用index代替了 - console.log(id) }, sendMsg () { - console.log("发送") // 消息为空不做任何操作 if (this.msg == "") { return 0; @@ -363,6 +469,7 @@ export default { if (res.data.success) { this.toUser = res.data.result this.params.talkId = res.data.result.id + this.getTalkMessage() } }) }, @@ -439,7 +546,88 @@ export default { } -