<!-- 人员绑定 -->
<template>
  <div class="container">
    <!-- 查询 -->
    <tab-search>
      <div slot="from">
        <el-form ref="form" :inline="true" label-width="40px">
          <el-form-item label="姓名">
            <el-input v-model="page.params.userName" clearable></el-input>
          </el-form-item>
          <el-button @click="onSearch()">查询</el-button>
          <!-- <el-button @click="resetSearch()">重置</el-button> -->
        </el-form>
      </div>
      <div slot="btn">
      </div>
    </tab-search>

    <!-- table -->
    <el-table :data="tableData" border style="width: 100%;">
      <el-table-column prop="id" label="序号" width="60" align="center">
        <template slot-scope="scope">
          {{(scope.$index+1)+(page.current-1)*page.size}}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="190" align="center">
        <template slot-scope="scope">
          <el-button @click="Register(scope.row)" type="primary" size="mini">
            {{scope.row.state == 1 ? "审核":"已通过"}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column prop="idNo" label="身份证号码" align="center">
      </el-table-column>
      <el-table-column prop="name" label="真实姓名" align="center">
      </el-table-column>
      <el-table-column prop="mobile" label="手机号码" align="center">
      </el-table-column>
      <el-table-column prop="userName" label="用户名" align="center">
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination :total="page.total" :page.sync="page.current" :limit.sync="page.size" @pagination="pagination" />
    <!-- 审核 -->
    <el-dialog :visible.sync="dialogVisible" :append-to-body="true" width="70%" style="margin-top: -10vh;">
      <div class="zcxx" v-if="showbtn == 1">
        <p>审核单位人员信息</p>
        <el-button type="primary" @click="dialogVisible=false" icon="el-icon-back" style="background-color: #0272c8;margin-right: 10px;">返回</el-button>
        <el-button type="primary" @click="verify(3)" icon="el-icon-circle-close" style="background-color: #d6432b; margin-right: 10px;">
          不通过
        </el-button>
        <el-button type="primary" @click="setinnerVisible" icon="el-icon-circle-check" style="background-color: #198e08;">
          通过
        </el-button>
      </div>
      <table style="font-size: 16px;">
        <tr>
          <td>真实姓名：</td>
          <td>{{verifyInfo.name }}</td>
          <td>身份证号：</td>
          <td>{{verifyInfo.idNo}}</td>
        </tr>
        <tr>
          <td>用户名：</td>
          <td>{{verifyInfo.userName}}</td>
          <td>手机号：</td>
          <td>{{verifyInfo.mobile}}</td>
        </tr>
        <tr style="vertical-align: middle;">
          <td>身份证正面照片：</td>
          <td>
            <eimage :url="verifyInfo.idFrontPhoto"></eimage>
          </td>
          <td>身份证背面照片：</td>
          <td>
            <eimage :url="verifyInfo.idBackPhoto"></eimage>
          </td>
        </tr>
      </table>
      <el-dialog
        width="30%"
        title="绑定部门"
        :visible.sync="innerVisible"
        append-to-body>
          <div class="block">
            <label class="demonstration">请选择部门: </label>
            <el-cascader
              v-model="departmentSid"
              :options="treedata"
              :props="props"></el-cascader>
              <el-button type="primary" size='mini' @click="toNav('deptManage')" style="margin-left: 10px;" circle icon="el-icon-plus"></el-button>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="setDepartment(0)">保存</el-button>
              <el-button  @click="innerVisible = false">返回</el-button>
            </span>
      </el-dialog>
    </el-dialog>
    <el-dialog
      width="30%"
      title="绑定部门"
      :visible.sync="bmdialog"
      append-to-body>
        <div class="block">
          <label class="demonstration">请选择部门: </label>
          <el-cascader
            v-model="departmentSid"
            :options="treedata"
            :props="props"></el-cascader>
            <el-button type="primary" size='mini' @click="toNav('RoleAdminister')" style="margin-left: 10px;" circle icon="el-icon-plus"></el-button>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="setDepartment(1)">保存</el-button>
            <el-button  @click="bmdialog = false">返回</el-button>
          </span>
    </el-dialog>
  </div>
</template>
<script>
  import staffOrg from '@/api/jlcyry/staffOrg/staffOrg.js'
  import departments from '@/api/system/departments/departments.js'
  import { getOrgTree } from '@/api/system/departments/departments.js'
  export default {
    data() {
      return {
        props: {
          value: "sid",
          label: "name",
          children: "orgDepartmentVoList"
        },
        departmentSid: '',
        dialogVisible: false,
        dialogFormVisible: false,
        innerVisible: false,
        bmdialog: false,
        showbtn: true,
        departmentTree: [],
        department: '',
        page: {
          total: 0, // 默认数据总数
          current: 1, // 默认开始页面
          params: {},
          size: 10, // 每页的数据条数
        },
        pageBackup: Object.assign({}, this.page),
        tableData: [],
        treedata: null,
        verifyInfo: { // 审核的表单字段
          "idBackPhoto": "",
          "idFrontPhoto": "",
          "idNo": "",
          "mobile": "",
          "name": "",
          "userName": ""
        },
        verifyBackup: Object.assign({}, this.verifyInfo),
      }
    },
    mounted() {
      this.getverifyList(this.page)
    },
    methods: {
      pagination(val) { // 分页
        this.page.current = val.pageNum
        this.page.size = val.pageSize
        this.getverifyList(this.page)
      },
      getverifyList(data) { // 获取table列表
        staffOrg.staffBingingList(data).then(res => {
          this.tableData = res.data.records
          this.page.total = res.data.total
        })
      },
      onSearch() { //查询
        this.getverifyList(this.page)
      },
      resetSearch() { // 查询重置
        this.page = {
            total: 0, // 默认数据总数
            current: 1, // 默认开始页面
            params: {},
            size: 10, // 每页的数据条数
          },
          this.getverifyList(this.page)
      },
      // 获取审核 表单内容
      Register(row) {
        this.dialogVisible = true
        this.showbtn = row.state
        this.verifyInfo = Object.assign({}, this.verifyBackup)
        let params = { // 请求的参数
          userName: row.userName
        }
        staffOrg.staffOrgBingingDetails(params).then(res => {
          console.log(res)
          this.verifyInfo = res.data
          this.verifyInfo.orgSid = row.orgSid
          this.verifyInfo.staffSid = row.staffSid
        })
      },
      verify(state) { // 审核 —— 通过 ，不通过
        let params = { // 请求的参数
          organizationSid: this.verifyInfo.orgSid,
          staffSid: this.verifyInfo.staffSid,
          state: state,
        }
        staffOrg.verify(params).then(res => {
          console.log(res)
          this.$message({
            type: 'success',
            message: res.msg
          });
          this.getverifyList(this.page)
          this.dialogVisible = false
          this.dialogFormVisible = false
        })
      },
      setDepartment(state){
        console.log(this.departmentSid)
        let params = { // 请求的参数
          departmentSid: this.departmentSid[this.departmentSid.length-1],
          staffSid: this.verifyInfo.staffSid,
        }
        staffOrg.setUpDepartment(params).then(res => {
          this.innerVisible = false
          this.bmdialog = false
          this.$message({
            type: 'success',
            message: res.msg
          });
          if(state == 0){
            this.verify(2)
          }
        })
      },
      setinnerVisible(){
        this.innerVisible = true
        this.getOrgTree()
      },
      setbmdialog(){
        this.bmdialog = true
        this.getOrgTree()
      },
      getOrgTree(){ // 获取部门树形列表
        function treeArr(data){
          if (data.length > 0) {
              for (var i = 0; i < data.length; i++) {
                if(data[i].orgDepartmentVoList.length > 0){
                  treeArr(data[i].orgDepartmentVoList)
                } else {
                  delete data[i].orgDepartmentVoList
                }
              }
          }
        }
        getOrgTree({organizationSid: this.$store.getters.userInfo.orgSid}).then(res => {
          let tree = res.data[0].orgDepartmentVoList
          treeArr(tree)
          this.treedata = tree
        })
      },
      delete(row) { // 删除当前行
        this.$confirm('确认要删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          user.delete().then(res => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      toNav(src){
        this.$router.push("/"+src);
      }
    }
  }
</script>

<style lang="scss" scoped="scoped">
  .el-image {
    width: 180px;
    height: 150px;
  }

  .el-image__preview {
    object-fit: none !important;
  }
  .demonstration{
      padding-right: 10px;
  }
  .zcxx {
    color: #000;
    width: 98%;
    margin: 0px auto 30px;
    background-color: #f7f9fc;
    border: 1px solid #e6e9f0;
    height: 60px;
    line-height: 60px;

    p {
      font-size: 18px;
      float: left;
      margin-top: 0px;
      margin-left: 10px;
      font-weight: bold;
      width: 300px;
    }

    .el-button {
      float: right;
      margin-top: 13px;
      border: none;
      width: 80px;
      padding: 0;
      text-align: center;
      padding-top: 10px;
      padding-bottom: 10px;
    }

  }

  table {
    width: 98%;
    margin: 0 auto;

    tr {
      height: 45px;
      vertical-align: top;
    }

    td:first-child {
      text-align: right;
      width: 20%;
    }

    td:nth-child(2) {
      padding-left: 30px;
      width: 23%;
    }

    td:nth-child(3) {
      text-align: right;
      width: 20%;
    }

    td:nth-child(4) {
      padding-left: 30px;

    }

    span {
      font-size: 14px;
      color: #015bff;
      margin-left: 20px;
    }

    .sfz {
      border: 1px solid #e6e9f0;
      width: 45%;

    }

    #bei {
      width: 21.4%;

    }
  }
</style>
