<template>
    <view>
        <view class="preview" v-if="draft">
            <text class="draft">[草稿]</text> {{ draft }}
        </view>
        <block v-else>
            <view class="preview" v-if="msg.objectName=='RC:TxtMsg'">
                <text v-if="conversationType == 3">{{ user.name }}：</text>{{ msg.content || '' }}
            </view>
            <view class="preview" v-if="msg.objectName=='RC:HQVCMsg'">
                <text v-if="conversationType == 3">{{ user.name }}：</text>[语音]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:ImgMsg'">
                <text v-if="conversationType == 3">{{ user.name }}：</text>[图片]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:GIFMsg'">
                <text v-if="conversationType == 3">{{ user.name }}：</text>[表情]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:FileMsg'">
                <text v-if="conversationType == 3">{{ user.name }}：</text>[文件]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:LBSMsg'">
                <text v-if="conversationType == 3">{{ user.name }}：</text>[位置]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:InfoNtf' && JSON.parse(msg.message).mediaType==0">
                <text v-if="conversationType == 3">{{ user.name }}：</text>[语音通话]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:InfoNtf' && JSON.parse(msg.message).mediaType==1">
                <text v-if="conversationType == 3">{{ user.name }}：</text>[视频通话]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:GrpNtf'">
                [{{ msg.message }}]
            </view>
            <view class="preview" v-if="msg.objectName=='RC:RcNtf'">
                <text v-if="conversationType == 3">{{ user.name }}：</text> 撤回了一条消息
            </view>
        </block>
    </view>
</template>

<script>
    export default {
        props: {
            msg: {
                type: Object,
                default: {}
            },
            conversationType: {
                type: Number,
                default: 0
            },
            draft: {
                type: String,
                default: ''
            },
            user: {
                type: Object,
                default: function() {
                    return {
                        name: ''
                    }
                }
            }
        }
    }
</script>

<style lang="scss" scoped>
    .preview {
        word-break: break-all;
        color: $text-gray-m;
        padding-top: 6rpx;
        padding-bottom: $padding;
        font-size: $title-size-m - 2;
        height: 32rpx;
        line-height: 32rpx;
        width: 520rpx;
        @extend .nowrap;
        
        .draft {
            color: $text-price;
            padding-right: 10rpx;
        }
    }
</style>
