<template>

	<view :class="[AppTheme]" class="content">
		<view v-for="(item, index) in orderList" :key="index" class="order-item">
			<view class="i-top b-b">
				<text class="time">订单编号:{{ item.oid }}</text>
				<text class="state">{{ item.type_status }}</text>

			</view>

			<scroll-view v-if="item.items.length > 1" class="goods-box"
				:class="[item.type === 5 ? 'goods-box2' : 'goods-box']" scroll-x>
				<view v-for="(goodsItem, goodsIndex) in item.items" :key="goodsIndex" class="goods-item"
					:class="[item.type === 5 ? 'goods-item2' : 'goods-item']">
					<image class="goods-img" mode="aspectFit" :class="[item.type === 5 ? 'goods-img2' : 'goods-img']"
						:src=" goodsItem.pic">
					</image>
					<view class="right_mess" v-if="item.type === 5">
						<view class="right_mess_p1">{{ goodsItem.name }}×{{ goodsItem.num }}</view>
						<view class="right_mess_p2"></view>
						<view class="right_mess_p3 text-neutral">金额:{{ goodsItem.price }}元</view>
					</view>
				</view>
			</scroll-view>
			<view v-if="item.items.length === 1" class="goods-box-single" v-for="(goodsItem, goodsIndex) in item.items"
				:key="goodsIndex">
				<image class="goods-img" :src=" goodsItem.pic" mode="aspectFill"></image>
				<view class="right">
					<text class="title clamp">{{ goodsItem.name }}</text>
					<text class="attr-box">x {{ goodsItem.num }}</text>
					<text class="price text-neutral">{{ goodsItem.price }}</text>
				</view>
			</view>

			<view class="price-box">
				共
				<text class="num">{{ item.totalnum }}</text>
				件商品 运费
				<text class="num price text-neutral">{{ item.yf }}</text>
				实付款
				<text class="price text-neutral">{{ Number(item.payprice) }}</text>
			</view>
		</view>
		<view style="padding-top: 100rpx;" v-if="!orderList||orderList.length==0">
			<u-empty  text="暂无记录" mode="data"></u-empty>
		</view>
		<u-loadmore v-else :status="loadingType" />
	</view>
</template>

<script>
	import order from '@/api/order/index.js';
	import mall from '@/api/mall/index.js';
	export default {
		data() {
			return {
				_freshing: false,
				triggered: true,

				primary: this.$theme.primary,
				settingFile: getApp().globalData.siteinfo,
				orderList: [],
				page: 1,
				pagesize: 5,
				loadingType: 'more',
				farm_id: '',
				type: '',

				orderList: [],
				page: 1,
				pagesize: 5,

				loadingType: 'more',

				farm_id: '',
				type: '',


			};
		},

		onLoad(options) {
			this.page = 1;

			this.farm_id = options.id;
			this.type = options.type

			this.tabCurrentIndex = +options.state;
			this.current = options.state
			this.getOrderList();
		},
		methods: {
			refresh() { //自定义下拉刷新
				console.log('下拉刷新了')
				if (this._freshing) return;
				this._freshing = true;

				//调用获取数据的函数
				// this.getData();
				if (!this.triggered)
					//界面下拉触发，triggered可能不是true，要设为true
					this.triggered = true;
				setTimeout(() => {
					this.triggered = false;
					this._freshing = false;
					uni.stopPullDownRefresh()
				}, 2000);
			},






			getOrderList(type) {
				this.loadingType = 'loading';
				order
					.weifarmcash({
						type: this.type,
						farm_id: this.farm_id,
						p: this.page
					})
					.then(res => {
						if (res.status == 1) {
							if (res.data.length >= this.pagesize) {
								this.loadingType = 'more';
								this.page++;
							} else {
								this.page++;
								this.loadingType = 'nomore';
							}
							this.orderList = this.orderList.concat(res.data);

						} else {
							this.loadingType = 'more';

						}
					});
			},


			onReachBottom() {
				console.log('到底了');
			},
			onPullDownRefresh() {
				this.orderList = [];
				this.page = 1;
				this.getOrderList();
				setTimeout(() => {
					uni.stopPullDownRefresh();
				}, 600);
			}
		}
	};
</script>

<style lang="scss">
	page,
	.content {
		background: $page-color-base;
		height: 100%;
		box-sizing: border-box;
	}

	.swiper-box {
		height: calc(100vh - 44px);
	}

	.list-scroll-content {
		height: 100%;
	}

	.navbar {
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: $tab-color-1;
			position: relative;

			&.current {
				color: $tab-color-1;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid $tab-color-2;
				}
			}
		}
	}

	.tuihuo {
		line-height: 70rpx;

		text-align: center;

		.text {
			text-align: center;
		}
	}

	.i-top {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		height: 126upx;
		padding: 0 0upx;
		font-size: $font-base;
		color: $font-color-dark;
		position: relative;

		.time {
			// flex: 1;
			// flex-grow: 1;
		}


		.state {
			color: $base-color;
		}

		.del-btn {
			padding: 10upx 0 10upx 36upx;
			font-size: $font-lg;
			color: $font-color-light;
			position: relative;

			&:after {
				content: '';
				width: 0;
				height: 30upx;
				border-left: 1px solid $border-color-dark;
				position: absolute;
				left: 20upx;
				top: 50%;
				transform: translateY(-50%);
			}
		}
	}

	.b-b {
		margin: 0 0rpx;

		.illustrate {
			margin-bottom: 20rpx;

		}

		.box-conter {
			height: 230rpx;
			width: 600rpx;
			border: 1rpx solid #cccccc;
		}
	}



	.uni-swiper-item {
		height: auto;
	}

	.f-tui {
		width: 100%;
		min-height: 270rpx;
		background: #fff;
		margin-top: 16rpx;
		padding-left: 30rpx;
		padding-bottom: 30rpx;
	}

	.tui-wrap {
		margin: 15rpx 0;
		display: flex;
		justify-content: space-around;

		.tui-btn {
			left: 520rpx;
			width: 40%;
			height: 68rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 15rpx;
			border-width: 1px;
			border-style: solid;
			margin-top: 20rpx;
			color: #fff;
		}
	}

	.order-item {
		display: flex;
		flex-direction: column;
		padding-left: 30upx;
		background: #fff;

		.i-top {
			display: flex;
			align-items: center;
			height: 80upx;
			padding-right: 30upx;
			font-size: $font-base;
			color: $font-color-dark;
			position: relative;

			.time {
				flex: 1;
				font-weight: bold;
			}

			.state {
				color: $base-color;
			}

			.del-btn {
				padding: 10upx 0 10upx 36upx;
				font-size: $font-lg;
				color: $font-color-light;
				position: relative;

				&:after {
					content: '';
					width: 0;
					height: 30upx;
					border-left: 1px solid $border-color-dark;
					position: absolute;
					left: 20upx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}

		/* 多条商品 */
		.goods-box {
			height: 160upx;
			padding: 20upx 0;
			white-space: nowrap;

			.goods-item {
				width: 120upx;
				height: 120upx;
				display: inline-block;
				margin-right: 24upx;
			}

			.goods-item2 {
				width: 100%;
				height: 160rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				margin-right: 0;
			}

			.goods-img {
				display: block;
				width: 100%;
				height: 100%;
			}

			.goods-img2 {
				display: block;
				width: 160rpx;
				height: 120rpx;
			}
		}

		.right_mess {
			width: auto;
			margin-left: 15rpx;
		}

		.right_mess_p1 {
			font-size: 28rpx;
			color: #000;
			letter-spacing: 5rpx;
		}

		.right_mess_p2 {
			font-size: 26rpx;
			color: #000;
			margin: 15rpx 0;
			letter-spacing: 5rpx;
		}

		.right_mess_p3 {
			font-size: 26rpx;
			letter-spacing: 5rpx;
		}

		.goods-box2 {
			height: auto;
		}

		/* 单条商品 */
		.goods-box-single {
			display: flex;
			padding: 20upx 0;

			.goods-img {
				display: block;
				width: 120upx;
				height: 120upx;
			}

			.right {
				flex: 1;
				display: flex;
				flex-direction: column;
				padding: 0 30upx 0 24upx;
				overflow: hidden;

				.title {
					font-size: $font-base + 2upx;
					color: $font-color-dark;
					line-height: 1;
					line-height: 40rpx;
					height: 40rpx;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}

				.attr-box {
					font-size: $font-sm + 2upx;
					color: $font-color-light;
					padding: 10upx 12upx;
				}

				.price {
					font-size: $font-base + 2upx;

					&:before {
						content: '￥';
						font-size: $font-sm;
						margin: 0 2upx 0 8upx;
					}
				}
			}
		}

		.price-box {
			display: flex;
			justify-content: flex-end;
			align-items: baseline;
			padding: 20upx 30upx;
			font-size: $font-sm + 2upx;
			color: $font-color-light;

			.num {
				margin: 0 8upx;
			}

			.price {
				font-size: $font-lg;

				&:before {
					content: '￥';
					font-size: $font-sm;
					margin: 0 2upx 0 8upx;
				}
			}
		}

		.action-box {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			height: 100upx;
			position: relative;
			padding-right: 30upx;
		}

		.action-btn {
			width: 160upx;
			height: 60upx;
			margin: 0;
			margin-left: 24upx;
			padding: 0;
			text-align: center;
			line-height: 60upx;
			font-size: $font-sm + 2upx;
			background: #fff;
			border-radius: 100px;

			&:after {
				border-radius: 100px;
			}

			&.recom {
				background: #fff9f9;
				border-width: 1rpx;
				border-style: solid;
			}
		}
	}

	/* load-more */
	.uni-load-more {
		display: flex;
		flex-direction: row;
		height: 80upx;
		align-items: center;
		justify-content: center;
		background-color: transparent;
	}

	.uni-load-more__text {
		font-size: 28upx;
		color: #999;
	}

	.uni-load-more__img {
		height: 24px;
		width: 24px;
		margin-right: 10px;
	}

	.uni-load-more__img>view {
		position: absolute;
	}

	.uni-load-more__img>view view {
		width: 6px;
		height: 2px;
		border-top-left-radius: 1px;
		border-bottom-left-radius: 1px;
		background: #999;
		position: absolute;
		opacity: 0.2;
		transform-origin: 50%;
		animation: load 1.56s ease infinite;
	}

	.uni-load-more__img>view view:nth-child(1) {
		transform: rotate(90deg);
		top: 2px;
		left: 9px;
	}

	.uni-load-more__img>view view:nth-child(2) {
		transform: rotate(180deg);
		top: 11px;
		right: 0;
	}

	.uni-load-more__img>view view:nth-child(3) {
		transform: rotate(270deg);
		bottom: 2px;
		left: 9px;
	}

	.uni-load-more__img>view view:nth-child(4) {
		top: 11px;
		left: 0;
	}

	.load1,
	.load2,
	.load3 {
		height: 24px;
		width: 24px;
	}

	.load2 {
		transform: rotate(30deg);
	}

	.load3 {
		transform: rotate(60deg);
	}

	.load1 view:nth-child(1) {
		animation-delay: 0s;
	}

	.load2 view:nth-child(1) {
		animation-delay: 0.13s;
	}

	.load3 view:nth-child(1) {
		animation-delay: 0.26s;
	}

	.load1 view:nth-child(2) {
		animation-delay: 0.39s;
	}

	.load2 view:nth-child(2) {
		animation-delay: 0.52s;
	}

	.load3 view:nth-child(2) {
		animation-delay: 0.65s;
	}

	.load1 view:nth-child(3) {
		animation-delay: 0.78s;
	}

	.load2 view:nth-child(3) {
		animation-delay: 0.91s;
	}

	.load3 view:nth-child(3) {
		animation-delay: 1.04s;
	}

	.load1 view:nth-child(4) {
		animation-delay: 1.17s;
	}

	.load2 view:nth-child(4) {
		animation-delay: 1.3s;
	}

	.load3 view:nth-child(4) {
		animation-delay: 1.43s;
	}

	@-webkit-keyframes load {
		0% {
			opacity: 1;
		}

		100% {
			opacity: 0.2;
		}
	}
</style>
