<template>
	<view class="body-background" :style="{backgroundImage:'url('+staticImage.bodyBackground+')'}"></view>
	<view class="app-wallpaper">

		<view class="chat-list-container row">
			<view v-for="item in chatList" class="chat-list-item-container col-12" :style="{
				backgroundImage:'url('+staticImage.chatBgImage+')'
			}">
				<view class="chat-item-background" @click="chatDetail(item)" :style="{
				backgroundImage:'url('+staticImage.chatLTBgImage+')'
			}">
					<view class="chat-item-content row">
						<view class="chat-item-left">
							<image class="img" :src="item.avatar" mode="aspectFill"/>
						</view>
						<view class="chat-item-right">
							<view class="chat-item-title-group row">
								<view class="chat-item-title">{{item.name}}</view>
								<view class="chat-item-time">{{item.create_time}}</view>
							</view>
							<view class="chat-item-desc">
								{{item.info}}
							</view>
						</view>
					</view>
				</view>
			</view>
<!--			<view class="chat-item-end row">-->
<!--				— 没有更多内容了 —-->
<!--			</view>-->
		</view>
    <u-loadmore :status="status" fontSize="28"
                color="#ACB4B6"
                line
                line-color="#ACB4B6"
                marginBottom="30" marginTop="30" @loadmore="getChatList()"/>
	</view>

</template>

<script>
	import {
		imghost
	} from '@/config/host.js'
	import HeaderNav from '@/components/HeaderNav/Index.vue';
	import FooterNav from '@/components/FooterNav/Index.vue';
	import RightNav from '@/components/RightNav/Index.vue';
	import MzButton from '@/components/MzButton/Index.vue';
	import api from '@/utils/functions.js';
	import {chatList} from "@/api/chat";
  import {cardList} from "@/api/card";
	export default {
		components: {
			HeaderNav,
			FooterNav,
			RightNav,
			MzButton
		},
		data() {
			return {
				title: 'Hello',
				loading: true,
				staticImage: {
					screenActiveImg: imghost + '/static/image/banner.png',
					orderCardBackground: imghost + '/static/image/order-card-background.png',
					wallpaperBgImage:imghost +'/static/image/background.png',
					chatBgImage:imghost +'/static/image/chat-list-background.png',
					chatLTBgImage:imghost +'/static/image/chat-list-lt-background.png',
					bodyBackground:imghost+'/static/image/background.png'
				},
				isTop: false,
				chatList:[],
        status:'loadmore',
        page:1,
			}
		},
		mounted() {
			this.getChatList();
		},
		methods: {
			chatDetail(item){
				uni.navigateTo({
					url:'/pages/ChatDetail/index?id='+item.id
				});
			},
			getChatList(){

        if(this.status === 'nomre'){
          return false;
        }
        this.status = 'loading';
        chatList(this.page, this.$store.state.userInfo.store_id > 0).then(res => {
          this.chatList.push.apply(this.chatList,res.data);
          if(res.data.length === 0){
            this.status = 'nomore';
          }else{
            this.status = 'loadmore';
          }
          this.page++;
        })
			}
		},
    onReachBottom() {
      this.getChatList();
    },
		onPageScroll(res) {
			if(res.scrollTop <= 20){
				uni.$emit('isTop', true);
			}else{
				uni.$emit('isTop', false);
			}
		},
		created() {
			// this.pagePadding = (api.navHeight().navPaddingTop +
			// 	api.navHeight().navHeight + (api.navHeight().headerPadding * 2))
		}
	}
</script>

<style lang="scss">
	@import '@/pages/Index/components/ChatPage/components/index.scss';
</style>