<template>
	<view>
		<view class="searchBox flex-between">
			<view class="flex-center">
				<u-search v-if="orderType==1" placeholder="请输入订单号" style="width:600rpx" bg-color="#fff" height="60"
					:show-action="false" v-model="msg1.OrderNo"></u-search>
				<u-search v-if="orderType==2" placeholder="请输入订单号" style="width:600rpx" bg-color="#fff" height="60"
					:show-action="false" v-model="msg2.ReOrderNo"></u-search>
			</view>
			<view class="flex-center" v-if="orderType==1" @click="getList1">
				搜索1
			</view>
			<view class="flex-center" v-if="orderType==2" @click="getList2">
				搜索2
			</view>
		</view>
		<view v-if="orderList.length > 0"
			style="height: calc(100vh - 100rpx);width: calc(100vw);overflow: hidden;box-sizing: border-box;">
			<scroll-view :scroll-y="true" :enable-back-to-top="true" :enable-flex="true" @scrolltolower="lower"
				:style="{ height: '100%' }">
				<view v-for="(item,index) in orderList" :key="index">
					<orderItem :data="item" :orderType="orderType" @update="updateList" 
						v-if="orderType === 1" />
					<saleAfterOrderItem :data="item" :orderType="orderType" @update="updateList"
						v-if="orderType === 2" />
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import tabbar from "./components/tabbar.vue";
	import orderItem from "./components/orderItem.vue";
	import saleAfterOrderItem from "./components/saleAfterOrderItem.vue";
	export default {
		components: {
			tabbar,
			orderItem,
			saleAfterOrderItem,
		},
		data() {
			return {
				orderType: 1, //1普通订单，2售后订单
				loading: false,
				status: "loadmore",
				loadText: {
					loadmore: "轻轻上拉，加载更多",
					loading: "努力加载中",
					nomore: "没有更多了",
				},
				page_count: 1,
				msg1: {
					pageIndex: 1,
					pageSize: 15,
					Name: "",
					OrderSource: 0,
					OrderType: 0,
					DeliveryMethod: 0,
					OrderId: 0,
					StartTime: "",
					EndTime: "",
					OrderStatus: 0,
					OrderNo: "",
					MerchantsNo: "",
					UserName: "",
					UserId: "",
					GoodsName: "",
					Consignee: "",
					Mobile: "",
					ProductCode: "",
					Recycled: 2,
					AnchorName: "",
					IsSelectPayMoney: 0,
					IsOffline: -1,
				},
				msg2: {
					pageIndex: 1,
					pageSize: 15,
					OrderSource: 0,
					OrderType: 0,
					DeliveryMethod: 0,
					OrderId: 0,
					StartTime: "",
					EndTime: "",
					OrderNo: "",
					UserName: "",
					UserId: 0,
					GoodsName: "",
					SelectStatus: 0,
					ReOrderNo: "",
					Consignee: "",
					Mobile: "",
				},
				readMsg:{
					Id:0,
					Type:1
				},
				orderList: [],
			};
		},
		methods: {
			getList1() {
				uni.showLoading({
					title: '加载中'
				});
				this.requestAdmin("/api/order/GetGoodsOrderPageList", this.msg1, (res) => {
				  uni.hideLoading();
				  this.page_count = res.data.pageCount;
				  if (this.page_count == 1) {
				    this.status = "nomore";
				  }
				  if (this.msg1.pageIndex === 1) {
				    this.orderList = res.data.pageData;
				  } else {
				    this.orderList = [...this.orderList, ...res.data.pageData];
				  }
				});
			},
			//售后订单数据
			getList2() {
				uni.showLoading({
					title: '加载中'
				});
				this.requestAdmin("/api/order/GetGoodsOrderAfterPageList", this.msg2, (res) => {
					uni.hideLoading();
					this.page_count = res.data.pageCount;
					if (this.msg2.pageIndex === 1) {
						this.orderList = res.data.pageData;
					} else {
						this.orderList = [...this.orderList, ...res.data.pageData];
					}
				});
			},
			// 刷新页面
			updateList() {
				if (this.orderType === 1) {
					this.msg1.pageIndex = 1;
					this.getList1();
				} else if (this.orderType === 2) {
					this.msg2.pageIndex = 1;
					this.getList2();
				}
			},
			lower(e) {
				if (this.orderType === 1) {
					if (this.msg1.pageIndex < this.page_count) {
						this.msg1.pageIndex++;
						this.status = "loading";
						this.getList1();
					}
				} else if (this.orderType === 2) {
					if (this.msg2.pageIndex < this.page_count) {
						this.msg2.pageIndex++;
						this.status = "loading";
						this.getList2();
						this.status = "nomore";
					}
				}
			},
			//订单标记已读
			getOrderRead(){
				this.requestAdmin("/api/MemberUser/SetAdminMessageLook", this.readMsg, (res) => {
					if(res.resultCode==1){
						// uni.showToast({
						// 	title: res.message,
						// 	icon: 'none',
						// })
					}
				});
			},
		},
		onLoad(options) {
			uni.setNavigationBarTitle({
				title: "订单管理",
			});
			if (options?.orderType) {
				if (options.orderType == 3) {
					if(options.OrderNo){
						this.msg2.ReOrderNo = options.OrderNo
					}
					this.orderType = 2;
					this.getList2();
				} else {
					if(options.OrderNo){
						this.msg1.OrderNo = options.OrderNo
					}
					this.orderType = 1;
					this.getList1();
				}
				this.readMsg.Type=options.orderType
			}
			if(options?.Id){
				this.readMsg.Id = options.Id;
				this.getOrderRead();
			}
			console.log(1,options)
			if(options.type){
				this.orderType=parseInt(options.type)
			}
		},
	};
</script>


<style>
	.searchBox {
		height: 90rpx;
		background-color: #efeff4;
		padding: 0 40rpx 0 20rpx;
	}

	.flex-between {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.flex-center {
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
