<template>
    <div>
        <!-- 文本消息 v-if="contentType === '7、10、13、14'" -->
        <div class="time-tips" v-if="contentType == 7 || contentType == 10 || contentType == 13 || contentType == 14">
            <div>{{chatObj.content}}</div>
        </div>
        <!-- 文本消息 v-if="contentType === '5'" -->
        <div class="time-tips" v-if="contentType == 5">
            <div>已向{{JSON.parse(chatObj.content).doctor_name}}医生求助
                <a href="javascript:void(0)" @click='translateDocMSg(chatObj)'>立即查看</a>
            </div>
        </div>
        <!-- 文本消息 v-if="contentType === '1'" -->
        <dl :class='[(chatMen ? "chat-right" : "chat-left")]' v-if="contentType == 0 || contentType == 1 || contentType == 6 || contentType == 8 || contentType == 15 || contentType == 16 || contentType == 17 || contentType == 18 || contentType == 19 || contentType == 20">
            <dt>
                <a>
                    <img :src='chatImg' class="c-images-cycle">
                </a>
            </dt>
            <div class="c-content">
                <span class="c-f12 name">{{chatObj.sender_name}}</span>
                <div class="c-msg">
                    <!-- 判断已读是否为能显示 1、chatMen (true) 2、是否已读 -->
                    <span class="yidu" v-show="chatMen && chatJudge && chatJudge > chatObj.timestamp">已读</span>
                    <dd v-if="chatObj.content_type != 6 && chatObj.content_type != 15 && chatObj.content_type != 16 && chatObj.content_type != 17 && chatObj.content_type != 18 && chatObj.content_type != 19  && chatObj.content_type != 20" class="word-bread">
                        <span v-if="contentType == 0" v-html='chatObj.content.split("</br>")[0]'></span>
                        <!--<span v-if="contentType == 0" v-html='chatObj.content'></span>-->
                        <span v-if="contentType != 0">{{chatObj.content}}</span>
                    </dd>
                    <dd v-if="chatObj.content_type == 6 && !handleContent(chatObj.content).title" class="word-bread">
                        <span>{{chatObj.content}}</span>
                    </dd>
                    <dd v-if="chatObj.content_type == 6 && handleContent(chatObj.content).title" class="word-bread">
                        <span class="sys-remind"><em class="bgc-fff">！</em> 本消息为系统提醒</span><br>
                        <span>{{handleContent(chatObj.content).title}}</span><br>
                        <span>{{handleContent(chatObj.content).tzMsg}}</span>
                    </dd>
                    <dd v-if="chatObj.content_type == 15" class="word-bread">
                        <span class="sys-remind"><em class="bgc-fff">！</em> 本消息为系统提醒</span><br>
                        <span>{{handleContent(chatObj.content).title}}</span><br>
                        <span>审核结果：{{handleContent(chatObj.content).result}}</span><br>
                        <span v-show="handleContent(chatObj.content).reason && handleContent(chatObj.content).reason != ''">原因：{{handleContent(chatObj.content).reason}}</span>
                    </dd>
                    <dd v-if="chatObj.content_type == 16 && chatMen" class="word-bread">
                        <span>{{handleContent(chatObj.content).text}}</span><br>
                    </dd>
                    <dd v-if="chatObj.content_type == 16 && !chatMen" class="word-bread">
                        <span class="sys-remind"><em class="bgc-fff">！</em> 本消息为系统提醒</span><br>
                        <span v-show="handleContent(chatObj.content).healthindexid">{{handleContent(chatObj.content).tzMsg}}</span><br v-show="handleContent(chatObj.content).healthindexid">
                        <span v-show="handleContent(chatObj.content).healthindexid">{{handleContent(chatObj.content).tzTime}}</span><br v-show="handleContent(chatObj.content).healthindexid">
                        <span>{{handleContent(chatObj.content).tzAlert}}<em @click='autoEdit()' v-show="handleContent(chatObj.content).healthindexid" class="font-set cur-pit">自动填入随访记录</em></span>
                    </dd>
                    <dd v-if="chatObj.content_type == 17" class="word-bread">
                        <span class="sys-remind" v-show="!chatMen"><em class="bgc-fff">！</em> 本消息为系统提醒</span><br v-show="!chatMen">
                        <span>{{handleContent(chatObj.content).text}}</span><br>
                    </dd>
                    <div class="textcenter" v-if="chatObj.content_type == 17">{{handleContent(chatObj.content).doctorremind}}</div>
                    <!-- <div class="textcenter" v-if="chatObj.content_type == 18 || chatObj.content_type == 19">暂不支持此类消息</div> -->
                    <dd v-if="chatObj.content_type == 18 || chatObj.content_type == 19 || chatObj.content_type == 20" class="word-bread">
                        <span>暂不支持此类消息</span><br>
                    </dd>
                </div>
            </div>
        </dl>
    </div>
    
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
    @import "../../assets/sass/message-chat";

    .sys-remind {
        display: inline-block;
        height: 18px;
        border-radius: 10px;
        padding: 2px 10px 0;
        background-color: #12B7f5;
        line-height: 18px;
        color: #ffffff;
    }
    .bgc-fff {
        display: inline-block;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        color: #12B7f5;
        font-size: 14px;
        text-align: center;
    }
    .chat-right .bgc-fff {
        background-color: #12B7f5;
        color: #fff
    }
    .chat-right .sys-remind {
        background-color: #fff;
        color: #12B7f5;
    }
    .font-set {
        color: #47A8EF!important;
    }
    .font-set:hover {
        text-decoration: underline;
    }
    .textcenter {
        text-align: right;
    }
</style>
<script>
export default {
    props: ['contentType', 'chatMen', 'chatJudge', 'chatObj', 'chatImg'],
    components: {

    },
    mounted() {

    },
    data() {
        return {}
    },
    methods: {
        handleContent(content) {
            let json = {
                title: false,
                tzMsg: ''
            }
            if (!content) return json
            try {
                json = JSON.parse(content)
            } catch (error) {
                return json
            }
            return json
        },
        translateDocMSg(obj) {
            this.$root.bus.$emit('translateDocMSg', obj)
        },
        // 自动填入随访记录
        autoEdit() {
            let obj = {
                healthindexid: this.handleContent(this.chatObj.content).healthindexid,
                type: this.handleContent(this.chatObj.content).type
            }
            this.$root.bus.$emit('followup', obj)
        }
    }
}
</script>
