<template>
	<mobile-frame>
		<view class="main">
			<view class="one">
				<!-- 聊天内容 -->
				<scroll-view class="scroll-view" scroll-y="true" scroll-with-animation="true"
					:scroll-into-view="scrollToView" refresher-enabled="true" :refresher-triggered="triggered"
					@refresherrefresh="getFresh">
					<view class="list-scroll-view">
						<view class="chat-ls" v-for="(item,index) in msgList" :key="index" :id="'msg'+ item._id">
							<view class="chat-time" v-if="item.time != ''">
								{{item.time}}
							</view>
							<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.msg_type =='0'">                           
									<view class="msg-text">{{item.content}}</view>
								</view>
								<!-- 图像 -->
								<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 class="message img" v-else-if="item.msg_type =='2'" @tap="toView(item)">
									<view class="msg-goods">
										<image :src="item.goodsInfo&&item.goodsInfo.file" class="image"
											mode="scaleToFill">
										</image>
										<view class="goods_1">
											<view class="name textOver">{{item.goodsInfo&&item.goodsInfo.name}}</view>
											<view class="money">
												<text class="money_1"
													v-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.leader_price"><text>团长价¥</text>{{item.goodsInfo.spec.leader_price||0}}</text>
												<text class="money_2"
													v-else-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.price"><text>特价¥</text>{{item.goodsInfo.spec.price||0}}</text>
												<text class="money_2"
													v-else><text>¥</text>{{item.goodsInfo.spec.sell_money||0}}</text>
												<text
													class="money_2"><text>¥</text>{{item.goodsInfo.spec.flow_money||0}}</text>
											</view>
											<view class="act" v-if="item.goodsInfo&&item.goodsInfo.act">
												<text class="label" v-for="(tag,index) in item.goodsInfo.act"
													:key="index">{{tag}}</text>
											</view>
											<view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
												<text>发送连接</text>
											</view>
										</view>
									</view>
								</view>
								<!-- 订单 -->
								<view class="message img" v-else-if="item.msg_type =='3'" @tap="toView(item)">
									<view class="msg-order">
										<view class="order_1">
											<view class="image" v-for="(tago,index) in item.ordernfo.goods"
												:key="index">
												<image v-if="tago.file.length>0" :src="tago.file&&tago.file[0].url"
													class="image" mode="scaleToFill">
												</image>
												<image v-else :src="tago.goods&&tago.goods.file[0].url" class="image"
													mode="scaleToFill">
												</image>
											</view>
										</view>
										<view class="order_2">
											<view class="no">订单号：{{item.ordernfo.no}}</view>
											<view class="status">
												<text>{{item.ordernfo.status}}</text>
												<view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
													<text>发送连接</text>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
							<view class="msg-m msg-right" v-else-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.msg_type =='0'">
									<view class="msg-text">{{item.content}}</view>
								</view>
								<!-- 图像 -->
								<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 class="message img" v-else-if="item.msg_type =='2'" @tap="toView(item)">
									<view class="msg-goods">
										<image :src="item.goodsInfo&&item.goodsInfo.file" class="image"
											mode="scaleToFill">
										</image>
										<view class="goods_1">
											<view class="name textOver">{{item.goodsInfo&&item.goodsInfo.name}}</view>
											<view class="money">
												<text class="money_1"
													v-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.leader_price"><text>团长价¥</text>{{item.goodsInfo.spec.leader_price||0}}</text>
												<text class="money_2"
													v-else-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.price"><text>特价¥</text>{{item.goodsInfo.spec.price||0}}</text>
												<text class="money_2"
													v-else><text>¥</text>{{item.goodsInfo.spec.sell_money||0}}</text>
												<text
													class="money_2"><text>¥</text>{{item.goodsInfo.spec.flow_money||0}}</text>
											</view>
											<view class="act" v-if="item.goodsInfo&&item.goodsInfo.act">
												<text class="label" v-for="(tag,index) in item.goodsInfo.act"
													:key="index">{{tag}}</text>
											</view>
											<view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
												<text>发送连接</text>
											</view>
										</view>
									</view>
								</view>
								<!-- 订单 -->
								<view class="message img" v-else-if="item.msg_type =='3'" @tap="toView(item)">
									<view class="msg-order">
										<view class="order_1">
											<view class="images" v-for="(tago,index) in item.ordernfo.goods"
												:key="index">
												<image v-if="tago.file.length>0" :src="tago.file&&tago.file[0].url"
													class="image" mode="scaleToFill">
												</image>
												<image v-else :src="tago.goods&&tago.goods.file[0].url" class="image"
													mode="scaleToFill">
												</image>
											</view>
										</view>
										<view class="order_2">
											<view class="no">订单号：{{item.ordernfo.no}}</view>
											<view class="status">
												<text>{{item.ordernfo.status}}</text>
												<view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
													<text>发送连接</text>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="two">
				<submit_1 @choseImg="choseImg" @inputs="inputs" @heights="heights" @sendGoods="sendGoods"
					@sendOrder="sendOrder"></submit_1>
			</view>
		</view>
		<!-- 规格 -->
		<uni-popup ref="specShow" background-color="#fff" type="bottom" :is-mask-click="false">
			<view class="popup">
				<view class="close">
					<text @click="toClose" class="iconfont icon-shanchu"></text>
				</view>
				<view class="info_1" v-if="popupShow=='1'">
					<goods_1 :marketList="list" @toPage="toPage" @toSend="toGoods"></goods_1>
				</view>
				<view class="info_1" v-else-if="popupShow=='2'">
					<order_1 :tabs="tabs" :status="status" :orderList="list" @toPage="toPage" @toSend="toOrder"
						@tabsChange="tabsChange">
					</order_1>
				</view>
			</view>
		</uni-popup>
	</mobile-frame>
</template>

<script>
	import moment from 'moment';
	import submit_1 from './components/submit_1.vue';
	import goods_1 from './components/goods_1.vue';
	import order_1 from './components/order_1.vue';
	export default {
		components: {
			submit_1,
			goods_1,
			order_1,
		},
		data() {
			return {
				// 用户信息
				user: {},
				// 房间号id
				id: '',
				// 店铺信息
				shop: {},
				shop_id: "",
				// 商品或订单信息条件
				goods: {},
				// 订单状态
				statusList: [],
				// 历史记录
				msgList: [],
				// 订单列表
				list: [],
				status: '0',
				tabs: {
					active: '0',
					menu: []
				},
				// 聊天记录
				total: 0,
				skip: 0,
				limit: 6,
				page: 0,
				// 判断是否跳到最后一条
				is_bottom: true,
				// 判断是否下拉刷新复位
				triggered: false,
				scrollToView: '', //滑动最后一条信息
				// 规格弹框
				popupShow: '1',
				// 判断是否是选择图片刷新
				is_img: false
			};
		},
		onShow: async function() {
			const that = this;
			// 判断是否是选择图片刷新
			if (!that.is_img) {
				if (that.id) {
					await that.clearPage();
					await that.search()
				}
				await that.searchOther();
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `goods`, e);
			that.$set(that, `id`, e.id);
			that.$set(that, `shop_id`, e.shop);
			that.watchlogin();
		},
		computed: {
			listenWebsocket() {
				return this.$store.state.websocketData;
			}
		},
		watch: {
			listenWebsocket: async function(newstr) {
				const that = this;
				if (newstr && newstr.type == 'chat' && newstr.room == that.id) {
					if (newstr.msg_type == '2') {
						// 商品
						res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
							id: newstr.content
						});
						if (res.errcode == '0') {
							let indexSpecs;
							// 显示最低价格的规格信息,不考虑库存问题
							if (res.data.specs && res.data.specs.length > 0) {
								// 规格排序
								indexSpecs = res.data.specs.sort(function(a, b) {
									let i, j;
									if (a.price) i = 'price'
									else i = 'sell_money'
									if (b.price) j = 'price'
									else j = 'sell_money'
									return a[i] - b[j];
								})
							}
							let act = res.data.act.map(i => {
								return i.tag
							})
							let goodsInfo = {
								"file": res.data && res.data.goods && res.data.goods.file && res.data.goods
									.file[0]
									.url,
								"name": res.data && res.data.goods && res.data.goods.name,
								"spec": indexSpecs[0],
								"act": act,
							}
							newstr.goodsInfo = goodsInfo
							newstr.is_send = '1'
						}
					} else if (newstr.msg_type == '3') {
						// 订单
						res = await that.$api(`/viewOrder/getOrder/${newstr.content}`)
						if (res.errcode == '0') {
							let status = that.statusList.find(i => i.value == res.data.status)
							// 过滤店铺订单
							let shop_goods;
							if (res.data.status != '0') {
								// 已支付订单
								shop_goods = res.data.goods
							} else {
								// 未支付订单
								if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
								else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
								if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
							}
							let ordernfo = {
								"no": res.data && res.data.no,
								"goods": shop_goods,
								"status": status.label || '暂无',
								"is_status": res.data.status
							}
							newstr.ordernfo = ordernfo
							newstr.is_send = '1'
						}
					}
					that.msgList.push(newstr);
					that.goBottom();
				}
			}
		},
		methods: {
			// 监听用户是否登录
			watchlogin() {
				const that = this;
				uni.getStorage({
					key: 'token',
					success: async function(res) {
						let user = that.$jwt(res.data);
						if (user) {
							// 查询状态
							let arr = await that.$api(`/dictData`, 'GET', {
								code: 'order_process'
							})
							if (arr.errcode == '0') that.$set(that, `statusList`, arr.data);
							that.$set(that, `user`, user)
						}
					}
				})
			},
			// 查询商品或订单信息
			async searchOther() {
				const that = this;
				let res;
				let statusList = that.statusList.filter((i) => {
					return i.value != '-2' && i.value != '-3';
				});
				var menu = statusList.map((item) => {
					return {
						title: item.label,
						active: item.value
					}
				})
				that.$set(that.tabs, `menu`, menu)
				// 发送商品信息
				if (that.goods && that.goods.goods) {
					// 商品
					res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
						id: that.goods.goods
					});
					if (res.errcode == '0') {
						let indexSpecs;
						// 显示最低价格的规格信息,不考虑库存问题
						if (res.data.specs && res.data.specs.length > 0) {
							// 规格排序
							indexSpecs = res.data.specs.sort(function(a, b) {
								let i, j;
								if (a.price) i = 'price'
								else i = 'sell_money'
								if (b.price) j = 'price'
								else j = 'sell_money'
								return a[i] - b[j];
							})
						}
						let act = res.data.act.map(i => {
							return i.tag
						})
						let goodsInfo = {
							"file": res.data && res.data.goods && res.data.goods.file && res.data.goods.file[0]
								.url,
							"name": res.data && res.data.goods && res.data.goods.name,
							"spec": indexSpecs[0],
							"act": act
						}
						let data = {
							"_id": 'goods' + moment(new Date()).valueOf(),
							"speaker": that.user._id,
							"content": that.goods.goods,
							"goodsInfo": goodsInfo,
							"time": moment().format('YYYY-MM-DD HH:mm:ss'),
							"msg_type": '2',
							"is_send": '0'
						}
						if (!that.id) data.shop = that.shop_id
						else data.room = that.id
						that.msgList.push(data);
					}
				} else if (that.goods && that.goods.order) {
					// 订单
					if (that.goods.status == '0') res = await that.$api(`/order/${that.goods.order}`)
					else res = await that.$api(`/orderDetail/${that.goods.order}`);
					if (res.errcode == '0') {
						let status = that.statusList.find(i => i.value == res.data.status)
						// 过滤店铺订单
						let shop_goods;
						if (that.goods.status != '0') {
							// 已支付订单
							shop_goods = res.data.goods
						} else {
							// 未支付订单
							if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
							else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
							if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
						}
						let ordernfo = {
							"no": res.data && res.data.no,
							"goods": shop_goods,
							"status": status.label || '暂无',
							"is_status": res.data.status
						}
						let data = {
							"_id": 'order' + moment(new Date()).valueOf(),
							"speaker": that.user._id,
							"content": that.goods.order,
							"ordernfo": ordernfo,
							"time": moment().format('YYYY-MM-DD HH:mm:ss'),
							"msg_type": '3',
							"is_send": '0'
						}
						if (!that.id) data.shop = that.shop_id
						else data.room = that.id
						that.msgList.push(data);
					}
				}
				// 跳转到最后一条数据 与前面的:id进行对照
				// 如果是下拉刷新聊天记录不跳到最后一条
				if (that.is_bottom == true) that.goBottom();
			},
			// 查询历史记录
			async search() {
				const that = this;
				// 查询房间信息
				// 如果是下拉刷新聊天记录不请求房间信息
				if (that.is_bottom == true) {
					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 info = {
					skip: that.skip,
					limit: that.limit,
					room: that.id
				}
				let res;
				res = await that.$api(`/chatRecord`, `GET`, {
					...info,
				}, 'chat');
				if (res.errcode == '0') {
					let msgList = [...res.data, ...that.msgList];
					msgList.sort(function(a, b) {
						return a.time > b.time ? 1 : -1;
					});
					that.$set(that, `total`, res.total)
					for (let val of msgList) {
						if (val.msg_type == '2') {
							// 商品
							res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
								id: val.content
							});
							if (res.errcode == '0') {
								let indexSpecs;
								// 显示最低价格的规格信息,不考虑库存问题
								if (res.data.specs && res.data.specs.length > 0) {
									// 规格排序
									indexSpecs = res.data.specs.sort(function(a, b) {
										let i, j;
										if (a.price) i = 'price'
										else i = 'sell_money'
										if (b.price) j = 'price'
										else j = 'sell_money'
										return a[i] - b[j];
									})
								}
								let act = res.data.act.map(i => {
									return i.tag
								})
								let goodsInfo = {
									"file": res.data && res.data.goods && res.data.goods.file && res.data.goods
										.file[0]
										.url,
									"name": res.data && res.data.goods && res.data.goods.name,
									"spec": indexSpecs[0],
									"act": act,
								}
								val.goodsInfo = goodsInfo
								val.is_send = '1'
							}
						} else if (val.msg_type == '3') {
							// 订单
							res = await that.$api(`/viewOrder/getOrder/${val.content}`)
							if (res.errcode == '0') {
								let status = that.statusList.find(i => i.value == res.data.status)
								// 过滤店铺订单
								let shop_goods;
								if (res.data.status != '0') {
									// 已支付订单
									shop_goods = res.data.goods
								} else {
									// 未支付订单
									if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
									else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
									if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
								}
								let ordernfo = {
									"no": res.data && res.data.no,
									"goods": shop_goods,
									"status": status.label || '暂无',
									"is_status": res.data.status
								}
								val.ordernfo = ordernfo
								val.is_send = '1'
							}
						}
					}
					that.$set(that, `msgList`, msgList);
				} else {
					uni.showToast({
						title: res.errmsg,
						icon: 'none'
					})
				}
				let id = that.msgList.filter(i => {
					if (i.speaker != that.user._id) return i.is_read = '0';
				})
				let ids = id.map(i => {
					return i._id
				})
				if (ids.length > 0) {
					// 信息已读
					res = await that.$api(`/chatRecord/read`, `POST`, {
						ids
					}, 'chat')
					if (res.errcode == '0') {} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none'
						})
					}
				}
			},
			// 进行图片的预览
			previewImg(e) {
				const that = this;
				// 预览图片
				uni.previewImage({
					current: 0,
					urls: [e],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) +
								'张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			// 判断是否是选择图片刷新
			choseImg(e) {
				const that = this;
				that.$set(that, `is_img`, e)
			},
			//接受输入内容
			async inputs(e) {
				const that = this;
				let user = that.user
				if (user._id) {
					//时间间隔处理
					let data = {
						"speaker": user._id,
						"content": e.message,
						"time": moment().format('YYYY-MM-DD HH:mm:ss'),
						"msg_type": e.type
					};
					// 发送给服务器消息
					if (!that.id) data.shop = that.shop_id
					else data.room = that.id
					let res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
					if (res.errcode == '0') {
						that.msgList.push(res.data);
					} else {
						uni.showToast({
							title: res.errmsg,
							icon: 'none'
						})
					}
					// 跳转到最后一条数据 与前面的:id进行对照
					that.goBottom();
				} else {
					uni.showToast({
						title: '未登录账号无法发送消息 ，请及时登录！',
						icon: 'none'
					})
				}
			},
			// 发送连接
			async toSend(e) {
				const that = this;
				//时间间隔处理
				let data = {
					"speaker": e.speaker,
					"content": e.content,
					"time": moment().format('YYYY-MM-DD HH:mm:ss'),
					"msg_type": e.msg_type
				};
				if (!that.id) data.shop = that.shop_id
				else data.room = that.id
				let res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
				if (res.errcode == '0') {
					e.is_send = '1'
					that.msgList = that.msgList.map(t => {
						return t.time === e.time ? e : t;
					});
				} else {
					uni.showToast({
						title: res.errmsg,
						icon: 'none'
					})
				}
			},
			// 发送商品
			async sendGoods() {
				const that = this;
				let res;
				let info = {
					skip: that.skip,
					limit: that.limit,
					shop: that.shop._id || that.shop_id
				};
				// 首页产品列表
				res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
					...info
				});
				if (res.errcode == '0') {
					let list = [...that.list, ...res.data];
					that.$set(that, `list`, list);
					that.$set(that, `total`, res.total)
					that.$set(that, `popupShow`, '1')
					that.$refs.specShow.open();
				}
			},
			// 发送商品
			async toGoods(e) {
				const that = this;
				let user = that.user
				if (user._id) {
					let res;
					// 商品
					res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
						id: e._id
					});
					if (res.errcode == '0') {
						let indexSpecs;
						// 显示最低价格的规格信息,不考虑库存问题
						if (res.data.specs && res.data.specs.length > 0) {
							// 规格排序
							indexSpecs = res.data.specs.sort(function(a, b) {
								let i, j;
								if (a.price) i = 'price'
								else i = 'sell_money'
								if (b.price) j = 'price'
								else j = 'sell_money'
								return a[i] - b[j];
							})
						}
						let act = res.data.act.map(i => {
							return i.tag
						})
						let goodsInfo = {
							"file": res.data && res.data.goods && res.data.goods.file && res.data.goods
								.file[0]
								.url,
							"name": res.data && res.data.goods && res.data.goods.name,
							"spec": indexSpecs[0],
							"act": act,
						}
						//时间间隔处理
						let data = {
							"speaker": user._id,
							"content": e._id,
							"time": moment().format('YYYY-MM-DD HH:mm:ss'),
							"msg_type": '2',
						};
						if (!that.id) data.shop = that.shop_id
						else data.room = that.id
						res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
						if (res.errcode == '0') {
							res.data.goodsInfo = goodsInfo
							res.data.is_send = '1'
							that.msgList.push(res.data);
						} else {
							uni.showToast({
								title: res.errmsg,
								icon: 'none'
							})
						}
					}
					// 跳转到最后一条数据 与前面的:id进行对照
					that.goBottom();
					that.toClose();
				} else {
					uni.showToast({
						title: '未登录账号无法发送消息 ，请及时登录！',
						icon: 'none'
					})
				}
			},
			// 分页
			toPage(e) {
				const that = this;
				let list = that.list;
				let limit = that.limit;
				if (that.total > list.length) {
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					let page = that.page + 1;
					that.$set(that, `page`, page)
					let skip = page * limit;
					that.$set(that, `skip`, skip)
					if (that.popupShow == '1') that.sendGoods();
					else that.sendOrder();
					uni.hideLoading();
				}
			},
			// 发送订单
			async sendOrder() {
				const that = this;
				let user = that.user;
				let status = that.status;
				let info = {
					skip: that.skip,
					limit: that.limit,
					customer: user._id,
					shop: that.shop._id || that.shop_id,
					status: status
				}
				let res;
				if (status == '0') {
					res = await that.$api(`/order`, 'GET', {
						...info,
					});
				} else {
					res = await that.$api(`/orderDetail`, 'GET', {
						...info,
					});
				}
				if (res.errcode == '0') {
					let list = [...that.list, ...res.data];
					for (let val of list) {
						val.zhStatus = that.searchStatus(val.status)
					}
					that.$set(that, `list`, list);
					that.$set(that, `total`, res.total)
					that.$set(that, `popupShow`, '2')
					that.$refs.specShow.open();
				} else {
					uni.showToast({
						title: res.errmsg,
						icon: 'none'
					})
				}
			},
			// 发送订单
			async toOrder(e) {
				const that = this;
				let user = that.user
				if (user._id) {
					let res;
					// 订单
					if (e.status == '0') res = await that.$api(`/order/${e._id}`)
					else res = await that.$api(`/orderDetail/${e._id}`);
					if (res.errcode == '0') {
						let status = that.statusList.find(i => i.value == res.data.status)
						// 过滤店铺订单
						let shop_goods;
						if (e.status != '0') {
							// 已支付订单
							shop_goods = res.data.goods
						} else {
							// 未支付订单
							if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
							else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
							if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
						}
						let ordernfo = {
							"no": res.data && res.data.no,
							"goods": shop_goods,
							"status": status.label || '暂无',
							"is_status": res.data.status
						}
						//时间间隔处理
						let data = {
							"speaker": user._id,
							"content": e._id,
							"time": moment().format('YYYY-MM-DD HH:mm:ss'),
							"msg_type": '3',
						};
						if (!that.id) data.shop = that.shop_id
						else data.room = that.id
						res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
						if (res.errcode == '0') {
							res.data.ordernfo = ordernfo
							res.data.is_send = '1'
							that.msgList.push(res.data);
						} else {
							uni.showToast({
								title: res.errmsg,
								icon: 'none'
							})
						}
					}
					// 跳转到最后一条数据 与前面的:id进行对照
					that.goBottom();
					that.toClose();
				} else {
					uni.showToast({
						title: '未登录账号无法发送消息 ，请及时登录！',
						icon: 'none'
					})
				}
			},
			// 查询状态
			searchStatus(e) {
				const that = this;
				let data = that.statusList.find((i) => i.value == e);
				if (data) return data.label
				else return '暂无'
			},
			// 选择选项卡
			tabsChange(e) {
				const that = this;
				that.$set(that.tabs, `active`, e.active)
				that.$set(that, `status`, e.active);
				that.$set(that, `list`, [])
				that.$set(that, `skip`, 0)
				that.$set(that, `limit`, 6)
				that.$set(that, `page`, 0)
				that.sendOrder()
			},
			// 关闭弹框
			toClose() {
				const that = this;
				that.$refs.specShow.close();
				that.$set(that, `list`, [])
				that.$set(that, `skip`, 0)
				that.$set(that, `limit`, 6)
				that.$set(that, `page`, 0)
			},
			// 店铺
			toShop() {
				const that = this;
				let id = that.shop._id
				uni.navigateTo({
					url: `/pagesHome/shop/index?id=${id}`
				})
			},
			// 查看详情
			toView(e) {
				const that = this;
				if (e.msg_type == '2') {
					let id = e.content;
					uni.navigateTo({
						url: `/pagesHome/order/detail?id=${id}`
					})
				} else {
					let status = e.ordernfo.is_status;
					uni.navigateTo({
						url: `/pagesMy/order/index?status=${status}`
					})
				}
			},
			//输入框高度
			heights(e) {
				const that = this;
				that.goBottom();
			},
			// 滚动到底部
			async goBottom() {
				const that = this;
				that.scrollToView = '';
				let lastItem = that.msgList.at(-1);
				that.$nextTick(function() {
					that.scrollToView = 'msg' + (lastItem._id)
				})
			},
			// 下拉刷新分页
			getFresh(e) {
				const that = this;
				that.$set(that, `triggered`, true)
				that.$set(that, `is_img`, false)
				let msgList = that.msgList;
				let limit = that.limit;
				setTimeout(() => {
					if (that.total > msgList.length) {
						uni.showLoading({
							title: '加载中',
							mask: true
						})
						let page = that.page + 1;
						that.$set(that, `page`, page)
						let skip = page * limit;
						that.$set(that, `skip`, skip)
						that.$set(that, `is_bottom`, false)
						that.search();
						uni.hideLoading();
					} else {
						uni.showToast({
							title: `没有更多聊天记录了`,
							icon: 'none'
						})
					}
					that.triggered = false;
				}, 1000)
			},
			clearPage() {
				const that = this;
				that.$set(that, `msgList`, [])
				that.$set(that, `skip`, 0)
				that.$set(that, `limit`, 6)
				that.$set(that, `page`, 0)
			},
		}
	}
</script>

<style lang="scss">
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;
		overflow: hidden;

		.one {
			position: relative;
			flex-grow: 1;

			.scroll-view {

				.chat-ls {
					padding: 2vw 2vw 0 2vw;

					.chat-time {
						font-size: 24rpx;
						color: rgba(39, 40, 50, 0.3);
						line-height: 34rpx;
						padding: 10rpx 0rpx;
						text-align: center;
					}

					.msg-m {
						display: flex;
						padding: 20rpx 0;

						.user-img {
							flex: none;
							width: 80rpx;
							height: 80rpx;
							border-radius: 40rpx;
							border: 1px solid #c0c0c0;
						}

						.message {
							flex: none;
							max-width: 480rpx;
						}

						.img {
							margin: 0 20rpx;
						}

						.msg-text {
							font-size: 32rpx;
							color: rgba(39, 40, 50, 1);
							line-height: 44rpx;
							padding: 18rpx 24rpx;
							word-break: break-all;
						}

						.msg-img {
							max-width: 400rpx;
							border-radius: 20rpx;
						}

						.msg-goods {
							display: flex;
							padding: 10rpx;
							background-color: #f0f0f0;
							border-radius: 20rpx 0rpx 20rpx 20rpx;

							.image {
								width: 100rpx;
								height: 100rpx;
								border-radius: 10rpx;
							}

							.goods_1 {
								width: 350rpx;
								margin: 0 0 0 10rpx;

								.name {
									font-size: 14px;
								}

								.money {
									.money_1 {
										color: #23B67A;
										font-size: 16px;
										padding: 0 1vw 0 0;
										font-weight: bold;

										text {
											font-size: 12px;
										}
									}

									.money_2 {
										font-size: 16px;
										padding: 0 1vw 0 0;
										color: #ff0000;
										font-weight: bold;

										text {
											font-size: 12px;
										}
									}

									.money_2:last-child {
										font-size: 14px;
										color: #858585;
										text-decoration: line-through;
									}
								}

								.act {
									.label {
										font-size: 12px;
										color: #FFA500;
										border: 1px solid #FFA500;
										border-radius: 5px;
										padding: 0 1vw;
										margin: 0 1vw 0 0;
									}
								}

								.button {
									text-align: right;
									margin: 5rpx 0 10rpx 0;

									text {
										font-size: 12px;
										padding: 10rpx;
										border-radius: 10rpx;
										color: #FF4500;
										background-color: #FFF8DC;
									}
								}
							}
						}

						.msg-order {
							width: 460rpx;
							padding: 10rpx;
							background-color: #f0f0f0;
							border-radius: 20rpx 0rpx 20rpx 20rpx;

							.order_1 {
								display: flex;
								flex-wrap: wrap;

								.image {
									width: 100rpx;
									height: 100rpx;
									border-radius: 10rpx;
									margin: 0 5rpx 0 0;
									border: 1rpx solid #858585;
								}
							}

							.order_2 {

								.no {
									font-size: 12px;
								}

								.status {
									display: flex;
									justify-content: space-between;
									margin: 5rpx 0;

									text {
										padding: 1rpx 2rpx;
										border-radius: 5px;
										font-size: 12px;
										color: #ff0000;
									}

									.button {
										text-align: right;

										text {
											font-size: 12px;
											padding: 10rpx;
											border-radius: 10rpx;
											color: #FF4500;
											background-color: #FFF8DC;
										}
									}
								}
							}
						}
					}

					.msg-left {
						flex-direction: row;

						.msg-text {
							word-break: break-all;
							margin-left: 16rpx;
							background-color: #f1f1f1;
							border-radius: 0rpx 20rpx 20rpx 20rpx;
						}

						.ms-img {
							margin-left: 16rpx;
						}

					}

					.msg-right {
						flex-direction: row-reverse;

						.msg-text {
							margin-right: 16rpx;
							background-color: rgba(255, 228, 49, 0.8);
							border-radius: 20rpx 0rpx 20rpx 20rpx;
						}

						.ms-img {
							margin-right: 16rpx;
						}
					}
				}
			}
		}

		.two {
			background-color: #f0f0f0;
			border-top: 1px solid rgba(39, 40, 50, 0.1);
		}
	}

	.uni-popup {
		z-index: 9999 !important;
	}

	.popup {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 80vh;

		.close {
			text-align: right;
			padding: 2vw;
		}

		.info_1 {
			position: relative;
			display: flex;
			flex-direction: column;
			height: 74vh;
		}
	}

	.scroll-view {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.list-scroll-view {
			display: flex;
			flex-direction: column;
		}
	}
</style>
