<template>
    <div class="global-im">
        <!-- 悬浮按钮与角标 -->
        <div class="im-trigger" :class="{ active: visible }" @click="toggleChat">
            <el-icon :size="18"><el-icon-chat-round /></el-icon>
            <div class="unreadCount">
                <el-badge :value="unreadCount" :hidden="unreadCount === 0" :max="99">
                    <i class="el-icon-chat-dot-round" style="font-size: 24px"></i>
                </el-badge>
            </div>
        </div>
    </div>
    <el-drawer v-model="visible" title="在线客服" size="100%" destroy-on-close :close-on-click-modal="false" :with-header="false">
        <el-container class="flex-column">
            <div class="drawer-detail-main">
                <div class="drawer-detail-header">
                    <div class="drawer-detail-header-body">
                        <div class="drawer-detail-header-left">在线客服</div>
                        <div class="drawer-detail-header-left">
                            <el-button type="default" icon="el-icon-close" @click="hideWindow">隐藏窗口</el-button>
                        </div>
                    </div>
                </div>
            </div>
            <el-main class="nopadding">
                <el-container>
                    <el-aside width="300px" v-loading="loadMsg">
                      <div class="chat-contact">
                        <div :class="checkChat==index?'contact-item active':'contact-item'" v-for="(item,index) in chatContact" :key="index" @click="checkChatItem(index)">
                          <div class="img"><el-image :src="item.avatar" fit="contain" style="width: 40px; height: 40px"></el-image></div>
                          <div class="kefu-store">
                            <div class="name">{{item.user.nickname}} <span v-if="item.last.num > 0">{{item.last.num}}</span></div>
                            <div class="desc" v-if="item.last.type=='text'">{{item.last.content}}</div>
                            <div class="desc" v-if="item.last.type=='order'">[订单消息]</div>
                            <div class="desc" v-if="item.last.type=='image'">[图片消息]</div>
                            <div class="desc" v-if="item.last.type=='video'">[视频消息]</div>
                            <div class="desc" v-if="item.last.type=='pay'">[支付消息]</div>
                            <div class="desc" v-if="item.last.type=='address'">[收集地址]</div>
                          </div>
                          <div class="time">
                            {{item.last.create_at}}
                          </div>
                        </div>
                      </div>
                    </el-aside>
                    <el-container v-if="chatItem">
                        <el-header><div class="msg-title">与{{ chatItem.user.nickname }}的对话</div></el-header>
                        <el-main class="nopadding" ref="main">
                            <div class="chat-container" v-if="chatItem">
                                <div class="loading-text" v-if="msgLoad">努力加载中...</div>
                                <div class="message-list" ref="messageListRef" @scroll="handleScroll">
                                    <template v-for="(item, index) in history.messages">
                                    <div class="z_index2" style="transform: rotate(-180deg)" :key="item.messageId" v-if="!item.isHide">
                                        <div class="icon_ text_26 color__ time">
                                            {{ renderMessageDate(item, index) }}
                                        </div>
                                        <div :key="item.messageIds" v-if="!item.recalled">
                                            <item :isMy="isSelf(item.senderId)" :myid="myid" :item="item" @onClick="onItem"
                                                @onLongpress="onLongpress" @mention="mention"></item>
                                        </div>
                                        <div class="icon_ text_26 recalled" v-else>
                                            <div class="">
                                                <span v-if="isSelf(item.senderId)">你</span>
                                                <span v-else>{{ item.senderData.name }}</span>
                                                撤回了一条消息
                                            </div>
                                            <div class="recalled-edit" v-if="item.type === 'text' && isSelf(item.senderId)"
                                                @click="recalledEdit(item)">重新编辑</div>
                                        </div>
                                    </div>
                                    </template>
                                </div>
                                <div class="input-area">
                                    <div class="quick-group">
                                        <div class="emoji-item">
                                            <el-popover placement="top" :width="400" trigger="click">
                                                <template #reference>
                                                    <div class="item-btn">
                                                        <el-image style="width:25px;height:25px;" src="https://jymini.oss-cn-guangzhou.aliyuncs.com/pc/face.svg"></el-image>
                                                        <div class="name">表情</div>
                                                    </div>
                                                </template>
                                                <div class="swiper-item-box">
                                                    <div class="flex_r swiper-item-box-l" v-for="(im, ix) in emojiList" :key="ix">
                                                        <div
                                                            class="icon_ emoji-item"
                                                            v-for="(item, index) in im"
                                                            :key="index"
                                                            :style="{ opacity: ix === opacityGroup && (index == 5 || index == 6 || index == 7) ? opacity : 1 }"
                                                        >
                                                            <el-image class="img" :src="emojiUrl + item.image" @click="chooseEmoji(item.text)"></el-image>
                                                        </div>
                                                    </div>
                                                </div>
                                            </el-popover>
                                        </div>
                                        <div class="emoji-item">
                                            <el-popover placement="top" :width="174">
                                                <template #reference>
                                                    <div class="item-btn">
                                                        <el-image style="width:25px;height:25px;" src="https://jymini.oss-cn-guangzhou.aliyuncs.com/pc/more.svg"></el-image>
                                                        <div class="name">图片</div>
                                                    </div>
                                                </template>
                                                <sc-upload v-model="uploadImg" :on-success="uploadSuccess"></sc-upload>
                                            </el-popover>
                                        </div>
                                        <div class="emoji-item" @click="showQuick">
                                            <div class="item-btn">
                                                <el-image style="width:25px;height:25px;" src="https://jymini.oss-cn-guangzhou.aliyuncs.com/pc/quick.svg"></el-image>
                                                <div class="name">快捷回复</div>
                                            </div>
                                        </div>
                                        <div class="emoji-item">
                                            <el-popover placement="top" :width="300" trigger="click">
                                                <template #reference>
                                                    <div class="item-btn">
                                                        <el-image style="width:26px;height:26px;" src="https://jymini.oss-cn-guangzhou.aliyuncs.com/pc/money.svg"></el-image>
                                                        <div class="name">补差价</div>
                                                    </div>
                                                </template>
                                                <el-form :model="priceForm" :rules="rules" ref="priceForm" label-position="top">
                                                    <el-form-item label="名称" prop="name" class="label-item">
                                                        <el-input v-model="priceForm.name" placeholder="请输入" clearable />
                                                        <div class="el-form-item-msg"></div>
                                                    </el-form-item>
                                                    <el-form-item label="差价金额" prop="price" class="label-item">
                                                        <el-input v-model="priceForm.price" placeholder="请输入" clearable>
                                                            <template #append>元</template>
                                                        </el-input>
                                                        <div class="el-form-item-msg"></div>
                                                    </el-form-item>
                                                    <el-form-item>
                                                        <el-button type="primary" :loading="isSaveing" @click="submitPrice()">确定发送</el-button>
                                                    </el-form-item>
                                                </el-form>
                                            </el-popover>
                                        </div>
                                    </div>
                                    <el-input
                                        type="textarea"
                                        :rows="3"
                                        v-model="inputMessage"
                                        placeholder="请输入消息..."
                                        @keyup.enter.native="handleKeyCode"
                                        @keydown.native="handleKeyCode"
                                    ></el-input>
                                    <div class="send-btn-group">
                                        <div class="send-btn-right">
                                            <el-button type="primary" @click="sendMessage">发送</el-button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </el-main>
                    </el-container>
                    <el-container v-else>
                        <div class="empty-data">
                            请选择左侧的聊天列表
                        </div>
                    </el-container>
                    <el-aside width="400px" v-if="chatItem">
                        <el-container>
                            <el-header>
                                <div class="msg-title">用户信息</div>
                            </el-header>
                            <el-main class="nopadding">
                                <el-card shadow="never" class="border-none">
                                    <el-descriptions :column="1" border>
                                        <el-descriptions-item label="昵称">{{ chatItem.user.nickname }}</el-descriptions-item>
                                        <el-descriptions-item label="OpenId">
                                            <el-tooltip effect="dark" placement="top-start" :content="chatItem.user.openid">
                                                查看
                                            </el-tooltip>
                                        </el-descriptions-item>
                                        <el-descriptions-item label="手机号码">{{chatItem.user.mobile}}</el-descriptions-item>
                                        <el-descriptions-item label="注册时间">{{chatItem.user.create_at}}</el-descriptions-item>
                                    </el-descriptions>
                                </el-card>
                                <el-card shadow="never" class="border-none" v-loading="orderLoad">
                                    <template #header>
                                        <div class="msg-title">订单列表</div>
                                    </template>
                                    <div class="order-list-chat" v-if="orderList.length > 0">
                                        <div class="m-order-s" v-for="(item,index) in orderList" :key="index">
                                            <div class="order-img"><el-image style="width: 60px;height: 60px;" :src="item.img" fit="fit"></el-image></div>
                                            <div class="order-info">
                                                <div class="title">{{item.product.product_name}}</div>
                                                <div class="desc">{{item.order_sn}}</div>
                                                <div class="price">{{this.$TOOL.money(item.price)}}</div>
                                            </div>
                                            <div class="order-status-btn">
                                                <div class="status primary cus" @click="sendAddress(item)">收集地址</div>
                                                <div class="status info cus" @click="sendOrder(item)">发送</div>
                                                <div class="status info" v-if="item.status=='0'">未支付</div>
                                                <div class="status primary" v-if="item.status=='1'">待使用</div>
                                                <div class="status success" v-if="item.status=='2'">已完成</div>
                                                <div class="status danger" v-if="item.status=='3'">已退款</div>
                                                <div class="status warn" v-if="item.status=='4'">退款中</div>
                                            </div>
                                        </div>
                                        <div class="order-page">
                                            <el-pagination :default-page-size="orderSize" small layout="prev, pager, next" @size-change="orderPageChange" @current-change="orderPageChange" :total="orderTotal" :hide-on-single-page="true" />
                                        </div>
                                    </div>
                                    <div class="order-list-chat" v-else>
                                        <el-empty description="没有订单" />
                                    </div>
                                </el-card>
                            </el-main>
                        </el-container>
                    </el-aside>
                </el-container>
            </el-main>
        </el-container>
    </el-drawer>
    <orderDetail ref="orderDetail" @success="orderSuccess"></orderDetail>
</template>

<script>
import {
	mapState
} from 'vuex';
import { Push } from "@/utils/push";
import { emojiMap } from "@/utils/emoji";
import item from '@/components/chat/index';
var pushObj = null;
let height2 = null;
const emojiUrl = 'https://imgcache.qq.com/open/qcloud/tim/assets/emoji/';
import {
	formatDate,
	to as tofn
} from '@/util/index.js';
import orderDetail from '@/components/imFloat/order';
let imageList = [];
export default {
    name: 'GlobalIM',
    components:{
        item,
        orderDetail
    },
    props: {
        user: { type: Object, default: () => {} }
    },
    data() {
        return {
            rules:{
                name: [
                    {required: true, message: '请输入'}
                ],
                price: [
                    {required: true, message: '请输入'}
                ],
            },
            priceForm:{
                name:"补差价"
            },
            uploadImg:"",
            loadMsg:false,
            history: {
				messages: [],
				allLoaded: false
			},
            msgLoad:false,
            orderList:[],
            orderLoad:false,
            orderTotal:0,
            orderPage:1,
            emojiUrl,
            loading:false,
            visible: false,           // 聊天窗口可见性
            unreadCount: 0,          // 未读消息数量
            inputMessage: '',        // 输入的消息
            timer: null,             // 定时器
            messages: [],
            // wsAuth:"https://tran.jsshuita.cn/plugin/webman/push/auth",
            // wsUrl: 'wss://tran.jsshuita.cn/ws',
            wsAuth:"http://127.0.0.1:9981/plugin/webman/push/auth",
            wsUrl: 'ws://127.0.0.1:3131',
            page:1,
            size:10,
            msgPage:1,
            msgSize:20,
            orderSize:10,
            chatContact:[],
            checkChat:null,
            chatItem:null,
            emojiList:[],
			sendId:null,
			myid: this.user.userId,
            userId:null,
            isSaveing:false
        }
    },
    watch: {
        chatItem(val){
            if (val) {
                this.$nextTick(() => {
                    this.$refs.messageListRef?.addEventListener('scroll', this.handleScroll)
                })
            }
        }
    },
	computed: mapState({
		//显示时间
		renderMessageDate() {
			return (message, index) => {
				if (message.timestamp - this.history.messages[index + 1]?.timestamp > 3 * 60 * 1000) {
					return formatDate(message.timestamp, 'timestamp');
				}
				return '';
			};
		},
		// 是否本人isMy
		isSelf() {
			return (senderId) => {
				const {
					member_id = this.myid
				} = {"member_id":this.myid};
				return senderId === `${member_id}`;
			};
		}
	}),
    mounted() {
        // console.log("pushObj")
        this.initEmoji()
        this.initPush();
        // this.simulateNewMessage()
    },
    beforeDestroy() {
        // if (this.timer) {
        //     clearInterval(this.timer)
        // }
        this.$refs.messageListRef.removeEventListener('scroll', this.handleScroll)
    },
    methods: {
        orderSuccess(type,data){
            console.log(data)
            switch(type) {
                case "address":
                    this.sendAddress(data)
                    break;
            }
        },
        async submitPrice(){
            var { priceForm,message } = this;
            var validate = await this.$refs.priceForm.validate().catch(()=>{});
            if(!validate){ return false }
            this.isSaveing = true;
            priceForm.type = "pay";
            priceForm.groupId = this.chatItem.poi_id
            priceForm.openid = this.chatItem.openid
            var resp = await this.$API.chat.price.post(priceForm);
            this.isSaveing = false;
            if (resp.code == 0) {
                return $message.error(resp.msg)
            }
            this.sendMessageData({
                payload: {
                    pay: resp.data,
                },
                type: 'pay'
            });
            this.uploadImg = "";
        },
        orderPageChange(e){
            this.orderPage = e;
            this.getOrderList()
        },
        hideWindow(){
            this.chatItem = null;
            this.msgPage = 1;
            this.unreadCount = 0;
            this.checkChat = null;
            this.orderList = [];
            this.orderPage = 1;
            this.visible = false;
        },
        handleScroll(e){
            const { scrollTop, clientHeight, scrollHeight } = e.target
            const isBottom = scrollTop + clientHeight >= scrollHeight - 5   // 5px 缓冲区
            const isTop = scrollTop <= 5
            console.log("滚动",this.history.allLoaded)
            if (isBottom && !this.history.allLoaded) {
                console.log('到达底部')
                // 加载更多等操作
                this.getMsgMore()
            }
            if (isTop && this.history.allLoaded) {
                // console.log('到达顶部')
            }
        },
        playAudio(){
            const audio = new Audio('/img/msn.mp3');
            audio.play().catch(error => {
                console.error("播放音频时出错:", error);
            });
        },
        onLongpress(){},
        onItem(data){
            switch(data.type)
            {
                case "order":
                    this.$nextTick(() => {
                        this.$refs.orderDetail.open("add").setData(data.payload.order)
                    })
                    break;
                case "address":
                    this.$nextTick(() => {
                        this.$refs.orderDetail.open("add").setData(data.payload.address)
                    })
                    break;
            }
        },
        chooseEmoji(data){
            this.inputMessage += data;
        },
        initEmoji() {
			let newList = [];
			let i = 1;
			for (let key in emojiMap) {
				let obj = {};
				obj['index'] = i;
				obj['text'] = key;
				obj['image'] = emojiMap[key];
				i++;
				newList.push(obj);
			}
			var list = [];
			let A = newList.filter((item, index) => {
				return (index + 1) % 8 === 0;
			});
			A.unshift({ index: 0 });
			A.push({ index: newList.length });
			this.emojiList = A.map((item, index) => {
				return newList.slice(A[index].index, A[index + 1]?.index || newList.length);
			});
			// this.scroll({ detail: { scrollTop: 10 } });
		},
        /**
         * 发送订单消息
         * @param data 
         */
        async sendOrder(data){
            var orderData = {"img":data.img,"name":data.product.product_name,"goods_id":data.life_goods_id,"order":data.out_order_no,"price":this.$TOOL.disMoney(data.pay_money),"status":data.status};
            var resp = await this.sendMessageApi("order",orderData);
            if (!resp) {
                return ;
            }
            this.sendMessageData({
                payload: {
                    order: orderData
                },
                type: 'order'
            });
        },
        /**
         * 收集地址消息
         * @param data 
         */
        async sendAddress(data){
            var orderData = {"img":data.img,"name":"完善会员资料","order":data.out_order_no,"status":0};
            var resp = await this.sendMessageApi("address",orderData);
            if (!resp) {
                return ;
            }
            this.sendMessageData({
                payload: {
                    address: orderData
                },
                type: 'address'
            });
        },
        async sendMessage(){
            if (!this.inputMessage) return ;
            var resp = await this.sendMessageApi("text",this.inputMessage);
            if (!resp) {
                this.inputMessage = "";
                return ;
            }
            this.sendMessageData({
                payload: {
                    text: this.inputMessage
                },
                type: 'text'
            });
            this.inputMessage = ""
        },
        sendMessageData({payload,type}){
			const message = {
				groupId: this.chatItem.poi_id,
				senderData: {
                    avatar:this.chatItem.avatar
                },
				senderId: this.myid,
				messageId: Date.now(),
				payload: payload,
				timestamp: Date.now(),
				type: type,
				recalled: false,
				status: 'success',
				isHide: 0
			};
			this.pushList(message);
        },
        handleKeyCode(event){
            if (event.keyCode == 13) {
                if (!event.ctrlKey) {
                    this.sendMessage()
                    event.preventDefault();
                } else {
                    this.inputMessage += "\n";
                }
            } else {
                return ;
            }
        },
        checkChatItem(index){
            this.checkChat = index;
            this.chatItem = this.chatContact[index]
            this.chatContact[index].last.num = 0;
            this.msgPage = 1;
            this.history.messages = []
            this.history.allLoaded = false
            this.orderList = [];
            this.orderPage = 1;
            this.getMsgData();
            this.getOrderList();
        },
        initPush(){
            var _this = this;
            if (!this.pushObj) {
                this.pushObj = new Push({
                    "url":this.wsUrl,
                    "app_key":"265c33b73d5c04f918978577df2c48d2",
                    "auth":this.wsAuth
                });
            }
            var user_channel = this.pushObj.subscribe('service-' + this.myid);
            user_channel.on('message', function (data) {
                _this.playAudio()
                _this.unreadCount ++;
                if (_this.chatItem && _this.chatItem.openid == data.openid) { // 当前窗口实时推送
                    _this.formatMsg(data);
                }
                // 给消息标红并更新最后一条消息
                var msgData = _this.chatContact;
                for (var i=0; i <= msgData.length;i ++) {
                    var item = msgData[i];
                    if (item && item.openid == data.openid) {
                        item.last.type = data.type;
                        item.last.num ++;
                        item.last.content = data.content;
                        item.last.create_at = data.create_at
                    }
                }
            })
        },
        formatMsg(item){
			var payload = {};
			if (item.type == 'text') {
				payload.text = item.content
			}
			if (item.type == 'order') {
				var order = JSON.parse(item.content)
				payload.order = order
			}
			if (item.type == 'pay') {
				var order = JSON.parse(item.content)
				payload.pay = order
			}
			if (item.type == 'address') {
				var order = JSON.parse(item.content)
				payload.address = order
			}
			if (item.type == 'image') {
				payload = {
					contentType: 'image/png',
					name: 'uni-image.png',
					size: 82942,
					url: item.content,
					width: 2732,
					height: 2732,
					thumbnail: item.content
				};
			}
			const message = {
				groupId: item.poi_id,
				senderData: {
					avatar:item.avatar,
					name:item.source==2?item.nick.truename:item.user.nickname
				},
				senderId: (item.source==1?item.openid:item.service_id),
				messageId: item.msgId,
				payload: payload,
				timestamp: item.time,
				type: item.type,
				recalled: false,
				status: 'success',
				isHide: 0
			};
			this.pushList(message);
		},
        async pushList(message) {
			this.initMessageItem(message);
			this.history.messages.unshift(message);
            console.log(this.history.messages)
			// 是否触发文字动效果
			if (message.type === 'text' || message.type === 'text_quote') {
				this.onSetText(message.payload.text);
			}
			// 缓存照片地址，
			if (message.type === 'image' || message.type === 'image_transmit') {
				imageList.push(message.payload.url);
			}
		},
		// 组装item
		initMessageItem(message, index) {
			message['isHide'] = 0;
			if (index === 0 && (message.type === 'text' || message.type === 'text_quote')) {
				this.onSetText(message.payload.text);
			}
		},
		// 文本触发效果相关========
		onSetText(text) {},
        // 切换聊天窗口
        async toggleChat() {
            this.visible = !this.visible
            this.loadMsg = true;
            this.chatContact = [];
            if (this.visible) {
                // 打开窗口时清除未读角标
                this.unreadCount = 0
            }
            var resp = await this.$API.chat.list.get({page:this.page,pageSize:this.size})
            this.loadMsg = false;
            if (resp.code == 0) {
              return this.$message.error(resp.msg)
            }
            this.chatContact = this.chatContact.concat(resp.data.rows)
            // this.chatItem = this.chatContact[0]
            // this.userId = this.chatItem.openid;
            // this.getMsgData();
        },
        /**
         * 加载更多
         */
        async getMsgMore(){
            this.history.allLoaded = true;
            this.msgLoad = true;
            var resp = await this.$API.chat.msg.get({"page":this.msgPage,"size":this.msgSize,"openid":this.chatItem.openid})
            this.msgLoad = false;
            if (resp.data.rows.length > 0) {
                this.msgPage ++;
                var msgData = []
				var list = resp.data.rows
                // 同步混入数据
                list.forEach((item, ix) => {
                    var payload = {};
                    if (item.type == 'text') {
                        payload.text = item.content
                    }
                    if (item.type == 'order') {
                        var order = JSON.parse(item.content)
                        payload.order = order
                    }
                    if (item.type == 'pay') {
                        var order = JSON.parse(item.content)
                        payload.pay = order
                    }
                    if (item.type == 'address') {
                        var order = JSON.parse(item.content)
                        payload.address = order
                    }
                    if (item.type == 'image') {
                        payload = {
                            contentType: 'image/png',
                            name: 'uni-image.png',
                            size: 82942,
                            url: item.content,
                            width: 2732,
                            height: 2732,
                            thumbnail: item.content
                        };
                    }
                    const message = {
                        groupId: item.poi_id,
                        senderData: {
                            avatar:item.avatar
                        },
                        senderId: (item.source==1?item.openid:item.service_id),
                        messageId: item.msgId,
                        payload: payload,
                        timestamp: item.time,
                        type: item.type,
                        recalled: false,
                        status: 'success',
                        isHide: 0
                    };
                    msgData[ix] = message
                });
                this.history.messages = [...this.history.messages, ...msgData];
                this.history.allLoaded = false;
            } else {
                this.history.allLoaded = true;
            }
        },
        /**
         * 首次加载
         */
        async getMsgData(){
            var resp = await this.$API.chat.msg.get({"page":this.msgPage,"size":this.msgSize,"openid":this.chatItem.openid})
            if (resp.data.rows.length > 0) {
                var msgData = resp.data.rows
                msgData.forEach((item,index)=>{
                    this.formatMsg(item);
                })
                this.msgPage ++;
            }
        },
        async uploadSuccess(data){
            var resp = await this.sendMessageApi("image",data.data.src);
            if (!resp) {
                return ;
            }
            this.sendMessageData({
                payload: {
                    contentType: 'image/png',
                    name: data.data.fileName,
                    size: 0,
                    url: data.data.src,
                    width: 2732,
                    height: 2732,
                    thumbnail: data.data.src
                },
                type: 'image'
            });
            this.uploadImg = "";
        },
        async sendMessageApi(type,content){
            this.chatContact[this.checkChat].last.num = 0;
            var resp = await this.$API.chat.send.post({type:type,content: content,groupId: this.chatItem.poi_id,openid:this.chatItem.openid})
            if (resp.code == 0) return false;
            this.chatContact[this.checkChat].last.type = type;
            this.chatContact[this.checkChat].last.content = content;
            this.chatContact[this.checkChat].last.create_at = resp.data.time;
            return true;
        },
        async getOrderList(){
            this.orderLoad = true;
            var resp = await this.$API.order.list.get({"page":this.orderPage,"pageSize":this.orderSize,"openid":this.chatItem.openid});
            this.orderLoad = false;
            if (resp.code == 0) {
                return ;
            }
            this.orderList = resp.data.rows;
            this.orderTotal = resp.data.total;
        }
    }
}
</script>

<style scoped lang="scss">
@import '@/style/index.scss';
.border-none{border: 0;}
.msg-title{font-size: 18px;font-weight: bold;}
.loading-text{background-color: #f8f8f8;text-align: center;font-size: 12px;}
.m-order-s{background-color: #f8f8f8;border-radius: 5px;display: flex;font-size: 14px;position: relative;margin-bottom: 10px;}
.m-order-s .order-img image{width: 60px;height: 60px;}
.m-order-s .order-info {padding: 10px;}
.m-order-s .order-info .title{font-size: 14px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
.m-order-s .order-info .desc{font-size: 12px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: #999;}
.m-order-s .order-info .price{font-size: 14px;color: #f00;}
.m-order-s .order-status-btn{position: absolute;right: 0;bottom: 0;display: flex;align-items: center;gap: 5px;}
.m-order-s .status{border-radius: 5px 0 5px 0;background-color: #909399;font-size: 12px;color: #fff;padding: 5px;}
.m-order-s .status.cus{cursor: pointer;}
.m-order-s .status.info{background-color: #909399;}
.m-order-s .status.primary{background-color: #409eff;}
.m-order-s .status.success{background-color: #67c23a;}
.m-order-s .status.danger{background-color: #f56c6c;}
.m-order-s .status.warn{background-color: #e6a23c;}

.hideStr{overflow: hidden;width: 80%;}
.contact-item{display: flex;align-items: center;background-color: #fff;padding: 10px;border-bottom: 1px solid #f8f8f8;cursor: pointer;}
.contact-item.active{background-color: #f8f8f8;}
.contact-item .kefu-store{margin-left: 10px;}
.contact-item .kefu-store .name{font-size: 14px;color: #333;display: flex;align-items: center;}
.contact-item .kefu-store .name span{background-color: #f00;color: #fff;width: 20px;height: 20px;display: flex;align-items: center;justify-content: center;border-radius: 20px;font-size: 12px;margin-left: 10px;}
.contact-item .kefu-store .desc{font-size: 12px;color: #666;margin-top: 5px;}
.contact-item .time{margin-left: auto;margin-right: 0;font-size: 12px;color: #666;}
.send-btn-group{margin-top: 10px;display: flex;align-items: center;justify-content: space-between;}
.send-btn-group .send-emoji{display: flex;align-items: center;gap: 15px;cursor: pointer;}
.quick-group{display: flex;align-items: center;gap: 10px;padding: 15px 0;}
.quick-group .item-btn{background-color: #f8f8f8;padding: 5px;border-radius: 3px;display: flex;align-items: center;gap: 5px;cursor: pointer;}
.z_index2{position: relative;z-index: 2;}
.empty-data{display: flex;width: 100%;text-align: center;justify-content: center;font-size: 18px;background-color: #f8f8f8;align-items: center;}
.swiper-item-box {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    max-height: 300px;
    overflow: auto;
    flex-wrap: wrap;
    align-items: flex-start;

    .swiper-item-box-l {
        // width: calc(62.5vw);
        width: calc(100%);
        flex-wrap: wrap;
        align-items: flex-start;
    }
    .swiper-item-box-r {
        width: calc(37.5%);
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .emoji-item {
        width: calc(12.5%);
        height: calc(12.5%);
        flex-shrink: 0;
        transition: all 0.1s;
        padding: 10px 0;
        
        .img {
            width: 55%;
            height: 55%;
            cursor: pointer;
        }
        &:hover {
            background-color: #f8f8f8;
        }
    }
}
.flex_r {
    display: flex;
    flex-direction: row;
}
.swiper-item-box-b {
    width: calc(38%);
    position: absolute;
    z-index: 99;
    right: 0rpx;
    bottom: 0px;
    padding: 0 0 40rpx 0;
    // background-color: #000;
    background-image: linear-gradient(to top, #ececec, #ececec, #ececec, #ececec, #ececec, rgba(0, 0, 0, 0));
}
.swiper-item-box-delete {
    width: 116rpx;
    height: calc(12.5%);
    border-radius: 10rpx;
    margin-right: 20rpx;
    background-color: #fff;
    .img {
        width: 45%;
        height: 45%;
        margin-right: 4rpx;
    }
}
.swiper-item-box-button {
    width: 116rpx;
    height: calc(12.5vw);
    border-radius: 10rpx;
    margin-right: 10rpx;
    background-color: #05c160;
}
.page {
	position: fixed;
	z-index: 1;
	top: 0;
	left: 0;
	bottom: 0;
	right: 0;
	background-color: #ededed;
}
.scroll-Y {
	width: 100%;
	height: 0;
	transition: all 0.2s;
	transform: rotate(180deg);
	background-color: #ededed;
	::-webkit-scrollbar {
		display: none;
	}
}
.scroll-view-str {
	width: 100%;
}

.message-list .time {
	width: 100%;
	color: #a3a3a3;
	line-height: 50px;
}

.message-list .recalled {
	width: 100%;
	height: 50rpx;
	margin: 20rpx 0;
	color: #a3a3a3;

	.recalled-edit {
		color: #5a6693;
		margin-left: 14rpx;
	}
}
@keyframes simple-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.global-im {
    .unreadCount{
        position: fixed;
        right: 42px;
        bottom: 162px;
        animation: simple-blink 2s ease-in-out infinite;
    }
  .im-trigger {
    position: fixed;
    right: 24px;
    bottom: 124px;
    width: 48px;
    height: 48px;
    background: #409eff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
    z-index: 2000;
    transition: all 0.3s;
    color: white;
    &:hover {
      background: #66b1ff;
    }
    &.active {
      background: #909399;
    }
  }
}
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  .message-list {
    flex: 1;
    overflow-y: auto;
    background-color: #f8f8f8;
    transition: all 0.2s;
    transform: rotate(180deg);
    .message-item {
      display: flex;
      margin-bottom: 16px;
      &.self {
        flex-direction: row-reverse;
        .content {
          margin-right: 12px;
          align-items: flex-end;
          .text {
            background: #95ec69;
          }
        }
      }
      &.other {
        .content {
          margin-left: 12px;
        }
      }
      .content {
        display: flex;
        flex-direction: column;
        max-width: 70%;
        .name {
          font-size: 12px;
          color: #999;
          margin-bottom: 4px;
        }
        .text {
          padding: 8px 12px;
          background: #f0f0f0;
          border-radius: 12px;
          word-break: break-all;
        }
        .time {
          font-size: 10px;
          color: #ccc;
          margin-top: 4px;
        }
      }
    }
  }
  .input-area {
    padding: 0 16px 16px 16px;
    border-top: 1px solid #eee;
  }
}
</style>