<template>

	<view>
		<button class="mini-btn" type="default" size="mini" v-for="item in orderButtonData" :disabled="disabledButton"
			@click="callBtnMethods(item.eventName)" :key="item.id">
			{{ item.text }}
		</button>
		<!-- <button class="mini-btn" type="default" size="mini"  @click="debtn">删除</button> -->
		<!-- 弹框 -->
		<view>
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="inputClose" mode="input" :title="title" @confirm="dialogInputConfirm">
					<view style="width:100%;">
						<uni-data-checkbox v-model="assignType" :localdata="assignTypeVisit" style="margin-bottom: 20px;" v-show="auditPlaceholder === 'show'"/>
						<uni-data-select v-model="Maintenancer" :localdata="maintenancerDate" @change="maintenancerChange" v-show="auditPlaceholder === 'show' && assignType === 0"/>
						<uni-easyinput type="textarea" autoHeight maxlength="100" v-model="cbreason" :placeholder="auditPlaceholder" v-show="auditPlaceholder !== 'show'"/>
					</view>
				</uni-popup-dialog>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import pageData from "@/pages/myTask/repairList/addRepair/pageData.js"
	export default {
		props: {
			orderButtonData: {
				type: Array,
				default () {
					return []
				}
			},
			wid: {
				type: String,
				default: ''
			},
			orderType: {
				type: String,
				default: ''
			},
			departid: {
				type: String,
				default: ''
			},
			maintenancer: {
				type: String,
				default: ''
			},
			firstType: {
				type: Number,
				default: 0
			},
			fid:{
				type:String,
				default:''
			}
		},
		data() {
			return {
				disabledButton:false,
				assignType: 0,
				assignTypeVisit: [{
					text: '转同事',
					value: 0
				},{
					text: '转组长',
					value: 1
				}],
				title:'请输入内容',
				Maintenancer: '', //维修人
				maintenancerDate: [], // 人员信息
				workOrderButton: [], // 工单按钮权限
				cbreason: '', //审核原因
				auditPlaceholder: '请输入不通过审核原因'
			}
		},
		onLoad(option) {
		},
		methods: {
			callBtnMethods(methodName) {
				this[methodName]();
			},
			/**
			* 工单列表（按钮）
			*/
		   
			// 工单指派
			transferBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/repairDetail/tranferDetail/tranferDetail?wid=" + this.wid 
				})
			},
			// 工单撤回
			orderReuturnBtn() {
				this.title = '撤回'
				this.cbreason = ''
				this.auditPlaceholder = '请输入要撤回原因'
				this.$refs.inputDialog.open()
			},
			// 工单退回
			orderBackBtn() {
				this.title = '退回'
				this.cbreason = ''
				this.auditPlaceholder = '请输入要退回原因'
				this.$refs.inputDialog.open()
			},
			// 工单编辑
			editBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/addRepair/addRepair?wid=" + this.wid + '&editState='+1
				})
			},
			// 工单删除
			deleteBtn() {
				this.confirmationAPI("FaultRepair/DeleteWorkOrder", "删除", "是否要删除", "取消了删除")
			},
			debtn() {
				this.confirmationAPI("Scheduling/DeleteSchedulingWorkOrder", "删除", "是否要删除", "取消了删除")
			},
			/**
			* 我的提交(工单)（按钮）
			*/
		   
			// 自行解决
			selfSolveBtn() {
				this.title = '异常结束'
				this.cbreason = ''
				this.auditPlaceholder = '请输入异常结束原因'
				this.$refs.inputDialog.open()
			},
			// 评价
			evaluateBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/repairDetail/evaluateDetail/evaluateDetail?wid=" + this.wid 
				})
			},
			//返修
			backOrderBtn() {
				this.title = '返修'
				this.cbreason = ''
				this.auditPlaceholder = '请输入返修原因'
				this.$refs.inputDialog.open()
			},
			// 撤回
			returnBtn() {
				this.title = '撤回'
				this.cbreason = ''
				this.auditPlaceholder = '请输入撤回原因'
				this.$refs.inputDialog.open()
			},
			// 编辑撤回
			returnEditBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/repairDetail/returnEditDetail/returnEditDetail?wid=" + this.wid + '&editState='+1
				})
			},
			// 咨询工单接单
			receivingBtn() {
				this.confirmationAPI("Con_WorkOrder/SureWorkOrder", "信息", "是否要接单", "取消了接单")
			},
			// 咨询退回
			zxBackBtn() {
				this.confirmationAPI("Con_WorkOrder/BackWorkOrder", "信息", "是否要退回", "取消了退回")
			},
			//咨询处理 
			zxDealBtn() {
				uni.navigateTo({
					url: "/pages/myTask/consultList/consultDetail/appointmentDeal/appointmentDeal?wid=" + this.wid
				})
			},
			//咨询编辑
			zxEditBtn() {
				uni.navigateTo({
					url: "/pages/myTask/consultList/consultDetail/editDetail/editDetail?wid=" + this.wid
				})
			},
			// 确认耗材
			readyBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/repairDetail/consumablesDeail/consumablesDeail?wid=" + this.wid 
				})
			},
			/**
			* 报修列表（按钮）
			*/
		   
			// 1查收
			checkBtn() {
				this.confirmationAPI("FaultRepair/checkWorkOrder", "信息", "是否要查收", "取消了查收")
			},
			// 2退回
			sendBackBtn() {
				this.cbreason = ''
				this.auditPlaceholder = '请输入退回原因'
				this.$refs.inputDialog.open()
			},
			// 4 协作
			cooperationBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/repairDetail/cooperationDetail/cooperationDetail?wid=" + this.wid 
					+ '&orderType=' + this.orderType + '&departid='+this.departid + '&maintenancer=' + this.maintenancer,
				})
			},
			// 转派
			assignBtn() {
				pageData.getApplicant(this.departid, (res) => {
					res.forEach(v => {
						if(v.text == this.maintenancer ) {
							v.disable = true
						}
					})
					this.maintenancerDate = res
				})
				this.title = '转派工单'
				this.cbreason = '1'
				this.auditPlaceholder = 'show'
				this.$refs.inputDialog.open()
			},
			// 延期
			replayBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/repairDetail/replayDetail/replayDetail?wid=" + this.wid + '&orderType=' + this.orderType + '&firstType='+this.firstType 
				})
			},
			maintenancerChange(e) {
				this.Maintenancer = e
			},
			// 完成
			finishBtn() {
				uni.navigateTo({
					url: "/pages/myTask/repairList/repairDetail/finishDetail/finishDetail?wid=" + this.wid 
				})
			},
			// 挂起
			hangBtn() {
				this.confirmationAPI("FaultRepair/HangUp", "信息", "是否要挂起", "取消了挂起")
			},
			// 到达
			arriveBtn() {
				this.confirmationAPI("FaultRepair/Arrive", "信息", "是否要到达", "取消了到达")
			},
			
			/**
			* 综合调度（按钮）
			*/
		   // 撤回
		   dispatchReturnBtn() {
			   this.confirmationAPI("Scheduling/MyRetract", "信息", "是否要撤回", "取消了撤回")
		   },
		   // 接单
		   dispatchReceivingBtn() {
			   this.confirmationAPI("Scheduling/CheckWorkOrder", "信息", "是否要接单", "取消了接单")
		   },
		   // 送达
		   dispatchArriveBtn() {
			   uni.navigateTo({
			   	url: "/pages/myTask/comDispatch/comDispatchDetail/dealDetail/dealDetail?wid=" + this.wid + '&state='+ 1
			   })
		   },
		   // 退回
		   dispatchBackBtn() {
		   		this.confirmationAPI("Scheduling/BackWorkOrder", "信息", "是否要退回", "取消了退回")	   
		   },
		   // 评价
		   dispatchEvaluateBtn() {
			   uni.navigateTo({
			   	url: "/pages/myTask/repairList/repairDetail/evaluateDetail/evaluateDetail?wid=" + this.wid + '&state='+ 1
			   })
		   },
		   // 编辑
		   dispatchEditBtn() {
			  uni.navigateTo({
			  	url: "/pages/myTask/comDispatch/addComDispatch/addComDispatch?wid=" + this.wid 
			  }) 
		   },
			// 车辆调度 （ 按钮开始 ）
			// 编辑
			editVehBtn() {
				uni.navigateTo({
					url: "/pages/myTask/vehicleSchedulList/applicantsList/addVehicle/addVehicle?wid=" + this.wid + '&editState='+1
				})
			},
			// 撤回
			revocationBtn(){
				this.confirmationAPI("T_Car_WorkOrder/WithdrawWorkOrder", "信息", "是否撤回", "取消了撤回")
			},
			// 评价
			evaluateBtn(){
				uni.navigateTo({
					url: "/pages/myTask/vehicleSchedulList/components/vehiccleDetail/evaluateDetail/evaluateDetail?wid=" + this.wid 
				})
			},
			// 接单
			takeOrderVeh(){
				console.log(this.fid)
				this.confirmationAPI("T_Car_WorkOrder/SureWorkOrder", "信息", "是否接单", "取消了接单")
			},
			// 退回
			sendBackVeh(){
				this.confirmationAPI("T_Car_WorkOrder/BackWorkOrder", "信息", "是否退回", "取消了退回")
			},
			// 抵达发车点
			departBtn(){
				this.confirmationAPI("T_Car_WorkOrder/StartCar", "信息", "是否抵达发车点", "取消了")
			},
			// 抵达目的地
			destinationBtn(){
				this.confirmationAPI("T_Car_WorkOrder/EndCar", "信息", "是否抵达目的地", "取消了")
			},
			// 催办调度中心
			urgeMyBtn() {
				this.cbreason = ''
				this.auditPlaceholder = '请输入催办原因'
				this.$refs.inputDialog.open()
			},
			// 催办申请人
			urgeOLBtn() {
				this.cbreason = ''
				this.auditPlaceholder = '请输入要催办原因'
				this.$refs.inputDialog.open()
			},
			// 车辆调度 （ 按钮结束 ）
			// 审核通过确认框
			dialogInputConfirm() {
				uni.showLoading({
					title: '加载中'
				})
				// 关闭窗口后，恢复默认内容
				if (!this.cbreason) {
					this.$mHelper.toast(this.auditPlaceholder)
					return
				}
				if (this.auditPlaceholder === '请输入退回原因') {
					const addParams = {BackReason: this.cbreason,WorkOrderCode: this.wid}
					this.workOrderContent("FaultRepair/BackWorkOrder",addParams)
				}else if(this.auditPlaceholder === 'show') {
					if(!this.Maintenancer) {
						this.$mHelper.toast('请选择指派人');
						return
					}
					const addParams = {ToUserCode: this.Maintenancer,WorkOrderCode: this.wid,type: this.assignType}
					this.workOrderContent("FaultRepair/Transfer",addParams)
				}else if(this.auditPlaceholder === '请输入异常结束原因') {
					const addParams = {result: this.cbreason,WorkOrderCode: this.wid,type:1}
					this.workOrderContent("FaultRepair/DealWorkOrder ",addParams)
				}else if(this.auditPlaceholder === '请输入返工原因') {
					const addParams = {ReturnReason: this.cbreason,WorkOrderCode: this.wid}
					this.workOrderContent("FaultRepair/ReturnWorkOrder ",addParams)
				}else if(this.auditPlaceholder === '请输入要退回原因') {
					// 调度中心
					const addParams = {BackReason: this.cbreason,WorkOrderCode: this.wid}
					this.workOrderContent("FaultRepair/ReBack",addParams)
				}else if(this.auditPlaceholder === '请输入要撤回原因') {
					// 调度中心
					const addParams = {BackReason: this.cbreason,workordercode: this.wid}
					this.workOrderContent("FaultRepair/Retract",addParams)
				}
				else if(this.auditPlaceholder === '请输入撤回原因') {
					// 申请人
					const addParams = {BackReason: this.cbreason,workordercode: this.wid}
					this.workOrderContent("FaultRepair/MyRetract",addParams)
				}
				else if(this.auditPlaceholder === '请输入催办原因') {
					// 调度中心
					const addParams = {reason: this.cbreason,workordercode: this.wid,urgetype:2}
					this.workOrderContent("WorkCommon/UrgeWorkOrder",addParams)
				}
				else if(this.auditPlaceholder === '请输入要催办原因') {
					// 申请人
					const addParams = {reason: this.cbreason,workordercode: this.wid,urgetype:1}
					this.workOrderContent("WorkCommon/UrgeWorkOrder",addParams)
				}
				this.$refs.inputDialog.close()
			},
			// 确认框方法，带输入框
			workOrderContent(url,addParams) {
				this.disabledButton = true
				this.$mHelper.httpPost(url,addParams,1 ,res=>this.disabledButton=res)
				uni.hideLoading()
			},
			//确认框方法
			confirmationAPI(url, title, content, canceContent) {
				this.disabledButton = true
				uni.showModal({
					title: title,
					content: content,
					success: (res) => {
						if (res.confirm) {
							const params = {}
							if(content == '是否要查收' || content == '是否要接单' || content == '是否要退回') {
								params.WorkOrderCode = this.wid
							}else if (content === '是否撤回' ||  content === '是否接单' || content === '是否退回' ){
								params.orderid = this.fid
							}else if(content === '是否抵达发车点' || content === '是否抵达目的地'){
								params.orderid = this.fid
								params.WorkOrderCode = this.wid
							} else{
								params.workordercode = this.wid
							}
							this.$mHelper.httpPost(url,params,1,res=>this.disabledButton=res)
						} else if (res.cancel) {
							this.disabledButton = false
							this.$mHelper.toast(canceContent);
						}
					}
				})
			},
			
		}
	}
</script>

<style lang="scss">
	.mini-btn {
		margin-right: 3px;
		color: #fff;
		background: #1e90ff;
	}
</style>
