<!-- 个人注册 -->
<template>
  <div class="container">
    <!-- 查询 -->
    <tab-search>
      <div slot="from">
        <el-form ref="form" :inline="true" label-width="80px">
          <el-form-item label="用户名">
            <el-input v-model="page.params.userName" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="btn">
        <el-button @click="onSearch()">查询</el-button>
        <el-button @click="resetSearch()">重置</el-button>
      </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="180" align="center">
        <template slot-scope="scope">
          <el-button @click="userRegister(scope.row)" type="primary" size="mini">
            {{scope.row.state == 1 ? "审核":"已审核"}}
          </el-button>
          <el-button @click.stop="Rowdelete(scope.row)" type="danger" size="mini">
            删除
          </el-button>
        </template>
      </el-table-column>
      <el-table-column prop="userName" label="用户名" align="center">
      </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="createTime" 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="handleVerify(3)" icon="el-icon-circle-close" style="background-color: #d6432b; margin-right: 10px;">不通过</el-button>
        <el-button type="primary" @click="handleVerify(2)" icon="el-icon-circle-check" style="background-color: #198e08;">通过</el-button>
      </div>
      <table style="font-size: 18px;">
        <tr>
          <td>真实姓名：</td>
          <td>{{userInfo.name }}</td>
          <td>身份证号：</td>
          <td>{{userInfo.idNo}}</td>
        </tr>
        <tr>
          <td>用户名：</td>
          <td>{{userInfo.userName}}</td>
          <td>手机号：</td>
          <td>{{userInfo.mobile}}</td>
        </tr>
        <tr style="vertical-align: middle;">
          <td>身份证正面照片：</td>
          <td>
            <eimage :url="userInfo.idFrontPhoto"></eimage>
          </td>
          <td>身份证背面照片：</td>
          <td>
            <eimage :url="userInfo.idBackPhoto"></eimage>
          </td>
        </tr>
      </table>
    </el-dialog>
    <remarks :dialogBack.sync="dialogBack" @verifyBack="verifyBack"></remarks>
  </div>
</template>
<script>
  import remarks from './remarks/index.vue'
  import user from '@/api/system/user/user1.js'
  export default {
    components:{remarks},
    data() {
      return {
        dialogVisible: false,
        showbtn: true,
        dialogBack: false,
        page: {
          total: 20, // 默认数据总数
          current: 1, // 默认开始页面
          params: { // 查询的参数
            state: '',
            userName: '',
            state: 1
          },
          size: 10, // 每页的数据条数
        },
        pageBackup: Object.assign({}, this.page),
        tableData: [], // tabel 数据
        userInfo:{ // 审核的表单字段
          "idBackPhoto": "",
          "idFrontPhoto": "",
          "idNo": "",
          "mobile": "",
          "name": "",
          "userName": ""
        },
        userBackup: Object.assign({}, this.userInfo),
      }
    },
    mounted() {
      this.getverifyList(this.page)
    },
    methods: {
      pagination(val) { // 分页
        this.page.current = val.pageNum
        this.page.size = val.pageSize
        this.getverifyList(this.page)
      },
      getverifyList(data){ // 获取列表
        user.verifyList(data).then(res => {
          console.log(res)
          this.tableData = res.data.records
          this.page.total = res.data.total
        })
      },
      onSearch() { //查询
        this.getverifyList(this.page)
      },
      resetSearch(){
        this.page = {
          total: 20, // 默认数据总数
          current: 1, // 默认开始页面
          params: { // 查询的参数
            state: '',
            userName: '',
            state: 1
          },
          size: 10, // 每页的数据条数
        }
        this.getverifyList(this.page)
      },
      userRegister(row){ // 获取审核表单内容
        console.log(row.userName)
        this.dialogVisible = true
        this.showbtn = row.state
        this.userInfo = Object.assign({}, this.userBackup)
        let params = { // 请求的参数
          userName: row.userName
        }
        user.userRegisterDetails(params).then(res => {
          console.log(res)
          this.userInfo = res.data
        })
      },
      verify(state){ // 审核的通过不通过

      },
      // 审核通过
      handleVerify(state){
        if(state == 2){
          let params ={ // 请求的参数
            state: state,
            remarks:'',
            userName: this.userInfo.userName,
          }
          user.verify(params).then(res => {
            this.getverifyList(this.page)
            this.$message({
              type: 'success',
              message: res.msg
            });
            this.dialogVisible = false
          })
        }else{
          this.dialogBack = true
        }
      },
      // 审核不通过
      verifyBack(remarks){
        let params ={ // 请求的参数
          state: 3,
          remarks:remarks,
          userName: this.userInfo.userName,
        }
        user.verify(params).then(res => {
          this.getverifyList(this.page)
          this.$message({
            type: 'success',
            message: res.msg
          });
          this.dialogBack = false
          this.dialogVisible = false
        })
      },
      Rowdelete(row) { // 删除当前行
        this.$confirm('确认要删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          user.userNameDelete({userName: row.userName}).then(res => {
            this.getverifyList(this.page)
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
    },
  }
</script>

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