<template>
	<view class="content">
		<view class="topView">
			<!-- tab -->
			<view class="tab">
				<view class="tabLine" :class="{tabActive:tabIndex==1}" @click="tabClick(1)">待处理</view>
				<view class="tabLine" :class="{tabActive:tabIndex==2}" @click="tabClick(2)">申请记录</view>
			</view>
			<!-- 搜索 -->
			<view class="searchBoxBg">
				<searchBox placeholder="订单号、售后单号" @search='search($event)'></searchBox>
			</view>
		</view>
		
		<!-- list -->
		<view class="listContent">
			<view class="itemBg" v-for="(item,index) in itemData">
				<view class="firstView">
					<view style="font-size: 24rpx; color: #999999;">申请单号：{{item.ServiceCode}}</view>
					<view class="rightView">
						<image src="../../static/img/icon_tuikuan2.png" mode="" style="width: 30rpx; height: 30rpx; margin-right: 10rpx;"></image>
						<view style="color: #666666; font-size: 24rpx;">退款</view>
					</view>
				</view>
				
				<view class="shopName">{{item.ShopName}}</view>
				<view class="itemName">{{item.itemNameList}}</view>
				<view class="itemName">{{item.goodNameList}}</view>
				<!-- ServiceState"：1待处理2退款成功3退款关闭 -->
				<view class="stateView" v-if="item.ServiceState==1">待平台处理</view>
				<view class="stateView" v-if="item.ServiceState==2">退款成功</view>
				<view class="stateView" v-if="item.ServiceState==2 && item.MoneyState==1">退款成功 退款金额￥{{item.Money}}元</view>
				<view class="stateView" v-if="item.ServiceState==3">退款关闭</view>
				
				<view style="display: flex; justify-content: flex-end;">
					<view class="detail" @click="goDetail(item.ID)">退款详情</view>
				</view>
			</view>
		</view>
	
		
		<!-- 上拉 加载更多 -->
		<view class="noMore" v-if="noMoreShow">没有更多数据</view>
		<!-- 无数据空白页 -->
		<view class="nodataBox" v-if="itemData.length == 0">
			<image src="../../static/img/pic_empty_def.png" mode="widthFix" class="nodataImg"></image>
			<view class="noTxt">暂无数据</view>
		</view>
		
	</view>
</template>

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

		data() {
			return {
				searchValue: '',
				page: 1,
				tabIndex: 1,
				itemData:[],
				noMoreShow: false,
			}
		},
		onLoad() {
			this.getData();
		},
		onShow() {
			this.page = 1
			this.getData();
		},
		methods: {
			goDetail(id){
				uni.navigateTo({
					
					url:'refundMoneyDetail?id='+id
				})
			},
			tabClick(num) {
				this.tabIndex = num;
				this.page = 1;
				this.getData()
			},
			search(val) {
				// console.log(val);
				this.searchValue = val
				this.page = 1
				this.getData()
			},
			getData() {
				uni.showLoading({
					title: '加载中'
				})
				var serviceStateStr = ''
				if (this.tabIndex == 1) {
					serviceStateStr = '1'
				}
				let url = 'worldKeepCar/keepCarMy/listTMSheetAfterServicePage',
					params = {
						page: this.page,
						limit: 10,
						name: this.searchValue,
						serviceState:serviceStateStr,
					}
				this.$http(url, params, 'GET').then(res => {
					uni.hideLoading()
					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 = false
					} else {
						this.noMoreShow = true
					}
			
				})
			}
		},
		
		
		onPullDownRefresh() {
			this.page = 1;
			this.getData()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.page++;
			this.getData()
		}
	}
</script>

<style>
	.content {
		background: #F4F5F7;
		min-height: 100vh;

	}

	.topView {
		background: #FFFFFF;
		position: fixed;
		width: 100%;
		height: 210rpx;
		z-index: 99;
	}

	.tab {
		background: #FFFFFF;
		display: flex;
		justify-content: space-around;
		line-height: 90rpx;
		height: 90rpx;
		width: 100%;

	}

	.tabLine {

		text-align: center;
	}

	.tabActive {
		color: #FF4F00;
		border-bottom: 4rpx solid #FF4F00;
	}

	.searchBoxBg {
		
		width: 100%;
		background-color: #FFFFFF;
		border-top: 1rpx solid #EEEEEE;
	}

	.searchBox {
		display: flex;
		height: 72rpx;
		margin: 24rpx;
		background-color: #F4F5F7;
		border-radius: 36rpx;
	}
	.listContent{
		padding-top: 210rpx;
		padding-bottom: 20rpx;
	}
	.itemBg {
		background-color: #FFFFFF;
		margin: 20rpx 24rpx;
		border-radius: 10rpx;
		padding: 20rpx;
	}
	.firstView{
		padding-bottom: 20rpx;
		display: flex;
		justify-content: space-between;
		
	}
	.rightView{
		display: flex;
		align-items: center;
	}
	.shopName{
		padding-bottom: 20rpx;
		color: #333333;
		font-size: 26rpx;
	}
	.itemName{
		padding-bottom: 20rpx;
		color: #666666;
		font-size: 24rpx;
	}
	.stateView{
		background-color: #F8F9FB;
		border-radius: 10rpx;
		color: #333333;
		font-size: 26rpx;
		
		padding: 20rpx;
	}
	.detail{
		color: #FF2400;
		font-size: 26rpx;
		margin-top: 20rpx;
		width: 150rpx;
		height: 56rpx;
		line-height: 56rpx;
		text-align: center;
		border-radius: 36rpx;
		border: 1rpx #FF2400 solid;
		
	}
	
	/* 空白页css */
	.nodataBox {
		text-align: center;
	}
	
	.nodataImg {
		width: 400rpx;
		padding-top: 300rpx;
	}
	
	.noTxt {
		font-size: 30rpx;
		color: #999999;
		padding-top: 50rpx;
	}
	
	.noMore {
		text-align: center;
		line-height: 50rpx;
		color: #999999;
		font-size: 28rpx;
	}
</style>
