<template>
	<view class="order">
		<view class="tab-box">
			<view class="tab" :class="[query.orderType == null?'active':'']" @click="handleTab(null)">
				全部
			</view>
		<!-- 	<view class="tab" :class="[query.orderType == 'USED'?'active':'']" @click="handleTab('USED')">
				已使用
			</view> -->
			<view class="tab" :class="[query.orderType == 'WAIT_PAYMENT'?'active':'']" @click="handleTab('WAIT_PAYMENT')">
				待付款
			</view>
			<view class="tab" :class="[query.orderType == 'WAIT_USE'?'active':'']" @click="handleTab('WAIT_USE')">
				待使用
			</view>
			<view class="tab" :class="[query.orderType == 'APPLY_REFUND'?'active':'']" @click="handleTab('APPLY_REFUND')">
				退款
			</view>
		</view>
		<u-empty v-if="!list.length && status == 'noMore'" mode="order" iconSize="200rpx" textSize="28rpx">
		</u-empty>
		<zs-list mt="0" @load="loadMore" :status="status">
			<view class="order-item" v-for="(item,index) in list" :key="index" @click="jump(item)">
				<view class="top-box">
					<view class="label">
						{{ item.shopInfo.shopName||'慧研学惠生活'}}
					</view>
					<view class="status">
						{{ item.goodsModelList[0] |filterType}}
					</view>
				</view>
				<view class="order-box">
					<zs-img radius="full" :src="formatImg(item.goodsModelList[0])" width="164rpx" height="164rpx"></zs-img>
					
					<view class="info">
						<view class="title">
							{{item.goodsModelList[0].goodsInfo.activityName||item.goodsModelList[0].goodsInfo.goodsName}}
						</view>
						<view class="time">
							{{$u.timeFormat(item.createTime,'yyyy-mm-dd hh:MM:ss')}}
						</view>
						<view class="price">
							¥{{item.payAmount}}
						</view>
					</view>
				</view>
			</view>
		</zs-list>
	</view>
</template>

<script>
	import {getOrderList} from '@/api/order.js'
	export default {
		data() {
			return {
				status: 'more',
				loading: false,
				query:{
					orderType:null,
					channel:'ZhongShu',
					page:0,
					size:10,
					userId:JSON.parse(uni.getStorageSync('userInfo')).userId
				},
				total:0,
				list: [],
				requestTask:null,
				imgUrl:{
					Kfc:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/xgJrwD0vChsW012ac1e138a0aa5a970e8f8c59dab926.png/1.png',
					MDL:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/K64jffEqRIDr487e8cab971c3b890d4066a26f5856d2.png/1.png',
					XBK:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/xMwtPkICBcam5513c4ac644054e60009cb8b1eb52e8f.png/1.png',
					NXDC:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/U9j6fgVmKeAt522ed50aa1a72f798260e0e30138d4c6.png/1.png',
					RXKF:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/zS5Q8sC9AAQca76eef36da2bd5a2ec234d75d8dcc044.png/1.png',
					XC:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/fA95my16Qunf967a9d992fc41134332926bcb5665881.png/1.png',
					KD:'https://hyxhsh.oss-cn-chengdu.aliyuncs.com/63b7c68b71a69169d1b33f92/store/bdb/user/avatar/wk5eyuvhighG206a7ea081e3f0b783ff2a9555375e85.png/1.png',
				}
			}
		},
		filters: {
			filterType: function(val) {
				if(val.refundLog&&val.refundLog.refund == 'REFUSAL_REFUND'){
					return '拒绝退款'
				}
				else if(val.jobFlowMap == 'Hotel'&&val.extend.orderInfo){
					return val.extend.orderInfo.orderStatus
				}
				else if(val.goodsState == 'APPLY_REFUND'){
					return '退款审核中'
				}else if(val.goodsState == 'CLOSE'){
					return '关闭订单'
				}else if(val.goodsState == 'REFUNDED'){
					return '已退款'
				}else if(val.goodsState == 'REFUSAL_REFUND'){
					return '拒绝退款'
				}else if(val.goodsState == 'APPLY_REFUNDING'){
					return '退款中'
				}else if(val.goodsState == 'USED'){
					if(val.jobFlowMap == 'YPP'){
						return '已出票'
					}else{
						return '订单已完成'
					}
					
				}else if(val.goodsState == 'WAIT_PAYMENT'){
					return '待付款'
				}else if(val.goodsState == 'WAIT_USE'){
					if(val.jobFlowMap == 'YPP'){
						return '出票中'
					}else{
						return '待使用'
					}
				}else{
					return ''
				}
			}
		},
		methods: {
			formatImg(item){
				if(item.jobFlowMap == 'Kfc'){
					return this.imgUrl[item.goodsInfo.ot] 
				}else if(item.jobFlowMap == 'Activity'){
					return item.goodsInfo.activityCover
				}else{
					return item.goodsInfo.goodsPath
				}
			},
			handleTab(val){
				this.query.orderType = val
				this.query.page = 0
				this.list = []
				this.getOrderList()
			},
			loadMore() {
				this.getOrderList()
				
			},
			jump(item) {
				// uni.setStorageSync('order',JSON.stringify(item))
				
				// 研学类型商品统一走研学订单详情
				if(item.goodsModelList[0].goodsInfo.isStudy){
					uni.navigateTo({
						url: '/study/pay/orderPay?id='+item.orderNo
					})
					return
				}

				if(item.goodsModelList[0].jobFlowMap == 'Ticket'){
					uni.navigateTo({
						url: '/my/order/scenic/detail?id='+item.orderNo
					})
				}
				else if(item.goodsModelList[0].jobFlowMap == 'Hotel'){
					uni.navigateTo({
						url: '/my/order/hotel/detail?id='+item.orderNo
					})
				}
				else if(item.goodsModelList[0].jobFlowMap == 'YPP'){
					uni.navigateTo({
						url: '/my/order/movie/detail?id='+item.orderNo
					})
				}
				else if(item.goodsModelList[0].jobFlowMap == 'Kfc'){
					uni.navigateTo({
						url: '/my/order/foodOrder/detail?id='+item.orderNo
					})
				}
				else if(item.goodsModelList[0].goodsInfo.activityName){
					uni.navigateTo({
						url: '/my/order/signUp/signUpDetail?id='+item.orderNo
					})
				}else if(item.goodsModelList[0].jobFlowMap == 'QiuXiang'){
					uni.navigateTo({
						url: '/my/order/trip/detail?id='+item.orderNo
					})
				}else{
					uni.navigateTo({
						url: './detail?id='+item.orderNo
					})
				}
			},
			getOrderList(){
				this.requestTask&&this.requestTask.abort()
				this.status = 'loading'
				getOrderList(this.query).then(res=>{
					this.requestTask =res.task
					if(res.state == 'Success'){
						this.total = res.content.totalElements
						this.list = this.list.concat(res.content.content) 
						this.list.length>=this.total?this.status = 'noMore':this.status = 'more'
						this.query.page++
						uni.stopPullDownRefresh()
					}
				})
			}
		},
		onPullDownRefresh() {
			this.query.page = 0
			this.list = []
			this.status = 'more'
			this.getOrderList()
		},
		onLoad(option) {
			this.query.orderType = option.type || null
		}
	}
</script>

<style lang="scss">
	.order {
		background: #efefef;
		padding: 90rpx 30rpx 0;
		min-height: 100vh;
		.tab-box{
			display: flex;
			position: fixed;
			width: 750rpx;
			height: 70rpx;
			left: 0%;
			top: 0%;
			z-index: 9;
			background: #fff;
			
			.tab{
				flex: 1;
				text-align: center;
				padding: 15rpx 0;
				font-size: 28rpx;
				color: #999999;
			}
			.tab.active{
				font-size: 32rpx;
				color: #222222;
				position: relative;
				&::after{
					content: '';
					width: 40rpx;
					height: 8rpx;
					box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255,255,255,0.16);
					border-radius: 46rpx 46rpx 46rpx 46rpx;
					background: $uni-color-primary;
					position: absolute;
					bottom: 0%;
					left: 50%;
					transform: translateX(-50%);
				}
			}
		}
		.zs-list {

			.order-item {
				background-color: #fff;
				border-radius: 8px;
				margin-bottom: 20rpx;
				.top-box{
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 20rpx;
					border-bottom:2rpx solid #F3F3F3;
					.label{
						font-weight: bold;
						color: #222222;
						font-size: 32rpx;
						width: 500rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
					.status{
						font-size: 28rpx;
						color: #999999;
					}
				}
				.order-box {
					padding: 25rpx;
					display: flex;

					.icon {
						width: 164rpx;
						height: 164rpx;
						border-radius: 16rpx;
						background-color: #999;
					}

					.info {
						margin-left: 25rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						.title {
							color: #0F0F0F;
							font-size: 28rpx;
						}

						.time {
							font-size: 26rpx;
							color: #999999;
						}
						.price{
							font-weight: bold;
							color: #181818;
						}

					}
				}
			}
		}
	}
</style>