<template>
	<view>
		<view style="width: 100%;text-align: center;position: fixed;height: 96rpx;z-index: 999;">
			<u-tabs :list="list" sticky :current="current" @change="change" active-color="#007AFF"></u-tabs>
		</view>
		<view style="position: absolute;top: 96rpx;width: 100%;">
			<view>
				<view v-if="!order.length" class="noData">您暂无相关订单哦~</view>
				<view v-else v-for="(item, index) in order" style="padding: 20rpx 20rpx 0rpx 20rpx" class="lisChild">
					<view class="item">
						<view style="display: flex;justify-content: space-between;align-items: center;height: 50rpx;" @click="openPopup(index)">
							<view style="color: #666666;font-size: 24rpx;">订单编号：{{ item.orderSn }}</view>
							<view style="color: #999999;font-size: 24rpx;">{{ $method.timestampToTime(item.createTime) }}</view>
						</view>
						<u-line color="#D6D6DB" />
						<view
							style="display: flex;justify-content: space-between;padding: 25rpx 0;border-bottom: 1rpx solid #eee;"
							v-for="(items, indexs) in item.orderGoodsList"
							:key="indexs"
						>
							<image src="/static/login_bg.jpg" style="height: 134rpx;width: 278rpx;border-radius: 16rpx;flex-shrink: 0;"></image>
							<view style="margin-left: 20rpx;flex:1;display: flex;flex-direction: column;">
								<view style="color: #333333;font-size: 30rpx;font-weight: bold;flex:1">{{ items.goodsName }}</view>
								<view class="priceTag">¥ {{ items.goodsPrice }}</view>
							</view>
						</view>
						<view style="height: 80rpx;display: flex;justify-content: space-between;align-items: center;">
							<view>
								<text style="color:#999;font-size: 24rpx;margin-right: 8rpx;">共{{ item.orderGoodsList.length }}项</text>
								<text style="color: #333;font-size: 30rpx;font-weight: bold;">合计</text>
								<text style="color:#ff2d55;font-size: 30rpx;font-weight: bold;">￥{{ item.payPrice }}</text>
							</view>
							<view style="display: flex;align-items: center;">
								<view class="btn2" v-if="item.orderStatus === 0">继续支付</view>
								<view class="btn2" v-if="item.orderStatus === -1 || item.orderStatus === -2">重新购买</view>
								<view class="btn2" v-if="item.orderStatus === 1 || item.orderStatus === 2">退款</view>
								<view class="btn1" v-if="item.orderStatus === -1 || item.orderStatus === -2" @click="delOrder(item)">删除订单</view>
								<view class="btn1" @click="closeOrder(item)" v-if="item.orderStatus === 0">取消订单</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
	components: {},
	data() {
		return {
			list: [
				{
					name: '待支付'
				},
				{
					name: '已支付'
				},
				{
					name: '已取消'
				}
			],
			list1: [1, 2, 3, 4, 5, 6, 7],
			current: 0,
			order: [],
			order1: [],
			order2: [],
			order3: []
		};
	},
	onPullDownRefresh() {},
	onLoad(option) {},
	onShow() {
		this.getOrderList();
		/* if(this.current === 2 && this.$method.isLogin()){
			this.$refs.refMy.init();
		} */
	},
	//分享功能
	onShareAppMessage(res) {
		var self = this;
		return {
			title: '中正',
			path: `/pages/index/index?inviteCode=` + userInfo == null ? '' : userInfo.userAccount
		};
	},
	methods: {
		openPopup() {},
		//删除订单
		delOrder(item) {
			var self = this;
			uni.showModal({
				content: '确定要删除该订单吗',
				success: function(res) {
					if (res.confirm) {
						self.$api
							.eddOrder({
								orderId: item.orderId,
								status: 0
							})
							.then(res => {
								if (res.data.code === 200) {
									self.$method.showToast('订单删除成功');
									self.getOrderList();
								}
							});
					}
				}
			});
		},
		//取消订单
		closeOrder(item) {
			var self = this;
			uni.showModal({
				content: '确定要取消该订单吗',
				success: function(res) {
					if (res.confirm) {
						self.$api
							.eddOrder({
								orderId: item.orderId,
								orderStatus: -1
							})
							.then(res => {
								if (res.data.code === 200) {
									self.$method.showToast('订单取消成功', 'success');
									self.getOrderList();
								}
							});
					}
				}
			});
		},
		//获取订单
		getOrderList() {
			this.$api.getorderlists({ status: 1 }).then(res => {
				if (res.data.code === 200) {
					var array1 = []; //待支付
					var array2 = []; //已支付
					var array3 = []; //已取消
					res.data.rows.forEach(item => {
						if (item.orderStatus === 0) {
							array1.push(item);
						}
						if (item.orderStatus === 1 || item.orderStatus === 2) {
							array2.push(item);
						}
						if (item.orderStatus === -1 || item.orderStatus === -2) {
							array3.push(item);
						}
					});
					this.order1 = array1;
					this.order2 = array2;
					this.order3 = array3;
					this.change(this.current);
				}
			});
		},
		change(index) {
			this.current = index;
			if (index === 0) {
				this.order = JSON.parse(JSON.stringify(this.order1));
			}
			if (index === 1) {
				this.order = JSON.parse(JSON.stringify(this.order2));
			}
			if (index === 2) {
				this.order = JSON.parse(JSON.stringify(this.order3));
			}
		}
	},
	onReachBottom() {},
	computed: { ...mapGetters(['userInfo']) }
};
</script>
<style>
page {
	background: #eaeef1;
}
</style>
<style scoped>
.lisChild:last-child {
	margin-bottom: 34rpx;
}
.noData {
	text-align: center;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #999999;
	margin: 160rpx 0;
}
.btn2 {
	width: 144rpx;
	height: 46rpx;
	background: #ffffff;
	border: 2rpx solid #007aff;
	border-radius: 16rpx;
	text-align: center;
	line-height: 48rpx;
	color: #007aff;
	margin: 0 8rpx;
}
.btn1 {
	width: 144rpx;
	height: 48rpx;
	background: #ffffff;
	border: 2rpx solid #999999;
	border-radius: 16rpx;
	text-align: center;
	line-height: 48rpx;
	color: #999999;
	margin: 0 8rpx;
}
.item {
	width: 100%;
	background: #ffffff;
	border-radius: 16rpx;
	/* margin-bottom: 20rpx; */
	padding: 15rpx;
}
.priceTag {
	font-size: 30rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #ff2d55;
	display: flex;
	flex-direction: row-reverse;
}

.bottomBox {
	position: fixed;
	bottom: 0;
	width: 100%;
	left: 0;
	height: 98rpx;
	background-color: #ffffff;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 30rpx;
}
</style>
