<template>
<view class="dispatch">
	<view class="dispatchItem">
		<image src="/static/news3/filter.png" mode="aspectFill"></image>
		<view class="right">
			<view class="title">
				{{info.server_name}}
			</view>
			<view class="num">
				x1
			</view>
			<view class="price">
				<text style="font-size: 26upx;">¥</text>
				<text>{{info.pay_price}}</text>
			</view>
		</view>
	</view>
	<view class="selectContent">
		<view class="left">
			接单师傅
		</view>
		<view class="right" @click="openPage()">
			<text>{{tabIndex>=0?list[tabIndex].real_name:'请选择接单师傅'}}</text>
			<u-icon name="arrow-right" color="#C3C3C3" size="28"></u-icon>
		</view>
		
	</view>
	<u-popup v-model="isShow" mode="bottom" border-radius="12" mask-close-able="false" closeable>
		<view class="goods-classify">
			<view class="goods-classify-hd">选择工程师</view>
			<view class="goods-classify-bd">
				<scroll-view scroll-y class="m">
					<view class="item" v-for="(a,i) in list" @click="tabMItem(i)"><view :class="tabIndex == i?'item-on':''">{{a.real_name}}</view></view>
				</scroll-view>
			</view>
		</view>	
	</u-popup>
	<view class="btn" @click="toPaidan()">
		确认派单
	</view>
</view>
</template>

<script>
import * as newFunApi from '@/api/newFun'
export default{
	data(){
		return{
			order_id: "",
			info: {},
			list: [],
			tabIndex: -1,
			isShow: false,
			isClick: true
		}
	},
	onLoad(o) {
		if(o.order_id && o.type == 'fuwuorder'){
			this.type = o.type
			this.order_id = o.order_id;
			this.getInfo()
			this.getList();
		}
		
	},
	methods:{
		openPage() {
			this.isShow = true
		},
		tabMItem(i){
			this.tabIndex = i;
			this.isShow = false
		},
		/**
		 * 获取详情
		 */
		async getInfo() {
			const {status, message, data} = await newFunApi.serverOrderDetails({
				order_id: this.order_id
			});
			if(status == 200){
				this.info = data.info
			}
		},
		/**
		 * 获取列表
		 */
		async getList() {
			const {status, message, data} = await newFunApi.serverGetEngineer({
				order_id: this.order_id
			});
			if(status == 200){
				this.list = data.list
			}
		},
		/**
		 * 派单
		 */
		async toPaidan() {
			if(this.isClick == false){
				return ;
			}
			this.isClick = false
			const {status, message, data} = await newFunApi.serverDispatchOrders({
				order_id: this.order_id,
				dealer_id: this.tabIndex <= -1?"":this.list[this.tabIndex].user_id
			});
			if(status == 200){
				this.isClick = true
				uni.showToast({
					title: "派单成功"
				})
				setTimeout(()=>{
					uni.navigateBack({
						delta: 1
					})
				},2000)
			}else{
				uni.showToast({
					icon: "none",
					title: message
				})
			}
		},
	}
}
</script>

<style lang="scss" scoped>
page{
	min-height: 100%;
	background-color: #F7F8FA;
}
.goods-classify{
	width: 100%;
	overflow: hidden;
	&-hd{
		padding: 30rpx 60rpx;
		position: relative;
		font-size: 32rpx;
		font-weight: 500;
		color: #303030;
		text-align: center;
		.a{
			display: flex;
			align-items: center;
			font-size: 28rpx;
			font-weight: 500;
			color: #FF624F;
			position: absolute;
			top: 30rpx;
			left: 40rpx;
			z-index: 2;
		}
	}
	&-bd{
		overflow: hidden;
		display: flex;
		align-items: flex-start;
		.l{
			width: 210rpx;
			height: 560rpx;
			background-color: #F7F8FA;
			.item{
				text-overflow: ellipsis;
				overflow: hidden;
				height: 70rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #303030;
				white-space: nowrap;
				line-height: 70rpx;
				padding-left: 30rpx;
				box-sizing: border-box;
				text-align: left;
				&-on{
					background-color: #fff;
					font-weight: 500;
				}
			}
		}
		.m{
			width: 100%;
			text-align: center;
			max-height: 560rpx;
			.item{
				text-overflow: ellipsis;
				overflow: hidden;
				height: 70rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #303030;
				white-space: nowrap;
				line-height: 70rpx;
				padding-left: 80rpx;
				box-sizing: border-box;
				text-align: left;
				&-on{
					color: #FF624F;
				}
			}
		}
		.r{
			width: 540rpx;
			height: 560rpx;
			.item{
				text-overflow: ellipsis;
				overflow: hidden;
				height: 70rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #303030;
				white-space: nowrap;
				line-height: 70rpx;
				padding-left: 80rpx;
				box-sizing: border-box;
				&-on{
					color: #FF624F;
				}
			}
		}
	}
}
.dispatchItem{
	display: flex;
	align-items: center;
	padding:40upx;
	background-color: #fff;
	border-top:1px solid #EBEBEB;
	image{
		width: 180upx;
		height:150upx;
	}
	.right{
		flex:1;
		margin-left:40upx;
		.title{
			
			font-size: 28upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #3B3B3B;
		
		}
		.num{
			
			font-size: 28upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #1E1E1E;
			margin-top:44upx;
		}
		.price{
			display: flex;
			align-items: center;
			justify-content: flex-end;
			font-size: 32upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #F21A1C;
			
		}
	}
}
.selectContent{
	padding:40upx;
	background-color: #fff;
	border-top:1px solid #EBEBEB;
	display: flex;
	align-items: center;
	justify-content: space-between;
	.left{
		
		font-size: 28upx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #3B3B3B;
		
	}
	.right{
		text{
		
			font-size: 28upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #B0B0B0;
			
		}
	}
}
.btn{
	width: 80%;
	height: 100upx;
	background: #FFAAA4;
	border-radius: 6px 6px 6px 6px;
	opacity: 1;
	line-height: 100upx;
	text-align: center;
	font-size: 28upx;
	font-family: PingFang SC, PingFang SC;
	font-weight: 500;
	color: #FFFFFF;
	margin:66upx auto;
	
}
</style>