<template>
	<view class="box">

		<view class="itemHistory" v-for="(item,index) in itemData" :key="index" @click="goDetail(item.id)">

			<view class="carPlate">
				<view class="time">{{item.createTime}}</view>

				<view class="stateBox">
					<view class="gray" v-if="item.hState==0">已取消</view>
					<view class="red" v-if="item.hState==1">未兑换</view>
					<view class="green" v-if="item.hState==2">已兑换</view>
					<image src="../../static/img/little_rightArrow.png" mode="" style="width: 24rpx;height: 24rpx;">
					</image>
				</view>
			</view>

			<view class="goodsBox">
				<image :src="item.url" mode="" style="width: 120rpx;height: 120rpx;"></image>
				<view class="goodsRight">
					<view class="goodsName">{{item.goodsName}}</view>
					<view class="goodsCount">
						<view class="jifen">{{item.integral/item.qty}}<span
								style="font-size: 24rpx; color: #333333; margin-left: 5rpx;">积分</span>
						</view>
						<view class="count">x{{item.qty}}</view>
					</view>
				</view>
			</view>

			<view class="sum">
				<span style="font-size: 24rpx; color: #666666; margin-right: 10rpx;">总计</span>
				<span style="font-size: 32rpx; color: #FF0000; font-weight: 500; margin-right: 5rpx;">{{item.integral}}</span>

				<span style=" font-size: 24rpx; color: #FF0000;">积分</span>
			</view>


		</view>

		<!-- 上拉 加载更多 -->
		<view class="noMore" v-if="noMoreShow && (itemData.length!=0)">没有更多数据</view>
		<!-- 无数据空白页 -->
		<nodata v-if="itemData.length==0"></nodata>

	</view>
</template>

<script>
	import nodata from '../../components/nodata/nodata.vue'
	export default {
		components: {
			nodata,
		},

		data() {
			return {
				page: 1,
				itemData: [],
				noMoreShow: false,
				avaIntegral: '',
			}
		},
		onLoad(opt) {
			this.avaIntegral = opt.avaIntegral
			this.page = 1
			this.myOrderCoupon()
		},
		methods: {
			goDetail(id) {
				uni.navigateTo({
					url: 'recordDetail?id=' + id
				})
			},
			myOrderCoupon() {
				uni.showLoading({
					title: '加载中'
				})
				this.$http('openIntegralMall/exchangeRecord', {

					page: this.page,
					limit: 10,
				}, 'GET').then(res => {
					uni.hideLoading();
					// var list = res.data.Items
					var list = res.data.Items

					// 处理 undefined和null转为空白字符串
					// list.forEach((item, index) => {
					// 	for (const key in item) {
					// 		item[key] = this.$praseStrEmpty(item[key])
					// 	}
					// })

					if (this.page == 1) {
						this.itemData = list
					} else {
						this.itemData = this.itemData.concat(list)
					}

					if (list.length < 10) {
						this.noMoreShow = true
					} else {
						this.noMoreShow = false
					}





				})
			},


		},

		// 下拉刷新 上拉加载更多
		onPullDownRefresh() {
			this.page = 1
			this.myOrderCoupon()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.page++;
			this.myOrderCoupon()
		},
	}
</script>

<style>
	.box {
		min-height: 100vh;
		background-color: #F4F5F7;
		padding: 20rpx 24rpx;
	}



	.itemHistory {

		padding: 30rpx 20rpx;
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
	}

	.time {
		font-size: 24rpx;
		color: #999999;
	}

	.stateBox {
		display: flex;
		align-items: center;
	}

	.carPlate {

		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.plate {
		font-size: 30rpx;
		color: #3C3C3C;

	}

	.gray {
		font-size: 24rpx;
		color: #999999;
	}

	.green {
		font-size: 24rpx;
		color: #00A040;
	}

	.red {
		font-size: 24rpx;
		color: #FF0000;

	}

	.goodsBox {
		display: flex;
		padding: 30rpx 0;

		border-bottom: 1rpx solid #EEEEEE;
	}

	.goodsRight {
		margin-left: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.goodsName {
		width: 522rpx;

		font-size: 26rpx;
		font-weight: 400;
		color: #3C3C3C;
		line-height: 37rpx;
		margin-bottom: 15rpx;
	}

	.goodsCount {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.jifen {

		height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		line-height: 45rpx;

	}

	.count {
		height: 33rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: #999999;
		line-height: 33rpx;
	}

	.sum {
		margin-top: 34rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}


	.noMore {
		text-align: center;
		line-height: 50rpx;
		color: #999999;
		font-size: 28rpx;
	}
</style>