|
|
@@ -1,28 +1,41 @@
|
|
|
<config>
|
|
|
{
|
|
|
- "navigationBarTitleText":'光之城-卡牌',
|
|
|
+ "navigationBarTitleText":'',
|
|
|
"backgroundColor":"#F5F7FA"
|
|
|
}
|
|
|
</config>
|
|
|
<template>
|
|
|
<div class="page">
|
|
|
- <div class="chat-list" @click="showAttach = false">
|
|
|
- <!-- <div class="product">
|
|
|
- <product-info :showBtn="false"></product-info>
|
|
|
- </div> -->
|
|
|
+ <div
|
|
|
+ id="chat-list"
|
|
|
+ class="chat-list"
|
|
|
+ @click="showAttach = false"
|
|
|
+ :style="{ paddingBottom: `calc(${100 + attachHeight}px + env(safe-area-inset-bottom))` }"
|
|
|
+ >
|
|
|
<chat-info
|
|
|
v-for="(item, index) in list"
|
|
|
:key="index"
|
|
|
:info="item"
|
|
|
:isMine="userInfo && item.sendId === userInfo.id"
|
|
|
+ :contentType="item.messageType"
|
|
|
></chat-info>
|
|
|
+
|
|
|
+ <div class="loading" v-if="loading">
|
|
|
+ <van-loading size="24px">加载中...</van-loading>
|
|
|
+ </div>
|
|
|
<!-- <chat-info isMine></chat-info>
|
|
|
<chat-info isMine contentType="image"></chat-info> -->
|
|
|
</div>
|
|
|
|
|
|
<div class="bottom-box">
|
|
|
<div class="input-box">
|
|
|
- <van-field :boder="false" placeholder="请输入需要咨询的问题" :value="message" />
|
|
|
+ <van-field
|
|
|
+ :boder="false"
|
|
|
+ placeholder="请输入需要咨询的问题"
|
|
|
+ :value="message"
|
|
|
+ @input="message = $event.detail"
|
|
|
+ @confirm="confirm"
|
|
|
+ />
|
|
|
|
|
|
<img src="/native/svgs/icon_liaotian_biaoqing.svg" alt="" class="icon" />
|
|
|
<img
|
|
|
@@ -43,8 +56,12 @@
|
|
|
|
|
|
<script>
|
|
|
import ChatInfo from '@/components/ChatInfo';
|
|
|
-import ProductInfo from '@/components/ProductInfo';
|
|
|
import { mapState } from 'vuex';
|
|
|
+import dayjs from 'dayjs';
|
|
|
+import * as calendar from 'dayjs/plugin/calendar';
|
|
|
+import 'dayjs/locale/zh-cn';
|
|
|
+dayjs.locale('zh-cn');
|
|
|
+dayjs.extend(calendar);
|
|
|
export default {
|
|
|
name: 'Chat',
|
|
|
components: {
|
|
|
@@ -56,11 +73,20 @@ export default {
|
|
|
showAttach: false,
|
|
|
topicInfo: null,
|
|
|
list: [],
|
|
|
- toUserId: 0
|
|
|
+ toUserId: 0,
|
|
|
+ loading: true,
|
|
|
+ timeFormat: {
|
|
|
+ sameDay: 'A hh:mm', // The same day ( Today at 2:30 AM )
|
|
|
+ nextDay: '[明天]', // The next day ( Tomorrow at 2:30 AM )
|
|
|
+ nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM )
|
|
|
+ lastDay: 'MM/DD HH:mm', // The day before ( Yesterday at 2:30 AM )
|
|
|
+ lastWeek: 'MM/DD HH:mm', // Last week ( Last Monday at 2:30 AM )
|
|
|
+ sameElse: 'YYYY/MM/DD' // Everything else ( 7/10/2011 )
|
|
|
+ }
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapState(['userInfo']),
|
|
|
+ ...mapState(['userInfo', 'systemInfo']),
|
|
|
attachHeight() {
|
|
|
return this.showAttach ? 114 : 0;
|
|
|
}
|
|
|
@@ -77,33 +103,79 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
loginMethods() {
|
|
|
+ console.log(this.$mp.options.toUserId);
|
|
|
+ let eventChannel = this.$mp.page.getOpenerEventChannel();
|
|
|
+
|
|
|
this.$http
|
|
|
.post('/topic/newTopic', {
|
|
|
- targetId: this.toUserId
|
|
|
+ targetId: this.$mp.options.toUserId
|
|
|
})
|
|
|
.then(res => {
|
|
|
this.topicInfo = res;
|
|
|
return this.getList();
|
|
|
})
|
|
|
.then(() => {
|
|
|
- // this.newMessage('欢迎管理本店,小店客服会尽快为您提供服务。', false, 'TEXT', true);
|
|
|
+ if (eventChannel && eventChannel.on) {
|
|
|
+ eventChannel.on('productInfo', data => {
|
|
|
+ this.newMessage(JSON.stringify(data), true, 'LINK');
|
|
|
+ setTimeout(() => {
|
|
|
+ this.newMessage('欢迎光临本店,小店客服会尽快为您提供服务。', false, 'TEXT', false);
|
|
|
+ }, 1000);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
},
|
|
|
sendImg() {
|
|
|
this.choosePhoto().then(res => {
|
|
|
console.log(res);
|
|
|
+ this.newMessage(res, true, 'IMAGE');
|
|
|
});
|
|
|
},
|
|
|
getList() {
|
|
|
+ this.loading = true;
|
|
|
return this.$http
|
|
|
.get('/message/findTopicMessages', {
|
|
|
topicId: this.topicInfo.id
|
|
|
})
|
|
|
.then(res => {
|
|
|
- this.list = res;
|
|
|
+ this.loading = false;
|
|
|
+ this.list = res.map((item, index) => {
|
|
|
+ let time = '';
|
|
|
+ if (index == 0) {
|
|
|
+ time = dayjs(item.createdAt).calendar(null, this.timeFormat);
|
|
|
+ } else {
|
|
|
+ const date1 = dayjs(item.createdAt);
|
|
|
+ if (date1.diff(res[index - 1].createdAt, 'minute') > 5) {
|
|
|
+ time = dayjs(item.createdAt).calendar(null, this.timeFormat);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ time: time
|
|
|
+ };
|
|
|
+ });
|
|
|
+ this.$nextTick(() => {
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.createSelectorQuery()
|
|
|
+ .select('#chat-list')
|
|
|
+ .boundingClientRect(rect => {
|
|
|
+ wx.pageScrollTo({
|
|
|
+ scrollTop: rect.height + 100
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .exec();
|
|
|
+ }, 100);
|
|
|
+ });
|
|
|
+ this.$http.post('/message/allRead', {
|
|
|
+ topicId: this.topicInfo.id
|
|
|
+ });
|
|
|
return Promise.resolve();
|
|
|
});
|
|
|
},
|
|
|
+ confirm(e) {
|
|
|
+ this.newMessage(e.detail);
|
|
|
+ this.message = '';
|
|
|
+ },
|
|
|
newMessage(info, isSend = true, messageType = 'TEXT', beenRead = false) {
|
|
|
let data = {
|
|
|
topicId: this.topicInfo.id,
|
|
|
@@ -133,11 +205,6 @@ page {
|
|
|
padding: 10px 20px 100px;
|
|
|
}
|
|
|
|
|
|
-.product {
|
|
|
- background-color: #fff;
|
|
|
- padding: 15px;
|
|
|
- border-radius: 12px;
|
|
|
-}
|
|
|
.bottom-box {
|
|
|
.bottom();
|
|
|
background-color: #fff;
|
|
|
@@ -201,4 +268,10 @@ page {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+.loading {
|
|
|
+ padding: 20px;
|
|
|
+ .flex();
|
|
|
+ justify-content: center;
|
|
|
+}
|
|
|
</style>
|