186 lines
4.3 KiB
Vue
Raw Normal View History

2022-12-28 10:08:51 +08:00
<template>
2022-12-28 14:54:57 +08:00
<div style="width: 350px;">
2022-12-29 18:20:06 +08:00
当前浏览
2022-12-28 11:23:46 +08:00
<div class="base">
<div>
<img :src="goodsDetail.thumbnail" class="image" />
</div>
<div style="margin-left: 13px">
<a @click="linkToGoods(goodsDetail.goodsId, goodsDetail.id)"> {{ goodsDetail.goodsName }} </a>
<div>
<span style="color: red;">{{ goodsDetail.price }}</span>
2022-12-28 10:08:51 +08:00
</div>
2022-12-28 11:23:46 +08:00
<div v-if="hide">
2022-12-29 18:20:06 +08:00
<el-button class="store-button" type="danger" v-if="!sendFlag && btnHide == 1" size="mini"
@click="submitSendMessage()" plain>发送</el-button>
2022-12-28 11:23:46 +08:00
</div>
</div>
2022-12-28 10:08:51 +08:00
</div>
2022-12-29 18:20:06 +08:00
<hr class="separate" />
2022-12-28 11:23:46 +08:00
</div>
2022-12-28 10:08:51 +08:00
</template>
<script>
import { Tag, button } from 'element-ui'
import { mapState, mapGetters } from "vuex";
2022-12-29 18:20:06 +08:00
import SocketInstance from "@/im-server/socket-instance";
2022-12-28 10:08:51 +08:00
export default {
2022-12-28 11:23:46 +08:00
data () {
return {
2022-12-29 18:20:06 +08:00
sendFlag: false,
2022-12-28 11:23:46 +08:00
btnHide: undefined,
hide: true
}
},
computed: {
...mapGetters(["talkItems"]),
...mapState({
id: (state) => state.user.id,
2022-12-29 18:20:06 +08:00
index_name: (state) => state.dialogue.index_name,
2022-12-28 11:23:46 +08:00
toUser: (state) => state.user.toUser,
}),
},
mounted () {
2022-12-29 18:20:06 +08:00
this.btnHide = localStorage.getItem('btnHide')
2022-12-28 11:23:46 +08:00
},
components: {
"el-tag": Tag,
"el-button": button,
Storage
},
methods: {
toGoods () {
alert("toGoods")
2022-12-28 10:08:51 +08:00
},
2022-12-28 11:23:46 +08:00
toMessage () {
alert(JSON.stringify(this.toUser))
alert("toMessage")
2022-12-28 10:08:51 +08:00
},
2022-12-28 11:23:46 +08:00
// 回车键发送消息回调事件
submitSendMessage () {
console.log("发送");
2022-12-29 18:20:06 +08:00
const context = this.goodsDetail
2022-12-28 11:23:46 +08:00
const record = {
operation_type: "MESSAGE",
to: this.toUser.userId,
from: this.id,
message_type: "GOODS",
context: context,
talk_id: this.toUser.id,
};
2022-12-29 18:20:06 +08:00
SocketInstance.emit("event_talk", record);
this.$store.commit("UPDATE_TALK_ITEM", {
index_name: this.index_name,
draft_text: "",
});
/**
* 插入数据
*/
const insterChat = {
createTime: this.formateDateAndTimeToString(new Date()),
fromUser: this.id,
toUser: record.to,
isRead: false,
messageType: "GOODS",
text: context,
float: "right",
};
console.log("insterChat", insterChat);
// console.log("插入对话记录",'')
// 插入对话记录
this.$store.commit("PUSH_DIALOGUE", insterChat);
// 获取聊天面板元素节点
let el = document.getElementById("lumenChatPanel");
// 判断的滚动条是否在底部
let isBottom =
Math.ceil(el.scrollTop) + el.clientHeight >= el.scrollHeight;
if (isBottom || record.to == this.id) {
this.$nextTick(() => {
el.scrollTop = el.scrollHeight;
});
} else {
this.$store.commit("SET_TLAK_UNREAD_MESSAGE", {
content: content,
nickname: record.name,
});
}
2022-12-28 11:23:46 +08:00
// 发送后隐藏按钮 0隐藏 1显示
2022-12-29 18:20:06 +08:00
localStorage.setItem('btnHide', 0)
2022-12-28 11:23:46 +08:00
this.hide = false
},
2022-12-28 10:08:51 +08:00
2022-12-29 18:20:06 +08:00
formateDateAndTimeToString (date) {
var hours = date.getHours();
var mins = date.getMinutes();
var secs = date.getSeconds();
var msecs = date.getMilliseconds();
if (hours < 10) hours = "0" + hours;
if (mins < 10) mins = "0" + mins;
if (secs < 10) secs = "0" + secs;
if (msecs < 10) secs = "0" + msecs;
return (
this.formatDateToString(date) + " " + hours + ":" + mins + ":" + secs
);
},
formatDateToString (date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
return year + "-" + month + "-" + day;
},
2022-12-28 11:23:46 +08:00
},
props: {
goodsDetail: {
type: Object,
default: null,
},
},
2022-12-28 10:08:51 +08:00
}
</script>
<style scoped lang="less">
.store-button {
2022-12-28 11:23:46 +08:00
background-color: white;
border-color: #F56C6C;
2022-12-28 10:08:51 +08:00
}
.base {
2022-12-28 11:23:46 +08:00
margin-top: 5px;
height: 120px;
display: flex;
2022-12-28 10:08:51 +08:00
2022-12-28 14:54:57 +08:00
div {
2022-12-28 11:25:40 +08:00
overflow: hidden;
text-overflow: ellipsis;
2022-12-28 11:22:54 +08:00
margin-top: 8px;
2022-12-28 11:25:40 +08:00
white-space: nowrap;
margin-top: 8px;
}
2022-12-28 14:54:57 +08:00
.image {
2022-12-28 11:23:46 +08:00
height: 100px;
margin-top: 3px;
width: 100px
}
2022-12-28 10:08:51 +08:00
}
2022-12-28 11:25:40 +08:00
.click-button {
margin-top: 8px;
background-color: white;
border-color: #F56C6C;
2022-12-28 11:22:54 +08:00
}
2022-12-28 11:25:40 +08:00
2022-12-28 10:08:51 +08:00
.separate {
2022-12-28 11:23:46 +08:00
margin-top: 8px;
2022-12-28 10:08:51 +08:00
}
</style>