<!--comps/msglist/msglist.wxml-->
<template name="txt">
    <text class="msg-text" style="float:left;">{{ item.data }}</text>
</template>
<template name="emoji">
    <image class="avatar" src="{{ '../../../images/faces/' + item.data }}" style="width:25px; height:25px; margin:0 0 2px 0; float:left;" />
</template>
<template name="img">
    <image class="avatar msg-img" src="{{item.msg.data}}" mode="aspectFit" bind:tap="previewImage" data-url="{{item.msg.data}}" />
</template>
<template name="video">
    <video class="msg-video" bindfullscreenchange="onFullscreenchange" src="{{ item.msg.data }}" controls autoplay />
</template>
<template name="audio">
    <audio src="{{ item.msg.url }}" controls autoplay />
</template>

<!-- view 换成 scroll-view效果更好 用view是为了要stopPullDownRefresh -->
<scroll-view scroll-y="true" class="{{view}} wrap {{isIPX?'scroll_view_X': ''}}" bind:tap="onTap" bindscroll="scrollmore" bindscrolltoupper="refresh" upper-threshold='-50' scroll-into-view="{{toView}}">
    <view class="message" wx:for="{{chatMsg}}" wx:key="mid" id="{{item.mid}}">
        <view class="{{item.style == 'self' ? 'row-right' : 'row-left'}}">
            <image class="photo" src="{{item.info.fromInfo.avatarurl || imgPath +'/chat-user.png'}}" wx:if="{{item.style != 'self'}}"></image>
            <view class="msgbox">
                <text class="user-text" wx:if="{{item.style != 'self'}}">{{item.info.fromInfo.nickname + ' ' + item.time}}</text>
                <text class="user-text" wx:if="{{item.style == 'self'}}">{{item.time + ' ' + item.info.fromInfo.nickname}}</text>
                <view wx:if="{{ item.msg.type == 'img' || item.msg.type == 'video' }}">
                    <template is="{{ item.msg.type }}" data="{{ item }}" />
                </view>
                <audio-msg wx:if="{{ item.msg.type == 'audio' }}" msg="{{ item }}"></audio-msg>
                <view wx:elif="{{ item.msg.type == 'txt' || item.msg.type == 'emoji' }}" data-msg="{{item}}" bindtap="clickMsg">
                    <view class="template" wx:for="{{ item.msg.data }}" wx:key="item">
                        <template is="{{ item.type }}" data="{{ item }}" />
                    </view>
                </view>
            </view>
            <image class="photo" src="{{item.info.fromInfo.avatarurl || imgPath +'/chat-user.png'}}" wx:if="{{item.style == 'self'}}"></image>
        </view>
    </view>
</scroll-view>
<view style="height: 1px;"></view>