<template>
	<view class="project-container">
		<view class="project-item">
			<view class="project-title">
				<view class="title-line"></view>
				<view class="title-label">房源管理</view>
			</view>
			<view class="project-content">
				<view class="air-item">
					<view class="test-item">
						<view class="name">总面积(㎡)</view>
						<view class="number">120</view>
					</view>
					<view class="line"></view>
					<view class="test-item">
						<view class="name">已租面积(㎡)</view>
						<view class="number">120</view>
					</view>
					<view class="line"></view>
					<view class="test-item">
						<view class="name">剩余面积(㎡)</view>
						<view class="number">120</view>
					</view>
				</view>
				<view class="air-item">
					<view class="test-item">
						<view class="name">总房源(个)</view>
						<view class="number">64</view>
					</view>
					<view class="line"></view>
					<view class="test-item">
						<view class="name">已租房源(个)</view>
						<view class="number">63</view>
					</view>
					<view class="line"></view>
					<view class="test-item">
						<view class="name">剩余房源(个)</view>
						<view class="number">1</view>
					</view>
				</view>
			</view>
		</view>
		<view class="project-item">
			<view class="project-title">
				<view class="title-line"></view>
				<view class="title-label">费用管理</view>
			</view>
			<view class="project-content">
				<view class="bill-subsection">
					<uv-subsection :list="list" :current="current" custom-style="height: 60rpx;border-radius: 30rpx;"
						custom-item-style="border-radius: 30rpx;" @change="change">
					</uv-subsection>
				</view>
				<view class="bill-charts">
					<qiun-data-charts type="pie" :opts="opts" :chartData="chartData" :canvas2d="true"
						canvasId="charts1">
					</qiun-data-charts>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['pie'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [5, 5, 5, 5],
					enableScroll: false,
					extra: {
						pie: {
							activeOpacity: 0.5,
							activeRadius: 10,
							offsetAngle: 0,
							labelWidth: 15,
							border: true,
							borderWidth: 3,
							borderColor: "#FFFFFF"
						}
					}
				},
				list: ['房租', '物业', '水电'],
				current: 0
			}
		},
		onReady() {
			this.getServerData();
		},
		methods: {
			getServerData() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						series: [{
							data: [{
								"name": "应收",
								"value": 50,
								"labelShow": false
							}, {
								"name": "已收",
								"value": 30,
								"labelShow": false
							}, {
								"name": "逾期",
								"value": 20,
								"labelShow": false
							}]
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},
			change(index) {
				this.current = index;
			}
		}
	}
</script>

<style lang="scss">
	.project-container {
		padding: 30rpx;

		.bill-subsection {
			margin-top: 30rpx;
		}

		.bill-charts {
			height: 400rpx;
		}

		.project-item {
			padding: 30rpx;
			background: #fff;
			margin-bottom: 20rpx;
			border-radius: 16rpx;

			.project-title {
				display: flex;
				align-items: center;
			}

			.title-line {
				width: 18rpx;
				height: 52rpx;
				background: $uni-primary;
				border-radius: 18rpx;
			}

			.title-label {
				font-size: 32rpx;
				font-weight: bold;
				margin-left: 20rpx;
			}

			.air-item {
				display: flex;
				align-items: center;
				margin-top: 20rpx;

				.test-item {
					flex: 1;
					width: 0;
					overflow: hidden;
					text-align: center;
					position: relative;
				}

				.name {
					font-size: 24rpx;
					margin-bottom: 8rpx;
					line-height: 36rpx;
					color: $uni-secondary-color;
				}

				.number {
					font-size: 18px;
					color: $uni-primary;
				}

				.line {
					height: 32rpx;
					width: 2rpx;
					background: $uni-border-1;
				}
			}
		}
	}
</style>