<template>
	<view class="content">
		<view class="one">
			<picker :range="years" @change="yearChange">
				{{ years[yearsIndex] }}
				<text v-if="yearsIndex!=0">年</text>
			</picker>
		</view>
		<view class="two">
			<scroll-view scroll-y="true" class="scroll-view">
				<view class="list-scroll-view">
					<view class="list" v-for="(item,index) in list" :key="index" @tap="toInfo(item)">
						<view class="list_1">
							{{item.year||'暂无'}}
						</view>
						<view class="list_2">
							总回款金额：
							<text>￥{{item.money||'0'}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 系统设置
				config: {},
				user: {},
				searchInfo: {},
				list: [],
				years: ["请选择年份", 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036,
					2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2045, 2047, 2048, 2049, 2050
				],
				yearsIndex: 0
			}
		},
		onLoad: function(e) {
			const that = this;
		},
		onShow: async function(e) {
			const that = this;
			that.searchToken();
		},
		onPullDownRefresh: async function() {
			const that = this;
			await that.search();
			uni.stopPullDownRefresh();
		},
		methods: {
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) {
						that.$set(that, `user`, res);
					}
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			async search() {
				const that = this;
				let user = that.user;
				let info = {
					time: that.years[that.yearsIndex],
				};
				if (user.role == 'cs') info.supplier = user._id;
				else if (user.role == 'ld') info.c_leader = user._id;
				else info.c_accounting = user._id;
				let res;
				res = await that.$api(`/Statistics/orderDetail`, 'GET', {
					...info
				});
				if (res.errcode == '0') {
					that.$set(that, `list`, res.data);
				} else {
					uni.showToast({
						title: res.errmsg,
						icon: 'none'
					})
				}
			},
			yearChange: function(e) {
				const that = this;
				that.$set(that, `yearsIndex`, e.detail.value);
				if (that.yearsIndex != 0) that.search();
			},
			// 查看详情
			toInfo(e) {
				console.log(e);
			},
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			padding: 2vw;
		}

		.two {
			position: relative;
			flex-grow: 1;
			background-color: var(--f9Color);

			.list {
				background-color: #fff;
				border: 1px solid var(--f5Color);
				padding: 2vw;
				margin: 2vw 2vw 0 2vw;
				border-radius: 5px;

				.list_1 {
					padding: 0 1vw;
					font-size: var(--font16Size);
					font-weight: bold;
				}

				.list_2:last-child {
					padding: 1vw;
					font-size: var(--font14Size);

					text {
						color: var(--fF0Color);
					}
				}
			}
		}
	}

	.scroll-view {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.list-scroll-view {
			display: flex;
			flex-direction: column;
		}
	}
</style>