zs 2 år sedan
förälder
incheckning
783f9baf29

+ 31 - 68
pages/message/index.vue

@@ -8,13 +8,18 @@
 					</view>
 					<view class="two">
 						<view class="list" v-for="(item,index) in list" :key="index" @tap="toInfo(item)">
-							<image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
+							<image class="image"
+								:src="item.shop&&item.shop.logo&&item.shop.logo.length>0?item.shop.logo[0].url:''"
+								mode="">
 							</image>
 							<view class="content">
-								<view class="name">{{item.shop}}</view>
-								<view class="news">{{item.last_chat}}</view>
+								<view class="name textOver">{{item.shop&&item.shop.name||'暂无'}}</view>
+								<view class="news textOver">{{item.last_chat}}</view>
+							</view>
+							<view class="time">
+								<view class="time_1">{{item.last_time}}</view>
+								<uni-badge :text="item.not_read" size="small"></uni-badge>
 							</view>
-							<view class="time">{{item.last_time}}</view>
 						</view>
 					</view>
 				</view>
@@ -32,67 +37,7 @@
 				},
 				user: {},
 				searchInfo: {},
-				list: [{
-						_id: '1111111',
-						shop: '客服1',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '222222',
-						shop: '客服2',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '333333',
-						shop: '客服3',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '444444',
-						shop: '客服4',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '555555',
-						shop: '客服5',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '666666',
-						shop: '客服6',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '77777777',
-						shop: '客服7',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '8888888',
-						shop: '客服8',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '99999999',
-						shop: '客服9',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					},
-					{
-						_id: '1010101010',
-						shop: '客服10',
-						last_chat: '宝贝上新啦,来看看是不是喜欢的',
-						last_time: '2023-01-12'
-					}
-				],
+				list: [],
 				total: 0,
 				skip: 0,
 				limit: 10,
@@ -103,6 +48,11 @@
 			const that = this;
 			await that.watchlogin();
 		},
+		onShow: async function() {
+			const that = this;
+			that.clearPage();
+			if (that.user && that.user._id) that.search();
+		},
 		onPullDownRefresh: async function() {
 			const that = this;
 			that.clearPage();
@@ -126,6 +76,7 @@
 			},
 			async search() {
 				const that = this;
+				let config = that.$config;
 				let info = {
 					skip: that.skip,
 					limit: that.limit,
@@ -138,6 +89,14 @@
 				}, 'chat');
 				if (res.errcode == '0') {
 					let list = [...that.list, ...res.data];
+					for (let val of list) {
+						if (val.last_chat) {
+							val.last_time = val.last_chat.time
+							let chat = val.last_chat.content.indexOf(config.stompUrl) != -1;
+							if (chat) val.last_chat = `[图片]`
+							else val.last_chat = val.last_chat.content
+						}
+					}
 					that.$set(that, `list`, list);
 					that.$set(that, `total`, res.total)
 				} else {
@@ -158,7 +117,7 @@
 			// 详情
 			toInfo(e) {
 				uni.navigateTo({
-					url: `/pagesMessage/message/info?id=${e._id}&name=${e.shop}`
+					url: `/pagesMessage/message/info?id=${e._id}`
 				})
 			},
 			// 分页
@@ -237,7 +196,7 @@
 				}
 
 				.content {
-					width: 52vw;
+					width: 40vw;
 					padding: 2vw;
 
 					.name {
@@ -252,11 +211,15 @@
 				}
 
 				.time {
-					width: 20vw;
+					width: 32vw;
 					text-align: right;
 					padding: 2vw 0;
 					font-size: 12px;
 					color: #C0C0C0;
+
+					.time_1 {
+						margin: 0 0 1vw 0;
+					}
 				}
 			}
 		}

+ 58 - 11
pagesHome/order/detail.vue

@@ -9,14 +9,18 @@
 							</banner_1>
 						</view>
 						<view class="one_2">
-							<text class="money_1" v-if="infospecs.leader_price"><text>团长价¥</text>{{infospecs.leader_price||0}}</text>
+							<text class="money_1"
+								v-if="infospecs.leader_price"><text>团长价¥</text>{{infospecs.leader_price||0}}</text>
 							<text class="money" v-if="infospecs.price"><text>特价¥</text>{{infospecs.price||0}}</text>
-							<text class="money" v-if="!infospecs.price&&!infospecs.leader_price"><text>¥</text>{{infospecs.sell_money||0}}</text>
+							<text class="money"
+								v-if="!infospecs.price&&!infospecs.leader_price"><text>¥</text>{{infospecs.sell_money||0}}</text>
 							<text class="money"><text>¥</text>{{infospecs.flow_money||0}}</text>
 						</view>
 						<view class="one_3" v-if="discount">
-							<text v-if="discount.full_decrement&&discount.full_decrement.length>0" class="act" v-for="(item,index) in discount.full_decrement" :key="index">{{item}}</text>
-							<text v-if="discount.full_fold&&discount.full_decrement.length>0" class="act" v-for="(item,index) in discount.full_fold" :key="index">{{item}}</text>
+							<text v-if="discount.full_decrement&&discount.full_decrement.length>0" class="act"
+								v-for="(item,index) in discount.full_decrement" :key="index">{{item}}</text>
+							<text v-if="discount.full_fold&&discount.full_decrement.length>0" class="act"
+								v-for="(item,index) in discount.full_fold" :key="index">{{item}}</text>
 						</view>
 						<view class="one_4">
 							<text class="num">已售{{info.goods&&info.goods.sell_num||0}}件</text>
@@ -63,7 +67,8 @@
 							</view>
 							<view class="one_7_2">
 								<view class="image" v-for="(set,index) in info.sets[0].set" :key="index">
-									<image class="image" :src="set.file&&set.file.length>0?set.file[0].url:''" mode="aspectFit">
+									<image class="image" :src="set.file&&set.file.length>0?set.file[0].url:''"
+										mode="aspectFit">
 									</image>
 								</view>
 								<view class="money">
@@ -75,7 +80,9 @@
 						<view class="one_8">
 							<view class="one_8_1">
 								<view class="shop_1">
-									<image class="image" :src="info.shop&&info.shop.logo&&info.shop.logo.length>0?info.shop.logo[0].url:''" mode="aspectFit"></image>
+									<image class="image"
+										:src="info.shop&&info.shop.logo&&info.shop.logo.length>0?info.shop.logo[0].url:''"
+										mode="aspectFit"></image>
 								</view>
 								<view class="shop_2">
 									<view class="name">{{info.shop&&info.shop.name}}</view>
@@ -114,7 +121,8 @@
 				</scroll-view>
 			</view>
 			<view class="two">
-				<uni-goods-nav :options="options" :button-group="buttonGroup" @click="toNavleft" @buttonClick="toNavright" />
+				<uni-goods-nav :options="options" :button-group="buttonGroup" @click="toNavleft"
+					@buttonClick="toNavright" />
 			</view>
 		</view>
 		<!-- 跳转菜单 -->
@@ -122,7 +130,8 @@
 			<text @tap="toMenubar" class="iconfont icon-gengduo"></text>
 		</view>
 		<view class="bar_2" v-if="is_menu">
-			<view class="list" v-for="(item,index) in barList" :key="index" v-if="item.is_use=='0'" @click="toPath(item)">
+			<view class="list" v-for="(item,index) in barList" :key="index" v-if="item.is_use=='0'"
+				@click="toPath(item)">
 				<image class="image" :src="item.normal&&item.normal.length>0?item.normal[0].url:''"></image>
 				<text class="name"> {{item.name}}</text>
 			</view>
@@ -133,7 +142,10 @@
 				<view class="close">
 					<text @click="toClose" class="iconfont icon-shanchu"></text>
 				</view>
-				<specs_1 :info="info" :specsInfo="specsInfo" :btn_type="btn_type" :is_zero="is_zero" :buy_num="buy_num" :popupShow="popupShow" :is_specs="is_specs" @diaView="diaView" @toSpecs="toSpecs" @toCount="toCount" @toMarket="toMarket" @toBuy="toBuy" @toGroup="toGroup" @diaSpecs="diaSpecs" @toSetMarket="toSetMarket" @toAct="toAct" @toDeatil="toDeatil">
+				<specs_1 :info="info" :specsInfo="specsInfo" :btn_type="btn_type" :is_zero="is_zero" :buy_num="buy_num"
+					:popupShow="popupShow" :is_specs="is_specs" @diaView="diaView" @toSpecs="toSpecs" @toCount="toCount"
+					@toMarket="toMarket" @toBuy="toBuy" @toGroup="toGroup" @diaSpecs="diaSpecs"
+					@toSetMarket="toSetMarket" @toAct="toAct" @toDeatil="toDeatil">
 				</specs_1>
 			</view>
 		</uni-popup>
@@ -180,6 +192,11 @@
 				discount: {},
 				// 底部菜单
 				options: [{
+						icon: 'headphones',
+						text: '客服',
+						type: 'chat',
+						route: 'pagesMessage/message/info',
+					}, {
 						icon: 'shop',
 						text: '店铺',
 						type: 'shop',
@@ -619,8 +636,8 @@
 					url: `/pagesRest/activity/info?id=${item._id}`
 				})
 			},
-			// 店铺,购物车
-			toNavleft(e) {
+			// 店铺,购物车,客服
+			async toNavleft(e) {
 				const that = this;
 				if (e.content.type == 'shop') {
 					that.toShop();
@@ -629,6 +646,36 @@
 						route: e.content.route
 					}
 					that.toPath(obj)
+				} else { //客服
+					if (that.user) {
+						let form = {
+							"customer": that.user && that.user._id,
+							"shop": that.info && that.info.shop && that.info.shop._id
+						}
+						// 查询该用户与该店铺是否有房间
+						let arr = await that.$api(`/room`, `GET`, form, 'chat');
+						if (arr.errcode == '0' && arr.total > 0) { //有直接进入
+							if (arr.data) {
+								uni.navigateTo({
+									url: `/pagesMessage/message/info?id=${arr.data._id}`
+								})
+							}
+						} else { //没有创建进入
+							let res = await that.$api(`/room`, `POST`, form, 'chat');
+							if (res.errcode == '0') {
+								if (res.data) {
+									uni.navigateTo({
+										url: `/pagesMessage/message/info?id=${res.data._id}`
+									})
+								}
+							}
+						}
+					} else {
+						uni.showToast({
+							title: '未登录账号,无法联系客服',
+							icon: 'none'
+						})
+					}
 				}
 			},
 			// 关闭弹框

+ 8 - 11
pagesMessage/message/components/submit_1.vue

@@ -3,7 +3,7 @@
 		<view class="submit">
 			<view class="submit-chat">
 				<!-- 文本框 -->
-				<textarea disable-default-padding="true" auto-height="true" fixed="true" class="btn" @confirm="inputs"
+				<textarea disable-default-padding="true" auto-height="true" fixed="true" class="btn" @input="inputs"
 					@focus="focus" v-model="msg"></textarea>
 				<view class="bt-img" @tap="more">
 					<text class="iconfont icon-gengduoneirong"></text>
@@ -39,9 +39,10 @@
 			//文字发送
 			inputs(e) {
 				var chatm = e.detail.value;
-				if (chatm.length > 1) {
+				var pos = chatm.indexOf('\n');
+				if (pos != -1 && chatm.length > 1) {
 					// 0为表情和文字
-					this.send(this.msg, 0)
+					this.send(this.msg, '0')
 				}
 			},
 			// 输入框聚焦
@@ -71,12 +72,8 @@
 						let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
 						const arr = await that.$apifile(`/point/upload`, 'file', tempFile[0], 'file');
 						if (arr.errcode == '0') {
-							let filePaths = {
-								name: arr.name,
-								uri: arr.uri,
-								url: serverUrl + arr.uri
-							}
-							that.send([filePaths], 1)
+							let filePaths = serverUrl + arr.uri
+							that.send(filePaths, '1')
 						} else {
 							uni.showToast({
 								title: arr.errmsg,
@@ -88,11 +85,11 @@
 			},
 			//发送
 			send(msg, type) {
-				let date = {
+				let data = {
 					message: msg,
 					type: type
 				}
-				this.$emit('inputs', date);
+				this.$emit('inputs', data);
 				setTimeout(() => {
 					this.msg = '';
 				}, 0)

+ 204 - 136
pagesMessage/message/info.vue

@@ -6,34 +6,35 @@
 				<scroll-view class="scroll-view" scroll-y="true" scroll-with-animation="true"
 					:scroll-into-view="scrollToView">
 					<view class="list-scroll-view">
-						<view class="chat-ls" v-for="(item,index) in unshiftmsg" :key="index" :id="'msg'+ index">
+						<view class="chat-ls" v-for="(item,index) in msgList" :key="index" :id="'msg'+ index">
 							<view class="chat-time" v-if="item.time != ''">
 								{{item.time}}
 							</view>
-							<view class="msg-m msg-left" v-if="item.speaker !=  friendName">
-								<image class="user-img" :src="item.file&&item.file.length>0?item.file[0].url:''">
+							<view class="msg-m msg-left" v-if="item.speaker !=  user._id">
+								<image @tap="toShop()" class="user-img"
+									:src="shop.logo&&shop.logo.length>0?shop.logo[0].url:''">
 								</image>
 								<!-- 文字 -->
-								<view class="message" v-if="item.TextType == 0">                           
+								<view class="message" v-if="item.msg_type =='0'">                           
 									<view class="msg-text">{{item.content}}</view>
 								</view>
 								<!-- 图像 -->
-								<view class="message img" v-else @tap="previewImg(item.content)">
-									<image :src="item.content&&item.content.length>0?item.content[0].url:''"
-										class="msg-img" mode="widthFix"></image>
+								<view class="message img" v-else-if="item.msg_type =='1'"
+									@tap="previewImg(item.content)">
+									<image :src="item.content" class="msg-img" mode="widthFix"></image>
 								</view>
 							</view>
-							<view class="msg-m msg-right" v-if="item.speaker == friendName">
-								<image class="user-img" :src="item.file&&item.file.length>0?item.file[0].url:''">
+							<view class="msg-m msg-right" v-if="item.speaker == user._id">
+								<image class="user-img" :src="user.icon&&user.icon.length>0?user.icon[0].url:''">
 								</image>
 								<!-- 文字 -->
-								<view class="message" v-if="item.TextType == 0">
+								<view class="message" v-if="item.msg_type =='0'">
 									<view class="msg-text">{{item.content}}</view>
 								</view>
 								<!-- 图像 -->
-								<view class="message img" v-else @tap="previewImg(item.content)">
-									<image :src="item.content&&item.content.length>0?item.content[0].url:''"
-										class="msg-img" mode="widthFix"></image>
+								<view class="message img" v-else-if="item.msg_type =='1'"
+									@tap="previewImg(item.content)">
+									<image :src="item.content" class="msg-img" mode="widthFix"></image>
 								</view>
 							</view>
 						</view>
@@ -56,88 +57,37 @@
 		},
 		data() {
 			return {
-				friendName: "zs",
+				// 用户信息
 				user: {},
-				info: {},
+				// 房间号id
 				id: '',
-				name: '',
-				msg: [],
-				// 反转数据接收
-				unshiftmsg: [{
-						"speaker": "zs",
-						"content": "这是第一条未读消息",
-						"time": "2023-01-12 12:21:03",
-						"TextType": 0
-					},
-					{
-						"speaker": "yy",
-						"content": "这是第二条未读消息",
-						"time": "2023-01-12 12:22:58",
-						"TextType": 0
-					},
-					{
-						"speaker": "zs",
-						"content": "这是第三条未读消息",
-						"time": "2023-01-12 12:22:03",
-						"TextType": 0
-					},
-					{
-						"speaker": "yy",
-						"content": "这是第四条未读消息",
-						"time": "2023-01-12 12:21:58",
-						"TextType": 0
-					},
-					{
-						"speaker": "zs",
-						"content": "这是第五条未读消息",
-						"time": "2023-01-12 12:22:03",
-						"TextType": 0
-					},
-					{
-						"speaker": "yy",
-						"content": "这是第六条未读消息",
-						"time": "2023-01-12 12:21:58",
-						"TextType": 0
-					},
-					{
-						"speaker": "zs",
-						"content": "这是第七条未读消息",
-						"time": "2023-01-12 12:22:03",
-						"TextType": 0
-					},
-					{
-						"speaker": "yy",
-						"content": "这是第八条未读消息",
-						"time": "2023-01-12 12:21:58",
-						"TextType": 0
-					},
-					{
-						"speaker": "zs",
-						"content": "这是第九条未读消息",
-						"time": "2023-01-12 12:22:03",
-						"TextType": 0
-					},
-					{
-						"speaker": "zs",
-						"content": "这是第十条未读消息",
-						"time": "2023-01-12 12:21:58",
-						"TextType": 0
-					},
-				],
-				imgMsg: [],
-				scrollToView: '',
+				// 店铺信息
+				shop: {},
+				// 历史记录
+				msgList: [],
+				scrollToView: '', //滑动最后一条信息
+				isSocketOpen: false, //socket是否打开
+				pingpangTimes: null, //socket心跳计时器
+				timeoutnum: null, //断开 重连倒计时,
+				closeType: 1, //断开判断:0代表不重连,1代表重连
 			};
 		},
+		onShow() {
+			const that = this;
+			// that.initWebpack(); //初始化
+			that.closeType = 1 //进入改为1,代表如果断开链接自动重连
+			if (that.id) that.search()
+		},
 		onLoad: async function(e) {
 			const that = this;
 			that.$set(that, `id`, e.id);
-			that.$set(that, `name`, e.name);
-			if (e.name) {
-				uni.setNavigationBarTitle({
-					title: e.name
-				});
-			}
-			await that.watchlogin();
+			that.watchlogin();
+		},
+		beforeDestroy() {
+			const that = this;
+			that.closeType = 0 //离开页面前改为0,代表离开后断开链接不再重连
+			clearInterval(that.pingpangTimes) //清除socket心跳定时器
+			uni.closeSocket() //关闭socket
 		},
 		methods: {
 			// 监听用户是否登录
@@ -147,58 +97,137 @@
 					key: 'token',
 					success: function(res) {
 						let user = that.$jwt(res.data);
-						if (user) {
-							that.$set(that, `user`, user)
-							// if (that.id) 
-							that.search()
-						}
+						if (user) that.$set(that, `user`, user)
 					}
 				})
 			},
+			// 查询历史记录
 			async search() {
 				const that = this;
 				let res;
+				res = await that.$api(`/chatRecord`, `GET`, {
+					room: that.id
+				}, 'chat');
+				if (res.errcode == '0') {
+					that.$set(that, `msgList`, res.data);
+				} else {
+					uni.showToast({
+						title: res.errmsg,
+						icon: 'none'
+					})
+				}
+				res = await that.$api(`/room/${that.id}`, `GET`, {}, 'chat')
+				if (res.errcode == '0') {
+					that.$set(that, `shop`, res.data && res.data.shop);
+					if (res.data && res.data.shop && res.data.shop.name) {
+						uni.setNavigationBarTitle({
+							title: res.data.shop.name
+						});
+					}
+				} else {
+					uni.showToast({
+						title: res.errmsg,
+						icon: 'none'
+					})
+				}
+				let id = that.msgList.filter(i => {
+					return i.speaker != that.user._id;
+				})
+				let ids = id.map(i => {
+					return i._id
+				})
+				res = await that.$api(`/chatRecord/read`, `POST`, {
+					ids
+				}, 'chat')
+				if (res.errcode == '0') {
+					console.log(res);
+				} else {
+					uni.showToast({
+						title: res.errmsg,
+						icon: 'none'
+					})
+				}
+				// 跳转到最后一条数据 与前面的:id进行对照
+				that.$nextTick(function() {
+					that.scrollToView = 'msg' + (that.msgList.length - 1)
+				})
+			},
+			// 初始化websocket链接
+			initWebpack() {
+				const that = this;
 				let config = that.$config;
 				let url = `wss://${config.stompUrl}/ws/exchange/t_m_dev_local/635f82e62df39d4755a25a4a`;
-				console.log(url);
+				//创建新的socket连接前确保旧的已关闭
 				uni.closeSocket()
 				uni.connectSocket({
 					url,
-					// header: {
-					// 	login: 'tehqDev',
-					// 	passcode: 'tehqDev'
-					// },
-					success: async function(res) {
+					success: function(res) {
 						console.log(res, 's');
-						// res = await that.$api(`/chatRecord`, `GET`, {
-						// 	room: that.id
-						// }, 'chat');
-						// if (res.errcode == '0') {
-						// 	console.log(res);
-						// } else {
-						// 	uni.showToast({
-						// 		title: res.errmsg,
-						// 		icon: 'none'
-						// 	})
-						// }
 					},
 					fail: function(err) {
 						console.log(err, 'e');
 					}
 				});
-				// 跳转到最后一条数据 与前面的:id进行对照
-				that.$nextTick(function() {
-					that.scrollToView = 'msg' + (that.unshiftmsg.length - 1)
+				//监听socket打开
+				uni.onSocketOpen(() => {
+					that.isSocketOpen = true
+					console.log('WebSocket连接已打开!');
+				})
+				//监听socket关闭
+				uni.onSocketClose(() => {
+					that.isSocketOpen = false
+					//断开链接时判断
+					if (that.closeType == 0) return
+					that.reconnect(); //重连
+					console.log('WebSocket连接已关闭!');
+				})
+				//监听socket错误
+				uni.onSocketError(() => {
+					that.isSocketOpen = false
+					//断开链接时判断
+					if (that.closeType == 0) return
+					that.reconnect(); //重连
+					console.log('WebSocket连接打开失败');
+				})
+				//监听socket消息
+				uni.onSocketMessage((res) => {
+					let info = JSON.parse(res.data)
+					if (info.cadmin != 5) {
+						that.msgList = that.msgList.concat(info) //获取实时聊天内容信息
+					}
 				})
+				//先确保清除了之前的心跳定时器
+				clearInterval(that.pingpangTimes)
+				//每过一段时间发送一次心跳,发送Ping,服务器会反馈pong,这样操作以保持socket一直是连接状态,防止断开连接,心跳停止
+				that.pingpangTimes = setInterval(() => {
+					uni.sendSocketMessage({
+						data: "ping",
+						success: () => {},
+						fail: () => {
+							that.isSocketOpen = false
+						}
+					});
+				}, 60000)
+			},
+			//重新连接
+			reconnect() {
+				const that = this;
+				//防止重复链接
+				if (that.isSocketOpen) return;
+				that.isSocketOpen = true;
+				//没连接上会一直重连,设置延迟避免请求过多
+				that.timeoutnum && clearTimeout(that.timeoutnum);
+				that.timeoutnum = setTimeout(function() {
+					that.initWebpack(); //新连接
+				}, 5000);
 			},
 			// 进行图片的预览
 			previewImg(e) {
 				const that = this;
-				let urls = e && e[0] && e[0].url;
 				// 预览图片
 				uni.previewImage({
 					current: 0,
-					urls: [urls],
+					urls: [e],
 					longPressActions: {
 						itemList: ['发送给朋友', '保存图片', '收藏'],
 						success: function(data) {
@@ -211,28 +240,67 @@
 				});
 			},
 			//接受输入内容
-			inputs(e) {
+			async inputs(e) {
 				const that = this;
-				//时间间隔处理
-				let data = {
-					"room": "1001",
-					"speaker": "zs",
-					"content": e.message,
-					"time": moment().format('YYYY-MM-DD HH:mm:ss'),
-					"TextType": e.type
-				};
-				// 发送给服务器消息
-				// onSendWS(JSON.stringify(data));
-
-				that.unshiftmsg.push(data);
-				// 跳转到最后一条数据 与前面的:id进行对照
-				that.$nextTick(function() {
-					that.scrollToView = 'msg' + (that.unshiftmsg.length - 1)
-				})
-				if (e.type == 1) {
-					that.imgMsg.push(e.message);
+				let user = that.user
+				if (user._id) {
+					//时间间隔处理
+					let data = {
+						"room": that.id,
+						"speaker": user._id,
+						"content": e.message,
+						"time": moment().format('YYYY-MM-DD HH:mm:ss'),
+						"msg_type": e.type
+					};
+					// 发送给服务器消息
+					// if (that.isSocketOpen) { //socket连接正常
+					let res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
+					if (res.errcode == '0') {
+						that.msgList.push(res.data);
+						// data = JSON.stringify(data) //后端规定的评论数据格式:json转字符串
+						// uni.sendSocketMessage({
+						// 	data,
+						// 	success: () => {
+						// 		uni.showToast({
+						// 			title: '发送成功',
+						// 			icon: 'none'
+						// 		})
+						// 	},
+						// 	fail: () => {
+						// 		uni.showToast({
+						// 			title: '发送失败,请稍后再试或重新进入此页面尝试',
+						// 			icon: 'none'
+						// 		})
+						// 	}
+						// });
+					} else {
+						uni.showToast({
+							title: res.errmsg,
+							icon: 'none'
+						})
+					}
+					// } else { //socket已断开
+					// 	uni.showToast({
+					// 		title: '聊天断开啦,请重新进入此页面尝试 ~',
+					// 		icon: 'none'
+					// 	})
+					// }
+					// 跳转到最后一条数据 与前面的:id进行对照
+					that.$nextTick(function() {
+						that.scrollToView = 'msg' + (that.msgList.length - 1)
+					})
+				} else {
+					uni.showToast({
+						title: '未登录账号无法发送消息 ,请及时登录!',
+						icon: 'none'
+					})
 				}
-				console.log(e)
+			},
+			// 店铺
+			toShop() {
+				uni.navigateTo({
+					url: `/pagesHome/shop/index`
+				})
 			},
 			//输入框高度
 			heights(e) {
@@ -244,7 +312,7 @@
 				const that = this;
 				that.scrollToView = '';
 				that.$nextTick(function() {
-					that.scrollToView = 'msg' + (that.unshiftmsg.length - 1)
+					that.scrollToView = 'msg' + (that.msgList.length - 1)
 				})
 			}
 		}

+ 14 - 4
pagesMy/order/index.vue

@@ -334,13 +334,23 @@
 					"customer": e.customer && e.customer._id,
 					"shop": e.shop && e.shop._id
 				}
-				let res = await that.$api(`/room`, `GET`, form, 'chat');
-				if (res.errcode == '0') {
-					if (res.data && e.shop) {
+				// 查询该用户与该店铺是否有房间
+				let arr = await that.$api(`/room`, `GET`, form, 'chat');
+				if (arr.errcode == '0' && arr.total > 0) { //有直接进入
+					if (arr.data && e.shop) {
 						uni.navigateTo({
-							url: `/pagesMessage/message/info?id=${res.data._id}&name=${e.shop.name}`
+							url: `/pagesMessage/message/info?id=${arr.data._id}`
 						})
 					}
+				} else { //没有创建进入
+					let res = await that.$api(`/room`, `POST`, form, 'chat');
+					if (res.errcode == '0') {
+						if (res.data && e.shop) {
+							uni.navigateTo({
+								url: `/pagesMessage/message/info?id=${res.data._id}`
+							})
+						}
+					}
 				}
 			},
 			// 输入框