<template>
	<view class="content">
		<view class="top">
			<u-navbar title=" " @leftClick="leftClick" height="44px" bgColor="rgb(255,255,255)" :placeholder="true">
				<view class="u-nav-slot" slot="center"> 
					<u-search placeholder="搜索我的订单" v-model="keyword" :showAction="false" @search="search"></u-search>
				</view>
			</u-navbar>
			<view class="tabs hflex acenter jbetween">
				<block v-for="(item,index) in tabs" :key="index">
					<view class="tab_item" :class="tab_active == index?'tab_active':''" @click="changeTab(index)">{{item.name}}</view>
				</block>
			</view>
		</view>
		<view class="box">
			<block v-for="(item,index) in pageList" :key="index">
				<view class="box_item">
					<view class="hflex acenter jbetween cell">
						<view class="hflex acenter" @click="toShop(item.id)">
							<view class="title">{{item.admin_name}}</view>
							<u-icon color="#B5B5B5" name="arrow-right" size="10"></u-icon>
						</view>
						<view class="text-blue" v-if="item.status == 0">已取消</view>
						<view class="text-blue" v-if="item.status == 2">待支付</view>
						<view class="text-blue" v-if="item.status == 3">待发货</view>
						<view class="text-blue" v-if="item.status == 4">待收货</view>
						<view class="text-blue" v-if="item.status == 5">已完成</view>
					</view>
					<view @click="toOrderDetail(item.id)">
						<view class="hflex acenter" v-if="item.goods_item.length == 1">
							<view>
								<image :src="item.goods_item[0].goods_cover" mode="aspectFill" class="img"></image>
							</view>	
							<view class="img_right">
								<view class="hflex acenter jbetween">
									<view class="name text_hide">{{item.goods_item[0].goods_name}}</view>
									<view class="price">￥{{item.goods_item[0].price_selling}}</view>
								</view>
								<view class="hflex jbetween" style="padding-top: 12rpx;">
									<view class="norm">{{item.goods_item[0].goods_spec}}</view>
									<view class="num">X{{item.goods_item[0].number_goods}}</view>
								</view>
							</view>
						</view>
						<view class="scroll_img" v-else>
							<scroll-view scroll-x="true" style="white-space: nowrap;" class="imgs hflex">
								<block v-for="(item2,index2) in item.goods_item" :key="index2">
									<view class="imgs_item">
										<image :src="item2.goods_cover" class="img"></image>
									</view>
								</block>
							</scroll-view>
							<view class="img_leng">共{{item.goods_item.length}}件</view>
						</view>
					</view>
					<view class="hflex acenter jend cell" v-if="item.payment_status == 2">
						<view class="price">实付款：￥{{item.payment_amount}}</view>
					</view>
					<view class="hflex acenter jend cell">
						<block v-if="item.status == 2">
							<view class="btn1">取消订单</view>
							<view class="btn1 btn2">立即支付</view>
						</block>
						<block v-if="item.status == 3">
							<view class="btn1" @click="toApply(item.id)">申请退款</view>
							<view class="btn1 btn2">提醒发货</view>
						</block>
						<block v-if="item.status == 4">
							<view class="btn1 btn2">确认收货</view>
						</block>
						<block v-if="item.status == 5">
							<!-- <view class="btn1">发表评价</view> -->
							<view class="btn1 btn2">再次购买</view>
						</block>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				keyword: '',
				tabs: [
					{
						name: '全部'
					},
					{
						name: '待支付'
					},
					{
						name: '待发货'
					},
					{
						name: '待收货'
					}
				],
				tab_active: 0,
				pageList: [
				]
			}
		},
		onLoad(options) {
			that = this
			that.tab_active = Number(options.id)
			that.getList()
		},
		methods: {
			// 返回
			leftClick() {
				console.log('返回');
				$api.jump(-1)
			},
			// 获取我的订单
			getList() {
				$api.req({
					url: '/data/api.Order/order_list',
					method: 'POST',
					data: {
						order_name: that.keyword?that.keyword: '',
						status: that.tab_active + 1
					}
				}, function(res) {
					if(res.code == 1) {
						console.log(res);
						that.pageList = res.data.list
					} 
				})
			},
			changeTab(index) {
				that.tab_active = index
				that.pageList = []
				that.getList()
			},
			// 店铺
			toShop(id) {
				$api.jump('/page_shop/pages/good/shop?id=' + id)
			},
			toOrderDetail(id) {
				$api.jump('/page_shop/pages/order/detail?id=' + id)
			},
			// 申请退款
			toApply(id) {
				$api.jump('/page_shop/pages/order/apply?id=' + id)
			},
			search(e) {
				that.getList()
			}
			
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F3F3F3;
		.top {
			box-sizing: border-box;
			// padding: 30rpx;
			// height: 540rpx;
			.u-nav-slot {
				position: absolute;
				top: 8rpx;
				left: 134rpx;
			}
			.tabs {
				background-color: #fff;
				width: 100%;
				box-sizing: border-box;
				padding: 20rpx 30rpx;
				.tab_item {
					font-size: 32rpx;
					font-weight: 400;
					color: #333333;
					line-height: 44rpx;
				}
				.tab_active {
					font-weight: 500;
					color: #222222;
					position: relative;
				}
				.tab_active::after {
					content: "";
					position: absolute;
					bottom: -14rpx;
					left: 12rpx;
					width: 40rpx;
					height: 6rpx;
					background: #506DFF;
					border-radius: 4rpx;
				}
			}
		}
		.box {
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			.box_item {
				background: #FFFFFF;
				border-radius: 20rpx;
				width: 100%;
				margin-top: 20rpx;
				box-sizing: border-box;
				padding: 0 20rpx;
				.cell {
					padding: 20rpx 0;
				}
				.title {
					font-size: 30rpx;
					font-weight: 500;
					color: #333333;
					line-height: 42rpx;
				}
				.text-blue {
					font-size: 26rpx;
					font-weight: 400;
					color: #506DFF;
					line-height: 36rpx;
				}
				.img {
					width: 160rpx;
					height: 160rpx;
					border-radius: 16rpx;
					
				}
				.img_right {
					margin-left: 16rpx;
					width: calc(100% - 176rpx);
					.name {
						width: 392rpx;
						font-size: 28rpx;
						font-weight: 500;
						color: #222222;
						line-height: 40rpx;
					}
					
					.norm {
						width: 308rpx;
						height: 84rpx;
						background: #F5F5F5;
						border-radius: 4rpx;
						font-size: 22rpx;
						font-weight: 400;
						color: #888888;
						line-height: 32rpx;
						box-sizing: border-box;
						padding: 12rpx;
					}
					.num {
						font-size: 24rpx;
						font-weight: 500;
						color: #888888;
						line-height: 28rpx;
					}
					
				}
				.scroll_img {
					position: relative;
					.imgs {
						width: 100%;
						height: 170rpx;
						overflow: hidden;
						white-space: nowrap;
						.imgs_item {
							width: 160rpx;
							height: 160rpx;
							border-radius: 16rpx;
							margin-right: 20rpx;
							display: inline-block;
						}
						
					}
					.img_leng {
						position: absolute;
						right: 0;
						top: 0;
						width: 130rpx;
						height: 160rpx;
						border-radius: 12rpx;
						font-size: 24rpx;
						font-weight: 500;
						color: #222222;
						line-height: 160rpx;
						text-align: center;
						background: linear-gradient(270deg, #FFFFFF 0%, rgba(255,255,255,0.78) 100%);
					}
				}
				
				.price {
					font-size: 30rpx;
					font-weight: 400;
					color: #222222;
					line-height: 24rpx;
				}
				.btn1 {
					width: 180rpx;
					height: 68rpx;
					border-radius: 36rpx;
					border: 1px solid #D0D0D0;
					text-align: center;
					font-size: 28rpx;
					font-weight: 400;
					color: #222222;
					line-height: 68rpx;
				}
				.btn2 {
					border: 1px solid #506DFF;
					color: #506DFF;
					margin-left: 32rpx;
				}
			}
		}
		.box:nth-last-child(1) {
			margin-bottom: 30rpx;
		}
	}
</style>