<template>
	<view>
		<u-navbar :title="title"  title-color="#101010" ></u-navbar>
		<view class="main" v-if="type=='AA'">
			<view class="item" v-for="(item,i) in list"
			 
			  @click="gotoUrl('/pages/deductionRecord/billPush?site=1&id='+item.id)"
			  
			 :key="i">
				<view class="item-message">
					<view>{{item.name}}</view>
					<view class="billAmount">￥{{item.billAmount}}元</view>
				</view>
				<view class="item-time" style="display: flex;justify-content: space-between;">
					  <!-- {{item.tenantName}} -->
					
					<view>{{item.createTime}}</view>
					<view >{{item.payTime?'已支付':''}}</view>
				</view>
			</view>
			<u-divider :isnone="list.length==0"   nonetext="没有找到相关内容"
				border-color="#CFD2D5">已经到底了</u-divider>
		</view>
		<view class="main" v-else >
			<view class="item" v-for="(item,i) in list" :key="i">
				<view class="item-message">
					<view v-html="item.content"></view>
					<view class="billAmount"></view>
				</view>
				<view class="item-time">
					{{item.createTime}}  <!-- {{item.tenantName}} -->
				</view>
			</view>
			<u-divider :isnone="list.length==0"   nonetext="没有找到相关内容"
				border-color="#CFD2D5">已经到底了</u-divider>
		</view>
	</view>
</template>

<script>
	import * as API from '@/apis/pagejs/message.js'
	
	export default {
		data() {
			return {
				type:0,
				formData:{
					pageIndex:1,
					pageSize:20,
				},
				typeName:"",
				list:[],
				recordsTotal:0
			}
		},
		computed:{
			title(){
				if(this.type=='AA'){
					return  '账单提醒'
				}else if(this.typeName){
					return  this.typeName
				}else{
					return  '消息提醒'
				}
			}
		},
		onLoad(op) {
			if(op.type){
				this.type=op.type;
				this.formData.type=op.type;
			}
			if(op.typeName){
				this.typeName=op.typeName;
				
			}
			
			this.getList()
		},
		onReachBottom() {
			
			if (this.list.length < this.recordsTotal) {
				this.myLoadmore();
			}
		},
		methods: {
			getList(){
				if(this.type=='AA'){
					this.getBillList()
				}else{
					this.getMessageList()
				}
				
			},
			myLoadmore() {
				this.formData.pageIndex += 1;
				this.getList()
			},
			getMessageList(){
				uni.showLoading({
					mask:true,title:'加载中...'
				})
				API.messageList(this.formData).then((res) => {
					uni.hideLoading();
					if(this.formData.pageIndex==1){
						this.list = [
							
							...res.data.data
						];
					}else{
						this.list = [
							...this.list,
							...res.data.data
						];
					}
					this.recordsTotal = res.data.recordsTotal;
					
					//this.list=response.data.data;
				}).catch(error => {
					uni.hideLoading();
					uni.showToast({
						icon: "none",
						title: error
					})
				})
			},
			getBillList(){
				uni.showLoading({
					mask:true,title:'加载中...'
				})
				API.billList(this.formData).then((res) => {
					uni.hideLoading();
					if(this.formData.pageIndex==1){
						this.list = [
							
							...res.data.data
						];
					}else{
						this.list = [
							...this.list,
							...res.data.data
						];
					}
					this.recordsTotal = res.data.recordsTotal;
					
					//this.list=response.data.data;
				}).catch(error => {
					uni.hideLoading();
					uni.showToast({
						icon: "none",
						title: error
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		background-color: #fff;
		margin-top: 24rpx;
		.item{
			padding: 32rpx;
			border-bottom: 1px solid rgba(244,244,244,1);
			.item-message{
				line-height: 44rpx;
				display: flex;
				    justify-content: space-between;
				color: rgba(51,51,51,1);
				.billAmount{
					    color: #F44336;
				}
				
			}
			.item-time{
				color: rgb(153,153,153);
				font-size: 24rpx;
				margin-top: 16rpx;
			}
		}
	}

</style>
