role.js 1.9 KB
/*
    yoho客服 im: 角色
    @author xuan.chen@yoh.cn
*/

'use strict';

class ChatRole {
    constructor(headIcon) {
        this.headIcon = headIcon;
    }

    changeIcon(src) {
        this.headIcon = src;
    }
}

class Customer extends ChatRole {
    sendMsg(msg, status) {
        status = status ? '' : '<i class="send-fail">!</i>';
        return `<div class="msg-wrap send-msg">
                    <img src="${this.headIcon}" alt="" class="head-icon">
                    <div class="chat-info">
                        ${status}
                        <span>${msg}</span> 
                    </div>
                </div>`;
    }

    sendImg(src, status) {
        status = status ? '' : '<i class="send-fail">!</i>';
        return `<div class="msg-wrap send-msg">
                    <img src="${this.headIcon}" alt="" class="head-icon">
                    <div class="chat-info">
                        ${status}
                        <span class="image">
                            <img src="${src}" alt="" data-lightbox="chat-image" class="chat-image">
                        </span> 
                    </div>
                </div>`;
    }
}

class Employee extends ChatRole {
    sendMsg(msg) {
        return `<div class="msg-wrap recevied-msg">
                    <img src="${this.headIcon}" alt="" class="head-icon">
                    <div class="chat-info">
                        <span>${msg}</span>
                    </div>
                </div>`;
    }

    sendImg(src) {
        return `<div class="msg-wrap recevied-msg">
                    <img src="${this.headIcon}" alt="" class="head-icon">
                    <div class="chat-info">
                        <span class="image">
                            <img src="${src}" alt="" class="chat-image">
                        </span> 
                    </div>
                </div>`;
    }
}

export {ChatRole, Customer, Employee};