<template>
	<view class="page">
		<u-tabs :font-size='28' :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		<view class="list">
			<view class="box" v-for="(item,index) in orderlist" :key="index">
				<view class="u-flex u-row-between">
					<text class="order">订单编号:{{item.order_on}}</text>
					<view class="">
						<text v-if="item.status==0" class="state">
							{{item.status_text}}
						</text>
						<text v-else class="state" style="color: rgba(0, 0, 0, 0.60);">
							{{item.status_text}}
						</text>
					</view>
				</view>
				<view class="book">
					<view class="u-flex" style="margin-top: 26rpx;" v-for="(item1,index) in item.goods">
						<view class="" style="padding: 0 20rpx;">
							<image :src="item1.good_item.image" style="width: 120rpx;height: 160rpx;" mode=""></image>
						</view>
						<view class="" style="margin-left: 20rpx;">
							<view class="name u-line-1">{{item1.good_item.title}}</view>
							<view class="type">资源类型：付费资源</view>
							<view class="money">¥{{item1.good_item.price}}</view>
						</view>
					</view>
					<view class="shapping u-flex " style="justify-content: end;">
						<text class="font1">商品金额:</text>
						<text class="font3">¥</text>
						<text class="font2">{{item.total_price}}</text>
					</view>
					<view class="u-flex " style="margin-top: 28rpx;justify-content: end;">
						<view v-if="item.status ==0" class="cancel" @click="cancel(item.id)">取消订单</view>
						<view v-if="item.status ==0" class="pay" style="color: #fff;">立即付款</view>
						<view v-if="item.status ==-1" class=" cancel" @click="delect(item.id)">删除订单</view>
						<view v-if="item.status ==1||item.status ==0" class="details cancel"
							@click="orderinfo(item.id)">查看详情</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '全部'
				}, {
					name: '待支付'
				}, {
					name: '已完成',
				}, {
					name: '已取消',
				}],
				current: 0,
				page: 1,
				limit: 10,
				status: '',
				orderlist: []
			};
		},
		onLoad() {
			this.getOrderList()
		},
		methods: {
			orderinfo(id) {
				uni.navigateTo({
					url: '/pages/success?id=' + id
				})
			},
			change(index) {
				this.current = index;
				if (this.current == 0) {
					this.status = ''
				} else if (this.current < 3) {
					this.status = index - 1
				} else if (this.current == 3) {
					this.status = -1
				}
				this.getOrderList()
			},
			//删除订单
			delect(id) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '确定删除该订单吗',
					success: function(res) {
						if (res.confirm) {
							that.delect1(id)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			delect1(id) {
				this.$u.post('api/order/delOrder', {
					id: id
				}).then(res => {
					if (res.code == 1) {
						this.$u.toast('订单已删除')
						this.getOrderList()
					}
				})
			},
			cancel(id) {
				var that = this
				uni.showModal({
					title: '提示',
					content: '确定取消该订单吗',
					success: function(res) {
						if (res.confirm) {
							that.cancel1(id)
						} else if (res.cancel) {
							console.log('用户点击取消');
							this.getOrderList()
						}
					}
				});
			},
			cancel1(id) {
				this.$u.post('api/order/cancellationOrder', {
					id: id
				}).then(res => {
					if (res.code == 1) {
						this.$u.toast('订单已取消')
					}
				})
			},
			getOrderList() {
				this.$u.post('api/order/getOrderList', {
					page: this.page,
					limit: this.limit,
					status: this.status
				}).then(res => {
					if (res.code == 1) {
						this.orderlist = res.data.data
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.cancel {
		width: 148rpx;
		height: 68rpx;
		border-radius: 8rpx;
		border: 2rpx solid #979797;
		line-height: 68rpx;
		text-align: center;
		margin-left: 20rpx;
	}

	.pay {
		width: 160rpx;
		height: 68rpx;
		background: #06A971;
		border-radius: 8rpx;
		line-height: 68rpx;
		text-align: center;
		margin-left: 20rpx;
	}

	.name {
		font-size: 28rpx;
		font-family: PingFangHK, PingFangHK;
		font-weight: 400;
		color: #333333;
		width: 500rpx;
	}

	.font1 {
		font-size: 26rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #222222;
	}

	.font2 {
		font-size: 36rpx;
		font-family: JDZhengHT, JDZhengHT;
		font-weight: 500;
		color: #222222;
	}

	.font3 {
		font-size: 26rpx;
		font-family: JDZhengHT, JDZhengHT;
		font-weight: 300;
		color: #222222;
		margin-left: 14rpx;
		margin-top: 10rpx;
	}

	.type {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #444444;
		margin-top: 8rpx;
	}

	.shapping {
		margin-top: 28rpx;

	}

	.money {
		font-size: 32rpx;
		font-family: SFPro, SFPro;
		font-weight: 400;
		color: #333333;
		margin-top: 42rpx;
	}

	::v-deep .u-tab-bar {
		background-color: #06A971 !important;
	}

	.state {
		font-size: 24rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		color: #CF1534;
	}

	::v-deep .u-tab-item {
		color: #222 !important
	}

	.book {
		margin: 28rpx 0 0 0;
		border-top: 2rpx solid rgba(151, 151, 151, 0.2);
	}

	.order {
		font-size: 24rpx;
		font-family: SFPro, SFPro;
		font-weight: 400;
		color: #222222;
	}

	.box {
		width: 694rpx;
		// height: 472rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		padding: 28rpx 20rpx 30rpx;
		margin-top: 20rpx;
		box-sizing: border-box;
	}

	.list {
		padding: 20rpx 28rpx;
	}

	.page {
		background: #F6F6F6;
		min-height: 100vh;

	}
</style>