<template>
  <div class="app-container space">

	<el-card class="box-card">		
        <div slot="header" class="clearfix">查询业务节点状态</div>
		<el-form ref="form2" :model="form2" label-width="80px">
			<el-row :gutter="12" >
				<el-form-item label="超时天数:" prop="timeSpan">
                	<el-input-number v-model="form2.timeSpan" :min="0" :max="30"></el-input-number>
				</el-form-item>
			</el-row>
			<el-form-item>
    			<el-button type="primary" @click="getBizStatusList" >发送</el-button>    		
  			</el-form-item>
			<!--
			<el-row :gutter="20">
				<el-col :span="4">
				    <div>
						<el-form-item label="进行中:">
							456/2
						</el-form-item>		
					</div>	
				</el-col>
				<el-col :span="4">
					<div>
                        <el-form-item label="暂停中:">
							456/2
						</el-form-item>	
					</div>
				</el-col>
				<el-col :span="6">
					<div>
                        <el-form-item label="线边库中:">
							456/2
						</el-form-item>	
					</div>
				</el-col>
			</el-row>		
		-->
			<el-row :gutter="10" v-for="(item, index) in bizStatuList" :key="item.id">
				<el-col :span="4">
					<el-form-item label="ID:">
					 {{bizStatuList[index].id}}
					</el-form-item>	
				</el-col>
				<el-col :span="6">
					<el-form-item label="名称:">
						{{bizStatuList[index].nodeName}}
					</el-form-item>
			    </el-col>
				<el-col :span="6">
					<el-form-item label="批次号:">
						{{bizStatuList[index].completeBatchNo}}
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="状态:">
						{{bizStatuList[index].exeStatus=="2"?"进行中":(bizStatuList[index].exeStatus=="4"? "暂存中":"线边库暂存中")}}
					</el-form-item>
				</el-col>				
			</el-row>	
		</el-form>
	</el-card>
	

	<el-card class="box-card">
        <div slot="header" class="clearfix">查询点库位锁定状态</div>
		<el-form label-width="80px">
		<el-row :gutter="10" v-for="storgeLock in storgeLockList" :key="storgeLock.id">
			    <el-col :span="6">
					<el-form-item label="名称:">
					 {{storgeLock.name}}
					</el-form-item>	
				</el-col>
				<el-col :span="3">
					<el-form-item label="启用状态:">
						{{storgeLock.status=="0"?"不可用":"可用"}}
					</el-form-item>
			    </el-col>
				<el-col :span="3">
					<el-form-item label="锁定状态:">
						{{storgeLock.lockStatus=="0"?"已锁定":"未锁定"}}
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="锁定节点:">
						{{storgeLock.campId}}
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="锁定批次:">
						{{storgeLock.completeBatchNo}}
					</el-form-item>
				</el-col>				
		   </el-row>
		</el-form>
	</el-card>

	<el-card class="box-card">
        <div slot="header" class="clearfix">查询不在线设备</div>
		<el-form label-width="80px">
		<el-row :gutter="10" v-for="offline in offlineList" :key="offline.id">
			    <el-col :span="6">
					<el-form-item label="名称:">
					 {{offline.name}}
					</el-form-item>	
				</el-col>
				<el-col :span="6">
					<el-form-item label="在线状态:">
						{{offline.onlineStatus=='0'?"下线":"上线"}}
					</el-form-item>
			    </el-col>
				<el-col :span="6">
					<el-form-item label="掉线状态:">
						{{offline.status=='0'?"掉线":"上线"}}
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="IP:">
						{{offline.ip}}
					</el-form-item>
				</el-col>								
		   </el-row>
		</el-form>
	</el-card>
	

	<el-card class="box-card">
        <div slot="header" class="clearfix">查询零件流程</div>
		<el-form ref="form3" :model="form3" label-width="120px">		
		<el-row :gutter="12" >
			<el-col :span="8">
				<el-form-item label="零件批次号:" prop="completeBatchNo">
                	<el-input v-model="form3.completeBatchNo" placeholder="零件批次号"></el-input>
				</el-form-item>
			</el-col>	
			<el-col :span="8">
				<el-form-item>
    				<el-button type="primary" @click="getWorkflowList" >发送</el-button>    		
  				</el-form-item>	
			</el-col> 
		</el-row>			 
		
		<el-row :gutter="10"  v-if="workflowList.task">	
			<el-col :span="4">
				<el-form-item label="零件名称" label-width="100px">
					 {{workflowList.task? workflowList.task.bomDesc:'任务已结束'}}
				</el-form-item>	
		   </el-col>			
		   <el-col :span="5">
				<el-form-item label="任务名称" label-width="100px">
					 {{workflowList.task? workflowList.task.procedureName:'任务已结束'}}
				</el-form-item>	
		 </el-col>
		 <el-col :span="5">
			  <el-form-item label="任务开始" label-width="100px">
					 {{workflowList.task? workflowList.task.startTime:'任务已结束'}}
			  </el-form-item>	
		  </el-col>
		  <el-col :span="7">
			  <el-form-item label="节点名称" label-width="100px">
					 {{workflowList.taskNode? workflowList.taskNode.nodeName:'节点已结束'}}
			  </el-form-item>	
		  </el-col>
		  <el-col :span="5">
			  <el-form-item label="节点开始" label-width="100px">
					 {{workflowList.taskNode? workflowList.taskNode.startTime:'节点已结束'}}
			  </el-form-item>	
		  </el-col>		
		  <el-col :span="6">
			  <el-form-item>
    				<el-button type="primary" @click="getWorkflowDetail" >查看详情</el-button>    		
  			  </el-form-item>	
		  </el-col>	
		</el-row>

      </el-form>		
	</el-card>	

	<el-card class="box-card">
        <div slot="header" class="clearfix">查询缓存关键字</div>		
		<el-form label-width="100px">
		<el-row :gutter="10">
			    <el-col :span="6">
					<el-form-item label="是否排产">
					 {{cacheKeyList.YUNJIAN_SHEDULE_FLAG==1? "排产进行中":"无排产"}}
					</el-form-item>	
				</el-col>
				<el-col :span="6">
					<el-form-item label="线边库调度">
					 {{cacheKeyList.YUNJIAN_XBK_SHEDULE==1? "自动调度中":"无调度"}}
					</el-form-item>	
				</el-col>
				<el-col :span="9">
					<el-form-item label="是否优先级" label-width="100px">
						{{cacheKeyList.PRIORITY_LOCK==1? "禁用":"启用"}}
					</el-form-item>
			    </el-col>												
		   </el-row>
		</el-form>	  
	</el-card>

	<tenant-view
      ref="view"
      :dialog-visible="tenantViewVisible"
      @close="viewClose"
    />
	
  </div>
</template>

<script>	
	// 【锁定记录、出入库记录】-API
	import toolQueryApi from "@/api/systemMgr/toolQuery"
	import elDragDialog from '@/directive/el-drag-dialog'
	// 【查看】组件
	import TenantView from "./components/View"	
	import { convertEnum, initDicts, initQueryParams } from '@/utils/commons'
	export default {
	  name: "ToolQuery",
	  directives: {elDragDialog},
	  components: {TenantView},
	  props: {
	  },
	  data () {
	    return {
		  form:{			
			zoneCode: "KT"
		  },
		  form2:{
            timeSpan: "2",
		  },
		  form3:{
            completeBatchNo: "",
		  },		  
		  workflowList:[],
		  zoneRateList:[],
		  orderTaskList: [],	     		  
		  bizStatuList: [],
		  agvLockList: [],
		  cacheCallbackList: [],
		  xbkDyTaskList:[],
		  zcwDyTaskList:[],
		  storgeLockList: [],
		  cacheKeyList: [],
		  offlineList:[],
		  lineList: [{"name":"框体","value":"KT"},{"name":"舱体","value":"CT"},{"name":"保障中心","value":"BZ"},{"name":"翼片","value":"YP"},{"name":"中舱","value":"ZC"}],
		  typeList: [{"name":"全部","value":"0"},{"name":"FANUC","value":"1"},{"name":"HEIDENHAIN","value":"2"},{"name":"DMG","value":"3"},{"name":"HELLER","value":"4"}],
	      tenantViewVisible: false,
	      tableKey: 0,
	      queryParams: initQueryParams({}),
	      selection: [],
	      loading: false
		}  	      
	  },
	  // 实例已经在内存中创建好，此时data和methods已将ok,如果要操作data中的数据或是调用methods中的方法，最早只能在created中操作
	  created() {
	  	// 调用常量-审核状态
	  	this.audioStatus = this.$constWKS.OPTTYPE
	  	// 加载【字典】
	  	initDicts(['NATION'], this.dicts);
	  	// 加载列表数据
	  	this.fetch()
		},
	  computed: {
	    currentUser () {
	      return this.$store.state.account.user
	    },
	    nationList() {
          return convertEnum(this.dicts.NATION)
        }
	  },
	  mounted () {
	   
	  },
	  methods: {  
		getWorkflowList(){
		  let completeBatchNo = this.form3.completeBatchNo? {"completeBatchNo" : this.form3.completeBatchNo.toString()}: null;
		  if(completeBatchNo==null){
			this.$message({
              	message: '输入数据不能为空',
              	type: 'warning'
            });
			return false	
		  }		
          toolQueryApi.getWorkflowList(completeBatchNo).then(response=>{
						const res = response.data
						if(res.isSuccess){
							this.workflowList = res.data
							console.log(this.workflowList)
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})
		},
		getWorkflowDetail(){
			this.$refs.view.setTenant({"completeBatchNo":this.form3.completeBatchNo.toString()})
        	this.tenantViewVisible = true	
		},
		viewClose() {
        	this.tenantViewVisible = false
        },		
	    getBizStatusList () {
			let query = this.form2.timeSpan ? {"timeSpan" : this.form2.timeSpan.toString()} : {}		
			toolQueryApi.getBizStatusList(query).then(response=>{
						const res = response.data
						if(res.isSuccess){
							this.bizStatuList = res.data.data
							//console.log(this.bizStatuList)
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})
	    },	   
	    getCacheCallbackList () {
			toolQueryApi.getCacheCallbackList({}).then(response=>{
						const res = response.data
						if(res.isSuccess){
							this.cacheCallbackList = res.data.data
							//console.log(this.cacheCallbackList)
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})
	    },
	    getStorgeLockList () {
	        toolQueryApi.getStorgeLockList({}).then(response=>{
						const res = response.data
						if(res.isSuccess){
							this.storgeLockList = res.data.data
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})
	    },
	    getCacheKeyList () {
			toolQueryApi.getCacheKeyList({}).then(response=>{
						const res = response.data
						if(res.isSuccess){
							this.cacheKeyList = res.data
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})	     
	    },
		getOfflineList () {
			toolQueryApi.getOfflineList({}).then(response=>{
						const res = response.data
						if(res.isSuccess){
							this.offlineList = res.data.data
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})	     
	    },		
		getOrderTaskList(){
			toolQueryApi.getOrderTaskList({}).then(response=>{
						const res = response.data
						console.log(res)
						if(res.isSuccess){
							this.orderTaskList = res.data.data.records
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})
		},
		getXbkDyTaskList(){
            toolQueryApi.getXbkDyTaskList({}).then(response=>{
						const res = response.data						
						if(res.isSuccess){
							this.xbkDyTaskList = res.data.data
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})
		},
		getZcwDyTaskList(){
            toolQueryApi.getZcwDyTaskList({}).then(response=>{
						const res = response.data						
						if(res.isSuccess){
							this.zcwDyTaskList = res.data.data
						}else{
							this.$message({
              					message: res.msg,
              					type: 'warning'
            				})
						}
				}).finally(()=>{
					return true		
			})
		},
	    fetch () {			
	      	this.getBizStatusList()
			this.getStorgeLockList()
			this.getCacheKeyList()
			this.getOfflineList()				
	    }
	  }
	}
</script>
<style lang="scss" scoped>
   .space  .box-card  {
     margin: 10px 0;
   }
</style>
