<!-- 人脸库 -->
<template>
  <div class="app-container faceLibrary">
    <div class="page-container faceLibraryPage">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="请输入"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="userType">
            <el-select v-model="queryParams.userType" placeholder="请选择类型" style="width: 200px">
              <el-option
                v-for="dict in optionList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-select v-model="queryParams.deptId" placeholder="请选择学院" style="width: 200px">
              <el-option
                v-for="dict in deptOptionList"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              />
            </el-select>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <div class="user-max-big-box scrollbar-box">
          <img class="null-img" v-if="!dataList[0]" src="@/assets/ZDimages/basicsModules/null-data-1.png">
          <div class="for-user-max-big-box"
               v-for="(item,index) in dataList">
            <div class="for-user-title-box">
              <p class="for-user-name-p">{{item.userName}}</p>
              <div class="for-text-box">
                <p>{{item.userType==1?'工号':(item.userType==2?'学号':'')}}：{{item.account}}</p>
                <p v-if="item.userType == 1">{{item.userState?'在职':'离职'}}</p>
                <p v-if="item.userType == 2">{{item.userState?'在读':'离校'}}</p>
              </div>
            </div>
            <div class="for-user-img-box">
              <img v-if="item.faceImg" :src="item.faceImg">
              <p v-else>未上传</p>
            </div>
            <!--<p class="for-user-time-p">{{parseTime(item.createTime,"{y}-{m}-{d} {h}:{i}")}}</p>-->
            <div class="for-user-button-box">
              <p @click="tableButton(item,1)">查看</p>
              <p @click="tableButton(item,2)" v-hasPermiRouter="['system:face:edit']">编辑</p>
            </div>
          </div>
        </div>
        <!--<el-table class="table-box" v-loading="loading" border :data="dataList">-->
          <!--<el-table-column label="用户名" prop="userName"  show-overflow-tooltip/>-->
          <!--<el-table-column label="工号/学号" prop="account" width="200" show-overflow-tooltip/>-->
          <!--<el-table-column label="类型" prop="userType" width="200" show-overflow-tooltip>-->
            <!--<template slot-scope="scope">-->
              <!--<span>{{scope.row.userType == 1?'老师':(scope.row.userType == 2?'学生':'')}}</span>-->
            <!--</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column label="人脸照片" prop="faceImg" width="200" show-overflow-tooltip>-->
            <!--<template slot-scope="scope">-->
              <!--<span style="cursor:pointer" :class="scope.row.faceImg?'lockImgSpan':''">{{scope.row.faceImg?'查看':'未上传'}}</span>-->
            <!--</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column label="状态" prop="userState" width="200" show-overflow-tooltip>-->
            <!--<template slot-scope="scope">-->
              <!--<span v-if="scope.row.userType == 1">{{scope.row.userState?'在职':'离职'}}</span>-->
              <!--<span v-if="scope.row.userType == 2">{{scope.row.userState?'在读':'离校'}}</span>-->
            <!--</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column label="创建时间" prop="createTime" width="200" show-overflow-tooltip>-->
            <!--<template slot-scope="scope">-->
              <!--<span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>-->
            <!--</template>-->
          <!--</el-table-column>-->
          <!--<el-table-column label="操作" width="120" show-overflow-tooltip v-if="tableButtonType">-->
            <!--<template slot-scope="scope">-->
              <!--<div class="table-button-box">-->
                <!--<p class="table-button-null"></p>-->
                <!--<p class="table-button-p"-->
                   <!--@click="tableButton(scope.row)"-->
                   <!--v-hasPermiRouter="['system:face:edit']"-->
                <!--&gt;编辑</p>-->
                <!--<p class="table-button-null"></p>-->
              <!--</div>-->
            <!--</template>-->
          <!--</el-table-column>-->
        <!--</el-table>-->
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <fullScreenView :fullScreenViewProps="fullScreenViewProps" ref="fullScreenView"></fullScreenView>
    <!--上传照片-->
    <el-dialog class="up-img-box" title="上传照片" :visible.sync="upFaceOpen" width="600px" append-to-body :close-on-click-modal="false">
      <div style="height:600px;width:580px;overflow: hidden">
        <el-upload
          ref="faceUpLoad"
          class="position-button"
          :action="uploadImgUrl"
          :data="upImportData"
          :show-file-list="false"
          :auto-upload="false"
          :on-change="faceChange"
          accept="image/jpeg,image/jpg,image/gif,image/png"
          :on-success="(res)=>handleAvatarSuccess(res)"
          :headers="headers"
          :before-upload="beforeAvatarUpload">
          <div v-if="!upFaceUrl" style="width:300px;height:300px;border: 1px dashed #E0E0E0;cursor: pointer;margin:120px 130px 0;">
            <p style="text-align: center;color:#999;font-weight:500;font-size: 20px;line-height:300px;margin:0;">+</p>
          </div>
          <div v-if="upFaceUrl" class="scrollbar-box" style="width:580px;margin:0 auto;max-height:700px;overflow-y: scroll">
            <img :src="upFaceUrl" style="width:540px;border: 1px dashed #E0E0E0;cursor: pointer;margin:0 auto 0;">
          </div>
        </el-upload>
      </div>
      <div slot="footer" class="dialog-footer dialog-footer-box">
        <p class="dialog-footer-button-null"></p >
        <p class="dialog-footer-button-info" @click="dialogOff">取消</p >
        <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p >
        <p class="dialog-footer-button-null"></p >
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import { getToken } from "@/utils/auth";
  import { getDeptDropList } from "@/api/commonality/permission";
  import { systemUserFaceList,systemUserFaceUpdate } from "@/api/systemManagement/index";
  import fullScreenView from "@/components/fullScreenView/fullScreenView.vue";
  export default {
    name: 'index',
    components: {
      fullScreenView
    },
    data () {
      return {
        uploadImgUrl: window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + "/system/user/face/update", // 上传的图片服务器地址
        headers: {
          Authorization: getToken(),
        },
        upImportData:{
          userId:null,
        },
        tableButtonType:this.hasPermiDom(['system:face:edit',]),
        //页面遮罩
        loading:false,
        //下拉列表数据
        optionList:[{value:'1',label:'老师'},{value:'2',label:'学生'}],
        deptOptionList:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
          userType:null,
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
        //图片预览功能
        fullScreenViewProps:[],
        //上传人脸
        upFaceOpen:false,
        upFaceUrl:null,
        upFaceType:false,
      }
    },
    created () {

    },
    mounted () {
      this.getDeptDropList();
      this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:"",
          userType :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        systemUserFaceList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(row,type){
        let self = this;
        if(row.faceImg && type == 1){
          this.$set(this,'fullScreenViewProps',[row.faceImg]);
          this.$refs['fullScreenView'].initialize();
        }else{
          this.$set(this.upImportData,'userId',row.userId)
          this.$set(this,'upFaceUrl',row.faceImg?row.faceImg:'')
          this.$set(this,'upFaceType',false)
          this.$set(this,'upFaceOpen',true);
        }
      },
      //关闭
      dialogOff(){
        this.$set(this,'upFaceOpen',false);
      },
      //提交
      dialogSubmit(){
        if(!this.upFaceType){
          this.msgError('请上传新的人脸照片')
          return
        }
        this.$refs.faceUpLoad.submit();
      },
      //上传
      handleAvatarSuccess(res, type) {
        if(res.code == 200){
          this.$set(this,'upFaceOpen',false);
          this.$set(this,'upFaceUrl',null);
          this.$set(this,'upFaceType',false);
          this.msgSuccess(res.message)
          this.getList();
          this.$forceUpdate()
        }else{
          this.msgError(res.message)
        }
      },
      beforeAvatarUpload(file) {
        let type = false;
        if (file.type == 'image/png' || file.type == 'image/jpeg' || file.type == 'image/jpg' || file.type == 'image/gif') {
          type = true;
        }else{
          this.msgError('只能上传png/jpeg/jpg/gif格式图片');
          type = false;
        }
        return type;
      },
      //照片选择
      faceChange(val){
        const windowURL = window.URL || window.webkitURL;
        this.upFaceUrl = windowURL.createObjectURL(val.raw)
        this.$set(this,'upFaceType',true)
      },
      /** 查询学院列表 */
      getDeptDropList() {
        getDeptDropList({deptName:"",level:2,deptType:1}).then(response => {
          this.$set(this, 'deptOptionList', response.data)
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .page-content-box{
    padding:20px 0;
  }
  .faceLibrary{
    .faceLibraryPage{
      .user-max-big-box{
        flex:1;
        .null-img{
          display: block;
          width:200px;
          margin:140px auto;
        }
        .for-user-max-big-box{
          display: inline-block;
          overflow: hidden;
          border:1px solid #0183FA;
          border-radius:8px;
          margin:0 0 20px 20px;
          .for-user-title-box{
            background-color: #0183FA;
            .for-user-name-p{
              color:#fff;
              padding:10px 20px 0;
              line-height:20px;
              font-size:16px;
              text-align: center;
            }
            .for-text-box{
              display: flex;
              margin-bottom:20px;
              padding:6px 0 10px 0;
              p{
                padding:0 20px;
                line-height:20px;
                font-size:14px;
                color:#fff;
              }
              p:nth-child(1){
                flex:1;
              }
              p:nth-child(2){
                text-align: right;
              }
            }
          }
          .for-user-time-p{
            color:#777;
            padding:0 20px;
            line-height:25px;
            font-size:14px;
            text-align: center;
            /*margin-bottom:4px;*/
          }
          .for-user-img-box{
            margin:0 20px 20px;
            p{
              width:250px;
              line-height:300px;
              text-align: center;
              /*border:1px solid #dedede;*/
              border-radius:4px;
              color:#999;
            }
            img{
              display: block;
              width:198px;
              height:198px;
              /*border:1px solid #dedede;*/
              border-radius:4px;
              overflow: hidden;
            }
          }
          .for-user-button-box{
            display: flex;
            border-top:1px solid #0183FA;
            p{
              flex:1;
              text-align: center;
              line-height:30px;
              font-size:14px;
              cursor: pointer;
              color: #0183FA;
            }
            p:hover{
              background: #0183FA;
              color: #fff;
            }
          }
        }
      }
      .lockImgSpan{
        color:#0183FA;
      }
    }
  }
</style>
