<template>
	<view class="all-container  pd-main backcor6 font15">
		<view class="mart20 backcorfff marb20">
			<view class="dis-flex height40 bor-botm1">
				<view class="flex-1 fotct fontwig6 ">桌台名称</view>
				<view class="flex-1 fotct fontwig6">订单金额</view>
				<view class="flex-1 fotct fontwig6">状态</view>
				<view class="flex-1 fotct fontwig6">操作</view>
			</view>
		
			<view class="dis-flex bor-botm1 paddtop10 paddbotm10 font14" @click="openOrderDetail(item)"
				v-for="(item,index) in orderList" :key="index">
				<view class="flex-1 fotct text1">
					{{item.tableName}}
				</view>
				<view class="flex-1 fotct text1">
					{{item.orderAmount}}
				</view>
				<view class="flex-1 fotct text1" :class="{'fcorred':item.status==1}">
					{{item.status | filterStatus}}
				</view>
				<view class="flex-1 fotct text1 dis-flex fcor41c" style="justify-content: space-around;">
					<text>详情</text>
					<text class="margle" @click.stop="goEditTableOrder(item)" v-if="item.status==1">编辑</text>
				</view>
			</view>
		</view>
		
		<!-- 查看详情 -->
		<uni-popup ref="popupDetail" type="bottom" background-color="#ffffff">
			<view style="height: 70vh;overflow-y: auto;" class="backcorfff  border-10r-lr pd-main font16">
				<view class="pop-contain pd-main">
					<view class="pop-title fontwig6"><text>详情</text></view>
					<view class="" v-if="orderDetail">
						<view class="width100 dis-flex bor-botm1 ">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">桌台编号</view>
							<view class="flex-1 fotct ">{{orderDetail.tableNumber}}</view>
						</view>
						<view class="width100 dis-flex bor-botm1 ">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">桌台名称</view>
							<view class="flex-1 fotct ">{{orderDetail.tableName}}</view>
						</view>
						<view class="width100 dis-flex bor-botm1 ">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">桌台状态</view>
							<view class="flex-1 fotct " :class="{'fcorred':orderDetail.status==1}">{{orderDetail.status | filterStatus}}</view>
						</view>
						<view class="width100 dis-flex bor-botm1 ">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">用餐人数</view>
							<view class="flex-1 fotct ">{{orderDetail.peopleNum}}人</view>
						</view>
						<view class="width100 dis-flex bor-botm1 ">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">订单金额</view>
							<view class="flex-1 fotct ">{{orderDetail.orderAmount}}元</view>
						</view>
						<view class="width100 dis-flex bor-botm1 ">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">创建时间</view>
							<view class="flex-1 fotct ">{{orderDetail.createTime | timeFormat}}</view>
						</view>
						<view class="width100 dis-flex bor-botm1 ">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">订单编号 </view>
							<view class="flex-1 fotct wb">{{orderDetail.orderNo}}</view>
						</view>
						<view class="width100 dis-flex bor-botm1 " v-if="orderDetail.status==2">
							<view class=" fotct fontwig6 backcor6 titleWidth minheight40">支付单号 </view>
							<view class="flex-1 fotct wb" >{{orderDetail.payOrderNo}}</view>
						</view>
						
					</view>
		
		
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {queryOrderList,queryOrderDetail} from '@/Utils/groupBuying.js'
	export default {
		data(){
			return{
				storeId:'',//门店id
				pageNum: 1,
				pageSize: 30,
				isNoMoreData: false, //是否加载中
				totalNum:0,
				orderList:[],
				orderDetail:null,
			}
		},
		onLoad(options) {
			this.storeId = options.storeId;
			
		},
		onShow(){
			this.formatOrderList();
		},
		onReachBottom() {
			this.queryOrderList();
		},
		filters:{
			filterStatus(type){
				switch (type) {
					case 0:
						return '不可用';
					case 1:
						return '未结账';
					case 2:
						return '已结账';
					default:
						return '未知';
				}
			},
		},
		methods:{
			/* 查询订单列表 */
			queryOrderList(){
				if (this.isNoMoreData) {
					return false;
				}
				
				uni.showLoading({
					title: '加载中...'
				})
				let params={
					storeId:this.storeId,
					pageNum:this.pageNum,
					pageSize:this.pageSize,
				}
				queryOrderList(params).then(res=>{
					uni.hideLoading();
					if (res.return_code == '000000' ) {
						this.totalNum = res.return_data.total;
						this.isNoMoreData = res.return_data.isLastPage;
						this.orderList = this.orderList.concat(res.return_data.list);
						if(!this.isNoMoreData){
							this.pageNum+=1
						}
					} else {
						uni.showToast({
							title: res.return_msg,
							duration: 2000,
							icon: 'none'
						})
					}
				})
				
			},
			formatOrderList(){
				this.pageNum=1;
				this.isNoMoreData=false;
				this.orderList=[];
				this.queryOrderList();
			},
			goEditTableOrder(item){
				uni.navigateTo({
					url:`./editTableOrder?storeId=${item.storeId}&serialNumber=${item.serialNumber}`
				})
			},
			/* 查询订单详情 */
			openOrderDetail(item){
				this.orderDetail=null;
				let params={
					orderNo:item.orderNo
				}
				uni.showLoading({
					mask:true
				})
				queryOrderDetail(params).then(res=>{
					uni.hideLoading()
					if (res.return_code == '000000') {
						this.orderDetail=res.return_data.order;
						this.$refs.popupDetail.open('bottom');
					} else {
						uni.showToast({
							title: res.return_msg,
							icon: 'none',
							duration: 2000
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	
/* 详情弹窗 */
	.pop-contain {
		text-align: center;
		padding-top: 50px;
		background-color: #ffffff;

		.pop-title {
			text-align: center;
			height: 50px;
			line-height: 50px;
			font-size: 18px;
			position: fixed;
			z-index: 10;
			top: 0;
			left: 0;
			right: 0;
			background: #ffffff;

		}
		.titleWidth {
			min-width: 80px;
			text-align: center;
		}
		.minheight40 {
			padding: 15px 0;
		}
		
		.wb{
			word-break: break-all;
		}
	}
</style>