<template>
	<view class="content">
		<view class="topView">
			<!-- tab -->
			<view class="tab">
				<view class="tabLine" :class="{tabActive:tabIndex==1}" @click="tabClick(1)">
					<view class="orderNum" v-show="num>0">{{num}}</view>
					待处理</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.ChangeCode}}</view>
					<view class="rightView">
						<image src="../../static/img/icon_change.png" mode="" style="width: 30rpx; height: 30rpx; margin-right: 10rpx;"></image>
						<view style="color: #666666; font-size: 24rpx;">更换门店</view>
					</view>
				</view>
				
				<view class="shopName">
					<text style="color: #999999; font-size: 26rpx;">更换前门店：</text>
				{{item.OldShopName}}</view>
				<view class="shopName">
					<text style="color: #999999; font-size: 26rpx;">更换后门店：</text>
					{{item.NewShopName}}</view>
				<!-- "ChangeState": //备注：1待处理2更换成功3更换关闭 -->
				<view class="stateView" v-if="item.ChangeState==1">待平台处理</view>
				<view class="stateView" v-if="item.ChangeState==2">更换成功</view>
				<view class="stateView" v-if="item.ChangeState==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,
				num:'',
			}
		},
		onLoad() {
			this.getData();
		},
		onShow() {
			this.page = 1
			this.getData();
		},
		methods: {
			goDetail(id){
				uni.navigateTo({
					url:'changeStoreDetail?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 changeStateStr = ''
				if (this.tabIndex == 1) {
					changeStateStr = '1'
				}
				let url = 'worldKeepCar/keepCarMy/listTMSheetChangeShopPage',
					params = {
						page: this.page,
						limit: 10,
						name: this.searchValue,
						changeState:changeStateStr,
					}
				this.$http(url, params, 'GET').then(res => {
					uni.hideLoading()
					var list = res.data.Items
					this.num = res.data.changeState
					// 处理 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.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;
		position: relative;
	}

	.tabActive {
		color: #FF4F00;
		border-bottom: 4rpx solid #FF4F00;
	}
	.orderNum {
		line-height: 26rpx;
		background: #FF4F00;
		padding: 0 8rpx;
		border-radius: 13rpx;
		color: #FFFFFF;
		font-size: 20rpx;
		position: absolute;
		top: 10rpx;
		right: -10rpx;
		z-index: 11;
	}
	.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;
	}
	.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>
