<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8"  style="margin-left: 0; margin-top: 10px">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="getList"
        v-hasPermi="['gateMr:gateMr:synchronous']"
      >同步</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" border>
      <el-table-column label="序号" align="center" type="index" width="60"></el-table-column>
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备型号" align="center" prop="deviceCode" />
      <el-table-column label="验票站点" align="center" prop="deviceAddress" />
      <el-table-column label="出口\入口" align="center" prop="isExit">
        <template slot-scope="scope">
          <span>{{ !scope.row.isExit&&scope.row.isExit!=0?'': scope.row.isExit==0?'入口': '出口'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="设备编码" align="center" prop="deviceNo" />
      <el-table-column label="在线状态" align="center" prop="onlineStatus">
        <template slot-scope="scope">
          <span>{{ !scope.row.onlineStatus&&scope.row.onlineStatus!=0?'': scope.row.onlineStatus==0?'离线': '在线'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加时间" align="center" prop="createTime" width="160" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="openOrCloseFun(scope.row,true)"
            v-hasPermi="['gateMr:gateMr:open']"
          >开闸</el-button>
          <el-button
            size="mini"
            type="text"
            @click="openOrCloseFun(scope.row,false)"
            v-hasPermi="['gateMr:gateMr:close']"
          >关闸</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>

import { pageList,openOrClose } from '@/api/device/gateMr'
export default {
  name: "gateMr",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: "",

      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 9999,
      },
      visibleStatus: false,
      newObj: {},
      visibleType: '',
      handleExportLoading: false,
      tableData: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      pageList(this.queryParams)
      .then(response => {
          this.dataList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    
    /**
     * 同步
     * @date 2022-10-24
     * @returns {any}
     */
    synchronousEven() {

    },
    /**
     *  开闸 或 关闸
     *  type=ture 开闸 
     */ 
    openOrCloseFun(row,type) {
      this.$confirm(`确定${type?'开闸':'关闸'}吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          let { code,data } = await openOrClose({id: row.id,status:type?1:2})
          this.$message.success("操作成功!");
        }).catch((error) => {
          console.error("error===",error)   
         // this.$message.error("操作失败!");      
        });
    }

  }
};
</script>
