<template>
	<view style="padding-bottom: 120rpx;">
		<!-- 分类列表 -->
		<view class="container">
			<view class="classify-list">
				<view class="list" v-for="(item,index) in classList" :class="{'action':classifyShow==item.id}"
					@click="onClassify(item,index)" :key="index">
					<text>{{item.name}}</text>
					<text class="line" v-show="classifyShow==item.id"></text>
				</view>
			</view>
		</view>
		<view class="updatePrice" style="padding: 0 20upx;">
			<view class="head-info">
				<!-- 搜索 -->
				<view class="searchContent">
					<u-input v-model="searchText" style="width:520rpx" confirm-type="search" @confirm="classifyShow==1?getList(1):getOrderList(1)"
						:placeholder="classifyShow==1?'输入订单编号':'收件人名字/订单号/发货公司'" />
					<u-icon v-if="classifyShow==1" name="search" class="search" @click="getList(1)"></u-icon>
					<u-icon v-if="classifyShow==2" name="search" class="search" @click="getOrderList(1)"></u-icon>
				</view>
			</view>
			<!-- 		<view class="bg">
				<image :src="$picUrl+'/static/news3/bg.png'" mode="widthFix"></image>
				<view class="text">
					只属于非商城订单
				</view>
			</view> -->
			<!-- v-if="goodsList.length>0" -->
			<view style="padding-bottom: 120upx;">
				<view class="dispatchContent" v-if="classifyShow==1" v-for="(item, index) in goodsList" :key="index">
					<view class="orderNum">
						订单号：{{item.order_no}}
					</view>
					<view class="dispatchItem" v-for="(item1, index) in item.goods">
						<image :src="item1.goods_image" mode="aspectFill"></image>
						<view class="right">
							<view class="title">
								{{item1.goods_name}}
							</view>
							<view style="display: flex;align-items: center;justify-content: space-between;">
								<view class="num">
									x{{item1.total_num}}
								</view>
								<view class="price">
									<text style="font-size: 26upx;">¥</text>
									<text>{{item1.total_price?Number(item1.total_price):item1.total_price}}</text>
								</view>
							</view>

						</view>
					</view>
					<view class="totalNum">
						<text>共计:</text>
						<text style="color: #F21A1C;">¥{{item.pay_price?Number(item.pay_price):item.pay_price}}</text>
					</view>
					<view class="footerBtn">
						<view class="wuliuBtn" v-if="classifyShow==1&&!item.transfer" @click="manualEntry(item)">
							调货记录
						</view>
						<view class="wuliuBtn" v-if="classifyShow==1&&item.transfer"
							@click="onCondiments(item.transfer)">
							调货记录
						</view>
					</view>
				</view>
				<view class="dispatchContent" v-if="classifyShow==2" v-for="(item, index) in goodsList" :key="index">
					<view class="orderNum">
						订单号：{{item.express_no}}
					</view>
					<view class="dispatchItem" v-for="(item1, index) in item.goods">
						<image :src="item1.image" mode="aspectFill"></image>
						<view class="right">
							<view class="title">
								{{item1.name}}
							</view>
							<view style="display: flex;align-items: center;justify-content: space-between;">
								<view class="num">
									x{{item1.num}}
								</view>
								<view class="price">
									<text style="font-size: 26upx;">¥</text>
									<text>{{item1.price}}</text>
								</view>
							</view>

						</view>
					</view>
					<view class="totalNum">
						<text>共计:</text>
						<text style="color: #F21A1C;">¥{{item.total_price}}</text>
					</view>
					<view class="footerBtn">
						<view class="wuliuBtn" v-if="classifyShow==2&&item.goods_sn&&item.goods_num"
							@click="onCondiments(item)">
							调货记录
						</view>
						<view class="wuliuBtn" v-if="classifyShow==2&&!item.goods_sn&&!item.goods_num"
							@click="manualEntry(item)">
							调货记录
						</view>
					</view>
				</view>
			</view>
			<view v-if="goodsList.length==0" style="margin-top: 250rpx;">
				<u-empty text="暂无记录～" mode="list"></u-empty>
			</view>
			<view class="goods-fd" v-if="classifyShow==2">
				<view class="btn" @click="manualEntry">手动录入</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as newFunApi from '@/api/newFun'
	export default {
		data() {
			return {
				searchText: '',
				goodsList: [],
				total: 1,
				pageNum: 1,
				classifyShow: 1,
				classList: [{
					id: 1,
					name: '商城订单',
				}, {
					id: 2,
					name: '非商城订单',
				}],
			}
		},
		onLoad(o) {},
		//页面卸载
		onUnload() {
			//关闭监听选择收货地址事件
			uni.$off('refreshData')
		},
		onShow() {
			this.classifyShow = 1
			// 调用列表接口
			if (this.classifyShow == 2) {
				this.getOrderList(1);
			} else {
				this.getList(1)
			}
		},
		onPullDownRefresh() {
			this.pageNum = 1;
			this.goodsList = [];
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000)
		},
		onReachBottom() {
			if (this.goodsList.length <= this.total) {
				this.pageNum++;
			}
		},
		methods: {
			onClassify(item, index) {
				this.searchText=''
				this.classifyShow = item.id;
				this.pageNum = 1;
				this.goodsList = []
				if (index == 1) {
					this.getOrderList(1);
				} else {
					this.getList(1)
				}
			},
			// 手动录入
			manualEntry(item) {
				uni.navigateTo({
					url: "/pages/news3/ManualEntry?type=" + this.classifyShow + '&order_id=' + item.order_id
				})
			},
			// 调货记录
			onCondiments(e) {
				uni.navigateTo({
					url: "/pages/news3/seasoningCondimentsRecord?item=" + JSON.stringify(e)
				})
			},
			async getList(type) {
				uni.showLoading({
					title: "加载中"
				})
				if (type == 1) {
					this.pageNum = 1;
					this.goodsList = []
				}
				let {
					status,
					message,
					data
				} = await newFunApi.shopOrderList({
					// dataType: 'all',
					dataType: 'receipt',
					page: this.pageNum,
					searchValue: this.searchText,
					payMethod: '',
					orderSource: '',
					betweenTime: '',
					delivery_type: '',
					user_id: '',
				});
				if (status == 200) {
					uni.hideLoading();
					this.total = data.list.total
					this.goodsList = this.goodsList.concat(data.list.data)
				}
			},
			/**
			 * 获取商品列表
			 */
			async getOrderList(type) {
				uni.showLoading({
					title: "加载中"
				})
				if (type == 1) {
					this.pageNum = 1;
					this.goodsList = []
				}
				let {
					status,
					message,
					data
				} = await newFunApi.deliveryList({
					page: this.pageNum,
					search: this.searchText
				});
				if (status == 200) {
					uni.hideLoading();
					this.goodsList = this.goodsList.concat(data.data)
					this.total = data.total
				}
			},
		}
	};
</script>

<style lang="scss" scoped>
	page {
		min-height: 100%;
		background-color: #F7F8FA;
	}

	.head-info {
		margin: 22upx 20upx;

		.searchContent {
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: relative;
			background-color: #fff;
			border-radius: 60upx;
			width: 680upx;
			margin-left: 15upx;

			::v-deep .u-input {
				background: #FFFFFF;
				border-radius: 30px 30px 30px 30px;
				opacity: 1;
				padding-left: 90upx !important;
			}

			.search {
				position: absolute;
				top: 20upx;
				left: 26upx;
				z-index: 9;
			}


		}
	}

	.bg {
		position: relative;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;

		image {

			height: auto;
			width: 690upx;
		}

		.text {
			height: 100%;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;

			font-size: 42upx;
			font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
			font-weight: 400;
			color: #FFFFFF;
			position: absolute;
			left: 0;
			top: 0;

		}
	}

	.orderNum {

		font-size: 28upx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #707070;
		margin: 16upx 0;

	}

	.dispatchContent {
		padding: 20upx 40upx;
		background: #FFF;
		border-radius: 6px;
		margin: 20upx 14upx;
	}

	.dispatchItem {
		display: flex;
		align-items: center;
		margin-bottom: 18upx;

		image {
			width: 158upx;
			height: 170upx;
		}

		.right {
			flex: 1;
			margin-left: 40upx;
			position: relative;
			display: flex;
			flex-direction: column;
			justify-content: space-around;

			.title {

				font-size: 28upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #000000;
				margin-bottom: 18upx;

			}

			.subTitle {

				font-size: 28upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #7C7C7C;
				margin: 14upx 0;

			}

			.num {

				font-size: 28upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #1E1E1E;
			}

			.price {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				font-size: 32upx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #FF584D;

			}
		}
	}

	.totalNum {
		text-align: right;
		margin-top: 26upx;

		text:first-child {
			font-size: 32upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 700;
			color: #3B3B3B;
		}

		text:nth-child(2) {
			font-size: 32upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 700;
			color: #3B3B3B;
			margin: 0 10upx;

		}

		text:nth-child(3) {
			font-size: 32upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			color: #F21A1C;

		}
	}

	.footerBtn {
		padding: 25upx 0 15upx 30upx;
		display: flex;
		align-items: center;
		border-top: 1px solid #F0F0F0;
		justify-content: flex-end;
		margin-top: 30upx;
	}

	.wuliuBtn {
		// padding:8upx 46upx;
		text-align: center;
		height: 66upx;
		line-height: 66upx;
		border: 1px solid #F63116;
		font-size: 28upx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #F83F11;
		border-radius: 20px;
		// width: 180upx;
		padding: 0 20rpx;
	}

	.goods-fd {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		padding: 0.9375rem;
		z-index: 99;
		background-color: #fafafa;
		box-sizing: border-box;

		.btn {
			width: 630rpx;
			line-height: 88rpx;
			background: #F34A40;
			border-radius: 88rpx;
			text-align: center;
			font-size: 28rpx;
			font-weight: 500;
			color: #FFFFFF;
			margin: auto;
		}
	}

	.empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100%;

		image {
			width: 114rpx;
			height: auto;
			margin-top: 200rpx;
		}
	}

	.container {
		background-color: #fff;


		.classify-list {
			white-space: nowrap;
			width: 100%;
			height: 100rpx;
			overflow-x: auto;
			overflow-y: hidden;

			.list {
				position: relative;
				display: inline-block;
				width: 50%;
				height: 100%;
				line-height: 100rpx;
				text-align: center;

				text {
					font-size: 28rpx;
					color: #3B3B3B;

				}

				.line {
					position: absolute;
					left: 50%;
					bottom: 10rpx;
					// width: 60%;
					// height: 8rpx;
					background: linear-gradient(to right, #f8f893, #fe9d00);
					// border-radius: 10rpx;
					transform: translate(-50%, 0);

					width: 60upx;
					height: 8upx;
					background: #FF6257;
					border-radius: 29px 29px 29px 29px;
					opacity: 1;
				}
			}

			.action {
				text {
					font-size: 32rpx;
					opacity: 1;
				}
			}
		}
	}
</style>
