<template>
	<view class="maintainOrder">
		<!-- header bar -->
		<view class="header">
			<view class="bars">
				<view :class="orderType == 1?'bar-select':'bar'" style="border-right: 1px solid #E6E6E6;"
					@click="changeOrderType(1)">
					进行中
				</view>
				<image v-if="orderType==1" :src="require('../../../static/sel.png')" alt="">
			</view>
			<view class="bars">
				<view :class="orderType == 0?'bar-select':'bar'" style="border-right: 1px solid #E6E6E6;"
					@click="changeOrderType(0)">
					已取消
				</view>
				<image v-if="orderType==0" :src="require('../../../static/sel.png')" alt="">
			</view>

			<view class="bars">
				<view :class="orderType == 6?'bar-select':'bar'" @click="changeOrderType(6)">
					已完成
				</view>
				<image v-if="orderType==6" :src="require('../../../static/sel.png')" alt="">
			</view>
		</view>
		<view style="height: 86rpx;"></view>
		<!-- 搜索 -->
		<view class="search">
			<view v-if="!search" @click="search = true">
				<image :src="require('../../../static/search.png')" class="searchIcon" alt="">
				<view class="search-text">
					搜索订单
				</view>
			</view>
			
			<input type="text" placeholder="请输入" confirm-type="search" v-model="searchTerm" @confirm="getListData(1)" @blur="noSearch()" focus v-else style="width: 80%;"/>
		</view>
		<!-- 订单 -->
		<view class="order" v-for="(item, index) in dataList" :key="index" @click="toPaths(item)">
			<view class="order-header">
				<view class="orderId">
					订单号：{{item.number}}
				</view>
				<view class="orderType" :style="item.status==0?'color: #666666':''">
					{{item.status==1?'待服务':item.status==2?'提车中':item.status==3?'作业中':item.status==4 && item.payStatus==2?'作业完成待支付':item.status==4 && item.payStatus==3?'已完成（已挂帐）':item.status==5?'作业完成已支付':item.status==6?'已完成':'已取消'}}
					<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>
						<view class="content">
							{{item.carTypeName}}
						</view>
					</view>
			</view>
			<view class="buttom">
				<view class="orderTime">
					{{item.time}}
				</view>
				<view @click.stop="onStatus(item)" class="orderBtn"
					:style="item.status==1?'background: #FFFFFF;border: 1px solid #ADADAD;color: #999999;':item.status==5?'background: #FFFFFF;color: #005EFF;border: 1px solid #005EFF;':''"
					v-if="item.status!=0 && item.status!=3 && item.isEvaluate == 2">
					{{item.status==1?'取消':item.status==2?'提车确认':item.status==3?'作业直播':item.status==4?'支付费用':item.isEvaluate ==2?'评价':''}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		repairOrderList,
		cancelOrder,
		orderEvaluate
	} from "@/api/maintain.js"
	const app = getApp();
	export default {
		components: {},
		data() {
			return {
				baseImagePath: this.baseImagePath,
				orderType: 1,
				dataList: [],
				searchTerm: "",
				pageNo: 1,
				pageSize: 20,
				search:false
			}
		},
		onShow: function() { //option为object类型，会序列化上个页面传递的参数
			this.pageNo = 1
			this.getListData(1);
			let that = this
			uni.$on('maintainEvaluateOver', function(data) {
				uni.showToast({
					title: data.data,
					icon: "none",
					duration: 1500
				});
				console.log(data.data);
			})
			uni.$on('deliveryOver', function(data) {
				uni.showToast({
					title: data.data,
					icon: "none",
					duration: 1500
				});
				console.log(data.data);
			})
		},
		onLoad(e) {
			app.globalData.requestToken = e.token;
			uni.setStorageSync('token',e.token)
		},
		watch: {
			orderType(val) {
				this.pageNo = 1;
				this.getListData(1);
			}
		},
		onReachBottom() {
			this.pageNo++
			this.getListData()
		},
		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: {
			noSearch(){
				if(!this.searchTerm){
					this.search = false
				}
				this.getListData(1)
				
			},
			changeOrderType(val) {
				this.orderType = val;
			},
			getListData(val) {
				let that = this;
				if(!this.searchTerm){
					this.search = false
				}
				console.log(this.orderType);
				repairOrderList({
					pageNo: that.pageNo,
					pageSize: that.pageSize,
					status: this.orderType,
					searchTerm: this.searchTerm
				}).then((res) => {
					if (val == 1) {
						that.dataList = [];
					}
					that.dataList = that.dataList.concat(res.data.rows)
					console.log('dataList参数',this.dataList);
				})
			},
			onStatus(item) {
			
				
				let that = this;
				if (item.status == 2) {
					this.$yrouter.push({
						path: "/pages/maintenance/maintainOrder/deliveryOfVehicle/index?data=" +
							encodeURIComponent(JSON.stringify(item))
					});
				} else if (item.status == 1) {
					cancelOrder({
						id: item.id
					}).then((res) => {
						this.pageNo = 1
						that.getListData(1)
					})
				}else if(item.status == 4){
					this.$yrouter.push({
						path: "/pages/maintenance/expensesList/expensesList?id=" + item.id
					});
				} else if (item.status == 5 || item.status == 6) {
					this.$yrouter.push({
						path: "/pages/preCarWash/washOrder/serviceEvaluation/index?type=" + 1 + "&detailId=" + item
							.id
					});
				}
			},
			toPaths(item) {
				this.$yrouter.push({
					path: "/pages/maintenance/maintainOrder/orderDetail/index?data=" + encodeURIComponent(JSON
						.stringify(item))
				});
			}
		}
	}
</script>

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

	.maintainOrder {
		.header {
			display: flex;
			align-items: center;
			width: 100%;
			height: 86rpx;
			background: #FFFFFF;
			position: fixed;
			top: 0;
			z-index: 999;
			.bars {
				width: 33%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				background-color: #FFFFFF;
				
				image {
					width: 34rpx;
					height: 11rpx;
				}

				.bar-select {
					width: 100%;
					height: 30rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					line-height: 31rpx;

				}

				.bar {
					width: 100%;
					height: 30rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #666666;
					line-height: 31rpx;
				}
			}

		}

		.search {
			width: 690rpx;
			height: 65rpx;
			background: #FFFFFF;
			border-radius: 32rpx;
			margin: 30rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			view{
				display: flex;
				align-items: center;
				justify-content: center;
				.searchIcon {
					width: 25rpx;
					height: 25rpx;
				}
				
				.search-text {
					padding-left: 15rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}
			
		}

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

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

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

				.orderType {
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #005BFF;
					line-height: 34rpx;

					image {
						width: 11rpx;
						height: 18rpx;
						margin-left: 9rpx;
					}
				}
			}

			.carView {
				display: flex;
				border-bottom: 1px solid #EEEEEE;
				align-items: center;
				justify-content: s;
				padding: 20rpx 0;
				image {
					width: 120rpx;
					height: 120rpx;
					background: #FFFFFF;
					border: 2px solid #F4F4F4;
					border-radius: 8rpx;
				}

				.carBody {
					padding: 32rpx;
					height: 100%;
					display: flex;
					align-items: center;
					flex-direction: column;
					.carTitle {
						display: flex;
						align-items: center;
						margin-bottom: 20rpx;
						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;
							padding: 0 15rpx 0 15rpx;
						}
					}

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

			.buttom {
				padding-top: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

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

				.orderBtn {
					width: 156rpx;
					height: 56rpx;
					text-align: center;
					background: linear-gradient(0deg, #008EFF 0%, #0036FF 100%);
					border-radius: 28rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 56rpx;
				}
			}
		}
	}
</style>
