<template>
  <d2-container>
	<div class="d2-table-view-full">
	  <div class="d2-table-view-header">
		<el-form label-width="70px" labelPosition="center" size="small" :inline="true" :model="filter" @keyup.enter.native="handleList" class="demo-form-inline">
		  <el-form-item label="设备号">
			<el-input style="width: 192px" v-model="filter.eqpNo" placeholder="设备号" clearable/>
		  </el-form-item>
		  <el-form-item label="起止时间">
			<el-date-picker
					v-model="time"
					type="datetimerange"
					value-format="yyyy-MM-dd HH:mm:ss"
					:default-time="['00:00:00', '23:59:59']"
					@change="dateChange"
					range-separator="至"
					start-placeholder="开始时间"
					end-placeholder="结束时间">
			</el-date-picker>
		  </el-form-item>
		  <el-form-item label="设备类型">
			 <custom-select :value="filter.eqpTyp" :isAll="true" v-model="filter.eqpTyp" typeName="设备类型" clearable/>
		  </el-form-item>
		 <el-form-item label="报文方向">
			<el-select v-model="filter.msgTo" placeholder="请选择" clearable>
				<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
				</el-option>
			</el-select>
		  </el-form-item>
		  <el-form-item label="报文类型">
					<custom-select :value="filter.msgTyp" :isAll="true" v-model="filter.msgTyp" typeName="报文类型" clearable/>
		  </el-form-item>
		  <el-form-item>
			<el-button   type="primary" @click="handleList('1')">查询</el-button>
		  </el-form-item>
		</el-form>
	  </div>
	  <div class="d2-table-view-content">
		<d2-crud
				title="设备报文列表"
				ref="d2Crud"
				:loading="loading"
				:columns="columns"
				:data="data"
				:options="tableOptions"/>
	  </div>
	  <div class="d2-table-view-footer">
		<el-pagination
						@current-change="handleCurrentChange"
						@size-change="handleSizeChange"
						:current-page.sync="currentPage"
						:page-size="tableOptions.pageList[0]"
						:page-sizes="tableOptions.pageList"
						layout="total,sizes, prev, pager, next,jumper"
						:total="pagination.total">
		</el-pagination>
	  </div>
	</div>
  </d2-container>
</template>

<script>
  import {getMessageList} from '../../../api/equ/register'
  import { tableOptions } from '../../../assets/options'
  import detailReq from './components/detailRequest'
  export default {
    name: 'equipment-request',
		components:{
			detailReq
		},
    data () {
      return {
					func:{
					select:false
				},
				list:[],
        time: '',
        loading: false,
        tableOptions,
        currentPage:1,
				options:[{ value: 'eqp',label: '服务器 → 终端机'},{ value: 'srv',label: '终端机 → 服务器'}],
				// options_1:[{ value: '0',label: '通行'},{ value: '1',label: '消费'},{ value: '2',label: '考勤'}],
        filter: {
          eqpNo:'',
					startTime:'',	
					endTime:'',	
					eqpTyp:null,	
					msgTo:'',
					msgTyp:'',
          pageSize: 10,
          pageNum: 1
        },
        pagination: {
          total: 0
        },
        columns: [
          {
            title: '序号',
            key: 'index',
            minWidth: '40',
            formatter (row, column, cellValue, index) {
              return index+1
            }
          },
		       {
            title: '设备号',
            key: 'eqpNo',
            minWidth: '60',
						showOverflowTooltip: true
		       },
          {
            title: '设备类型',
            key: 'eqpTyp',
            minWidth: '70',
					formatter (row, column, cellValue, index) {
							if(cellValue === '1'){
								return '补贴机'
							}else if(cellValue === '2'){
								return '考勤机'
							}else if(cellValue === '3'){
								return '考勤门禁机'
							}else if(cellValue === '4'){
								return '门禁机'
							}else if(cellValue === '5'){
								return '人脸机'
							}else if(cellValue === '6'){
								return '发卡机'
							}else if(cellValue === '0'){
								return '消费机'
							}     
						}
          },
          {
            title: '报文编码',
            key: 'msgCode',
            minWidth: '90',
						showOverflowTooltip: true
          },
          {
            title: '报文类型',
            key: 'paramName',
            minWidth: '90',
						showOverflowTooltip: true,
						// formatter (row, column, cellValue, index) {
						// 	if(cellValue === '0'){
						// 		return '通行'
						// 	}else if(cellValue === '1'){
						// 		return '消费'
						// 	}else if(cellValue === '2'){
						// 		return '考勤'
						// 	}
						// }
          },
          {
            title: '报文日期',
            key: 'msgTm',
            minWidth: '90',
						showOverflowTooltip: true
          },
          {
            title: '报文方向',
            key: 'msgTo',
            minWidth: '90',
						showOverflowTooltip: true,
            formatter (row, column, cellValue, index) {
							if(cellValue === 'eqp' ){
								return '服务器 → 终端机'
							}else if(cellValue === 'srv'){
								return '终端机 → 服务器'
							}
            }
          },
          {
            title: '报文明细',
            key: 'msgDat',
            minWidth: '150',
						component: { 
							name: detailReq,
						}
          },
        ],
        data: []
      }
    },
    methods: {
      handleList (val) {
        if(val){this.filter.pageNum=1
        this.currentPage = 1}
        this.loading = true
        getMessageList(this.filter).then(res => {
          this.loading = false
          this.data = res.page.list
          this.pagination.total = res.page.total
        }).catch(err => {
          this.loading = false
        })
      },

      handleCurrentChange (val) {
        this.filter.pageNum = val
        this.handleList()
      },
			handleSizeChange (val) {
			this.filter.pageNum = 1
			this.filter.pageSize = val
			this.handleList()
			},
      dateChange (val) {
        if(val == null){
        	this.filter.startTime = ''
        	this.filter.endTime = ''
        }else{
        	this.filter.startTime = val[0]
        	this.filter.endTime = val[1]
        }
      },
			getMtInfoList () {
				/* selectEqTypeList().then(res => {
					this.list = res.data
				}).catch(err => {
				}) */
			},
		/* 	getFunction () {
			  this.$GetFunction({
			    menuUrl:this.$route.path
			  }).then(res=>{
			    res.data.forEach(item=>{
			      if (item.functionType === 'select') {
			        if (item.remarks === 'true') {
			          this.func.select = true
			        } else {
			          this.func.select = false
			        }
			      }    
			    })
			  })
			} */
    },
    mounted () {
			//this.getFunction ()
      this.time = this.$setInitTime()
      this.filter.startTime = this.time[0].format('yyyy-MM-dd hh:mm:ss')
      this.filter.endTime = this.time[1].format('yyyy-MM-dd hh:mm:ss')
	  this.filter.pageSize = this.tableOptions.pageList[0]
	  this.tableOptions = this.$calcTableHeight(tableOptions,80)
      this.handleList()
	  //this.getMtInfoList ()
    }
  }
</script>
