12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226 |
- <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/info?id=${e.content}&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 {
- .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: var(--fFB1Color);
- 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 {
- .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: var(--fFB1Color);
- }
- .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;
- }
- .msg-goods {
- display: flex;
- padding: 10rpx;
- background-color: #f0f0f0;
- border-radius: 0rpx 20rpx 20rpx 20rpx;
- }
- .msg-order {
- width: 460rpx;
- padding: 10rpx;
- background-color: #f0f0f0;
- 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;
- }
- .msg-goods {
- display: flex;
- padding: 10rpx;
- background-color: #f0f0f0;
- border-radius: 20rpx 0rpx 20rpx 20rpx;
- }
- .msg-order {
- width: 460rpx;
- padding: 10rpx;
- background-color: #f0f0f0;
- 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>
|