<template>
	<view class="page">
		
		<navbar
		:title="uid ? '用户订单信息' : '订单中心'"
		:leftClick="uid"
		@leftClick="$utils.navigateBack"
		/>
		
		<uv-tabs :list="tabs" 
		:activeStyle="{color : '#FD5100', fontWeight : 600}"
		lineColor="#FD5100"
		lineHeight="8rpx"
		lineWidth="50rpx"
		@click="clickTabs"></uv-tabs>
		
		<view v-if="orderList.records.length > 0" class="list">
			<view class="item" 
			v-for="(item, index) in orderList.records"
			@click="toOrderDetail(item.id)"
			:key="index">
	
				<view class="top">
					<view class="service">
						<text>{{ tabs[item.type + 1].name }}</text>
					</view>
					<view class="status">
						<text> {{item.status_dictText}}</text>
					</view>
				</view>
	
				<view class="content"
				v-for="(p, i) in item.orderDetails"
				:key="i">
	
					<view class="left">
						<image mode="aspectFill" :src="p.pic"></image>
					</view>
	
					<view class="right">
						<!-- <view class="text-hidden-1">
							客户姓名：{{item.userName}}
						</view>
						<view class="text-hidden-1">
							产品规格：{{item.sku}}
						</view>
						<view class="text-hidden-1">
							租赁地址：{{item.userAddress}}
						</view>
						<view class="text-hidden-1">
							数量：{{ item.num }}
						</view> -->
						
						<view class="text-hidden-1">
							产品名称：{{p.goodsName}}
						</view>
						<view class="text-hidden-1">
							产品规格：{{p.sku}}
						</view>
						<view class="text-hidden-1">
							数量：{{ p.num }}
						</view>
						
					</view>
	
				</view>
				
				<view class="userInfo">
					<text>{{ item.userName }}</text>
					<text>{{ item.userPhone }}</text>
					<text>{{ item.userAddress }}</text>
				</view>
				<view class="userInfo">
					<text>下单时间：</text>
					<text>{{ item.createTime }}</text>
				</view>
	
				<!-- 水洗店按钮 -->
				<view class="bottom" v-if="userShop">
					<view class="pay">
						
						<view
						v-if="item.washPay && item.type == 1">
							水洗费用：{{ item.washPay }}元
						</view>
						
					</view>
					
					<!-- 待接单 -->
					<view 
					 v-if="[4, 18, 19].includes(item.status)"
					@click.stop="orderConfirmAccept(item)" class="b2">
						确认接单
					</view>
					
					<!-- 待收货 -->
					<template v-if="item.status == 2">
						<view @click.stop="confirmReceiveGoods(item)" class="b2">
							确认收货
						</view>
						<view @click.stop="" class="b1">
							查看物流
						</view>
					</template>
						
					<!-- 待检查 -->
					<template v-if="item.status == 5">
						<view @click.stop="orderConfirmedDamage(item, 1)" class="b2"
						>
							确认下一步
						</view>
						
						<!-- <view @click.stop="$utils.navigateTo
						(`/pages_order/order/damageReport?id=${item.id}`)" class="b1"
						>
							破损上报
						</view> -->
						<view @click.stop="$utils.navigateTo
						(`/pages_order/order/damageReport?id=${item.id}`)" class="b1"
						>
							破损上报
						</view>
					</template>
					
					<view
					 v-if="[8, 12].includes(item.status)"
					@click.stop="orderId = item.id;$refs.deliverGoods.open()" class="b2">
						发货填写单号
					</view>
					
					<view
					 v-if="[6].includes(item.status)"
					@click.stop="orderFinishedWashing(item)" class="b2">
						水洗完成
					</view>
					
				</view>
				
				<!-- 酒店按钮 -->
				<view class="bottom"
				v-else>
				
					<view class="pay">
						<!-- <view
						v-if="item.washPay">
							水洗费用：{{ item.washPay }}元
						</view>
						
						<view
						v-if="item.rentPay">
							租赁费用：{{ item.rentPay }}元
						</view>
						
						<view
						v-if="item.deposit">
							押金：{{ item.deposit }}元
						</view> -->
						
						<view class="price"
						v-if="item.orderPay">
							合计：<text class="num">{{ item.orderPay }}元</text>
						</view>
					</view>
					
					
					<!-- 取消订单 -->
					<view class="">
						<view 
						@click.stop="orderCancel(item)" class="b1"
						v-if="[0, 3].includes(item.status)">
							取消订单
						</view>
					</view>
					
					
					<!-- 待支付 -->
					<view class="">
						<view 
						@click.stop="payOrder(item.orderLogId, 
						item.id, item.status == 10)" class="b2"
						v-if="[0, 3, 10].includes(item.status)">
							{{ item.status == 10 ? '支付费用' : '立即付款' }}
						</view>
					</view>
					
					<!-- 待收货 -->
					<template v-if="item.status == 2">
						<view @click.stop="confirmReceiveGoods(item)" class="b2">
							确认收货
						</view>
						<view @click.stop="" class="b1">
							查看物流
						</view>
					</template>
						
				</view>
	
			</view>
		</view>
		
		<uv-empty
		v-else
		text="空空如也"
		textSize="30rpx"
		iconSize="200rpx"
		icon="list"></uv-empty>
		
		<deliverGoods 
		ref="deliverGoods"
		:orderId="orderId"
		@getData="getData"/>
		
		<tabber select="2" v-if="!uid"/>
	</view>
</template>

<script>
	
	// 状态 
	// 租赁订单：0待支付 1待发货 2待收货  
	// 水洗订单：3待支付 4水洗店接单 5水洗店检查
	// 6开始清洗
	// 换货订单：7待回收 8待发货 9平台待收货
	// 10平台检查损失待用户支付 18待接单
	// 退货订单：11待回收 12待发货 13平台待收货
	// 14平台检查损失并且退还定金 19待接单
	// 15 已完成
	import tabber from '@/components/base/tabbar.vue'
	import { mapGetters } from 'vuex'
	import mixinOrder from '@/mixins/order.js'
	import deliverGoods from '@/components/userShop/deliverGoods.vue'
	export default {
		components : {
			tabber,
			deliverGoods,
		},
		mixins : [mixinOrder],
		computed : {
			...mapGetters(['userShop']),
		},
		data() {
			return {
				tabs: [{
						name: '全部'
					},
					{
						name: '租赁押金'
					},
					{
						name: '水洗租赁'
					},
					{
						name: '破损换货'
					},
					{
						name: '退货退款'
					}
				],
				queryParams: {
					pageNo: 1,
					pageSize: 10
				},
				// orderList: [
				// 	{
				// 		money : 99.99,
				// 		address : '广东省广州市越秀区城南故事C3栋2802',
				// 		name : '李**',
				// 		phone : '150*****091',
				// 		unit : '120*40*75【桌子尺寸】',
				// 		image : 'https://img95.699pic.com/photo/50058/1378.jpg_wh860.jpg',
				// 		status_dictText : '已完成',
				// 	}
				// ], //订单列表数据
				orderList : {
					records : [],
					total : 0,
				},
				type : -1,
				uid : 0,
				orderId : 0,
			}
		},
		onLoad(args) {
			this.uid = args.uid || 0
		},
		onShow() {
			this.getData()
			if(this.userShop){
				this.tabs[1].name = '租赁订单'
				this.$forceUpdate()
			}
		},
		onPullDownRefresh() {
			this.getData()
		},
		//滚动到屏幕底部
		onReachBottom() {
			if(this.queryParams.pageSize < this.orderList.total){
				this.queryParams.pageSize += 10
				this.getData()
			}
		},
		methods: {
			getData(){
				let queryParams = {
					...this.queryParams,
				}
				if(this.type != -1){
					queryParams.type = this.type
				}
				
				// 水洗店查询用户订单
				if(this.uid != 0){
					queryParams.uid = this.uid
				}
				this.$api('orderPage', queryParams, res => {
					uni.stopPullDownRefresh()
					if(res.code == 200){
						this.orderList = res.result
					}
				})
			},
			//点击tab栏
			clickTabs({ index, name }) {
				if (index == 0) {
					this.type = -1;
				} else {
					this.type = index - 1;
				}
				this.queryParams.pageSize = 10
				this.getData()
			},
			//跳转订单详情页面
			toOrderDetail(id) {
				uni.navigateTo({
					url: '/pages_order/order/orderDetail?id=' + id
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.page{
	}
	.list {
		.item {
			width: calc(100% - 40rpx);
			background-color: #fff;
			margin: 20rpx;
			box-sizing: border-box;
			border-radius: 16rpx;
			padding: 30rpx;
	
			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 30rpx;
	
				.service {}
	
				.status {
					font-size: 26rpx;
					font-weight: 600;
				}
			}
	
			.content {
				display: flex;
				margin: 10rpx 0;
	
				.left {
					width: 130rpx;
					height: 130rpx;
					border-radius: 10rpx;
	
					image {
						width: 130rpx;
						height: 130rpx;
						border-radius: 10rpx;
					}
				}
	
				.right {
					width: calc(100% - 160rpx);
					color: #777;
					font-size: 24rpx;
					padding-left: 20rpx;
					line-height: 40rpx;
					background-color: #F8F8F8;
				}
			}
			
			.userInfo{
				font-size: 24rpx;
				margin-bottom: 10rpx;
				text{
					margin-right: 26rpx;
				}
			}
	
			.bottom {
				display: flex;
				justify-content: flex-end;
				font-size: 25rpx;
				.pay{
					margin: 12rpx;
					margin-right: auto;
				}
				.price {
					font-weight: 900;
					text {
						color: #ff780099;
						font-size: 30rpx;
					}
				}
				.b1 {
					border: 1px solid #777;
					color: #777;
					box-sizing: border-box;
					display: flex;
					justify-content: center;
					align-items: center;
				}
	
				.b2 {
					background: $uni-color;
					color: #fff;
					flex-shrink: 0;
					display: flex;
					justify-content: center;
					align-items: center;
				}
	
				.b1,.b2 {
					margin: 12rpx;
					border-radius: 28rpx;
					padding: 8rpx 28rpx;
					margin-bottom: 0;
				}
			}
		}
	}
</style>
