<template>
  <div>
    <el-card class="cardbg">
      <div class="steps">
        <div class="step" :class="stepindex > index ? 'stepcolor' : ''" v-for="(item, index) in steplist" :key="index"
          @click="selectstep(index)">
          <img src="../assets/img/gou.png" class="l1" alt="" v-if="stepindex > index" />
          <img src="../assets/img/1.png" class="l1" alt="" v-else-if="index == 0" />
          <img src="../assets/img/2.png" class="l1" alt="" v-else-if="index == 1" />
          <img src="../assets/img/3.png" class="l1" alt="" v-else-if="index == 2" />
          <span>{{ item.title }}</span>
          <img src="../assets/img/rightwhite.png" class="r2" alt="" v-if="index != steplist.length - 1" />
        </div>
        <div class="selectoptionClass" v-if="userInfo.type==0">
          <selectoption></selectoption>
        </div>
      </div>
      <el-carousel trigger="click" height="700px" :autoplay="false" indicator-position="none" arrow="never"
        ref="cardShow" :initial-index="0">
        <el-carousel-item>
          <el-row :gutter="20" style="box-sizing: border-box; margin: 0 0 0 10px">
            <el-col :span="6">
              <el-card shadow="nerver" class="h700 cardbg">
                <el-tree :data="roomlist" node-key="id" ref="tree" @node-click="onClick" :props="defaultProps">
                </el-tree>
              </el-card>
            </el-col>
            <el-col :span="18">
              <div class="container">
                <div class="handle-box">
                  <el-tabs v-model="activeName" @tab-click="handleClick">
                    <el-tab-pane label="所属房间" name="first"></el-tab-pane>
                  </el-tabs>
                  <div class="nextstep" @click="stepnext">下一步</div>
                </div>
                <div class="room-list" v-if="activeName == 'first'">
                  <div class="room-li" v-for="(item, index) in tableData" :key="index"
                    @click="item.check?checkfun(index, false):checkfun(index, true)">
                    <checkInRoom :data="item" :index="index"></checkInRoom>
                    <img src="../assets/img/check1.png" class="check-img" alt="" v-if="item.check" />
                    <img src="../assets/img/check.png" class="check-img" alt="" v-else />
                  </div>
                  <div class="totalPosition">
                    <el-pagination layout="total" :total="tableData.length"></el-pagination>
                  </div>
                </div>
                <div class="room-list" v-if="activeName == 'second'">
                  <div class="room-li" v-for="(item, index) in tableData1" :key="index"
                    @click="item.check?checkfun1(index, false):checkfun1(index, true)">
                    <checkInRoom :data="item" :index="index"></checkInRoom>
                    <img src="../assets/img/check1.png" class="check-img" alt="" v-if="item.check" />
                    <img src="../assets/img/check.png" class="check-img" alt="" v-else />
                  </div>
                </div>
                <div class="room-list" v-if="activeName == 'third'">
                  <div class="room-li" v-for="(item, index) in tableData2" :key="index"
                    @click="item.check?checkfun2(index, false):checkfun2(index, true)">
                    <checkInRoom :data="item" :index="index"></checkInRoom>
                    <img src="../assets/img/check1.png" class="check-img" alt="" v-if="item.check" />
                    <img src="../assets/img/check.png" class="check-img" alt="" v-else />
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-carousel-item>
        <el-carousel-item>
          <el-card shadow="nerver">
            <div class="pagehead">
              <div class="fjry">房间添加人员信息 <span style="font-size: 12px;margin-left: 20px;"><i
                    class="el-icon-location-information"></i>{{ addressName }}</span></div>
              <div class="fjrynext">
                <div class="nextstep" @click="stepnext">下一步</div>
              </div>
            </div>
            <div class="secondcontent">
              <el-form ref="form" :model="personInfo" :inline="true" :rules="rules" label-width="80px">
                <el-form-item label="姓名" prop="name">
                  <el-autocomplete v-model="personInfo.name" class="widthThree" :maxlength="8" size="small"
                    :fetch-suggestions="querySearchAsync" placeholder="请输入内容" @select="handleSelect" clearable>
                    <template slot-scope="{ item }">
                      <div class="name">{{ item.name }}->{{item.number}}</div>
                    </template>
                  </el-autocomplete>
                </el-form-item>
                <el-form-item label="系统编号" prop="phone">
                  <el-input v-model="personInfo.phone" size="small" placeholder="为11位唯一识别,如:20220810104"
                    :clearable="true" class="widthThree" type="number" :maxlength="11" @change="phoneChange">
                  </el-input>
                </el-form-item>
                <el-form-item label="校园卡号" prop="number">
                  <el-input v-model="personInfo.number" size="small" :clearable="true" class="widthThree"
                    :maxlength="18"></el-input>
                </el-form-item>
                <el-form-item label="物理卡号" prop="cardId">
                  <el-input v-model="personInfo.card" size="small" :clearable="true" class="widthThree"
                    :maxlength="18"></el-input>
                </el-form-item>
                <el-form-item label="身份" prop="type">
                  <el-select v-model="personInfo.type" size="small" class="widthThree" placeholder="请选择身份" clearable>
                    <el-option :label="item.label" :value="item.value" v-for="(item,index) in userType" :key="index">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="所属部门" prop="enterpriseId">
                  <el-cascader :options="enterpriseListOption" v-model="personInfo.enterpriseId" ref="cascader" class="widthThree" :props="props"
                    collapse-tags clearable @change="checkEnterpriseList"></el-cascader>
                </el-form-item>
                <el-form-item label="入住时间">
                  <el-date-picker v-model="value2[0]" size="small" type="datetime" placeholder="选择入住日期时间"
                    default-time="12:00:00">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="退租时间">
                  <el-date-picker v-model="value2[1]" size="small" type="datetime" placeholder="选择退租日期时间"
                    default-time="12:00:00">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                  <el-select v-model="personInfo.sex" size="small" class="widthThree" placeholder="请选择性别" clearable>
                    <el-option label="男" :value="1" selected></el-option>
                    <el-option label="女" :value="2"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="备注" prop="remarks">
                  <el-input v-model="personInfo.remarks" size="small" :clearable="true" class="widthThree"
                    :maxlength="100"></el-input>
                </el-form-item>
                <el-button type="primary" @click="handleEditperson" size="small">添加</el-button>
              </el-form>
            </div>
          </el-card>
          <div class="bottomcontent">
            <el-card shadow="nerver">
              <div class="pagehead">
                <div class="fjry">已入住人员信息</div>
              </div>
              <div class="bottomtable">
                <el-table :data="uselist" stripe class="table" height="300" ref="multipleTable"
                  header-cell-class-name="table-header" highlight-current-row @current-change="handleCurrentChange1">
                  <el-table-column prop="name" label="姓名"></el-table-column>
                  <el-table-column prop="phone" label="手机号" :maxlength="11" type="number"></el-table-column>
                  <el-table-column prop="number" label="校园卡号"></el-table-column>
                  <el-table-column prop="cardId" label="物理卡号"></el-table-column>
                  <el-table-column label="性别">
                    <template slot-scope="scope">
                      <span v-if="scope.row.sex == 1">男</span>
                      <span v-if="scope.row.sex == 2">女</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="租期" width="400">
                    <template slot-scope="scope">
                      <span>{{scope.row.startTimeText}}</span>-
                      <span>{{scope.row.endTimeText}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column fixed="right" label="操作" width="100">
                    <template slot-scope="scope">
                      <el-button @click="deletefun(scope.row)" type="danger" size="mini">移除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-card>
          </div>
        </el-carousel-item>
        <el-carousel-item>
          <el-row :gutter="20">
            <el-col :span="18">
              <el-card shadow="nerver" height="400">
                <div class="pagehead">
                  <div class="fjry">人员录入凭证</div>
                  <div class="fjrynext">
                    <div class="nextstep1">
                      <i class="el-icon-location-information"></i><span>{{ addressName }}</span>
                    </div>
                  </div>
                </div>
                <div class="personnelVoucher">
                  <div class="person-item pointer" v-for="(item, index) in uselist" :key="index"  @click="getOnePersonCerTificate(item)">
                    <div class="item-content">
                      <img src="../assets/img/avator.d7401229.png" alt="" class="avator" />
                      <div class="contentpz">
                        <div>姓名：</div>
                        <div>物理卡号：</div>
                        <div>校园卡号：</div>
                      </div>
                      <div class="contentpz">
                        <div>{{ item.name }}</div>
                        <div>{{ item.cardId }}</div>
                        <div>{{ item.number }}</div>
                      </div>
                    </div>
                    <div class="item-bottom" @click="showelectfun(index)">
                      <span>录入凭证 <i class="el-icon-arrow-down"></i></span>
                    </div>
                    <div class="types" :class="selectpztype == index ? 'types1' : ''">
                      <el-select v-model="documentType" placeholder="请选择" size="small" class="documentType">
                        <el-option label="人脸" value="10"></el-option>
                        <el-option label="指纹" value="11"></el-option>
                        <el-option label="身份证" value="12"></el-option>
                        <el-option label="NFC" value="13"></el-option>
                        <el-option label="密码" value="14"></el-option>
                      </el-select>
                      <el-button type="primary" size="small" @click="showVoucherBoxfun">添加</el-button>
                    </div>
                  </div>
                </div>
              </el-card>
              <div class="bottomcontent">
                <el-card shadow="nerver">
                  <div class="pagehead">
                    <div class="fjry">已录入凭证信息</div>
                  </div>
                  <div class="bottomtable">
                    <el-table :data="uselist2" stripe class="table" height="225" ref="multipleTable"
                      header-cell-class-name="table-header" highlight-current-row @current-change="handleCurrentChange1"
                      v-if="dataShow">
                      <el-table-column prop="name" label="姓名"></el-table-column>
                      <el-table-column prop="pzname" label="凭证名称"></el-table-column>
                      <el-table-column label="类型">
                        <template slot-scope="scope">
                          <span v-if="scope.row.type == 10">人脸</span>
                          <span v-if="scope.row.type == 11">指纹</span>
                          <span v-if="scope.row.type == 12">身份证</span>
                          <span v-if="scope.row.type == 13">NFC</span>
                          <span v-if="scope.row.type == 14">密码</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="有效期" width="500">
                        <el-date-picker v-model="alreadyTime" size="small" @change="changeDate" type="datetimerange"
                          align="right" start-placeholder="开始日期" end-placeholder="结束日期">
                        </el-date-picker>
                      </el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <el-button size="small" @click="addpz(scope.$index, scope.row)">添加</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </el-card>
              </div>
            </el-col>
            <el-col :span="6">
              <el-card shadow="nerver" height="600">
                <div class="pagehead">
                  <div class="fjry">待下发凭证</div>
                  <div class="fjrynext">
                    <div class="nextstep" @click="complete">下一步</div>
                  </div>
                </div>
                <div class="bottomtable">
                  <el-table :data="uselist1" stripe class="table" height="620" ref="multipleTable"
                    header-cell-class-name="table-header" highlight-current-row @current-change="handleCurrentChange1">
                    <el-table-column prop="pzname" label="凭证名称"></el-table-column>
                    <el-table-column prop="username" label="人员名称"></el-table-column>
                    <el-table-column label="类型">
                      <template slot-scope="scope">
                        <span v-if="scope.row.pztype == 0">人脸</span>
                        <span v-if="scope.row.pztype == 1">指纹</span>
                        <span v-if="scope.row.pztype == 2">身份证</span>
                        <span v-if="scope.row.pztype == 3">NFC</span>
                        <span v-if="scope.row.pztype == 4">密码</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作">
                      <template slot-scope="scope">
                        <el-button size="mini" @click="deletepz(scope.$index, scope.row)">移除</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </el-carousel-item>
        <el-carousel-item>
          <el-row :gutter="20">
            <el-col :span="15">
              <el-card shadow="always">
                <div class="pagehead">
                  <div class="fjry">下发凭证</div>
                  <div class="fjrynext">
                    <div class="nextstep1">
                      <i class="el-icon-location-information"></i><span>{{ currentRow.name }}</span>
                    </div>
                  </div>
                </div>
                <el-checkbox-group v-model="checkList" @change="checkBoxfun">
                  <div class="personnelVoucher personnelVoucher1">
                    <div class="person-item pointer" v-for="(item, index) in uselist1" :key="index">
                      <el-checkbox :label="index"></el-checkbox>
                      <div class="item-content">
                        <img src="../assets/img/avator.d7401229.png" alt="" class="avator" />
                        <div class="contentpz">
                          <div>姓名：</div>
                          <div>物理卡号：</div>
                          <div>类型：</div>
                        </div>
                        <div class="contentpz">
                          <div>{{ item.name }}</div>
                          <div>{{ item.NFC }}</div>
                          <div>
                            <span v-if="item.pztype == 0">人脸</span>
                            <span v-if="item.pztype == 1">指纹</span>
                            <span v-if="item.pztype == 2">身份证</span>
                            <span v-if="item.pztype == 3">NFC</span>
                            <span v-if="item.pztype == 4">密码</span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </el-checkbox-group>
              </el-card>
            </el-col>
            <el-col :span="1" class="display-center"><img src="../assets/img/choose.1fda8508.png" alt="" /></el-col>
            <el-col :span="8">
              <el-card shadow="always">
                <div class="pagehead">
                  <div class="fjry">选择设备</div>
                  <div class="fjrynext">
                    <div class="nextstep" @click="complete">完成</div>
                  </div>
                </div>
                <div class="device-list">
                  <div class="device-item" v-for="(item, index) in deviceList" :key="index">
                    <div class="display-center device-info1">
                      <img src="../assets/img/lock.2451264a.png" alt="" />
                    </div>
                    <div class="device-info2">
                      <div class="device-info-title">{{ item.roomName }}</div>
                      <div class="device-info-line"></div>
                      <div class="device-info">
                        <div>电池电量：{{ item.battery }}</div>
                        <div>
                          状态：<span v-if="item.lockStatus == 0">在线</span><span v-if="item.lockStatus == 1">离线</span><span
                            v-if="item.lockStatus == 2">异常</span>
                        </div>
                        <div>序列号：{{ item.deviceNum }}</div>
                      </div>
                    </div>
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </el-carousel-item>
      </el-carousel>
    </el-card>
    <zw ref="mychild"></zw>
    <!-- 凭证录入弹框 -->
    <el-dialog title="录入凭证" :visible.sync="VoucherBox" width="40%">
      <el-form ref="form" :model="voucherfrom" label-width="70px" v-if="documentType == 10">
        <el-form-item label="凭证名称">
          <el-input v-model="voucherfrom.pzname" size="small" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item label="请上传照片" label-width="150">
          <el-upload action="#" list-type="picture-card" :auto-upload="false" :modal-append-to-body='false'>
            <i slot="default" class="el-icon-plus"></i>
            <div slot="file" slot-scope="{ file }">
              <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
              <span class="el-upload-list__item-actions">
                <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                  <i class="el-icon-zoom-in"></i>
                </span>
                <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleDownload(file)">
                  <i class="el-icon-download"></i>
                </span>
                <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
                  <i class="el-icon-delete"></i>
                </span>
              </span>
            </div>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible" :modal-append-to-body='false'>
            <img width="100%" :src="dialogImageUrl" alt="" />
          </el-dialog>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker v-model="value2[0]" size="small" type="datetime" placeholder="选择开始日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker v-model="value2[1]" size="small" type="datetime" placeholder="选择结束日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="voucherfrom" label-width="70px" v-if="documentType == 11">
        <el-form-item label="凭证名称">
          <el-input v-model="voucherfrom.pzname" size="small" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker v-model="value2[0]" size="small" type="datetime" placeholder="选择开始日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker v-model="value2[1]" size="small" type="datetime" placeholder="选择结束日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="录入">
          <el-radio-group v-model="voucherfrom.fingerprintAlias" size="small">
            <el-radio-button label="左手大拇指"></el-radio-button>
            <el-radio-button label="左手食指"></el-radio-button>
            <el-radio-button label="右手大拇指"></el-radio-button>
            <el-radio-button label="右手食指"></el-radio-button>
          </el-radio-group>
          <el-button type="primary" @click="addfir" size="small" v-if="deviceList[0].manufactureId==201||deviceList[0].manufactureId==221">GX1000-zh采集指纹
          </el-button>
          <iframe src="static/equipment/mafp_serial/index.html" frameborder="0" style="width: 100%; height: 350px"
            id="iframeBox" v-else></iframe>
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="voucherfrom" label-width="90px" v-if="documentType == 12">
        <el-form-item label="凭证名称">
          <el-input v-model="voucherfrom.pzname" size="small" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item label="识别身份证">
          <!-- <el-input v-model="voucherfrom.IDcard" :clearable="true" @change="avoidRepetition($event,12)"></el-input> -->
          <el-input placeholder="请输入内容" size="small" v-model="voucherfrom.IDcard" :clearable="true"
            @change="avoidRepetition($event,12)">
            <el-button slot="append" @click.native="addNfc" v-if="deviceList[0].manufactureId==201||deviceList[0].manufactureId==221">GX1000-zh采集卡
            </el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker v-model="value2[0]" size="small" type="datetime" placeholder="选择开始日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker v-model="value2[1]" size="small" type="datetime" placeholder="选择结束日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="voucherfrom" label-width="70px" v-if="documentType == 13">
        <el-form-item label="凭证名称">
          <el-input v-model="voucherfrom.pzname" size="small" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item label="NFC号码">
          <!-- <el-input v-model="voucherfrom.NFC" :clearable="true" @change="avoidRepetition($event,13)"></el-input> -->
          <el-input placeholder="请输入内容" size="small" v-model="voucherfrom.NFC" :clearable="true"
            @change="avoidRepetition($event,13)">
            <el-button slot="append" @click.native="addNfc" v-if="deviceList[0].manufactureId==201||deviceList[0].manufactureId==221">GX1000-zh采集卡
            </el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="常开卡" v-if="deviceList[0].manufactureId==101">
          <el-switch v-model="regularCard"  active-text="是否是常开卡" active-color="#13ce66" inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker v-model="value2[0]" size="small" type="datetime" placeholder="选择开始日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker v-model="value2[1]" size="small" type="datetime" placeholder="选择结束日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="voucherfrom" label-width="70px" v-if="documentType == 14">
        <el-form-item label="凭证名称">
          <el-input v-model="voucherfrom.pzname" size="small" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item label="设置密码">
          <el-input v-model="voucherfrom.password" show-password oninput="value=value.replace(/[^\d]/g,'')"
            :clearable="true" @change="avoidRepetition($event,14)"></el-input>
        </el-form-item>
        <el-form-item label="确认密码">
          <el-input v-model="voucherfrom.password1" size="small" show-password
            oninput="value=value.replace(/[^\d]/g,'')" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker v-model="value2[0]" size="small" type="datetime" placeholder="选择开始日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker v-model="value2[1]" size="small" type="datetime" placeholder="选择结束日期时间"
            default-time="12:00:00">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="VoucherBox = false" size="small">取 消</el-button>
          <el-button type="primary" @click="saveVoucherfrom" size="small">确 定</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 编辑弹出框 -->
    <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
      <el-form ref="form" :model="form" label-width="70px">
        <el-form-item label="用户名">
          <el-input v-model="form.name" size="small" :clearable="true"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="form.address" size="small" :clearable="true"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editVisible = false" size="small">取 消</el-button>
          <el-button type="primary" @click="saveEdit" size="small">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import zTree from "../components/zTree1.vue";
  import cardReader from "../components/cardReader/index.vue";
  import {
    httpGet,
    httpPost
  } from "../api";
  import checkInRoom from "../components/checkInRoom.vue";
  import {
    ztreeToElementTree,ztreeToElementTree2,
    uniqueArray,
    dec2hex,
    group,
    getcurrentTime,
    getcurrentTime1
  } from "../utils/index";
  import ICINLocker from "../utils/equipment.js"
  import zw from "./zw.vue"
  import moment from 'moment'
  import utils from "../utils/util.js";
  let nowDate = new Date()
  var currentTime = nowDate
  var endcurrentTime = getcurrentTime1(6)
  export default {
    inject: ['reload'],
    name: "campus",
    data() {
      return {
        regularCard:false,
        props: {
          multiple: true,
          emitPath: false
        },
        enterpriseListOption:[],
        alreadyTime: [currentTime, endcurrentTime],
        boxHeight: '',
        boxHeightstyle: '',
        selectoption: [],
        selectoptionValue: '',
        value2: [currentTime, endcurrentTime],
        roomlist: [],
        SelectedList: [],
        defaultProps: {
          children: "children",
          label: "name",
        },
        zwid: '',
        fingerprintId: 0,
        url: "../equipment/cardReader/ic01java.html",
        steplist: [{
            src: "../assets/img/1.png",
            title: "房源选择"
          },
          {
            src: "../assets/img/2.png",
            title: "人员登记"
          },
          {
            src: "../assets/img/3.png",
            title: "录入凭证"
          },
          // { src: "../assets/img/4.png", title: "下发权限" },
        ],
        checkList: [0],
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        stepindex: 0,
        stepindex1: 0,
        query: {
          address: "",
          name: "",
          pageIndex: 1,
          pageSize: 10,
          activeName: "first",
        },
        activeName: "first",
        tableData: [],
        tableData1: [],
        tableData2: [],
        multipleSelection: [],
        delList: [],
        editVisible: false,
        pageTotal: 0,
        personInfo: {
          cardId: "",
          name: "",
          phone: "",
          number: "",
          sex: 1,
          type: 0,
          education: "",
          email: "",
          leaseTerm: "",
          rent: "",
          birth: "",
          nation: "",
          address: "",
          remarks: "",
          enterpriseId: ""
        },
        rules: {
          name: [{
              required: true,
              message: "请输入姓名",
              trigger: "blur"
            },
            {
              min: 1,
              max: 8,
              message: "长度在 1 到 8 个字符",
              trigger: "blur"
            },
          ],
          cardId: [{
            required: true,
            message: "请输入物理卡号",
            trigger: "blur"
          }],
          type: [{
            required: true,
            message: "请选择身份",
            trigger: "blur"
          }],
          number: [{
            required: true,
            message: "请输入学号",
            trigger: "blur"
          }],
          phone: [{
            required: true,
            message: "请输入手机号",
            trigger: "blur"
          }],
          enterpriseId: [{
            required: true,
            message: "请选择所属部门",
            trigger: "blur"
          }],
        },
        form: {},
        idx: -1,
        id: -1,
        showIndex: 0,
        ztreeObj: null,
        uselist: [],
        uselist1: [],
        uselist2: [],
        zNodes: [],
        setting: {
          edit: {
            enable: false,
            drag: {
              isMove: false,
            },
            showRemoveBtn: false,
            showRenameBtn: false,
          },
          check: {
            enable: false,
          },
          data: {
            simpleData: {
              enable: true,
              pIdKey: "pid",
            },
          },
          view: {
            showIcon: true,
            addHoverDom: this.addHoverDom,
            removeHoverDom: this.removeHoverDom,
          },
        },
        currentRow: [],
        options: [],
        state: "",
        loading: false,
        timeout: null,
        documentType: "",
        selectpztype: -1,
        VoucherBox: false,
        startdate: "",
        enddate: "",
        voucherfrom: {
          password: "",
          password1: "",
          startdate: "",
          enddate: "",
          fingerprint: "",
          IDcard: "",
          name: "",
          NFC: "",
          fingerprintAlias: '',
          pzname: ''
        },
        deviceList: [],
        personselect: true,
        devperson: [],
        userInfo: {
          type: ''
        },
        dataShow: true,
        enterpriselist: [],
        ZNodesTree: [],
        userType: [],
        addressName: "",
        checkEnterpriseNode:[]
      };
    },
    components: {
      zTree,
      cardReader,
      checkInRoom,
      zw
    },
    watch: {
      alreadyTime: function(newValue, oldValue) {
        this.dataShow = false
        this.$nextTick(() => {
          this.alreadyTime = newValue
          this.dataShow = true
        })
      }
    },
    beforeCreate() {
      // var tenantId = JSON.parse(localStorage.getItem('tenantId'))
      // if (tenantId == 400) {
      //   this.$store.commit('defaultsettenantid')
      // }
    },
    created() {
      this.userType = this.$MANUFACTURER.userType
      this.userInfo = JSON.parse(localStorage.getItem('info'))
      this.selectoption = JSON.parse(localStorage.getItem('selectoption'))
      this.selectoptionValue = localStorage.getItem('tenantId')
      this.getalllist();
      this.getEnterprise()
    },
    mounted() {
      this.imgLoad();
      // 监听窗口变动大小计算banner高度
      window.addEventListener("resize", () => {
        this.imgLoad()
      });

    },
    methods: {
      checkEnterpriseList(e) {
        this.$nextTick(() => {
          var list = this.$refs['cascader'].getCheckedNodes()
          this.checkEnterpriseNode = list
          console.log(this.checkEnterpriseNode)
        })
      },
      phoneChange(e){
        this.personInfo.id=""
      },
      // 凭证避免重复
      avoidRepetition(e, type) {
        var person = this.uselist[this.selectpztype]
        if (type == 12) {
          this.uselist2.map(li => {
            var content = JSON.parse(li.content)
            if (li.cardId == person.cardId && content.password == e && li.type == 12) {
              this.$message.error("该身份证已存在")
              this.voucherfrom.IDcard = ''
            }
          })
        } else if (type == 13) {
          this.uselist2.map(li => {
            var content = JSON.parse(li.content)
            if (li.cardId == person.cardId && content.password == e && li.type == 13) {
              this.$message.error("该NFC已存在")
              this.voucherfrom.NFC = ''
            }
          })
        } else if (type == 14) {
          this.uselist2.map(li => {
            var content = JSON.parse(li.content)
            if (li.cardId == person.cardId && content.password == e && li.type == 14) {
              this.$message.error("该密码已存在")
              this.voucherfrom.password = ''
            }
          })
        }
      },
      // 指纹别名
      fingerprintAliasMethod(e) {
        var person = this.uselist[this.selectpztype]
        this.uselist2.map(li => {
          var content = JSON.parse(li.content)
          if (li.cardId == person.card && content.fingerprintAlias == e && li.type == 11) {
            this.$message.error("该指纹已存在")
            this.voucherfrom.fingerprintAlias = ''
          }
        })
      },
      getEnterprise() {
        httpGet("", this.$api.getEnterprise).then((res) => {
          res.data.list.map(li => {
            li['pid'] = li.parentId
            li['label'] = li.name
            li['value'] = li.id
          })
          var array = utils.uniqueArray(res.data.list, "id");
          var roomlistZNodes = ztreeToElementTree2(array, []);
          this.enterpriseListOption = roomlistZNodes
          this.enterpriselist = res.data.list;
        });
      },
      changeDate(val) {
        console.log(val)
        this.$forceUpdate();
        this.alreadyTime = val;
      },
      imgLoad() {
        this.$nextTick(function() {
          this.boxHeight = (document.documentElement.clientHeight - 100) + 'px;'
        });
      },
      selectTenantId(e) {
        localStorage.setItem('tenantId', e)
        this.reload()
      },
      // 读卡
      // readCardFun() {
      //   var _this = this
      //   this.$refs.mychild.cardFun(0x8010, function(data) {
      //     if (data.status == 0) {
      //       _this.voucherfrom.NFC = data.cardNo.toUpperCase()
      //       _this.$message.success("读取成功")
      //     } else {
      //       _this.$message.error("读取失败")
      //     }
      //   })
      // },
      // // 读卡
      // readCardFun1() {
      //   var _this = this
      //   this.$refs.mychild.cardFun(0x8010, function(data) {
      //     if (data.status == 0) {
      //       _this.voucherfrom.idcard = data.cardNo.toUpperCase()
      //       _this.$message.success("读取成功")
      //     } else {
      //       _this.$message.error("读取失败")
      //     }
      //   })
      // },
      // 采集指纹
      addfir() {
        var _this = this
        this.$refs.mychild.addFingerprintFun(0x8014, function(data) {
          localStorage.setItem('fingerprint', data)
          _this.localFingerprint = data
        })
      },
      setVoucherNfc(data) {
        if (data.cardType == 50) {
          var nfc = ""
          var str = data.cardNo.substr(0, 8)
          var arr4 = group(str, 2).reverse();
          arr4.map((li) => {
            nfc += li;
          });
          this.voucherfrom.NFC = nfc.toUpperCase()
        } else if (data.cardType == 36) {
          this.voucherfrom.IDcard = data.cardNo.toUpperCase()
        }
      },
      addNfc() {
        var _this = this
        this.$refs.mychild.cardFun(0x8010, function(data) {
          if (data.status == 0) {
            _this.setVoucherNfc(data)
          } else {
            _this.$message.error("读卡错误，请检查读卡器是否正常！")
          }
        })
      },
      //添加房源
      addRoom() {
        var data = {};
        httpGet(data, this.$api.getSiteList).then((res) => {
          res.data.list.list.map(li => {
            var name = utils.findIndexArray(this.ZNodesTree, li.id, [])
            var path = ''
            if (name) {
              path = name.join('/')
            }
            li['path'] = path
          })
          var array = uniqueArray(res.data.list.list, 'id')
          this.roomlist = ztreeToElementTree(array, {});
        });
      },
      selectCheck(e) {
        if (e == '左手大拇指') {
          this.fingerprintId = 0
          this.voucherfrom.nam = '左手大拇指'
        } else if (e == '左手食指') {
          this.fingerprintId = 1
          this.voucherfrom.nam = '左手食指'
        } else if (e == '右手大拇指') {
          this.fingerprintId = 2
          this.voucherfrom.nam = '右手大拇指'
        } else if (e == '右手食指') {
          this.fingerprintId = 3
          this.voucherfrom.nam = '右手食指'
        }
      },
      // 人脸图片上传功能
      handleRemove(file) {
        console.log(file);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      handleDownload(file) {
        console.log(file);
      },

      checkfun(index, status) {
        this.tableData.map((li) => {
          li.check = false;
        });
        this.tableData[index].check = status;
        this.currentRow = this.tableData[index];
      },
      checkfun1(index, status) {
        this.tableData1.map((li) => {
          li.check = false;
        });
        this.tableData1[index].check = status;
        this.currentRow = this.tableData1[index];
      },
      checkfun2(index, status) {
        this.tableData2.map((li) => {
          li.check = false;
        });
        this.tableData2[index].check = status;
        this.currentRow = this.tableData2[index];
      },
      // 选中凭证
      checkBoxfun() {
        console.log(this.checkList);
      },
      // 添加凭证
      complete() {
        if (this.checkList.length == 0) {
          this.$message.error("请选择下发凭证");
        } else {
          this.uselist1.map((li, index) => {
            setTimeout(()=>{
              this.addpzcomp(index);
            },1000)
          });
          this.stepindex = 0
          setTimeout(() => {
            this.uselist1 = []
          }, 2000)
        }
      },
      addpzcomp(i) {
        var str = {};
        var endTime = new Date(this.uselist1[i].endTime).getTime();
        var startTime = new Date(this.uselist1[i].startTime).getTime();
        endTime = parseInt(endTime / 1000)
        startTime = parseInt(startTime / 1000)
        var passwordStartTime = moment(startTime * 1000).format("YYYYMMDDHHmmss");
        var passwordEndTime = moment(endTime * 1000).format("YYYYMMDDHHmmss");
        var pzname = '',
          cardName = this.uselist1[i].name
        if (this.deviceList[0].manufactureId == 201 || this.deviceList[0].manufactureId == 221) {
          var data3 = {}
          var userPassword = this.uselist1[i].userPassword
          var userTelephone = this.uselist1[i].userTelephone
          if (this.uselist1[i].pztype == 1) {
            cardName = cardName + '-' + this.uselist1[i].pzname
            pzname = this.uselist1[i].pzname
            var fingerprint = this.uselist1[i].fingerprint
            ICINLocker.addFingerPrints(this.deviceList[0].deviceNum, this.deviceList[0].imei, userPassword, 0, this
              .uselist1[i].fingerprint, startTime, endTime, cardName, this.deviceList[0].roomName, (
                callback) => {
                if (callback.success) {
                  str = {
                    pzname: pzname,
                    imei: this.deviceList[0].imei,
                    deviceNum: this.deviceList[0].deviceNum,
                    userTelephone: userTelephone,
                    userPassword: userPassword,
                    fingerprintAlias: this.uselist1[i].fingerprintAlias,
                    password: '',
                    length: fingerprint.length / 2,
                    fpTimeId: '',
                    operateMode: 16,
                    order: 6216,
                    fingerprint: fingerprint,
                    passwordStartTime: startTime,
                    passwordEndTime: endTime,
                    cardName:cardName,
                    roomName:this.deviceList[0].roomName
                  }
                  var data = {
                    cardId: this.uselist1[i].cardId,
                    content: JSON.stringify(str),
                    deviceNum: this.deviceList[0].deviceNum,
                    type: this.uselist1[i].pztype,
                    imei: this.deviceList[0].imei,
                    serial: callback.data.serialNumber,
                    startTime: startTime,
                    endTime: endTime,
                  };
                  httpPost(data, this.$api.addCertificates).then((res) => {
                    if (res.success) {
                      this.$message.success("添加成功")
                    } else {
                      this.$message.error("添加失败")
                    }
                  });
                } else {
                  this.$message.error("下发失败")
                }
              })
            this.$refs.cardShow.setActiveItem(0);
            return
          } else if (this.uselist1[i].pztype == 2) {
            var idcard = ''
            if (this.uselist1[i].IDcard.length == 16) {
              idcard = this.uselist1[i].IDcard
            } else {
              idcard = dec2hex(this.uselist1[i].IDcard);
            }
            if (this.uselist1[i].pzname) {
              cardName = cardName + '-' + this.uselist1[i].pzname
              pzname = this.uselist1[i].pzname
            } else {
              cardName = cardName + '-身份证' + this.uselist1[i].pzid || 1
              pzname = '身份证' + this.uselist1[i].pzid || 1
            }
            // var arr4 = group(idcard, 2).reverse();
            // var nfc = "";
            // arr4.map((li) => {
            //   nfc += li;
            // });
            if (idcard.length != 16) {
              this.$message.error("卡格式错误，请重新录入")
              return
            }
            str = {
              pzname: pzname,
              imei: this.deviceList[0].imei,
              deviceNum: this.deviceList[0].deviceNum,
              userTelephone: userTelephone,
              userPassword: userPassword,
              operateMode: 13,
              order: 6213,
              password: idcard.toUpperCase(),
              passwordStartTime: startTime,
              passwordEndTime: endTime,
              is: false,
              cardName:cardName,
              roomName:this.deviceList[0].roomName
            }
            ICINLocker.RfCardRegister(this.deviceList[0].deviceNum, this.deviceList[0].imei, userPassword, 1, 1, idcard
              .toUpperCase(), 36, startTime, endTime, 6213, cardName, this.deviceList[0].roomName, (
                callback) => {
                if (callback.success) {
                  var data = {
                    cardId: this.uselist1[i].cardId,
                    content: JSON.stringify(str),
                    deviceNum: this.deviceList[0].deviceNum,
                    type: this.uselist1[i].pztype,
                    imei: this.deviceList[0].imei,
                    serial: callback.data.serialNumber,
                    startTime: startTime,
                    endTime: endTime,
                  };
                  httpPost(data, this.$api.addCertificates).then((res) => {
                    if (res.success) {
                      this.$message.success("添加成功")
                    } else {
                      this.$message.error("添加失败")
                    }
                  });
                } else {
                  this.$message.error("下发失败")
                }
              })
            this.$refs.cardShow.setActiveItem(0);
            return
          } else if (this.uselist1[i].pztype == 3) {
            var nfc = "";
            if (this.uselist1[i].NFC.length == 8) {
              // nfc = this.uselist1[i].NFC
              nfc = utils.cardFormatConversion(this.uselist1[i].NFC)
              nfc=nfc+'00000000'
            } else {
              var arr2 = dec2hex(this.uselist1[i].NFC);
              var arr4 = group(arr2, 2)
              arr4.map((li) => {
                nfc += li;
              });
              nfc=nfc+'00000000'
            }
            if (this.uselist1[i].pzname) {
              cardName = cardName + '-' + this.uselist1[i].pzname
              pzname = this.uselist1[i].pzname
            } else {
              cardName = cardName + '-NFC' + this.uselist1[i].pzid || 1
              pzname = 'NFC' + this.uselist1[i].pzid || 1
            }
            if (nfc.length != 16) {
              this.$message.error("卡格式错误，请重新录入")
              return
            }
            str = {
              pzname: pzname,
              imei: this.deviceList[0].imei,
              deviceNum: this.deviceList[0].deviceNum,
              userTelephone: userTelephone,
              userPassword: userPassword,
              operateMode: 10,
              order: 6210,
              password: nfc.toUpperCase(),
              passwordStartTime: startTime,
              passwordEndTime: endTime,
              is: false,
              cardName:cardName,
              roomName:this.deviceList[0].roomName
            }
            ICINLocker.RfCardRegister(this.deviceList[0].deviceNum, this.deviceList[0].imei, userPassword, 1, 1, nfc
              .toUpperCase(), 50, startTime, endTime, 6210, cardName, this.deviceList[0].roomName, (
                callback) => {
                if (callback.success) {
                  var data = {
                    cardId: this.uselist1[i].cardId,
                    content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
                    deviceNum: this.deviceList[0].deviceNum,
                    type: this.uselist1[i].pztype,
                    imei: this.deviceList[0].imei,
                    serial: callback.data.serialNumber,
                    startTime: startTime,
                    endTime: endTime,
                  };
                  httpPost(data, this.$api.addCertificates).then((res) => {
                    if (res.success) {
                      this.$message.success("添加成功")
                    } else {
                      this.$message.error("添加失败")
                    }
                  });
                } else {
                  this.$message.error("下发失败")
                }
              })
            this.$refs.cardShow.setActiveItem(0);
            return
          } else if (this.uselist1[i].pztype == 4) {
            if (this.uselist1[i].pzname) {
              cardName = cardName + '-' + this.uselist1[i].pzname
              pzname = this.uselist1[i].pzname
            } else {
              cardName = cardName + '-密码' + this.uselist1[i].pzid || 1
              pzname = '密码' + this.uselist1[i].pzid || 1
            }
            str = {
              pzname: pzname,
              imei: this.deviceList[0].imei,
              deviceNum: this.deviceList[0].deviceNum,
              userTelephone: userTelephone,
              userPassword: userPassword,
              operateMode: 7,
              order: 6207,
              password: this.uselist1[i].password,
              passwordStartTime: startTime,
              passwordEndTime: endTime,
              is: false,
              cardName:cardName,
              roomName:this.deviceList[0].roomName
            }
            ICINLocker.addForeverPassword(this.deviceList[0].deviceNum, this.deviceList[0].imei, userPassword, 1, this
              .uselist1[i].password, 255, startTime, endTime, 6207, cardName, this.deviceList[0]
              .roomName, (callback) => {
                if (callback.success) {
                  var data = {
                    cardId: this.uselist1[i].cardId,
                    content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
                    deviceNum: this.deviceList[0].deviceNum,
                    type: this.uselist1[i].pztype,
                    imei: this.deviceList[0].imei,
                    serial: callback.data.serialNumber,
                    startTime: startTime,
                    endTime: endTime,
                  };
                  httpPost(data, this.$api.addCertificates).then((res) => {
                    if (res.success) {
                      this.$message.success("添加成功")
                    } else {
                      this.$message.error("添加失败")
                    }
                  });
                } else {
                  this.$message.error("下发失败")
                }
              })
            this.$refs.cardShow.setActiveItem(0);
            return
          }

        } else if (this.deviceList[0].manufactureId == 101) {
          if (this.uselist1[i].pztype == 1) {
            cardName = cardName + '-' + this.uselist1[i].pzname
            pzname = this.uselist1[i].pzname
            var fpId = new Date();
            str = {
              username: this.uselist1[i].username,
              pzname: pzname,
              imei: this.deviceList[0].imei,
              deviceNum: this.deviceList[0].deviceNum,
              userTelephone: this.uselist1[i].userTelephone,
              userPassword: this.uselist1[i].userPassword,
              fingerprintAlias: this.uselist1[i].fingerprintAlias,
              password: 'F1',
              length: this.uselist1[i].fingerprint.length / 2,
              fpTimeId: fpId.getTime(),
              order: 6216,
              operateMode: 16,
              fingerprint: this.uselist1[i].fingerprint,
              fingerprintStartTime: passwordStartTime,
              fingerprintEndTime: passwordEndTime,
              cardName: cardName,
              roomName: this.deviceList[0].roomName,
            };
            httpPost(str, this.$api.fingerprintTransfer).then((res1) => {
              if (res1.success) {
                var data = {
                  cardId: this.uselist1[i].cardId,
                  content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
                  deviceNum: this.deviceList[0].deviceNum,
                  type: this.uselist1[i].pztype,
                  imei: this.deviceList[0].imei,
                  serial: res1.data.serialNumber,
                  startTime: startTime,
                  endTime: endTime,
                };
                httpPost(data, this.$api.addCertificates).then((res) => {});
                this.$refs.cardShow.setActiveItem(0);
              } else {
                this.$message.error("下发失败");
              }
            });
            return false;
          } else if (this.uselist1[i].pztype == 2) {
            var idcard = ''
            if (this.uselist1[i].IDcard.length == 16) {
              var idcard = this.uselist1[i].IDcard
            } else {
              idcard = dec2hex(this.uselist1[i].IDcard);
            }
            if (this.uselist1[i].pzname) {
              cardName = cardName + '-' + this.uselist1[i].pzname
              pzname = this.uselist1[i].pzname
            } else {
              cardName = cardName + '-身份证' + this.uselist1[i].pzid || 1
              pzname = '身份证' + this.uselist1[i].pzid || 1
            }
            str = {
              username: this.uselist1[i].username,
              pzname: pzname,
              cardId: this.uselist1[i].cardId,
              imei: this.deviceList[0].imei,
              deviceNum: this.deviceList[0].deviceNum,
              userTelephone: this.uselist1[i].userTelephone,
              operateMode: 13,
              order: 6213,
              userPassword: this.uselist1[i].userPassword,
              password: idcard.toUpperCase(),
              passwordStartTime: passwordStartTime,
              passwordEndTime: passwordEndTime,
              is: false,
              cardName: cardName,
              roomName: this.deviceList[0].roomName,
            };
          } else if (this.uselist1[i].pztype == 3) {
            var nfc = "";
            if (this.uselist1[i].NFC.length == 8) {
              nfc = this.uselist1[i].NFC
            } else {
              var arr2 = dec2hex(this.uselist1[i].NFC);
              var arr4 = group(arr2, 2)
              arr4.map((li) => {
                nfc += li;
              });
            }
            if (this.uselist1[i].pzname) {
              cardName = cardName + '-' + this.uselist1[i].pzname
              pzname = this.uselist1[i].pzname
            } else {
              cardName = cardName + '-NFC' + this.uselist1[i].pzid || 1
              pzname = 'NFC' + this.uselist1[i].pzid || 1
            }
            str = {
              username: this.uselist1[i].username,
              pzname: pzname,
              cardId: this.uselist1[i].cardId,
              imei: this.deviceList[0].imei,
              deviceNum: this.deviceList[0].deviceNum,
              userTelephone: this.uselist1[i].userTelephone,
              operateMode: 10,
              order: 6210,
              userPassword: this.uselist1[i].userPassword,
              password: nfc.toUpperCase(),
              passwordStartTime: passwordStartTime,
              passwordEndTime: passwordEndTime,
              is: false,
              cardName: cardName,
              roomName: this.deviceList[0].roomName,
            };
          } else if (this.uselist1[i].pztype == 4) {
            if (this.uselist1[i].pzname) {
              cardName = cardName + '-' + this.uselist1[i].pzname
              pzname = this.uselist1[i].pzname
            } else {
              cardName = cardName + '-NFC' + this.uselist1[i].pzid || 1
              pzname = 'NFC' + this.uselist1[i].pzid || 1
            }
            str = {
              username: this.uselist1[i].username,
              pzname: pzname,
              cardId: this.uselist1[i].cardId,
              imei: this.deviceList[0].imei,
              deviceNum: this.deviceList[0].deviceNum,
              password: this.uselist1[i].password,
              userTelephone: this.uselist1[i].userTelephone,
              operateMode: 7,
              order: 6207,
              passwordStartTime: passwordStartTime,
              passwordEndTime: passwordEndTime,
              userPassword: this.uselist1[i].userPassword,
              is: false,
              cardName: cardName,
              roomName: this.deviceList[0].roomName,
            };
          }
          httpPost(str, this.$api.getDeviceOperateUserInfo).then((res1) => {
            if (res1.success) {
              var data = {
                cardId: this.uselist1[i].cardId,
                content: JSON.stringify(str), //operateMode:NFC-10、把人员添加到凭证-1
                deviceNum: this.deviceList[0].deviceNum,
                type: this.uselist1[i].pztype,
                imei: this.deviceList[0].imei,
                serial: res1.data.serialNumber,
                startTime: startTime,
                endTime: endTime,
              };
              httpPost(data, this.$api.addCertificates).then((res) => {});
              this.$message.success("下发成功");
              // this.deviceList = [];
            } else {
              this.$message.error("下发失败");
            }
          });
          this.$refs.cardShow.setActiveItem(0);
        }
      },
      Bytes2Str(arrBytes) {
        var str = "";
        for (var i = 0; i < arrBytes.length; i++) {
          var tmp;
          var num = parseInt(arrBytes[i]);
          if (num < 0) {
            //此处填坑，当byte因为符合位导致数值为负时候，需要对数据进行处理
            tmp = (255 + num + 1).toString(16);
          } else {
            tmp = num.toString(16);
          }
          if (tmp.length == 1) {
            tmp = "0" + tmp;
          }
          if (i > 0) {
            str += "" + tmp;
          } else {
            str += tmp;
          }
        }
        return str;
      },
      stringToHex(str) {
        var val = "";
        for (var i = 0; i < str.length; i++) {
          val += parseInt(str[i]).toString(16);
        }
        return val;
      },
      getTypeSort(data, type, cardId) {
        var num = 1
        data.map(li => {
          if (li.type == type && li.cardId == cardId) {
            num++
          }
        })
        return num
      },
      // 提交凭证录入弹框内容
      saveVoucherfrom() {
        var _this = this
        if (this.value2[0] == '' || this.value2[1] == '') {
          this.$message.error("请选择开始和结束时间")
          return false;
        }
        // if (this.voucherfrom.pzname == '') {
        //   this.$message.error("请填写凭证名称");
        //   return
        // }
        var sort = this.getTypeSort(this.uselist2, this.documentType, this.uselist[_this.selectpztype].cardId)
        var pzname = this.voucherfrom.pzname
        if (this.documentType == 12) {
          if (this.voucherfrom.IDcard == "") {
            this.$message.error("身份证号不能为空")
            return
          }
        } else if (this.documentType == 13) {
          if (this.voucherfrom.NFC == "") {
            this.$message.error("NFC不能为空")
            return
          }
          if (this.voucherfrom.NFC.length != 8) {
            this.$message.error("NFC格式错误，请重新录入")
            return
          }
        } else if (this.documentType == 14) {
          if (this.voucherfrom.password == "") {
            this.$message.error("密码不能为空")
            return
          }
        }
        if (pzname == '') {
          if (this.documentType == 11) {
            pzname = '指纹' + sort
          } else if (this.documentType == 12) {
            pzname = '身份证' + sort
          } else if (this.documentType == 13) {
            pzname = 'NFC' + sort
          } else if (this.documentType == 14) {
            pzname = '密码' + sort
          }
        }
        if (this.documentType == 11) {
          var fingerprint = localStorage.getItem("fingerprint");
          if (this.deviceList[0].manufactureId == 101) {
            var array = fingerprint.split(",");
            var num = this.Bytes2Str(array);
            this.voucherfrom.fingerprint = num;
            if (fingerprint == "") {
              this.$message.error("请录入指纹");
              return;
            }
          } else {
            this.voucherfrom.fingerprint = fingerprint
          }
          if (this.voucherfrom.fingerprintAlias == '') {
            this.$message.error("请选择指纹别名");
            return;
          }
        }
        if (this.voucherfrom.password != this.voucherfrom.password1) {
          this.$message.error("两次输入的密码不一致，请重新输入！");
          return;
        } else if (
          parseInt(this.voucherfrom.password.length) % 2 != 0 &&
          this.voucherfrom.password.length != 0
        ) {
          this.$message.error("输入的密码长度需要为6位！");
          return;
        } else {
          var NFCData=this.voucherfrom.NFC
          if(this.regularCard){
            NFCData=NFCData+'AA55'
          }
          var row = {
            username: _this.uselist[_this.selectpztype].name,
            pzname: pzname,
            cardId: _this.uselist[_this.selectpztype].cardId,
            siteId: _this.uselist[_this.selectpztype].siteId,
            userPassword: JSON.parse(this.uselist[_this.selectpztype].info).userPassword,
            userTelephone: JSON.parse(_this.uselist[_this.selectpztype].info).userTelephone,
            password: _this.voucherfrom.password,
            phone: _this.uselist[_this.selectpztype].phone,
            fingerprint: _this.voucherfrom.fingerprint,
            fingerprintId: _this.fingerprintId,
            fingerprintAlias: _this.voucherfrom.fingerprintAlias,
            pztype: _this.documentType,
            IDcard: _this.voucherfrom.IDcard,
            NFC: NFCData,
            name: _this.uselist[_this.selectpztype].name,
            id: _this.uselist[_this.selectpztype].id,
            startdate: this.time(+new Date(_this.startdate)),
            enddate: _this.time(+new Date(_this.enddate)),
            startTime: _this.value2[0],
            endTime: _this.value2[1],
          };
          _this.addpzMethods(row)
          _this.creatVoucher(row)
          _this.VoucherBox = false;
          _this.$message.success("提交成功");
        }
      },
      addpzMethods(row) {
        var myDate = new Date();
        var fingerprintId = myDate.getTime();
        let voucherType = ""
        if (row.pztype == 10) {
          voucherType = 0
        } else if (row.pztype == 11) {
          voucherType = 1
        } else if (row.pztype == 12) {
          voucherType = 2
        } else if (row.pztype == 13) {
          voucherType = 3
        } else if (row.pztype == 14) {
          voucherType = 4
        }
        var rowdata = {
          username: row.username,
          pzname: row.pzname,
          cardId: row.cardId,
          siteId: row.siteId,
          userPassword: row.userPassword,
          userTelephone: row.userTelephone,
          password: row.password,
          phone: row.userTelephone,
          fingerprint: row.fingerprint,
          fingerprintAlias: row.fingerprintAlias,
          fingerprintId: fingerprintId,
          pztype: voucherType,
          IDcard: row.IDcard,
          NFC: row.NFC,
          name: row.name,
          id: row.id,
          startdate: row.startdate,
          enddate: row.enddate,
          startTime: row.startTime,
          endTime: row.endTime,
        };
        this.uselist1.push(rowdata);
        // this.uselist2.splice(index, 1);
      },
      creatVoucher(row) {
        var cardName = "",
          pzname = ""
        if (row.pztype == 11) {
          var fingerprint = row.fingerprint;
          if (row.pzname) {
            pzname = row.pzname
          } else {
            pzname = '指纹' + row.pzid || 1
          }
          var str = {
            username: row.username,
            pzname: pzname,
            userTelephone: row.userTelephone,
            userPassword: row.userPassword,
            fingerprintAlias: row.fingerprintAlias,
            password: "",
            passwordStartTime: parseInt(row.startTime.getTime() / 1000),
            passwordEndTime: parseInt(row.endTime.getTime() / 1000),
            operateMode: 16,
            order: 6216,
            fingerprint: fingerprint,
          };
          var data = {
            cardId: row.cardId,
            content: JSON.stringify(str),
            type: row.pztype,
            startTime: parseInt(row.startTime.getTime() / 1000),
            endTime: parseInt(row.endTime.getTime() / 1000),
          };
          httpPost(data, this.$api.addCertificates).then((res) => {

          });
          this.uselist2 = []
          this.getOnePersonCerTificate(row)
          return false;
        } else if (row.pztype == 12) {
          var arr2 = ''
          if (row.IDcard.length == 16) {
            arr2 = row.IDcard
          } else if (row.IDcard.length == 0) {
            this.$message.error("请输入身份证")
            return false
          } else {
            arr2 = dec2hex(row.IDcard);
          }
          cardName = row.username
          if (row.pzname) {
            cardName += '-' + row.pzname
            pzname = row.pzname
          } else {
            cardName += '-身份证' + row.cardId || 1
            pzname = '身份证' + row.cardId || 1
          }
          str = {
            username: row.username,
            pzname: row.pzname,
            userTelephone: row.userTelephone,
            userPassword: row.userPassword,
            operateMode: 13,
            order: 6213,
            password: arr2.toUpperCase(), //this.voucher.idcard,
            passwordStartTime: moment(row.startTime.getTime() / 1000).format('YYYYMMDDHHmmss'),
            passwordEndTime: moment(row.endTime.getTime() / 1000).format('YYYYMMDDHHmmss'),
            is: false,
            cardName: cardName
          };
        } else if (row.pztype == 13) {
          var nfc = "";
          if (row.NFC.length == 8) {
            nfc = row.NFC
          } else if (row.NFC.length == 0) {
            this.$message.error("请输入NFC")
            return false
          } else {
            var array3 = dec2hex(row.NFC);
            var arr4 = group(array3, 2)
            arr4.map((li) => {
              nfc += li;
            });
          }
          cardName = row.username
          if (row.pzname) {
            cardName += '-' + row.pzname
            pzname = row.pzname
          } else {
            cardName += '-NFC' + row.cardId || 1
            pzname = 'NFC' + row.cardId || 1
          }
          str = {
            username: row.username,
            pzname: row.pzname,
            operateMode: 10,
            order: 6210,
            userTelephone: row.userTelephone,
            userPassword: row.userPassword,
            password: nfc.toUpperCase(), //this.voucher.nfc,
            passwordStartTime: moment(row.startTime.getTime() / 1000).format('YYYYMMDDHHmmss'),
            passwordEndTime: moment(row.endTime.getTime() / 1000).format('YYYYMMDDHHmmss'),
            is: false,
            cardName: cardName
          };
        } else if (row.pztype == 14) {
          if (row.password.length != 6) {
            this.$message.error("密码长度为6位")
            return false
          } else if (row.password.length == 0) {
            this.$message.error("请输入密码")
            return false
          }
          cardName = row.username
          if (row.pzname) {
            cardName += '-' + row.pzname
            pzname = row.pzname
          } else {
            cardName += '-密码' + row.cardId || 1
            pzname = '密码' + row.cardId || 1
          }
          str = {
            username: row.username,
            pzname: row.pzname,
            password: row.password,
            userTelephone: row.userTelephone,
            userPassword: row.userPassword,
            operateMode: 7,
            order: 6207,
            passwordStartTime: moment(row.startTime.getTime() / 1000).format('YYYYMMDDHHmmss'),
            passwordEndTime: moment(row.endTime.getTime() / 1000).format('YYYYMMDDHHmmss'),
            is: false,
            cardName: cardName
          };
        }
        var data = {
          cardId: row.cardId,
          content: JSON.stringify(str),
          type: row.pztype,
          startTime: parseInt(row.startTime.getTime() / 1000),
          endTime: parseInt(row.endTime.getTime() / 1000)
        };
        httpPost(data, this.$api.addCertificates).then((res) => {
          this.uselist2 = []
          this.getOnePersonCerTificate(row)
        });
      },
      getcertififun(id, callback) {
        var data = {
          pageNum: 1,
          pageSize: 1,
          orderBy: "create_at desc",
          // orderType: "desc",
          // orderBy: "createAt",
          q: {
            cardId: id,
          },
        };
        httpGet(data, this.$api.getCertificates).then((res) => {
          callback(res)
        })
      },
      // 点击显示录入凭证弹框
      showVoucherBoxfun() {
        console.log(this.documentType);
        this.VoucherBox = true;
        this.startdate = this.uselist[this.selectpztype].startTime;
        this.enddate = this.uselist[this.selectpztype].endTime;
        console.log(this.uselist[this.selectpztype])
        var NFC = ''
        var array3 = dec2hex(this.uselist[this.selectpztype].cardId);
        var arr4 = group(array3, 2).reverse()
        arr4.map((li) => {
          NFC += li;
        });
        if (NFC.length != 8) {
          this.voucherfrom.NFC = ""
        } else {
          this.voucherfrom.NFC = NFC.toUpperCase()
        }
      },
      // 点击显示选择录入凭证类型
      showelectfun(i) {
        if (this.selectpztype == i) {
          this.selectpztype = -1;
        } else {
          this.selectpztype = i;
        }
      },
      time(time = +new Date()) {
        var date = new Date(time + 8 * 3600 * 1000); // 增加8小时
        return date.toJSON().substr(0, 19).replace("T", " ");
      },
      // 已录入凭证添加
      addpz(index, row) {
        var myDate = new Date();
        var fingerprintId = myDate.getTime();
        let voucherType = ""
        if (row.type == 10) {
          voucherType = 0
        } else if (row.type == 11) {
          voucherType = 1
        } else if (row.type == 12) {
          voucherType = 2
        } else if (row.type == 13) {
          voucherType = 3
        } else if (row.type == 14) {
          voucherType = 4
        }
        console.log(row)
        var rowdata = {
          username: row.name,
          pzname: row.contentJSON.pzname,
          pzid: row.contentJSON.userTelephone.substr(row.contentJSON.userTelephone.length - 1, row.contentJSON
            .userTelephone.length - 5),
          cardId: row.cardId,
          siteId: this.deviceList[0].roomId,
          userPassword: row.contentJSON.userPassword,
          userTelephone: row.contentJSON.userTelephone,
          password: row.contentJSON.password,
          phone: row.contentJSON.userTelephone,
          fingerprint: row.contentJSON.fingerprint,
          fingerprintAlias: row.contentJSON.fingerprintAlias,
          fingerprintId: fingerprintId,
          pztype: voucherType,
          IDcard: row.contentJSON.password,
          NFC: row.contentJSON.password,
          name: row.name,
          id: row.id,
          startdate: this.time(+new Date(this.alreadyTime[0])),
          enddate: this.time(+new Date(this.alreadyTime[1])),
          startTime: this.alreadyTime[0],
          endTime: this.alreadyTime[1],
        };
        this.uselist1.push(rowdata);
        // this.uselist2.splice(index, 1);
      },
      // 移除已添加人员凭证
      deletepz(index, row) {
        this.uselist1.splice(index, 1);
      },
      // 移除人员
      deletefun(row) {
        if (this.deviceList[0].manufactureId == 201||this.deviceList[0].manufactureId == 221) {
          var data = {
            lockerId: this.deviceList[0].deviceNum,
            imei: this.deviceList[0].imei,
            lockerUserId: JSON.parse(row.info).userPassword,
            keyId: JSON.parse(row.info).userPassword,
            role: 0,
            action: 2, //1--添加、2--删除、3--修改
            order: 6203,
            cardName: row.name,
            roomName: this.deviceList[0].roomName
          }
          httpPost(data, this.$api.ZGduserOperation).then(res => {
            this.$message.success("下发成功");
            var data = [];
            var str = {
              siteId: row.siteId,
              cardId: row.cardId,
            };
            data.push(str);
            httpPost(data, this.$api.unbindCard).then((res) => {
              this.$message.success("删除成功");
              this.getroomperson();
            });
          })
        } else if (this.deviceList[0].manufactureId == 101) {
          var str1 = {
            imei: this.deviceList[0].imei,
            deviceNum: this.deviceList[0].deviceNum,
            userTelephone: JSON.parse(row.info).userTelephone,
            // cardId:this.personInfo.cardId,
            userPassword: JSON.parse(row.info).userPassword,
            password: "20210816",
            passwordStartTime: "20210813010101",
            passwordEndTime: "20680813010101",
            operateMode: 3,
            order: 6203,
            is: false,
            cardName: row.name,
            roomName: this.deviceList[0].roomName
          };
          if (JSON.parse(row.info).pass) {
            str1['pass'] = true
          }
          httpPost(str1, this.$api.getDeviceOperateUserInfo).then((res2) => {
            if (res2.success) {
              this.$message.success("下发成功");
              var data = [];
              var str = {
                siteId: row.siteId,
                cardId: row.cardId,
              };
              data.push(str);
              httpPost(data, this.$api.unbindCard).then((res) => {
                this.$message.success("删除成功");
                this.getroomperson();
              });
            }
          });

        }
      },
      // 获取人员
      querySearchAsync(queryString, cb) {
        var q = {
          name: queryString,
        };
        var data = {
          pageSize: 30,
          pageNum: 1,
          q: JSON.stringify(q),
        };
        var personInfo = [];
        this.loading = true;
        httpPost(data, this.$api.getlistNum).then((res) => {
          personInfo = res.data.list;
          this.personselect = false;
          personInfo.map(li => {
            if (li.name == queryString) {
              this.personselect = true;
            }
          })
          var restaurants = res.data.list;
          var results = queryString ?
            restaurants.filter(this.createFilter(queryString)) :
            restaurants;
          cb(results);
        });
      },
      createFilter(queryString) {
        return (restaurant) => {
          return restaurant.name.indexOf(queryString) === 0;
        };
      },
      handleSelect(item) {
        this.personInfo = item;
        this.personselect = true
      },
      // 返回
      selectstep(i) {
        if (i < this.stepindex) {
          this.stepindex = i;
          this.$refs.cardShow.setActiveItem(i);
        }
      },
      // 下一步
      stepnext() {
        if (this.stepindex == 0) {
          this.getroomperson();
          this.getItems();
        }
        if (this.currentRow.id) {
          var name = utils.findIndexArray(this.roomlist, this.currentRow.id, [])
          this.addressName = name.join('/')
          this.$refs.cardShow.next();
          this.stepindex += 1;
          this.stepindex1 = this.stepindex;
        } else {
          this.$message.error("请选择房间");
        }
      },
      // 下发凭证下一步
      stepnext1() {
        if (this.uselist1.length == 0) {
          this.$message.error("请选择凭证");
        } else {
          this.$refs.cardShow.next();
          this.stepindex += 1;
          this.stepindex1 = this.stepindex;
        }
      },
      // 获取对应房间门锁
      getItems() {
        var t = {
          roomIds: [this.currentRow.id],
          lockType: 1
        };
        var data = {
          q: JSON.stringify(t),
        };
        httpPost(data, this.$api.getDeviceItems).then((res) => {
          this.deviceList = res.data.list;
          if (res.data.list.length == 0) {
            this.$message.error("请先绑定门锁");
          }
        });
      },
      // 查询选择的人员凭证
      getOnePersonCerTificate(row){
          var data1 = {
            pageNum: 0,
            pageSize: 0,
            q: JSON.stringify({
              cardId: row.cardId,
              types: "10,11,12,13,14"
            }),
            orderBy: "create_at desc",
          };
          httpGet(data1, this.$api.getCertificates).then((res) => {
            if (res.success) {
            let dataOne=utils.zlib_unzip(res.data)
              var list = []
              dataOne.map(li => {
                li['contentJSON'] = JSON.parse(li.content)
                li['pzname'] = JSON.parse(li.content).pzname
                if(li.type==11){
                  var fdStart=li.pzname.indexOf("蓝牙")
                  if(fdStart!=0){
                    list.push(li)
                  }
                }else{
                  list.push(li)
                }
              })
              list.sort(function(a, b) {
                return a.createAt - b.createAt
              })
              this.uselist2 = list.reverse()
            } else {
              this.$message.error("获取该门锁凭证失败")
            }
          })
      },
      getroomperson() {
        var q = {
          id: this.currentRow.id,
        };
        var data = {
          q: JSON.stringify(q),
        };
        this.uselist2 = []
        httpGet(data, this.$api.getSiteTenant).then((res) => {
          res.data.list.map(li => {
            li['startTimeText'] = moment(li.startTime).format("YYYY-MM-DD HH:mm:ss")
            li['endTimeText'] = moment(li.endTime).format("YYYY-MM-DD HH:mm:ss")
          })
          this.uselist = res.data.list;
        });
      },
      getalllist() {
        var data = {};
        httpGet(data, this.$api.getTree).then((res) => {
          var temp = {},
            arr = []
          res.data.map((item, index) => {
            if (!temp[item.id]) {
              arr.push(item)
              temp[item.id] = true
            }
          })
          var array = uniqueArray(res.data, 'id')
          this.ZNodesTree = ztreeToElementTree(array, {});
          this.zNodes = arr;
          this.addRoom()
        });
      },
      onClick: function(treeNode) {
        // 点击事件
        if (treeNode.children) {
          var str = treeNode.children[0].acreage || "";
          if (str == "" || str == null) {
            this.fatherMethod(treeNode.pid);
          } else {
            this.fatherMethod(treeNode.id);
          }
        } else {
          this.fatherMethod(treeNode.id);
        }
      },
      fatherMethod(id) {
        var q = {
          ancestor: id,
          isRoom: 1
        };
        var data = {
          q: JSON.stringify(q),
        };
        httpGet(data, this.$api.getSiteList).then((res) => {
          var tableData = [],
            tableData1 = [],
            tableData2 = [];
          res.data.list.list.map((li, index) => {
            li.check = false;
            tableData.push(li);
            var name = utils.findIndexArray(this.ZNodesTree, li.id, [])
            var path = ''
            if (name) {
              path = name.join('/')
            }
            li['path'] = path
            if (li.id == id) {
              this.tableData.splice(index, 1);
            } else if (li.count == 0) {
              tableData2.push(li);
            } else if (li.count > 0) {
              tableData1.push(li);
            }
          });
          this.tableData = tableData;
          this.pageTotal = tableData.length;
          this.tableData1 = tableData1;
          this.tableData2 = tableData2;
        });
      },
      handleClick(tab, event) {
        if (tab.name == "second") {
          this.pageTotal = this.tableData1.length;
        } else if (tab.name == "third") {
          this.pageTotal = this.tableData2.length;
        }
      },
      handleChange(value) {
        console.log(value);
      },
      // 触发搜索按钮
      handleSearch() {
        this.$set(this.query, "pageIndex", 1);
        this.getData();
      },
      // 删除操作
      handleDelete(index) {
        // 二次确认删除
        this.$confirm("确定要删除吗？", "提示", {
            type: "warning",
          })
          .then(() => {
            this.$message.success("删除成功");
            this.tableData.splice(index, 1);
          })
          .catch(() => {});
      },
      // 多选操作
      handleCurrentChange(val) {
        this.currentRow = val;
      },
      handleCurrentChange1(val) {
        // this.currentRow = val;
      },
      delAllSelection() {
        const length = this.multipleSelection.length;
        let str = "";
        this.delList = this.delList.concat(this.multipleSelection);
        for (let i = 0; i < length; i++) {
          str += this.multipleSelection[i].name + " ";
        }
        this.$message.error(`删除了${str}`);
        this.multipleSelection = [];
      },
      // 编辑操作
      handleEdit(index, row) {
        this.idx = index;
        this.form = row;
        this.editVisible = true;
      },
      getRandomNumber(n) {
        var arr = new Array(n); //用于存放随机数
        var randomNumber = ""; //存放随机数
        for (var i = 0; i < arr.length; i++)
          arr[i] = parseInt(Math.random() * 10);
        var flag = 0;
        for (var i = 0; i < arr.length - 1; i++) {
          for (var j = i + 1; j < arr.length; j++) {
            if (arr[i] == arr[j]) {
              flag = 1;
              break;
            }
          }
          if (flag) break;
        }
        for (var i = 0; i < arr.length; i++) {
          randomNumber += arr[i];
        }
        return randomNumber;
      },
      // 添加人员绑定
      handleEditperson() {
        if (this.value2[0] == '' || this.value2[1] == '') {
          this.$message.error("请选择入住和退租时间")
          return false;
        }
        var phone = this.personInfo.phone
        if (this.deviceList.length == 0) {
          this.$message.error("请先绑定设备");
          return false;
        } else {
          var result = this.uselist.some(item=> item.cardId==this.personInfo.id)
          if (!result) {
            if (this.personInfo.name == "" || this.personInfo.type === "" || this
              .personInfo.number == "" || this.personInfo.phone == "" || this.personInfo.enterpriseId == "") {
              this.$message.error("请填写完整信息");
            } else {
              if (this.personselect) {
                var data = [{
                  cardId: this.personInfo.id,
                  remark: this.personInfo.remarks,
                  siteId: this.currentRow.id,
                  startTime: this.value2[0],
                  endTime: this.value2[1]
                }, ];
                var str = {
                  imei: this.deviceList[0].imei,
                  deviceNum: this.deviceList[0].deviceNum,
                  userTelephone: JSON.parse(this.personInfo.info).userTelephone,
                  // cardId:this.personInfo.cardId,
                  userPassword: JSON.parse(this.personInfo.info).userPassword,
                  password: JSON.parse(this.personInfo.info).userPassword,
                  operateMode: 26,
                  order: 6226,
                  passwordStartTime: "20210813010101",
                  passwordEndTime: "20680813010101",
                  is: false,
                  cardName: this.personInfo.name,
                  roomName: this.deviceList[0].roomName
                };
                this.devperson.push(str);
                if (this.deviceList[0].manufactureId == 201||this.deviceList[0].manufactureId == 221) {
                  var data1 = {
                    lockerId: this.deviceList[0].deviceNum,
                    imei: this.deviceList[0].imei,
                    lockerUserId: JSON.parse(this.personInfo.info).userPassword,
                    keyId: JSON.parse(this.personInfo.info).userPassword,
                    role: 0,
                    action: 1,
                    order: 6226,
                    cardName: this.personInfo.name,
                    roomName: this.deviceList[0].roomName
                  };
                  httpPost(data1, this.$api.ZGduserOperation).then(res => {
                    if (res.success) {
                      var locakUserdata = {
                        deviceNum: this.deviceList[0].deviceNum,
                        imei: this.deviceList[0].imei,
                        cardId: this.personInfo.id,
                        content: JSON.stringify(
                          data1
                        ), //operateMode:NFC-10、把人员添加到凭证-1
                        type: 26,
                        serial: res.data.serialNumber,
                        startTime: this.value2[0].getTime() / 1000,
                        endTime: this.value2[1].getTime() / 1000,
                      }
                      utils.sendLockUser(locakUserdata, (callbackLOCK) => {

                      })
                      this.$message.success("添加成功");
                      httpPost(data, this.$api.bindCard).then((res2) => {
                        this.getroomperson();
                      });
                    } else {
                      this.$message.error(res.msg);
                    }
                  })
                } else if (this.deviceList[0].manufactureId == 101) {
                  httpPost(str, this.$api.getDeviceOperateUserInfo).then((res2) => {
                    if (res2.success) {
                      var locakUserdata = {
                        deviceNum: this.deviceList[0].deviceNum,
                        imei: this.deviceList[0].imei,
                        cardId: this.personInfo.id,
                        content: JSON.stringify(
                          str
                        ), //operateMode:NFC-10、把人员添加到凭证-1
                        type: 26,
                        serial: res2.data.serialNumber,
                        startTime: this.value2[0].getTime() / 1000,
                        endTime: this.value2[1].getTime() / 1000,
                      }
                      utils.sendLockUser(locakUserdata, (callbackLOCK) => {

                      })
                      this.$message.success("添加成功");
                      httpPost(data, this.$api.bindCard).then((res) => {
                        this.getroomperson();
                      });
                    } else {
                      this.$message.error("添加失败");
                    }
                  });
                }
              } else {
                var infostr = {
                  userTelephone: phone,
                  userPassword: phone.substring(phone.length - 6, phone.length),
                  userId: phone.substring(phone.length - 6, phone.length),
                  keyId: phone.substring(phone.length - 6, phone.length)
                };
                var data2 = {
                  card: this.personInfo.card,
                  cardState: 1,
                  name: this.personInfo.name,
                  number: this.personInfo.number,
                  info: JSON.stringify(infostr),
                  phone: this.personInfo.phone,
                  // enterpriseId: this.personInfo.enterpriseId,
                  sex: parseInt(this.personInfo.sex),
                  type: this.personInfo.type,
                };
                var str1 = {
                  imei: this.deviceList[0].imei,
                  deviceNum: this.deviceList[0].deviceNum,
                  userTelephone: phone,
                  userPassword: phone.substring(phone.length - 6, phone.length),
                  password: phone.substring(phone.length - 6, phone.length),
                  operateMode: 26,
                  order: 6226,
                  passwordStartTime: "20210813010101",
                  passwordEndTime: "20680813010101",
                  is: false,
                  cardName: this.personInfo.name,
                  roomName: this.deviceList[0].roomName
                };
                if (this.deviceList[0].manufactureId == 201||this.deviceList[0].manufactureId == 221) {
                  var data1 = {
                    lockerId: this.deviceList[0].deviceNum,
                    imei: this.deviceList[0].imei,
                    lockerUserId: phone.substring(phone.length - 6, phone.length),
                    keyId: phone.substring(phone.length - 6, phone.length),
                    role: 0,
                    action: 1,
                    order: 6226,
                    cardName: this.personInfo.name,
                    roomName: this.deviceList[0].roomName
                  };
                  httpPost(data1, this.$api.ZGduserOperation).then(res => {
                    if (res.success) {
                      this.$message.success("添加成功");
                      httpPost(data2, this.$api.addCard).then((res3) => {
                        this.editVisiblelist = false;
                        var locakUserdata = {
                          deviceNum: this.deviceList[0].deviceNum,
                          imei: this.deviceList[0].imei,
                          cardId: res3.data,
                          content: JSON.stringify(
                            data1
                          ), //operateMode:NFC-10、把人员添加到凭证-1
                          type: 26,
                          serial: res.data.serialNumber,
                          startTime: this.value2[0].getTime() / 1000,
                          endTime: this.value2[1].getTime() / 1000,
                        }
                        let dataprise = []
                        this.checkEnterpriseNode.map(li => {
                          var obj = {
                            itemId: res3.data,
                            orderId: li.value,
                          }
                          dataprise.push(obj)
                        })
                        console.log(dataprise)
                        if (dataprise.length > 0) {
                          httpPost(dataprise, this.$api.personBindEnterprise).then(res => {

                          })
                        }
                        utils.sendLockUser(locakUserdata, (callbackLOCK) => {

                        })
                        this.getlist(res3.data);
                      });
                    } else {
                      this.$message.error("添加失败");
                    }
                  })
                } else {
                  httpPost(str1, this.$api.getDeviceOperateUserInfo).then(
                    (res2) => {
                      if (res2.success) {
                        this.$message.success("下发成功");
                        httpPost(data2, this.$api.addCard).then((res) => {
                          var locakUserdata = {
                            deviceNum: this.deviceList[0].deviceNum,
                            imei: this.deviceList[0].imei,
                            cardId: res.data,
                            content: JSON.stringify(
                              str1
                            ), //operateMode:NFC-10、把人员添加到凭证-1
                            type: 26,
                            serial: res2.data.serialNumber,
                            startTime: this.value2[0].getTime() / 1000,
                            endTime: this.value2[1].getTime() / 1000,
                          }
                          let dataprise = []
                          this.checkEnterpriseNode.map(li => {
                            var obj = {
                              itemId: res.data,
                              orderId: li.value,
                            }
                            dataprise.push(obj)
                          })
                          if (dataprise.length > 0) {
                            httpPost(dataprise, this.$api.personBindEnterprise).then(res => {

                            })
                          }
                          utils.sendLockUser(locakUserdata, (callbackLOCK) => {

                          })
                          this.editVisiblelist = false;
                          this.getlist(res.data);
                        });
                      } else {
                        this.$message.error("添加失败");
                      }
                    }
                  );
                }
              }
            }
          }else{
            this.$message.error("此人员已存在");
          }
        }
      },
      getlist(cardId) {
        var q = {
          id: cardId,
        };
        var data = {
          pageNum: 1,
          pageSize: 10,
          q: JSON.stringify(q),
        };
        httpPost(data, this.$api.getlistNum).then((res) => {
          var data = [{
            cardId: res.data.list[0].id,
            remark: this.personInfo.remarks,
            siteId: this.currentRow.id,
            startTime: this.value2[0],
            endTime: this.value2[1]
          }, ];
          httpPost(data, this.$api.bindCard).then((res) => {
            this.getroomperson();
          });
        });
      },
      // 删除人员
      handleDeleteperson(index) {
        // 二次确认删除
        this.$confirm("确定要删除吗？", "提示", {
            type: "warning",
          })
          .then(() => {
            this.$message.success("删除成功");
            this.uselist.splice(index, 1);
          })
          .catch(() => {});
      },
      // 保存编辑
      saveEdit() {
        this.editVisible = false;
        this.$message.success(`修改第 ${this.idx + 1} 行成功`);
        this.$set(this.tableData, this.idx, this.form);
      },
      // 分页导航
      handlePageChange(val) {
        this.$set(this.query, "pageIndex", val);
      },
    },
  };
</script>

<style scoped>
  .steps {
    background: rgba(236, 239, 255, 0.8);
    display: flex;
    flex-wrap: wrap;
    height: 44px;
    width: 100%;
    margin-bottom: 40px;
    box-sizing: border-box;
    align-items: center;
    text-align: center;
    justify-content: center;
    position: relative;
  }

  .selectoptionClass {
    position: absolute;
    left: 30px;
  }

  .step {
    cursor: pointer;
    width: 25%;
    position: relative;
    height: 100%;
    line-height: 44px;
  }

  .steps .l1 {
    width: 22px;
    height: 22px;
    margin-right: 9px;
    vertical-align: middle;
  }

  .steps span {
    vertical-align: middle;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 700;
    color: #666;
  }

  .container {
    position: relative;
    padding: 15px;
  }

  .totalPosition {
    position: absolute;
    bottom: 0;
    left: 20px;
  }

  .steps .r2 {
    width: 28px;
    height: 44px;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
  }

  .steps .stepcolor {
    color: #8078ea;
  }

  .handle-box {
    margin-bottom: 10px;
    position: relative;
  }

  .nextstep {
    position: absolute;
    right: 0;
    top: 0;
    padding: 6px 15px;
    background: #6971ab;
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
  }

  .nextstep1 {
    position: absolute;
    right: 0;
    top: 0;
    /* padding: 6px 15px; */
    color: #444;
    font-size: 14px;
    cursor: pointer;
  }

  .nextstep1 i {
    font-size: 20px;
    vertical-align: middle;
  }

  .nextstep1 span {
    vertical-align: middle;
  }

  .handle-select {
    width: 120px;
  }

  .handle-input {
    width: 300px;
    display: inline-block;
  }

  .table {
    width: 100%;
    font-size: 14px;
  }

  .red {
    color: #ff0000;
  }

  .mr10 {
    margin-right: 10px;
  }

  .mright {
    margin-right: 10px;
    display: inline-block;
  }

  .table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
  }

  .elrow {
    margin-bottom: 20px;
  }

  .grid-content {
    position: relative;
    z-index: 99;
    display: flex;
    align-items: center;
    overflow: hidden;
    justify-content: space-around;
    -webkit-box-align: center;
  }

  /* 加的 */
  .colposition {
    display: flex;
    align-items: center;
    position: relative;
    box-sizing: border-box;
    border: 2px solid hsla(0, 0%, 100%, 0.2);
    /* width: 100%; */
  }

  .grid-cont-right {
    flex: 1;
    text-align: left;
    padding-left: 20px;
    box-sizing: border-box;
    font-size: 16px;
    color: #666;
    font-size: 14px;
    line-height: 32px;
  }

  .grid-num {
    font-size: 24px;
  }

  .grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
  }

  .grid-con-1 {
    position: relative;
  }

  .grid-con-1::before {
    position: absolute;
    content: "";
    top: 50%;
    right: 0;
    width: 1px;
    transform: translateY(-50%);
    height: 70px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    border-left: 1px dashed #666;
  }

  .grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
  }

  .grid-con-1 .grid-num {
    /* color: rgb(45, 140, 240); */
    color: #333;
  }

  .grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
  }

  .grid-con-2 .grid-num {
    /* color: rgb(45, 140, 240); */
    color: #333;
  }

  .grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
  }

  .grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
  }

  .nulldiv {
    text-align: center;
    color: #999;
    font-size: 16px;
    font-weight: 400;
  }

  .nullimg {
    margin: 30px auto;
    max-width: 300px;
  }

  .el-card__body {
    padding: 0;
  }

  .cardbg {
    /* height: 800px; */
    /* overflow-y: scroll; */
    background: #fff;
    /* margin: 20px; */
    padding: 0;
  }

  .pagehead {
    position: relative;
  }

  .pagehead .fjry {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #333;
    position: relative;
    margin-bottom: 20px;
  }

  .pagehead .fjry::before {
    content: "";
    width: 3px;
    height: 18px;
    position: absolute;
    left: -30px;
    top: 50%;
    transform: translateY(-50%);
    background: #8078ea;
    border-radius: 1px;
    margin: 0 10px 0 18px;
  }

  .secondcontent {
    border-top: 1px solid#EEE;
    padding-top: 20px;
  }

  .secondcontent .el-form-item {
    width: 24%;
  }

  .secondcontent .w250 {
    width: 250px;
  }

  .bottomcontent {
    margin-top: 20px;
  }

  .bottomcontent .el-table th>.cell {
    text-align: center;
    font-size: 14px;
  }

  .bottomcontent>>>.el-table .cell {
    text-align: center;
    font-size: 14px;
  }

  .bottomcontent>>>.el-table .el-table__row .el-table__cell {
    padding: 10px 0;
  }

  .personnelVoucher {
    border-top: 1px solid#EEE;
    padding-top: 20px;
    display: flex;
    flex-wrap: wrap;
    overflow: auto;
    height: 300px;
    align-content: flex-start;
  }

  .person-item {
    width: 270px;
    height: 135px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #91bde4;
    border-top: 5px solid #59adf7;
    margin-right: 31px;
    margin-bottom: 20px;
    position: relative;
  }

  .person-item .item-content {
    height: 100px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .item-content .contentpz {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #333;
    line-height: 25px;
  }

  .item-content .avator {
    width: 60px;
    height: 60px;
    margin: 0 17px 0 22px;
  }

  .item-bottom {
    width: 270px;
    height: 30px;
    background: rgb(89 173 247 / 21%);
    text-align: center;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 700;
    color: rgb(21, 154, 216);
    line-height: 30px;
    border-radius: 0 0 10px 10px;
    cursor: pointer;
  }

  .item-bottom .el-icon-arrow-down {
    margin-left: 9px;
    font-size: 16px;
  }

  .person-item .types {
    position: absolute;
    top: 136px;
    left: 0;
    z-index: 199;
    height: 70px;
    width: 270px;
    border-radius: 0 0 6px 6px;
    -webkit-box-shadow: 0 5px 20px 0 rgb(22 115 255 / 15%);
    box-shadow: 0 5px 20px 0 rgb(22 115 255 / 15%);
    background: #fff;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    padding: 0 20px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    display: none;
    opacity: 0;
    transition: all 0.5s;
  }

  .person-item .types1 {
    display: flex;
    opacity: 1;
  }

  .types .proof-label {
    font-size: 14px;
    color: #606266;
    padding-right: 10px;
  }

  .types .documentType {
    width: 180px;
  }

  .types .el-button {
    margin-left: 10px;
  }

  .fingerprint-proof {
    box-sizing: border-box;
  }

  .fingerprint-type {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .finger-list {
    text-align: left;
    padding: 20px 0;
  }

  .finger-list img {
    height: 80px;
    width: 80px;
  }

  .person-item>>>.el-checkbox {
    position: absolute;
    right: 10px;
    top: 10px;
  }

  .person-item>>>.el-checkbox .el-checkbox__label {
    display: none;
  }

  .person-item>>>.el-checkbox__input .el-checkbox__inner {
    border-radius: 50%;
    width: 18px;
    height: 18px;
  }

  .person-item>>>.el-checkbox__input .el-checkbox__inner::after {
    left: 6px;
    top: 3px;
  }

  .display-center {
    width: 50px;
    height: 696px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
  }

  .personnelVoucher1 {
    height: 620px;
  }

  .display-center img {
    width: 32px;
    height: 106px;
  }

  .device-list {
    width: 100%;
    height: 620px;
    padding: 40px 30px 30px 30px;
    overflow: auto;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }

  .device-list .device-item {
    width: 100%;
    height: 200px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 6px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin-bottom: 19px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    position: relative;
    cursor: pointer;
  }

  .display-center {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
  }

  .device-info1 {
    width: 139px;
    height: 100%;
  }

  .device-info1 img {
    width: 38px;
    height: 128px;
  }

  .device-info2 {
    width: 367px;
  }

  .device-info-title {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #00a397;
    margin: 40px 0 13px;
  }

  .device-info-line {
    width: 100%;
    height: 1px;
    background: #eee;
    margin-bottom: 10px;
  }

  .device-info {
    font-size: 14px;
    font-weight: 400;
    color: #333;
    line-height: 27px;
  }

  .device-info .btnDanger {
    color: #fa5555;
  }

  .device-info .btnSuccess {
    color: #67c23a;
  }

  .room-li {
    display: inline-block;
    vertical-align: top;
    margin-right: 16px;
    margin-bottom: 29px;
    position: relative;
  }

  .room-li .check-img {
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 10px;
    width: 18px;
    height: 18px;
  }

  .h700 {
    height: 600px;
    overflow: auto;
  }

  .room-list {
    height: 500px;
    overflow: auto;
  }

  .selectoptions {
    position: absolute;
    top: 0.2rem;
    right: 1.2rem;
    width: 1.5rem;
    z-index: 99;
  }

  .selectoptions .handle-input {
    width: 1.5rem;
  }

  .widthThree {
    width: 3rem;
  }
</style>
