<template>
	<el-tabs v-model="activeName" @tab-click="handleClick">
		<el-tab-pane label="订单列表" name="first">
			
			<div style="margin:5px;text-align:left;">
				<div style="position: relative;display: inline-block;margin:5px;">
					<span>技师昵称：</span>
					<el-input style="width: 200px;" @keydown.enter.native="select" placeholder="请输入技师昵称"
						v-model="artificerName">
					</el-input>&nbsp;&nbsp;
				</div>
				<div style="position: relative;display: inline-block;margin:5px;">
					<span>技师电话：</span>
					<el-input style="width: 200px;" @keydown.enter.native="select" placeholder="请输入技师电话"
						v-model="artificerPhone">
					</el-input>&nbsp;&nbsp;
				</div>
				<div style="position: relative;display: inline-block;margin:5px;">
					<span>用户昵称：</span>
					<el-input style="width: 200px;" @keydown.enter.native="select" placeholder="请输入用户昵称"
						v-model="userName">
					</el-input>&nbsp;&nbsp;
				</div>
				<div style="position: relative;display: inline-block;margin:5px;">
					<span>用户电话：</span>
					<el-input style="width: 200px;" @keydown.enter.native="select" placeholder="请输入用户电话"
						v-model="phone">
					</el-input>&nbsp;&nbsp;
				</div>
				<div style="display: inline-block;margin-bottom: 6px;">
					<span>是否超时：</span>
					<el-select v-model="overTimeOrders" style="width:150px;margin-left: 10px;" @change="select()">
						<el-option v-for="item in statesnumCs" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="display: inline-block;margin-bottom: 6px;">
					<span>是否警告：</span>
					<el-select v-model="warning" style="width:150px;margin-left: 10px;" @change="select()">
						<el-option v-for="item in statesnumCs" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<div style="display: inline-block;margin-bottom: 6px;">
					<span>状态：</span>
					<el-select v-model="status" style="width:150px;margin-left: 10px;" @change="animeDat(status)">
						<el-option v-for="item in statesnum" :key="item.value" :label="item.label" :value="item.value">
						</el-option>
					</el-select>&nbsp;&nbsp;&nbsp;&nbsp;
				</div>
				<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="select">查询
				</el-button>
				<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="cleans">重置
				</el-button>
			</div>
			<el-table v-loading="tableDataLoading" :data="tableData.list">
				<el-table-column fixed prop="id" label="编号" width="80">
					<template slot-scope="scope">
						<span>
							{{scope.$index+1}}
						</span>
					</template>
				</el-table-column>
				<el-table-column prop="userName" label="用户昵称" width="100">
					<template slot-scope="scope">
						<span style="color: #4f9dec;cursor: pointer;" @click="updates(scope.row.userId)">
							{{ scope.row.userName?scope.row.userName:'未绑定'}}
						</span>
					</template>
				</el-table-column>
				<el-table-column prop="artificerName" label="技师昵称" width="100">
					<template slot-scope="scope">
						<span style="color: #4f9dec;cursor: pointer;" @click="updates(scope.row.artificerId)">
							{{ scope.row.artificerName?scope.row.artificerName:'未绑定'}}
						</span>
					</template>
				</el-table-column>
				
				
				<el-table-column prop="phone" label="用户电话" width="160">
				</el-table-column>
				<el-table-column prop="artificerPhone" label="技师电话" width="160">
				</el-table-column>
				<el-table-column prop="address" label="服务地址"  width="200"></el-table-column>
				<el-table-column prop="longitude" label="用户经度" width="160">
				</el-table-column>
				<el-table-column prop="latitude" label="用户纬度" width="160">
				</el-table-column>
				<el-table-column prop="artificerAddress" label="技师地址"  width="200"></el-table-column>
				<el-table-column prop="artificerLongitude" label="技师经度" width="160">
				</el-table-column>
				<el-table-column prop="artificerLatitude" label="技师纬度" width="160">
				</el-table-column>
				<el-table-column prop="startTime" label="开始服务时间" width="100">
				</el-table-column>
				<el-table-column prop="endTime" label="预估结束时间" width="100">
				</el-table-column>
				<el-table-column prop="startAddress" label="开始服务地址" width="200">
				</el-table-column>
				<el-table-column prop="accomplishAddress" label="完成服务地址" width="200">
				</el-table-column>
				<el-table-column prop="artificerStartTime" label="技师出发时间">
				</el-table-column>
				<el-table-column prop="artificerEndTime" label="技师到达时间">
				</el-table-column>
				<el-table-column prop="endTimes" label="订单完成时间" width="100">
				</el-table-column>
				<el-table-column prop="createTime" label="创建时间" width="160"></el-table-column>
				<el-table-column prop="warning" label="是否警告" fixed="right" width="80">
					<template slot-scope="scope">
						<span style="color: #f56c6c;" v-if="scope.row.warning==1">是</span>
						<span style="color: #999;" v-else>否</span>
					</template>
				</el-table-column>
				<el-table-column prop="overTimeOrders" label="是否超时" fixed="right" width="80">
					<template slot-scope="scope">
						<span style="color: #f56c6c;" v-if="scope.row.overTimeOrders==1">是</span>
						<span style="color: #999;" v-else>否</span>
					</template>
				</el-table-column>
				<el-table-column prop="status" label="订单状态" fixed="right">
					<template slot-scope="scope">
						<span style="color: #f56c6c;" v-if="scope.row.status==1">待支付</span>
						<span style="color: #E87D0D;" v-if="scope.row.status==2">待服务</span>
						<span style="color: #009900;" v-if="scope.row.status==3">待评价</span>
						<span style="color: #999;" v-if="scope.row.status==4">已取消</span>
						<span style="color: #999;" v-if="scope.row.status==5">已完成</span>
						<span style="color: red;" v-if="scope.row.status==6">服务中</span>
						<span style="color: #E87D0D;" v-if="scope.row.status==7">技师出发</span>
						<span style="color: #E87D0D;" v-if="scope.row.status==8">技师到达</span>
					</template>
				</el-table-column>
				<el-table-column prop="createAt" label="处理状态" width="120" fixed="right">
					<template slot-scope="scope">
						<el-button size="mini" type="danger" :disabled="!isAuth('orderCenter:wancheng')" v-if="scope.row.status==2||scope.row.status==6||scope.row.status==7||scope.row.status==8"
							@click="wancheng(scope.row)" style="margin:5px;" plain>完成订单</el-button>
						<!-- <span v-if="scope.row.type=='1'" style="color: #13ce66;">已处理</span>
						<span v-else style="color: #ff4949;">待处理</span>
						<el-button  v-if="scope.row.type!=='1'" size="mini" type="danger" style="margin: 5px;" :disabled="!isAuth('emergencyHelp:chuli')"
							@click="classdelete(scope.row)">处理
						</el-button> -->
					</template>
				</el-table-column>
			</el-table>
			<div style="text-align: center;margin-top: 10px;float:right">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page"
					layout="total,sizes, prev, pager, next,jumper" :total="tableData.totalCount">
				</el-pagination>
			</div>
			
		</el-tab-pane>
	</el-tabs>
</template>
<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				classify: 1,
				indentNumber: '',
				imageUrl: '',
				url: '',
				complaintState: '',
				activeName: 'first',
				tableDataLoading: true,
				dialogFormVisible: false,
				dialogFormVisible2: false,
				tableData: [],
				checkBoxData: [], //多选框选择的值
				
				content: '',
				status: '',
				helpTakeId: '',
				indentNumbers: '',
				complaintId: '',
				message: '',
				title: '',
				type: 3,
				form: {
					id: '',
					illegal: '',
					forfeitMoney: '',
				},
				formLabelWidth: '200px',
				dialogFormVisible1: false,
				guangaoData: {},
				illegal: '',
				illegalId: '',
				forfeitMoney: '',
				illegalList: [],
				phone:'',
				artificerName:'',
				userName:'',
				artificerPhone:'',
				overTimeOrders:0,
				warning:0,
				statesnumCs: [{
						value: 0,
						label: '全部'
					},
					{
						value: 1,
						label: '是'
					},
					{
						value: 2,
						label: '否'
					}
				],
				statesnum: [{
						value: '',
						label: '全部'
					},
					// {
					// 	value: 1,
					// 	label: '待支付'
					// },
					{
						value: 2,
						label: '待服务'
					},
					// {
					// 	value: 3,
					// 	label: '待评价'
					// },
					// {
					// 	value: 4,
					// 	label: '已取消'
					// },
					{
						value: 5,
						label: '已完成'
					},
					{
						value: 6,
						label: '服务中'
					},
					{
						label: '技师出发',
						value: 7
					},
					{
						label: '技师到达',
						value: 8
					},
				],
			}
		},
		methods: {
			// 多选
			changeFun(val) {
				this.checkBoxData = val
			},
			//处理默认选中当前日期
			// getNowTime () {
			// 	var now = new Date()
			// 	var year = now.getFullYear() //得到年份
			// 	var month = now.getMonth() //得到月份
			// 	var date = now.getDate() //得到日期
			// 	var hh = now.getHours() < 10 ? '0' + now.getHours() : now.getHours()
			// 	var mm = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes()
			// 	var ss = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds()
			// 	month = month + 1
			// 	month = month.toString().padStart(2, '0')
			// 	date = date.toString().padStart(2, '0')
			// 	var defaultDate = `${year}-${month}-${date} ${hh}:${mm}:${ss}`
			// 	return defaultDate
			// 	this.$set(this.info, 'stockDate', defaultDate)
			// },
			// tabs切换
			handleClick(tab, event) {
				if (tab._props.label == '订单列表') {
					this.page = 1
					this.limit = 10
					this.dataSelect()
				}
				
			},
			handleSizeChange(val) {
				this.limit = val
				this.dataSelect()
			},
			handleCurrentChange(val) {
				this.page = val
				this.dataSelect()
			},
			
			// 查询资源列表
			select() {
				this.page = 1
				this.limit = 10
				
				this.dataSelect()
			},
			// 重置资源列表
			cleans() {
				this.phone = ''
				this.artificerName = ''
				this.userName = ''
				this.artificerPhone = ''
				this.illegalId = ''
				this.overTimeOrders = 0
				this.warning = 0
				this.status = ''
				this.page = 1
				this.dataSelect()
			},
			// select选择事件
			animeDat(state) {
				this.page = 1
				this.complaintState = state
				console.log(state)
				this.dataSelect()
			},
			animeDat1(state) {
				this.page = 1
				this.illegalId = state
				this.dataSelect()
			},

			
			// 获取数据列表
			dataSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('artificer/selectArtificerOrdersList'),
					method: 'get',
					params: this.$http.adornParams({
						'page':this.page,
						'limit':this.limit,
						'artificerName':this.artificerName,
						'phone':this.phone,
						'artificerPhone':this.artificerPhone,
						'userName':this.userName,
						'overTimeOrders':this.overTimeOrders,
						'status':'',
						'warning':this.warning
						
					})
				}).then(({
					data
				}) => {
					if (data && data.code === 0) {
						this.tableDataLoading = false
						let returnData = data.data
						this.tableData = returnData
					}
				})
			},
			// 详情跳转
			updates(userId) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId: userId
					}
				})
			},
			// 处理
			classdelete(row) {
				this.$confirm(`确定处理该投诉?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl('message/auditMessage'),
						method: 'post',
						params: this.$http.adornParams({
							'ids': row.id,
							'status': 1,
							'auditContent': '',
						})
					}).then(({
						data
					}) => {
						if (data.code == 0) {
							this.$message({
								message: '操作成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.dataSelect()
								}
							})
						} else {
							this.$message({
								message: data.msg,
								type: 'warning',
								duration: 1500,
								onClose: () => {}
							})
						}
			
					})
				}).catch(() => {})
			},
			dataSelectD(){
				if(this.$route.query.types){
					if(this.$route.query.types==1){
						this.warning =1
						this.overTimeOrders =0
					}else{
						this.warning =0
						this.overTimeOrders =1
					}
				}else{
					this.warning = 0
					this.overTimeOrders = 0
				}
				this.dataSelect()
			},
			// 完成订单
			wancheng(row){
				let delid = row.ordersId
				this.$confirm(`确定进行完成订单操作吗?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl('artificer/accomplishOrders?ordersId='+delid),
						method: 'post',
						params: this.$http.adornParams({})
					}).then(({
						data
					}) => {
						if(data.code==0){
							this.$message({
								message: '操作成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.dataSelect()
								}
							})
						}else{
							this.$message({
								message: data.msg,
								type: 'warning',
								duration: 1500,
								onClose: () => {
								}
							})
						}
						
					})
				})
			},
		},
		mounted() {
			if(this.$route.query.types){
				if(this.$route.query.types==1){
					this.warning =1
					this.overTimeOrders =0
				}else{
					this.warning =0
					this.overTimeOrders =1
				}
			}else{
				this.warning = 0
				this.overTimeOrders = 0
			}
			this.dataSelect()
		},
		watch: {
			'$route': 'dataSelectD'
		}
	}
</script>

<style>
	.customWidth {
		width: 80% !important;
	}
</style>
