<template>
	<view>
		<scroll-list ref="list" :option="option" @load="load" @refresh="refresh" @loadSuccess="loadSuccess"
			@scrolltolower="scrolltolower">
			<view v-for="(item, index) in list" :key="index" @click="handleTest(item)">
				<view class="infoBody">
					<view>
						<view style="border-bottom: 1px #b8b8b8 solid;">
							<uni-row class="demo-uni-row">
								<uni-col :span="20">
									<view class="demo-uni-col dark"
										style="font-size: 36rpx;margin: -20rpx 0 0 0;font-weight: bold;letter-spacing:5rpx;">
										{{changeTypes [parseInt(item.changeType)-1] }}
									</view>
								</uni-col>
								<uni-col :span="4">
									<view v-if="item.changeType != '2'" class="demo-uni-col light"
										style="color: rgb(55,186,189);margin-bottom: 10rpx;">
										{{"+ "+item.amassScore}}
									</view>
									<view v-else class="demo-uni-col light"
										style="color: rgb(55,186,189);margin-bottom: 10rpx;">
										{{"- "+item.amassScore}}
									</view>
								</uni-col>
							</uni-row>
						</view>
						<uni-row class="demo-uni-row">
							<uni-col>
								<view class="demo-uni-col light" style="padding: 8rpx;color: #b1b1b1;">
								</view>
							</uni-col>
						</uni-row>
						<uni-row class="demo-uni-row">
							<uni-col :span="11">
								<view class="demo-uni-col light" style="color: #727272;">
									{{userName}}
								</view>
							</uni-col>
							<uni-col :span="13">
								<view class="demo-uni-col light" style="color: #727272;">
									{{item.changeDate}}
								</view>
							</uni-col>
						</uni-row>
					</view>
				</view>
			</view>
		</scroll-list>
	</view>
</template>
<style lang="scss">
	.page-wrap {}

	.infoBody {
		background-color: #ffffff;
		padding: 40rpx 40rpx 20rpx 40rpx;
		border-radius: 20rpx;
		margin: 20rpx;
		box-shadow: 0px 2px 10px #cccccc;
	}
</style>
<script>
	export default {
		data() {
			return {
				option: {
					page: 1,
					size: 5,
					auto: true
				},
				userName: uni.getStorageSync("userInfo").nickName,
				page: 1,
				list: [],
				total: 0,
				changeTypes: ['使用积分卡', '兑换礼品', '退还', '平台操作']
			}
		},
		onLoad() {},
		onShow() {
			this.refresh({
				page: 1,
				size: 5
			})
		},
		methods: {
			handleTest(item) {
				item.pageType = 1
				uni.setStorageSync("approval", item)
				this.$goto('../ge/geApproval')
			},
			async taskList(paging) {
				// 发送请求
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/asl?uc=' + uni.getStorageSync("userInfo").userName + '&pageNum=' + paging.page +
						'&pageSize=' + paging.size,
					method: 'get',
					urlType: 2
				});
				if (res.code === 200) {
					setTimeout(() => {
						if (paging.page === 1) {
							//this.list = res.rows
							this.total = res.total
							this.$refs.list.loadSuccess({
								list: res.rows,
								total: this.total
							});
						} else if (paging.page > 1) {
							for (var i = 0; i < res.rows.length; i++) {
								this.list.push(res.rows[i])
							}
							this.$refs.list.loadSuccess({
								list: this.list,
								total: this.total
							});
						}
					}, 300)
				}
			},
			// 刷新刷剧
			refresh(paging) {
				this.taskList(paging)
			},
			scrolltolower(e) {
				console.log(e)
			},
			load(paging) {
				console.log(2, paging)
				this.taskList(paging)
			},
			loadSuccess(list) {
				console.log(3, list)
				this.list = list
			}
		}
	}
</script>
