<template>
  <div class="p-2">
    <div class="searvh">
      <el-input v-model="search.cardNo" clearable size="small" class="w-4 mb-2" placeholder="请输入卡号"></el-input>
      <el-input v-model="search.authName" clearable size="small" class="w-4 mb-2" placeholder="请输入权限名称"></el-input>
      <el-date-picker v-model="search.startTime" clearable size="small" class="w-4 mb-2" type="datetime"
        placeholder="选择开始日期时间">
      </el-date-picker>
      <el-date-picker v-model="search.endTime" clearable size="small" class="w-4 mb-2" type="datetime"
        placeholder="选择结束日期时间">
      </el-date-picker>
    </div>
    <div>
      <el-table :data="tableData" stripe style="width: 100%" height="600">
        <el-table-column type="index" width="80" label="序号">
        </el-table-column>
        <el-table-column prop="deviceNum" label="设备号">
        </el-table-column>
        <el-table-column prop="roomName" label="房间名称">
        </el-table-column>
        <el-table-column prop="name" label="用户名称">
        </el-table-column>
        <el-table-column prop="startTimeText" label="开始时间">
        </el-table-column>
        <el-table-column prop="endTimeText" label="结束时间">
        </el-table-column>
        <el-table-column prop="createAt" label="创建时间">
        </el-table-column>
        <el-table-column  label="操作">
          <template #default="scope">
            <el-link type="primary" @click="deleteBlueToothMethods(scope.$index,scope.row)">删除</el-link>
            <el-link type="danger" @click="deleteBlueToothCompelsMethods(scope.$index,scope.row)">删除记录</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  import {
    httpPost,httpGet
  } from "../api";
  import moment from 'moment'
  import utils from "../utils/util.js"
  export default {
    inject: ['reload'],
    name: "offInCardList",
    data() {
      return {
        search: {
          cardNo: "",
          authName: "",
          endTime: "",
          startTime: ""
        },
        tableData:[]
      }
    },
    created() {
      this.getBluetoothBuck()
    },
    methods: {
      deleteBlueToothCompelsMethods(index,row){
        this.$confirm("确定要删除平台记录吗？", "提示", {
          type: "warning",
        }).then(() => {
          var data = {
            ids: [row.id],
          };
          httpPost(data, this.$api.deleteCertificates).then((
            res) => {
            if (res.success) {
              this.$message.success("删除成功！");
              this.getBluetoothBuck()
            }
          });
        })
      },
      deleteBlueToothMethods(index,row){
        this.$confirm("确定要删除蓝牙扣人员吗？", "提示", {
          type: "warning",
        }).then(() => {
          var resultArr=JSON.parse(row.content)
          var data = {
            lockerId: resultArr.deviceNum,
            imei: resultArr.imei,
            lockerUserId: resultArr.iotId,
            keyId: resultArr.iotId,
            role: 0,
            action: 2, //1--添加、2--删除、3--修改
            order: 6203,
            cardName: resultArr.username,
            roomName: resultArr.roomName,
            pass:true
          }
          httpPost(data, this.$api.ZGduserOperation).then(res => {
            if (res.success) {
              this.$message.success('删除用户成功')
              var dataOne = {
                ids: [row.id],
              };
              httpPost(dataOne, this.$api.deleteCertificates).then((
                res) => {
                if (res.success) {
                  this.$message.success("删除成功！");
                  this.getBluetoothBuck()
                }
              });
              this.getBluetoothBuck()
            } else {
              this.$message.error(res.msg)
            }
          })
        })
      },
      getBluetoothBuck(){
        var dataall={
          pageNum: 0,
          pageSize: 0,
          orderBy: "create_at desc",
          q: {
            inStatus: "0,1,702",
            types: "36"
          },
        }
        httpGet(dataall, this.$api.getCertificates).then((resall) => {
            let dataOne=utils.zlib_unzip(resall.data)
          if(resall.code==200){
            dataOne.map(li=>{
              var content=JSON.parse(li.content)
              li.endTimeText=moment(li.endTime*1000).format("YYYY-MM-DD HH:mm:ss")
              li.startTimeText=moment(li.startTime*1000).format("YYYY-MM-DD HH:mm:ss")
              li.name=content.username
              li.roomName=content.roomName
              li.deviceNum=content.deviceNum
              li.createAt=moment(li.createAt).format("YYYY-MM-DD HH:mm:ss")
            })
            this.tableData=dataOne
          }
        });
      },

    }
  }
</script>

<style>
</style>
