123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- <template>
- <!-- #ifdef H5 -->
- <view class="message_view_page">
- <!-- 横幅 -->
- <view class="gonggao" @click="goFpzn">
- <view>防骗手册,为您保驾护航</view>
- <text class="iconfont icon-jinru"></text>
- </view>
- <!-- 商品信息 -->
- <view class="goods_info">
- <!-- 商品图片 -->
- <view class="goods_img">
- <image v-if="goodsDetail.goodsPicUrl" style="width: 100%; height: 100%;" mode="aspectFill"
- :src="imageUrl + goodsDetail.goodsPicUrl"></image>
- </view>
- <!-- 商品描述 -->
- <view class="goods_text">
- <view class="goods_name">{{goodsDetail.title}}</view>
- <view class="goods_pon">
- <view>
- <view class="goods_jiag">{{goodsDetail.amount?"¥"+goodsDetail.amount:"面议"}}</view>
- <view class="goods_fuwu">卖家包运费</view>
- </view>
- <view class="go_goods_btn" @click="goGoodsDetail">立即购买</view>
- </view>
- </view>
- </view>
- <!-- 聊天内容 -->
- <view class="message_view">
- <scroll-view class="message_view_scroll" :scroll-y="true" :scroll-top="scrollTop" :enhanced="true"
- :bounces="false" :show-scrollbar="false" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">
- <view style="box-sizing: border-box;padding: 10rpx 0;" ref="scrollviewDiv" class="scrollviewDiv">
- <view v-for="(item,index) in list" :key="index">
- <!-- 右消息 -->
- <view class="msg_view" v-if="userId===item.userId">
- <!-- 占位 -->
- <view class="msg_user_img_kong">
- </view>
- <view class="msg_view_info msg_view_info_right">
- <view class="msg_view_conent">
- {{item.message}}
- </view>
- <view class="msg_view_time">{{item.createTime}}</view>
- </view>
- <!-- 头像 -->
- <view class="msg_user_img">
- <image v-if="item.userPic" style="width: 100%; height: 100%;" mode="aspectFill"
- :src="imageUrl + item.userPic"></image>
- <image v-else style="width: 100%; height: 100%;" mode="aspectFill" src="@/static/common/logo.png">
- </image>
- </view>
- </view>
- <!-- 左消息 -->
- <view class="msg_view" v-else>
- <!-- 头像 -->
- <view class="msg_user_img">
- <image v-if="item.userPic" style="width: 100%; height: 100%;" mode="aspectFill"
- :src="imageUrl + item.userPic"></image>
- <image v-else style="width: 100%; height: 100%;" mode="aspectFill" src="@/static/common/logo.png">
- </image>
- </view>
- <view class="msg_view_info msg_view_info_left">
- <view class="msg_view_conent">{{item.message}}</view>
- <view class="msg_view_time">{{item.createTime}}</view>
- </view>
- <!-- 占位 -->
- <view class="msg_user_img_kong">
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </view>
- <!-- 输入框 -->
- <view>
- <view class="text_input_view">
- <view class="text_input_lay">
- <view class="text_input_tengh">
- <input class="uni-input_chat" type="text" confirm-type="send" focus placeholder="请输入" v-model="message" @confirm="send"/>
- </view>
- <!-- 更多功能 -->
- <!-- <view class="text_input_mount" @click="gengduo = !gengduo">
- +
- </view> -->
- <!-- 发送消息 -->
- <view class="text_input_mount" @click="send">
- <image style="width: 50%; height: 53%;" mode="aspectFill" src="/static/tabBar/icon_issue01.png"></image>
- </view>
- </view>
- </view>
- <view v-if="gengduo" class="gengduo_view">
- <view class="gengduo_view_ay">
- <view class="gengduo_view_icon"></view>
- <view class="gengduo_view_name">相册</view>
- </view>
- <view class="gengduo_view_ay">
- <view class="gengduo_view_icon"></view>
- <view class="gengduo_view_name">拍照</view>
- </view>
- <view class="gengduo_view_ay">
- <view class="gengduo_view_icon"></view>
- <view class="gengduo_view_name">位置</view>
- </view>
- <view class="gengduo_view_ay">
- <view class="gengduo_view_icon"></view>
- <view class="gengduo_view_name">举报</view>
- </view>
- </view>
- </view>
- </view>
- <!-- #endif -->
- <!-- #ifndef H5 -->
- <web-view :src="webViewHref('/pages/message/msgView',pam,crossPagePam)" @message="crossPage.$listener"></web-view>
- <!-- #endif -->
- </template>
- <script>
- import api from '@/common/http/'
- export default {
- data() {
- return {
- imageUrl: this.$imageUrl,
- scrollTop: 0,
- gengduo: false,
- pam: {},
- list: [],
- message: "",
- userId: this.$store.state.user.userId,
- goodsDetail: {},
- ids: {},
- sendBool: true
- }
- },
- onLoad(pam) {
- this.pam = pam
- },
- onShow() {
- // #ifdef H5
- this.getGoods()
- this.getMsgList(2, () => {
- this.getNewList()
- this.$nextTick(() => {
- uni.createSelectorQuery().select('.message_view_scroll').boundingClientRect(data => {
- uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data2 => {
- this.scrollTop = data2.height - data.height
- }).exec()
- }).exec()
- })
- })
- // #endif
- },
- onHide() {
- // #ifdef H5
- if (this.timeId) {
- clearTimeout(this.timeId)
- }
- // #endif
- },
- destroyed() {
- // #ifdef H5
- if (this.timeId) {
- clearTimeout(this.timeId)
- }
- // #endif
- },
- methods: {
- // #ifdef H5
- goGoodsDetail() {
- if (!this.pam.goodsId) {
- return
- }
- this.$navToPage({
- url: '/pages/goods/detail?id=' + this.pam.goodsId
- })
- },
- getGoods() {
- if (!this.pam.goodsId) {
- return
- }
- api.postJson('/goods/detail', {
- id: this.pam.goodsId,
- }, false).then(res => {
- this.goodsDetail = res.data
- })
- },
- getNewList() {
- if (this.timeId) {
- clearTimeout(this.timeId)
- }
- uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data1 => {
- this.getMsgList(0, () => {
- this.timeId = setTimeout(this.getNewList, 3000)
- this.$nextTick(() => {
- uni.createSelectorQuery().select('.message_view_scroll').boundingClientRect(data => {
- uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data2 => {
- if (data1.height - data.height - this.scrollTop < 10) {
- this.scrollTop = data2.height - data.height
- }
- }).exec()
- }).exec()
- })
- })
- }).exec()
- },
- getMsgList(flag, cb) {
- api.postJson('/user/talk/list', {
- userId: this.$store.state.user.userId,
- flag: flag,
- ...(() => {
- if (this.pam.goodsId) {
- return {
- goodsId: this.pam.goodsId,
- }
- }
- return {}
- })(),
- ...(() => {
- if (this.pam.groupId) {
- return {
- groupId: this.pam.groupId,
- }
- }
- return {}
- })(),
- ...(() => {
- if (this.list.length) {
- return {
- id: this.list[flag ? 0 : this.list.length - 1].id
- }
- }
- return {}
- })(),
- }, false).then(res => {
- var newlist = res.data.filter(item => {
- var bool = !this.ids[item.id]
- this.ids[item.id] = true
- return bool
- })
- if (flag) {
- this.list.unshift(...newlist)
- } else {
- this.list.push(...newlist)
- }
- cb && cb()
- })
- },
- upper() {
- // console.log("顶")
- uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data => {
- var oldHeight = data.height
- this.getMsgList(1, () => {
- this.$nextTick(() => {
- uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data2 => {
- this.scrollTop = data2.height - oldHeight
- }).exec()
- })
- })
- }).exec()
- },
- lower() {
- // console.log("底")
- },
- scroll(e) {
- this.scrollTop = e.detail.scrollTop
- },
- send() {
- if (!this.sendBool) {
- return
- }
- this.sendBool = false
- if (this.pam.goodsId && this.$store.state.user.userId && this.message) {
- api.postJson('/user/talk/send', {
- message: this.message,
- userId: this.$store.state.user.userId,
- goodsId: this.pam.goodsId,
- ...(() => {
- if (this.pam.groupId) {
- return {
- groupId: this.pam.groupId,
- }
- }
- return {}
- })(),
- }, false).then(res => {
- this.message = ""
- this.getNewList()
- this.sendBool = true
- }).catch(() => {
- this.sendBool = true
- })
- } else {
- this.sendBool = true
- }
- },
- goFpzn(item) {
- this.$navToPage({
- url: '/pages/mine/parse?type=1'
- })
- },
- // #endif
- // #ifndef H5
- // #endif
- },
- }
- </script>
- <style lang="scss" scoped>
- page {
- height: 100%;
- overflow: hidden;
- }
- .message_view_page {
- overflow: hidden;
- width: 100%;
- /* #ifdef H5 */
- height: 100%;
- /* #endif */
- /* #ifndef H5 */
- height: 100vh;
- /* #endif */
- display: flex;
- flex-direction: column;
- .msg_view {
- width: 100%;
- height: auto;
- box-sizing: border-box;
- padding: 10rpx 20rpx;
- display: flex;
- .msg_view_info {
- flex: 1;
- min-height: 80rpx;
- .msg_view_conent {
- display: inline-block;
- max-width: 100%;
- height: auto;
- background: #fff;
- border-radius: 10rpx;
- box-sizing: border-box;
- padding: 18rpx;
- word-break: break-all;
- }
- .msg_view_time {
- margin-top: 8rpx;
- font-size: 22rpx;
- color: #aaa;
- }
- }
- .msg_view_info_left {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- box-sizing: border-box;
- padding-left: 30rpx;
- }
- .msg_view_info_right {
- display: flex;
- flex-direction: column;
- align-items: flex-end;
- padding-right: 30rpx;
- }
- .msg_user_img_kong {
- width: 80rpx;
- height: 80rpx;
- }
- .msg_user_img {
- background: #fff;
- width: 80rpx;
- height: 80rpx;
- border-radius: 40rpx;
- }
- }
- .gengduo_view {
- width: 100%;
- height: auto;
- box-sizing: border-box;
- padding: 8rpx 20rpx 18rpx 20rpx;
- background: #fff;
- display: flex;
- justify-content: space-around;
- .gengduo_view_ay {
- width: 110rpx;
- }
- .gengduo_view_icon {
- width: 110rpx;
- height: 110rpx;
- border-radius: 16rpx;
- background: #eee;
- margin-bottom: 16rpx;
- }
- .gengduo_view_name {
- font-size: 22rpx;
- text-align: center;
- color: #aaa;
- }
- }
- .text_input_view {
- width: 100%;
- height: 100rpx;
- box-sizing: border-box;
- padding: 18rpx 20rpx;
- background: #fff;
- .text_input_lay {
- width: 100%;
- height: 100%;
- display: flex;
- .text_input_tengh {
- flex: 1;
- height: 100%;
- box-sizing: border-box;
- padding-right: 18rpx;
- .uni-input_chat {
- border-radius: 34rpx;
- width: 100%;
- height: 100%;
- box-sizing: border-box;
- border: 1rpx solid #eee;
- padding: 0 10rpx;
- }
- }
- .text_input_mount {
- width: 64rpx;
- height: 64rpx;
- font-size: 52rpx;
- font-weight: bold;
- color: #999;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- }
- }
- .goods_info {
- width: 100%;
- height: auto;
- padding: 20rpx;
- box-sizing: border-box;
- background: #fff;
- display: flex;
- .goods_img {
- width: 100rpx;
- height: 100rpx;
- }
- .goods_text {
- flex: 1;
- min-height: 100rpx;
- height: auto;
- box-sizing: border-box;
- padding-left: 16rpx;
- .goods_name {
- width: 100%;
- margin-bottom: 10rpx;
- font-size: 28rpx;
- font-weight: bold;
- overflow: hidden;
- /*超出部分隐藏*/
- white-space: nowrap;
- /*禁止换行*/
- text-overflow: ellipsis;
- /*省略号*/
- }
- .goods_jiag {
- font-size: 26rpx;
- color: red;
- }
- .goods_fuwu {
- font-size: 24rpx;
- color: #aaa;
- }
- .goods_pon {
- width: 100%;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .go_goods_btn {
- width: auto;
- height: auto;
- box-sizing: border-box;
- padding: 14rpx 28rpx;
- border-radius: 10rpx;
- font-size: 24rpx;
- font-weight: bold;
- color: #fff;
- background: rgb(250, 42, 42);
- }
- }
- }
- }
- .message_view {
- width: 100%;
- flex: 1;
- position: relative;
- .message_view_scroll {
- position: absolute;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- }
- }
- .gonggao {
- width: 100%;
- height: 80rpx;
- background: #fff2d4;
- box-sizing: border-box;
- padding: 0 20rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- font-size: 24rpx;
- color: rgb(230, 138, 19);
- view {
- color: rgb(230, 138, 19);
- }
- }
- }
- </style>
|