<template>
	<view class="page">
		<!-- 导航栏 -->
		<navbar title="订单中心" leftClick @leftClick="$utils.navigateBack" bgColor="#E3441A" color="#fff" />

		<!-- 订单筛选 -->
		<view class="tabs">
			<uv-tabs :list="tabs" 
			:activeStyle="{color : '#fff', fontWeight : 600}" 
			lineColor="#fff"
			:inactiveStyle="{color: 'rgba(255,255,255,.8)'}" 
			lineHeight="8rpx" 
			lineWidth="50rpx" 
			:current="current"
			@click="clickTabs"></uv-tabs>
		</view>

		<view class="list">
			<view class="item" v-for="(item, index) in list" @click="toOrderDetail(item.id)" :key="index">
				<view class="content" :key="index" v-for="(good, index) in item.commonOrderSkuList">
					<view class="top">
						<view class="service">
							{{ good.title }}
						</view>
						<view class="status">
							<text> {{ tabs[Number(item.state) + 1].name }}</text>
						</view>
					</view>

					<view class="main">
						<view class="left">
							<image mode="aspectFill" :src="good.image && good.image.split(',')[0]"></image>
						</view>

						<view class="right">
							<view class="text-hidden-1">
								客户姓名：{{item.name}}
							</view>
							<view class="text-hidden-1">
								下单时间：{{item.createTime}}
							</view>
							<view class="text-hidden-1">
								联系电话：{{item.phone}}
							</view>

						</view>
					</view>

				</view>

				<view class="bottom">
					<view class="price">
						<text class="total-title">总价格：</text>
						<text class="unit">￥</text>
						<text class="num">{{item.price}}</text>
						<text class="c-unit">元</text>
					</view>

					<view @click.stop="toPayOrder(item)" class="btn" v-if="item.state == 0">
						立即付款
					</view>

					<view @click.stop="cancelOrder(item)" class="btn" v-if="item.state == 0">
						取消订单
					</view>

					<view class="btn" @click.stop="confirmOrder(item)" v-if="item.state == 2">
						确认收货
					</view>

					<view @click.stop="$refs.customerServicePopup.open()" class="btn" v-if="item.state > 0">
						联系客服
					</view>
				</view>

			</view>
			<view style="
			margin-top: 20rpx;
			min-width: 700rpx;">
				<uv-empty mode="list" v-if="list.length == 0"></uv-empty>
			</view>
		</view>
		
		<customerServicePopup ref="customerServicePopup" />

		<tabber select="order" />
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import mixinsList from '@/mixins/list.js'
	import mixinsOrder from '@/mixins/order.js'
	import tabber from '@/components/base/tabbar.vue'
	import customerServicePopup from '@/components/config/customerServicePopup.vue'
	
	export default {
		mixins: [mixinsList, mixinsOrder],
		components: {
			tabber,
			customerServicePopup,
		},
		computed: {},
		data() {
			return {
				tabs: [{
						name: '全部'
					},
					{
						name: '待付款'
					},
					{
						name: '待发货'
					},
					{
						name: '待收货'
					},
					{
						name: '已完成'
					},
					{
						name: '已取消'
					}
				],
				current: 0,
				mixinsListApi: 'getOrderPageList',
			}
		},
		onLoad(args) {
			this.current = args.type || 0
			this.clickTabs({
				index: this.current
			})
		},
		methods: {
			//点击tab栏
			clickTabs({
				index
			}) {
				if (index == 0) {
					delete this.queryParams.state
				} else {
					this.queryParams.state = index - 1
				}
				this.getData()
			},
			//跳转订单详情页面
			toOrderDetail(id) {
				uni.navigateTo({
					url: '/pages_order/order/orderDetail?id=' + id
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {}

	.tabs {
		background: $uni-color;
	}

	.list {
		.item {
			width: calc(100% - 40rpx);
			background-color: #fff;
			margin: 20rpx;
			box-sizing: border-box;
			border-radius: 16rpx;
			padding: 30rpx;

			.content {
				.top {
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 34rpx;

					.status {
						font-weight: 600;
						color: #FFAC2F;
					}
				}

				.main {
					display: flex;
					margin: 20rpx 0rpx;

					.left {
						display: flex;
						align-items: center;
						justify-content: center;
						width: 180rpx;
						height: 180rpx;

						image {
							width: 95%;
							height: 95%;
							border-radius: 10rpx;
						}
					}

					.right {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						width: calc(100% - 200rpx);
						color: #777;
						font-size: 26rpx;
						padding: 30rpx 20rpx;
						box-sizing: border-box;
						margin-left: 20rpx;
						border-radius: 10rpx;
						background-color: #F8F8F8;
					}
				}
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				font-size: 25rpx;

				.price {
					.total-title {}

					.num {
						font-size: 36rpx;
					}

					.num,
					.unit,
					.c-unit {
						color: $uni-color;
					}
				}

				.btn {
					border: 1px solid #C7C7C7;
					padding: 10rpx 20rpx;
					border-radius: 40rpx;
					color: #575757;
				}
			}
		}
	}
</style>