<template>
	<view class="billall">
		<!-- 	<u-cell-group>
			<u-cell :title="mytitle" value="修改" :isLink="true" @click="floorchange">
				<u-icon slot="icon" size="40" name="map"></u-icon>
			</u-cell>
		</u-cell-group> -->
		<view class="topbill">
			<view class="topbilledit">
				<view class="changetime1">
					<picker mode="date" :value="myday" fields="month" @change="dateChange">
						<view class="selestDate">{{myday}}</view>
					</picker>
				</view>
				<view class="changetime2">
					<u-icon name="arrow-down-fill" color="#666666" size="20"></u-icon>
				</view>
			</view>
			<view class="topbilledit" @click="typechange">
				<view class="changetime1">
					{{mytype}}
				</view>
				<view class="changetime2">
					<u-icon name="arrow-down-fill" color="#666666" size="20"></u-icon>
				</view>
			</view>
			<view class="topbilledit" @click="typechanges">
				<view class="changetime1">
					{{mytypes}}
				</view>
				<view class="changetime2">
					<u-icon name="arrow-down-fill" color="#666666" size="20"></u-icon>
				</view>
			</view>
		</view>

		<view class="u-listdata">


			<u-list @scrolltolower="scrolltolower" :pagingEnabled='true'>
				<u-list-item v-for="(item, index) in indexList" :key="index">

					<view class="companylist" @click="seedetail(item)">
						<!-- <view class="settled" v-if="item.isSettled==0">
							已催费
						</view>
						<view class="outstanding" v-if="item.isSettled==1">
							未催费
						</view> -->
						<view class="settled" :style="{
						                'background-color': item.isExpedit == 1 ? '#09C700' : '#FA5555',
						              }">
							{{ item.isExpedit == 1 ? "已催费" : "未催费" }}
						</view>

						<h3>{{item.tenantName}}</h3>
						<view class="Currentamount">
							欠费金额: <span>￥{{item.amount}}</span>
						</view>
						<view class="Currentamount">
							计费周期: {{item.costCycle}}
						</view>
						<view class="Currentamount">
							欠费天数:￥{{item.arrearDay}}
						</view>
						<view class="Currentamount">
							欠费类型: {{item.tel}}
						</view>


						<view class="Currentamount">
							联系电话: {{item.phone}}
						</view>
						<view class="Callfee" @click.stop="handleClick(item.id)">
							催费
						</view>
					</view>

				</u-list-item>
			</u-list>

		</view>




		<u-picker :show="showtype" :columns="columnstype" keyName="label" @confirm="confirmtype" @cancel='canceltype'>
		</u-picker>
		<u-picker :show="showtypes" :columns="columnstypes" keyName="dictLabel" @confirm="confirmtypes"
			@cancel='canceltypes'>
		</u-picker>

		<u-notify ref="uNotify" :show="showdct" message="服务器请求失败"></u-notify>
	</view>
</template>

<script>
	import {
		isEmpty,
		getDictDataList
	} from "@/utils/index";
	export default {
		components: {},
		data() {
			const currentDate = this.getDate({
				format: 'yyyy-mm'
			})
			return {
				setyesno: true,
				indexList: [],
				dataList: [],
				dataForm: {
					cycle: "",
					billType: "",
					arrearDay: "",
					isExpedit: "",
					page: 1,
					limit: 10,
				},
				showtypes: false,
				showtype: false,
				showdct: false,
				mytitle: '',
				alldata: [],

				loading: false,
				columns: [],
				pd: true,
				columnData: [],
				myday: '',
				mytype: '全部',
				mytypes: "全部",
				showPicker: false,
				myday: currentDate,
				columnstype: [
					[{
							label: '全部',
							id: ''
						}, {
							label: '水费',
							id: 'Water'
						},
						{
							label: '电费',
							id: 'Elec'
						},
						{
							label: '物业费',
							id: 'PropertyFee'
						}
					]
				],
				columnstypes: [],


			}
		},
		//监听页面加载，其参数为上个页面传递的数据，参数类型为 Object（用于页面传参
		onLoad() {
			this.columnstypes = [getDictDataList("ArrearageDay")];


			console.log('00', getDictDataList("ArrearageDay"), getDictDataList("PayType"), getDictDataList("isExpedit"))

			//	this.loadmore();
		},
		//监听页面初次渲染完成。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {
			// 微信小程序需要用此写法
		},

		//监听页面隐藏
		onHide() {},
		//监听窗口尺寸变化
		onResize() {},
		//监听页面卸载
		onUnload() {},
		//监听用户下拉动作，一般用于下拉刷新
		onPullDownRefresh() {},


		methods: {
			seedetail(e) {
				  console.log('222',e.tenantName)
				
				// console.log('111111111111111111',faltesdata)
				uni.navigateTo({
				 url: `/pages/index/Immediatecollection/Chargedetails/Chargedetails?companyOrgId=${e.tenantName}`
				})
			},
			handleClick(e) {
				console.log('111111111111111111', e)
				this.$api.post('/expeditrecord/charge', {
						data: e
					})
					.then(res => {
						if (res.data.code == 0) {
							uni.showToast({
								title: '催费成功',
								icon: 'none',
								duration: 1500
							})
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 1500
							})
						}

					})
			},
			scrolltolower() {
				if (this.pd) {
					this.getalldata();
				} else {
					return
				}
			},
			typechanges() {
				this.showtypes = true;
			},
			getalldata() {

				this.$api.get('/expeditrecord/apppage', this.dataForm)
					.then(res => {

						if (res.data.data.list.length != 0) {
							this.indexList.push(...res.data.data.list);
							this.dataForm.page = this.dataForm.page + 1;
							this.pd = true;
						} else {
							uni.showToast({
								title: '暂无更多数据了',
								icon: 'none',
								duration: 1500
							})
							this.pd = false;
						}

					})
			},


			canceltype() {
				this.showtype = false;
			},
			confirmtype(e) {
				//	console.log('111111111111111111', e.value[0])
				this.showtype = false;
				this.mytype = e.value[0].label;
				this.dataForm.billType = e.value[0].id;
				this.dataForm.page = 1;
				this.getalldata();
			},
			confirmtypes(e) {
				// console.log('22222', e.value[0])
				this.showtypes = false;
				this.mytypes = e.value[0].dictLabel;
				this.dataForm.arrearDay = e.value[0].dictValue;
				this.dataForm.page = 1;
				this.getalldata();
			},
			canceltypes() {
				this.showtypes = false;
			},
			typechange() {
				this.showtype = true;
			},
			dateChange(e) {
				//  console.log('3333',e)
				this.myday = e.target.value;
				this.dataForm.cycle = e.target.value;
				this.dataForm.page = 1;
				this.getalldata();
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				// day = day > 9 ? day : '0' + day;
				return `${year}-${month}`;
			},






		}
	}
</script>

<style lang="scss">
	.Currentamount {
		padding-left: 30rpx;
		height: 50rpx;
		line-height: 50rpx;
		color: #BCB3A7;

		span {
			color: #FA5555;
			padding-left: 9rpx;
		}
	}

	.Callfee {
		width: 100rpx;
		height: 45rpx;
		text-align: center;
		line-height: 45rpx;
		color: #5C8FFF;
		border: 1px solid #5C8FFF;
		font-size: 22rpx;
		position: absolute;
		bottom: 10rpx;
		right: 10px;
		font-weight: bold;
	}

	.companylist {
		margin: 20rpx 30rpx;
		background: #fff;
		height: 340rpx;
		border-radius: 10px;
		position: relative;

		h3 {
			height: 70rpx;
			line-height: 70rpx;
			padding-left: 30rpx;
		}
	}

	.settled {
		background-color: #09C700;
		width: 100rpx;
		height: 40rpx;
		text-align: center;
		line-height: 40rpx;
		color: #fff;
		font-size: 14rpx;
		position: absolute;
		top: 0px;
		right: 0px;
		border-top-right-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}

	.outstanding {
		background-color: #FA5555;
		width: 100rpx;
		height: 40rpx;
		text-align: center;
		line-height: 40rpx;
		color: #fff;
		font-size: 14rpx;
		position: absolute;
		top: 0px;
		right: 0px;
		border-top-right-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}



	.billall {}

	.topbill {
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 100rpx;
		background-color: #e6e6e6;
	}

	.topbilledit {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.changetime1 {
		padding-right: 10rpx;
	}
</style>
