<template>
	<view class="order">
		<view class="bars">
			<view style="display: flex;">
				<view :class="orderType == ''?'bar-select':'bar'" @click="changeType('')">
					全部
					<image v-if="orderType==''" :src="require('../../../static/sel.png')" alt="">
				</view>
			</view>
			<view style="display: flex;">
				<view :class="orderType == '2'?'bar-select':'bar'" @click="changeType('2')">
					待服务
					<image v-if="orderType=='2'" :src="require('../../../static/sel.png')" alt="">
				</view>
				<span v-if="orderNum>0">{{orderNum}}</span>
			</view>
			<view style="display: flex;">
				<view :class="orderType == '4'?'bar-select':'bar'" @click="changeType('4')">
					已取消
					<image v-if="orderType=='4'" :src="require('../../../static/sel.png')" alt="">
				</view>
			</view>
			<view style="display: flex;">
				<view :class="orderType == '3'?'bar-select':'bar'" @click="changeType('3')">
					已完成
					<image v-if="orderType=='3'" :src="require('../../../static/sel.png')" alt="">
				</view>
			</view>
		</view>
		<view style="height: 80rpx;"></view>
		<view class="body" v-for="(item, index) in orderList" :key="index" @click="toPath(item)">
			<view class="header">
				<view class="orderId">
					订单编号：{{item.orderNumber}}
				</view>
				<view class="orderType" :style="item.status==1 || item.status==2?'color: #005BFF;':'color: #666666;'">
					{{item.status==1?'待支付':item.status==2?'待服务':item.status==3?'已完成':item.status==4?'已取消':'进行中'}}
					<image :src="require('../../../static/choose.png')" alt="">
				</view>
			</view>
			<view class="carView">
				<image :src="baseImagePath+item.carLogo" alt="">
					<view class="carBody">
						<view class="carTitle">
							<image :src="require('../../../static/car.png')" alt="">
								<span>{{item.carNumber}}</span>
								<view class="border"></view>
								<span>{{item.carMadelLevel}}</span>
								<view class="border"></view>
								<span>{{item.carWashType}}</span>
						</view>
						<view class="content">
							{{item.carTypeName}}
						</view>
					</view>
			</view>
			<view class="shop">
				<image :src="require('../../../static/shop.png')" alt="">
					<view style="padding-left: 16rpx;">
						门店：{{item.shopName}}
					</view>

			</view>
			<view class="times" :style="item.orderType==2?'border-bottom: 1px solid #EEEEEE;':''">
				<image :src="require('../../../static/time.png')" alt="">
					<view style="padding-left: 16rpx;">
						时间：{{item.time}}
					</view>
			</view>
			<view v-if="item.status==3 && item.isEvaluate == 2">
				<view class="buttomBtn" @click.stop="toEvaluation(item.id)">
					评价
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		carwashOrderList
	} from "@/api/carWash.js"
	const app = getApp();
	export default {
		components: {},
		data: function() {
			return {
				requestStatus: false,
				baseImagePath: this.baseImagePath,
				orderNum: null,
				orderType: "",
				orderList: [],
				pageNo: 1,
				pageSize: 20,
			}
		},
		onReachBottom() {
			let that = this
			that.pageNo++
			this.getPage()
		},
		onLoad(e) {
			app.globalData.requestToken = e.token;
			uni.setStorageSync('token', e.token)
		},
		onShow() {
			this.pageNo = 1
			this.getPage(1)
		},
		onBackPress(options) {
			console.log('11111');
			// 这里可以自定义返回逻辑，比如下面跳转其他页面
			// #ifdef APP-PLUS
			if (plus.os.name.toLowerCase() === 'android') {
				plus.runtime.quit();
			} else {
				plus.runtime.quit();
			}
			// #endif
			// return true 表示禁止默认返回
			return true;
		},
		methods: {
			changeType(val) {
				this.orderType = val;
				this.pageNo = 1;
				this.getPage(1);
			},
			getPage(val) {
				let data = {
					status: this.orderType,
					pageNo: this.pageNo,
					pageSize: this.pageSize
				}
				let that = this;
				carwashOrderList(data).then((res) => {
					console.log(res);
					that.orderNum = res.data.beServiceNum;
					if (val == 1) {
						that.orderList = [];
					}
					that.orderList = that.orderList.concat(res.data.carWashOrderListVO.rows)
				})
			},
			toPath(item) {
				console.log('订单详情', item);
				this.$yrouter.push({
					path: "/pages/preCarWash/washOrder/orderDetail/index?data=" + encodeURIComponent(JSON
						.stringify(item))
				});
			},
			toEvaluation(id) {
				if (this.requestStatus) {
					// 利用 return 终止函数继续运行
					return false;
					console.log(1);

				}
				this.$yrouter.push({
					path: "/pages/preCarWash/washOrder/serviceEvaluation/index?type=3&detailId=" + id
				});
				console.log('按钮点击函数执行');
				// 执行函数
				this.requestStatus = true;
				setTimeout(() => {
					// 模拟执行完毕
					// 改变 requestStatus
					this.requestStatus = false;
				}, 1000);
			}
		}
	}
</script>

<style lang="less">
	page {
		background: #F5F5F5;
	}

	.order {
		.bars {
			width: 100%;
			height: 80rpx;
			background: #FFFFFF;
			box-shadow: 0px 1px 0px 0px rgba(55, 55, 55, 0.1);
			display: flex;
			justify-content: space-around;
			align-items: center;
			position: fixed;
			top: 0;
			z-index: 999;

			.bar {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
				background-color: #FFFFFF;
			}

			span {
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #005BFF;
				padding-left: 12rpx;
			}
		}

		.bar-select {
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;

			image {
				width: 34rpx;
				height: 11rpx;
			}
		}

		.body {
			background: #FFFFFF;
			border-radius: 10rpx;
			margin: 20rpx;
			padding: 30rpx;

			.header {
				display: flex;
				justify-content: space-between;
				border-bottom: 1rpx solid #EEEEEE;
				padding-bottom: 30rpx;

				.orderId {
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					line-height: 34rpx;
				}

				.orderType {
					display: flex;
					align-items: center;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;

					line-height: 34rpx;

					image {
						padding-left: 8rpx;
						width: 11rpx;
						height: 18rpx;
					}
				}
			}

			.carView {
				display: flex;

				image {
					width: 120rpx;
					height: 120rpx;
					background: #FFFFFF;
					border: 2rpx solid #F4F4F4;
					border-radius: 8rpx;
					margin-top: 32rpx;
				}

				.carBody {
					padding: 32rpx;

					.carTitle {
						display: flex;

						image {
							width: 33rpx;
							height: 27rpx;
							margin-top: 0rpx;
						}

						.border {
							width: 1px;
							height: 20rpx;
							background: #DBDBDB;
						}

						span {
							font-size: 30rpx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #333333;
							line-height: 31rpx;
							padding: 0 15rpx 0 15rpx;
							white-space: nowrap;
						}
					}

					.content {
						font-size: 26rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #666666;
						line-height: 34rpx;
						padding: 20rpx 60rpx 20rpx 0;
					}
				}
			}

			.shop {
				display: flex;
				align-items: center;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				line-height: 34rpx;

				image {
					width: 30rpx;
					height: 26rpx;
				}
			}

			.times {
				display: flex;
				align-items: center;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				line-height: 34rpx;
				margin-top: 31rpx;
				padding-bottom: 30rpx;

				image {
					width: 30rpx;
					height: 26rpx;
				}
			}

			.buttomBtn {
				width: 148rpx;
				height: 56rpx;
				background: #FFFFFF;
				border: 1px solid #003EFF;
				border-radius: 28rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #0051FF;
				line-height: 56rpx;
				text-align: center;
				margin: 26rpx 31rpx 0 74%;
			}
		}
	}
</style>