<template>
	<view class="view">
		<mescroll-uni ref="mescroll" @getData="getList">
			<block slot="list">
				<view class="order-list" v-if="dataList.length > 0">
					<view class="order-item" v-for="(orderItem, orderIndex) in dataList" :key="orderIndex" @click="toDetail(orderItem.order_id)">
						<view class="order-header">

							<text class="font-size-base">订单号：{{ orderItem.order_no }}</text>
							<!-- $$${{orderItem.is_invoice}} -->
						</view>
						<view class="order-body" >
							<view class="goods-wrap" v-for="(goodsItem, goodsIndex) in orderItem.order_goods"
								:key="goodsIndex">
								<view class="goods-img">
									<image :src="$util.img(goodsItem.sku_image, { size: 'mid' })"
										@error="imageError(orderIndex, goodsIndex)" mode="aspectFill" :lazy-load="true">
									</image>
								</view>
								<view class="goods-info">
									<view class="pro-info">
										<view class="goods-name" v-if="goodsItem.goods_class == 2">
											{{ goodsItem.goods_name }}
										</view>
										<view class="goods-name" v-else>
											{{ goodsItem.sku_name }}
										</view>

									</view>
									<view class="goods-sub-section">
										<text class="goods-price">
											<text class="unit price-style small">
												{{ $lang('common.currencySymbol') }}
											</text>
											<text class="price-style large">
												{{
													parseFloat(goodsItem.price)
														.toFixed(2)
														.split('.')[0]
												}}
											</text>
											<text class="unit price-style small">
												.{{
													parseFloat(goodsItem.price)
														.toFixed(2)
														.split('.')[1]
												}}
											</text>
										</text>
										<text class="goods-num">
											<text class="iconfont icon-close"></text>
											{{ goodsItem.num }}
										</text>
									</view>
									<view class="goods-action">
										<!-- <view class="action-btn">加购物车</view> -->
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-else>
					<ns-empty :isIndex="false" :text="$lang('emptyTips')"></ns-empty>
				</view>
			</block>
		</mescroll-uni>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: []
			}
		},
		methods: {
			toDetail(order_id) {
				uni.navigateTo({
					url: `/pages_tool/invoice/detail?order_id=${order_id}`
				})
			},
			getList(mescroll) {
				this.$api.sendRequest({
					url: "/api/order/lists",
					data: {
						page: mescroll.num,
						page_size: mescroll.size,
						order_status: "all",
						invoice: 1,
						invoice_status:1
					},
					success: res => {
						let newArr = [];
						let msg = res.message;
						if (res.code == 0 && res.data) {
							newArr = res.data.list;
						} else {
							this.$util.showToast({
								title: msg
							});
						}
						mescroll.endSuccess(newArr.length);
						//设置列表数据
						if (mescroll.num == 1) {
							this.dataList = []; //如果是第一页需手动制空列表
							this.related_id = 0;
						}
						this.dataList = this.dataList.concat(newArr); //追加新数据
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.view {
		padding: 0 24rpx 32rpx;

		.card {
			margin-top: 24rpx;
			padding: 32rpx;
			background-color: #fff;
			border-radius: 24rpx;

			.top {
				display: flex;
				align-items: center;

				.left {
					flex-grow: 1;

					.text {
						font-size: 32rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 600;
						color: #333333;
					}

					.label {
						position: relative;
						top: -4rpx;

						margin-left: 16rpx;
						padding: 8rpx;
						font-size: 22rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #21BBF3;

						height: 36rpx;
						border-radius: 8rpx;
						border: 1rpx solid rgba(33, 187, 243, 0.2);
					}
				}

				.right {
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					color: var(--fontColor);

					image {
						width: 28rpx;
						height: 28rpx;
					}

				}
			}

			.bottom {
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				color: #999999;
			}
		}
	}

	.order-item {
		margin: $margin-updown $margin-both;
		border-radius: $border-radius;
		background: #fff;
		position: relative;

		.order-header {
			display: flex;
			align-items: center;
			position: relative;
			padding: $padding 30rpx 26rpx 30rpx;

			&.waitpay {
				padding-left: 70rpx;

				.icon-yuan_checked,
				.icon-yuan_checkbox {
					font-size: $font-size-toolbar;
					position: absolute;
					top: 48%;
					left: 20rpx;
					transform: translateY(-50%);
				}

				.icon-yuan_checkbox {
					color: $color-tip;
				}
			}

			.icon-dianpu {
				display: inline-block;
				line-height: 1;
				margin-right: 12rpx;
				font-size: $font-size-base;
			}

			.status-name {
				flex: 1;
				text-align: right;
				font-size: $font-size-base;
				font-weight: 600;
			}
		}

		.order-body {
			.goods-wrap {
				display: flex;
				position: relative;
				padding: 0 30rpx 30rpx 30rpx;

				&:last-of-type {
					margin-bottom: 0;
				}

				.goods-img {
					width: 160rpx;
					height: 160rpx;
					margin-right: 20rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: $border-radius;
					}
				}

				.goods-info {
					flex: 1;
					position: relative;
					max-width: calc(100% - 180rpx);
					display: flex;
					flex-direction: column;

					.pro-info {
						flex: 1;
					}

					.goods-name {
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						line-height: 1.5;
						font-size: $font-size-base;
						color: $color-title;
					}

					.goods-sub-section {
						width: 100%;
						line-height: 1.3;
						display: flex;
						margin-top: 14rpx;

						.goods-price {
							font-size: $font-size-tag;
							color: var(--price-color);
							flex: 1;
							font-weight: bold;
						}

						.goods-num {
							font-size: $font-size-tag;
							color: $color-tip;
							flex: 1;
							text-align: right;
							line-height: 1;

							.iconfont {
								font-size: $font-size-tag;
							}
						}

						.goods-type {
							font-size: $font-size-tag;
						}

						.unit {
							font-size: $font-size-tag;
							margin-right: 2rpx;
						}

						view {
							flex: 1;
							line-height: 1.3;
							display: flex;
							flex-direction: column;

							&:last-of-type {
								text-align: right;

								.iconfont {
									line-height: 1;
									font-size: $font-size-tag;
								}
							}
						}
					}

					.goods-action {
						text-align: right;

						.action-btn {
							line-height: 1;
							padding: 14rpx 20rpx;
							color: $color-title;
							display: inline-block;
							border-radius: $border-radius;
							background: #fff;
							border: 2rpx solid #999;
							font-size: $font-size-tag;
							margin-left: 10rpx;
						}
					}
				}
			}
		}

		.order-footer {
			.order-base-info {
				.total {
					padding: $padding;
					font-size: $font-size-tag;
					background: rgba(248, 248, 248, 0.5);
					display: flex;

					&>text {
						flex: 1;
						line-height: 1;
						margin-left: 10rpx;
					}
				}

				.order-type {
					padding-top: 20rpx;
					flex: 0.5;

					&>text {
						line-height: 1;
					}
				}
			}

			.order-action {
				text-align: right;
				padding: 30rpx;
				// display: flex;
				position: relative;

				.order-time {
					position: absolute;
					top: 35rpx;
					left: 30rpx;
					display: flex;
					align-items: center;
					font-size: 10px;
					color: #b5b6b9;

					image {
						width: 26rpx;
						height: 26rpx;
						margin-right: 6rpx;
					}
				}

				.action-btn {
					line-height: 1;
					padding: 20rpx 26rpx;
					color: #333;
					display: inline-block;
					border-radius: $border-radius;
					background: #fff;
					border: 2rpx solid #999;
					font-size: $font-size-tag;
					margin-left: 10rpx;
				}
			}
		}
	}
</style>