|
|
@@ -31,7 +31,6 @@
|
|
|
</view>
|
|
|
|
|
|
<view v-if="message.messageType == 'text'|| message.messageType != 'goods'" class="message-content-wrapper">
|
|
|
- <view class="username" v-if="isMultiUser">{{ message.username }}</view>
|
|
|
<view class="message-bubble left-bubble">
|
|
|
<text class="message-text">{{ message.message }}</text>
|
|
|
</view>
|
|
|
@@ -39,9 +38,6 @@
|
|
|
</view>
|
|
|
|
|
|
<view v-if="message.messageType == 'goods'" class="goods-content-wrapper">
|
|
|
- <view class="username align-right" v-if="isMultiUser">{{
|
|
|
- message.username
|
|
|
- }}</view>
|
|
|
<view class="goods-info left-bubble">
|
|
|
<view class="goods-main" @click="toGoodsDetail(message.goodsInfo)">
|
|
|
<image class="goods-image" :src="message.goodsInfo.goodsImg" mode="aspectFill"></image>
|
|
|
@@ -49,12 +45,12 @@
|
|
|
<view class="goods-name-wrapper">
|
|
|
<text class="goods-name">{{message.goodsInfo.goodsName}}</text>
|
|
|
</view>
|
|
|
- <view class="sales-info" v-if="message.goodsInfo.goodsPriceType == 2">
|
|
|
+ <!-- <view class="sales-info" v-if="message.goodsInfo.goodsPriceType == 2">
|
|
|
<text class="delivery-time">商家标价</text>
|
|
|
</view>
|
|
|
<view class="sales-info" v-if="message.goodsInfo.notExpired === false">
|
|
|
- <text class="delivery-time">报价窗口过期</text>
|
|
|
- </view>
|
|
|
+ <text class="delivery-time">改价窗口过期</text>
|
|
|
+ </view> -->
|
|
|
<text v-if="message.goodsInfo.goodsPriceType != 0" class="goods-price">¥{{ parseFloat(message.goodsInfo.goodsPrice).toFixed(2) }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -78,16 +74,12 @@
|
|
|
<!-- 右侧消息(我的) -->
|
|
|
<view class="message-right" v-if="message.isMine">
|
|
|
<view v-if="message.messageType == 'text'|| message.messageType != 'goods'" class="message-content-wrapper">
|
|
|
- <view class="username align-right" v-if="isMultiUser">{{ message.username}}</view>
|
|
|
<view class="message-bubble right-bubble">
|
|
|
<text class="message-text">{{ message.message }}</text>
|
|
|
</view>
|
|
|
<view class="message-time align-right">{{ message.time }}</view>
|
|
|
</view>
|
|
|
<view v-if="message.messageType == 'goods'" class="goods-content-wrapper">
|
|
|
- <view class="username align-right" v-if="isMultiUser">
|
|
|
- {{ message.username }}
|
|
|
- </view>
|
|
|
<view class="goods-info right-bubble">
|
|
|
<view class="goods-main" @click="toGoodsDetail(message.goodsInfo)">
|
|
|
<image class="goods-image" :src="message.goodsInfo.goodsImg" mode="aspectFill"/>
|
|
|
@@ -95,15 +87,15 @@
|
|
|
<view class="goods-name-wrapper">
|
|
|
<text class="goods-name">{{ message.goodsInfo.goodsName }}</text>
|
|
|
</view>
|
|
|
- <view class="sales-info" v-if="message.goodsInfo.goodsPriceType == 2">
|
|
|
+ <!-- <view class="sales-info" v-if="message.goodsInfo.goodsPriceType == 2">
|
|
|
<text class="delivery-time">商家标价</text>
|
|
|
</view>
|
|
|
<view class="sales-info" v-if="(message.goodsInfo.goodsPriceType == 0 && message.goodsInfo.notExpired === true)">
|
|
|
<text class="delivery-time">等待商家标价</text>
|
|
|
</view>
|
|
|
<view class="sales-info" v-if="message.goodsInfo.notExpired === false">
|
|
|
- <text class="delivery-time">报价窗口过期</text>
|
|
|
- </view>
|
|
|
+ <text class="delivery-time">改价窗口过期</text>
|
|
|
+ </view> -->
|
|
|
<text v-if="message.goodsInfo.goodsPriceType != 0" class="goods-price">¥{{ parseFloat(message.goodsInfo.goodsPrice).toFixed(2) }}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -199,8 +191,6 @@ export default {
|
|
|
scrollTop: 0,
|
|
|
scrollIntoView: "",
|
|
|
placeholderStyle: "color: #ccc; font-size: 28upx;",
|
|
|
- // 是否多人聊天
|
|
|
- isMultiUser: false,
|
|
|
// 当前用户信息
|
|
|
currentUser: {
|
|
|
userId: 0,
|
|
|
@@ -228,66 +218,22 @@ export default {
|
|
|
keyboardHeight: 0, // 键盘高度
|
|
|
isKeyboardShow: false, // 键盘是否显示
|
|
|
currentGoodsInfo: {}, // 进入聊天页面时,带过来的商品信息
|
|
|
+ pageParams: {}, // 页面参数
|
|
|
};
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
- // console.log("---------- options: ", options);
|
|
|
- if (options.goodsId) {
|
|
|
- this.currentGoodsInfo = {
|
|
|
- ...options
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- if (options.chatPerson) {
|
|
|
- // 设置聊天人名称
|
|
|
- uni.setNavigationBarTitle({
|
|
|
- title: options.chatPerson
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // 根据传入参数判断是否多人聊天
|
|
|
- if (options.isMultiUser) {
|
|
|
- this.isMultiUser = options.isMultiUser === "true";
|
|
|
- }
|
|
|
-
|
|
|
- if (this.loginInfo.id) {
|
|
|
- this.currentUser.userId = parseInt(this.loginInfo.id);
|
|
|
- if(this.currentUser.userId == 0) {
|
|
|
- console.error('userId 出错 ---------- this.currentUser.userId: ', this.currentUser.userId);
|
|
|
- }
|
|
|
- }
|
|
|
- if (options.customId) {
|
|
|
- this.currentUser.customId = parseInt(options.customId);
|
|
|
- if(this.currentUser.customId == 0) {
|
|
|
- console.error('customId 出错 ---------- this.currentUser.customId: ', this.currentUser.customId);
|
|
|
- }
|
|
|
- }
|
|
|
- if (options.shopId) {
|
|
|
- this.currentUser.shopId = parseInt(options.shopId);
|
|
|
- if(this.currentUser.shopId == 0) {
|
|
|
- console.error('shopId 出错 ---------- this.currentUser.shopId: ', this.currentUser.shopId);
|
|
|
- }
|
|
|
- }
|
|
|
- if (options.name) {
|
|
|
- this.currentUser.username = options.name;
|
|
|
- }
|
|
|
- if (options.avatar) {
|
|
|
- this.currentUser.avatar = options.avatar;
|
|
|
- }
|
|
|
-
|
|
|
- // 获取房间号
|
|
|
- if (this.currentUser.customId && this.currentUser.shopId) {
|
|
|
- this.room = "custom_id-" + this.currentUser.customId + "AND" + "shop_id-" + this.currentUser.shopId;
|
|
|
- } else {
|
|
|
- // 如果没有传入房间号,使用默认值或生成一个
|
|
|
- this.room = "default_room";
|
|
|
- }
|
|
|
- // console.log("---------- this.room: ", this.room);
|
|
|
-
|
|
|
- // 加载聊天记录
|
|
|
- this.loadChatHistory();
|
|
|
- // 连接WebSocket
|
|
|
- this.connectWebSocket();
|
|
|
+ const eventChannel = this.getOpenerEventChannel();
|
|
|
+ eventChannel.on('acceptDataFromOpenerPage', (data) => {
|
|
|
+ this.pageParams = data;
|
|
|
+ // console.log("---------- pageParams: ", data);
|
|
|
+ this.initializePage(data);
|
|
|
+ })
|
|
|
+
|
|
|
+ // 兼容旧版本通过 options 传递参数
|
|
|
+ // if (Object.keys(options).length > 0) {
|
|
|
+ // this.pageParams = options;
|
|
|
+ // this.initializePage(options);
|
|
|
+ // }
|
|
|
},
|
|
|
onReady() {
|
|
|
// 页面加载完成后滚动到底部
|
|
|
@@ -313,6 +259,7 @@ export default {
|
|
|
onUnload() {
|
|
|
// 页面卸载时关闭WebSocket连接
|
|
|
this.disconnectWebSocket();
|
|
|
+ this.goBack();
|
|
|
},
|
|
|
onHide() {
|
|
|
// 页面隐藏时可以选择性地关闭连接(根据业务需求)
|
|
|
@@ -326,6 +273,73 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
init() {},
|
|
|
+
|
|
|
+ initializePage(params) {
|
|
|
+ if (params.goodsId) {
|
|
|
+ this.currentGoodsInfo = {
|
|
|
+ ...params
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (params.chatPerson) {
|
|
|
+ // 设置聊天人名称
|
|
|
+ uni.setNavigationBarTitle({
|
|
|
+ title: params.chatPerson
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.loginInfo.id) {
|
|
|
+ this.currentUser.userId = parseInt(this.loginInfo.id);
|
|
|
+ if(this.currentUser.userId == 0) {
|
|
|
+ console.error('userId 出错 ---------- this.currentUser.userId: ', this.currentUser.userId);
|
|
|
+ this.$msg("登录用户数据异常,请稍后再试");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (params.customId) {
|
|
|
+ this.currentUser.customId = parseInt(params.customId);
|
|
|
+ if(this.currentUser.customId == 0) {
|
|
|
+ console.error('customId 出错 ---------- this.currentUser.customId: ', this.currentUser.customId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (params.shopId) {
|
|
|
+ this.currentUser.shopId = parseInt(params.shopId);
|
|
|
+ if(this.currentUser.shopId == 0) {
|
|
|
+ console.error('shopId 出错 ---------- this.currentUser.shopId: ', this.currentUser.shopId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (params.name) {
|
|
|
+ this.currentUser.username = params.name;
|
|
|
+ }
|
|
|
+ if (params.avatar) {
|
|
|
+ this.currentUser.avatar = params.avatar;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取房间号
|
|
|
+ if (this.currentUser.customId && this.currentUser.shopId) {
|
|
|
+ this.room = "custom_id-" + this.currentUser.customId + "AND" + "shop_id-" + this.currentUser.shopId;
|
|
|
+ } else {
|
|
|
+ // 如果没有传入房间号,使用默认值或生成一个
|
|
|
+ this.room = "default_room";
|
|
|
+ }
|
|
|
+ // console.log("---------- this.room: ", this.room);
|
|
|
+
|
|
|
+ // 加载聊天记录
|
|
|
+ this.loadChatHistory();
|
|
|
+ // 连接WebSocket
|
|
|
+ this.connectWebSocket();
|
|
|
+ },
|
|
|
+ goBack() {
|
|
|
+ // 获取事件通道
|
|
|
+ const eventChannel = this.getOpenerEventChannel()
|
|
|
+
|
|
|
+ // 返回时传递数据给页面 A
|
|
|
+ eventChannel.emit('acceptDataFromOpenedPage', {
|
|
|
+ status: 'ok',
|
|
|
+ message: '页面 B 处理完成',
|
|
|
+ timestamp: Date.now()
|
|
|
+ })
|
|
|
+ },
|
|
|
// 加载聊天历史记录
|
|
|
loadChatHistory() {
|
|
|
const userId = this.currentUser.userId;
|
|
|
@@ -1105,7 +1119,7 @@ export default {
|
|
|
//console.log("res", res)
|
|
|
if (res.code == 1) {
|
|
|
if (res.data.price != -1) {
|
|
|
- parsed.goodsPriceType = 2; // 报价类型
|
|
|
+ parsed.goodsPriceType = 2; // 类型
|
|
|
parsed.goodsPrice = parseFloat(res.data.price).toFixed(2);
|
|
|
}
|
|
|
}
|
|
|
@@ -1129,7 +1143,7 @@ export default {
|
|
|
},
|
|
|
// 查看商品
|
|
|
toGoodsDetail(goodsInfo) {
|
|
|
- this.disconnectWebSocket();
|
|
|
+ this.disconnectWebSocket();// 离开本页面,必须断开WebSocket连接
|
|
|
// console.log("---------- goodsInfo: ", goodsInfo);
|
|
|
const goodsId = parseInt(goodsInfo.goodsId);
|
|
|
const categoryId = parseInt(goodsInfo.categoryId);
|
|
|
@@ -1155,8 +1169,8 @@ export default {
|
|
|
},
|
|
|
// 去购买
|
|
|
toBuy(goodsInfo) {
|
|
|
- this.disconnectWebSocket();
|
|
|
- // console.log("---------- goodsInfo: ", goodsInfo);
|
|
|
+ this.disconnectWebSocket();// 离开本页面,必须断开WebSocket连接
|
|
|
+ console.log("---------- goodsInfo: ", goodsInfo);
|
|
|
const goodsId = parseInt(goodsInfo.goodsId);
|
|
|
const categoryId = parseInt(goodsInfo.categoryId);
|
|
|
const hdId = parseInt(goodsInfo.hdId);
|
|
|
@@ -1164,6 +1178,7 @@ export default {
|
|
|
const price = parseFloat(goodsInfo.goodsPrice).toFixed(2);
|
|
|
const priceType = goodsInfo.goodsPriceType;
|
|
|
if (isNaN(goodsId) || isNaN(categoryId) || isNaN(hdId) || isNaN(account) || isNaN(price)) {
|
|
|
+ console.log("商品数据异常", goodsId, categoryId, hdId, account, price)
|
|
|
this.$msg("商品数据异常");
|
|
|
return;
|
|
|
}
|
|
|
@@ -1343,16 +1358,6 @@ export default {
|
|
|
width: 72%;
|
|
|
}
|
|
|
|
|
|
-.username {
|
|
|
- font-size: 24upx;
|
|
|
- color: $fontColor3;
|
|
|
- margin-bottom: 8upx;
|
|
|
-
|
|
|
- &.align-right {
|
|
|
- text-align: right;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
.message-bubble {
|
|
|
padding: 20upx 24upx;
|
|
|
border-radius: 16upx;
|
|
|
@@ -1622,7 +1627,7 @@ export default {
|
|
|
/* #ifdef APP-PLUS */
|
|
|
.input-area {
|
|
|
// App端底部安全区域
|
|
|
- padding-bottom: calc(20upx + env(safe-area-inset-bottom));
|
|
|
+ padding-bottom: calc(1upx + env(safe-area-inset-bottom));
|
|
|
}
|
|
|
/* #endif */
|
|
|
</style>
|