<template>
	<div class="container">
    <div class="tab-header">
      <el-form ref="form" :inline="true" :model="form" label-width="80px">
        <el-row :gutter="20">
          <el-col :span="16">
            <el-form-item label="单位名称">
              <el-input v-model="page.params.organizationName"></el-input>
            </el-form-item>
            <el-form-item label="用户名">
              <el-input v-model="page.params.userName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item style="float: right;">
              <el-button @click="onSearch()">查询</el-button>
              <el-button @click="resetSearch()">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

		<!-- table -->
    <div class="table-describe clearfix">
      <h4 style="">用户信息列表</h4>
      <pagination class="pagesize" layout="sizes" :total="page.total" :page.sync="page.current" :limit.sync="page.size" @pagination="pagination"/>
    </div>
		<el-table :data="tableData" border style="width: 100%;">
			<el-table-column label="序号" width="50px" type="index" align="center">
			</el-table-column>
			<el-table-column label="操作" width="200px" align="center">
				<template slot-scope="scope">
					<!-- <el-button @click="getrolelist(scope.row)" type="primary" size="mini"
          :disabled="!scope.row.organizationName">
						设置角色
					</el-button> -->
					<el-button @click="initPwd(scope.row)" type="primary" size="mini">
						初始化密码
					</el-button>
					<el-button @click="delUser(scope.row)" type="danger" size="mini">
						删除
					</el-button>
				</template>
			</el-table-column>
			<el-table-column prop="userName" label="用户名" align="center">
        <template slot-scope="scope">
          <span class="tablerow-click" @click="userinfo(scope.row)">{{scope.row.userName}}</span>
        </template>
			</el-table-column>
			<el-table-column prop="idNo" label="身份证号码" align="center">
			</el-table-column>
			<el-table-column prop="name" label="真实姓名" width="120px" align="center">
			</el-table-column>
			<el-table-column prop="mobile" label="手机号码" align="center" width="140px">
			</el-table-column>
      <!-- <el-table-column prop="role" label="角色" align="center" width="140px">
      </el-table-column> -->
      <el-table-column prop="organizationName" label="单位名称" align="center">
        <template slot-scope="scope">
          <span class="tablerow-click" @click="orgInfo(scope.row)">{{scope.row.organizationName}}</span>
        </template>
      </el-table-column>
		</el-table>
		<pagination :total="page.total" :page.sync="page.current" :limit.sync="page.size" @pagination="pagination"/>

    <el-dialog title="用户信息" :visible.sync="showuserInfo" width="70%" >
    	<table class="tishi" cellspacing="0">
    		<tr>
    			<td style="border-bottom: none; border-right: none;">真实姓名</td>
    			<td style="border-bottom: none;">
            {{userInfoFrom.name}}
    			</td>
          <td style="border-bottom: none; border-right: none;">身份证号码</td>
          <td style="border-bottom: none;">
          	{{userInfoFrom.idNo}}
          </td>
    		</tr>
    		<tr>
    			<td style="border-bottom: none; border-right: none;">用户名</td>
    			<td style="border-bottom: none;">
    				{{userInfoFrom.userName}}
    			</td>
    		  <td style="border-bottom: none; border-right: none;">手机号码</td>
    		  <td style="border-bottom: none;">
    		  	{{userInfoFrom.mobile}}
    		  </td>
    		</tr>
        <tr>
        	<td style="border-right: none;">身份证正面照片</td>
        	<td>
        		<eimage :url="userInfoFrom.idFrontPhoto"></eimage>
        	</td>
          <td style="border-right: none;">身份证背面照片</td>
          <td>
          	<eimage :url="userInfoFrom.idBackPhoto"></eimage>
          </td>
        </tr>
    	</table>
    </el-dialog>


    <el-dialog title="" :visible.sync="showOrgInfo" width="70%" >
      <lockorginfo :orgInfo="OrgInfoFrom"></lockorginfo>
    </el-dialog>


    <el-dialog title="设置角色" :visible.sync="roledialog" width="40%">
      <table class="e-table" cellspacing="0">
      	<tr>
      		<td style="border-bottom: none; border-right: none;">用户名</td>
      		<td style="border-bottom: none;">
      			{{rolefrom.userName }}
      		</td>
      	</tr>
      	<tr>
      		<td style="border-right: none;">角色</td>
      		<td>
      			 <el-select v-model="rolefrom.roleSid" placeholder="请选择">
      			    <el-option
      			      v-for="item in rolelist"
      			      :key="item.sid"
      			      :label="item.roleName"
      			      :value="item.sid">
      			    </el-option>
      			  </el-select>
      		</td>
      	</tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveUserRole()">保 存</el-button>
        <el-button @click="roledialog = false">关 闭</el-button>
      </span>
    </el-dialog>
	</div>
</template>

<script>
  import { userListByAdmin, verifyList, initPwd, delUser, getUserINfo, getOrgINfo, initUserRole, saveUserRole } from '@/api/system/user/Auser.js'
  import { roleList } from '@/api/system/Role/roleManage.js'

  import lockorginfo from './components/orgInfo.vue'
 	export default {
    components:{ lockorginfo },
		data() {
			return {
        imageUrl: '',
        dialogImageUrl: '',
        showuserInfo: false,
        showOrgInfo: false,
        dialogVisible: false,
        roledialog: false,
				form: {},
				page: {
					total: 0, // 默认数据总数
					current: 1, // 默认开始页面
					size: 10, // 每页的数据条数
          params: {
          	isAdmin: '',
            organizationName: '',
          	state: 2,
          	userName: ''
          }
				},
        pageBackup: Object.assign({}, this.page),
				tableData: [],
        userInfoFrom: {},
        OrgInfoFrom: {},
        rolelist: [],
        rolefrom: {
          roleSid: '',
          userSid: ''
        }
			}
		},
		mounted() {
      this.getverifyList(this.page)
		},
		methods: {
      pagination(val) { // 分页
        this.page.current = val.pageNum
        this.page.size = val.pageSize
        this.getverifyList(this.page)
      },
			onSearch() { //查询
			  this.getverifyList(this.page)
			},
			resetSearch(){ // 重置
			  this.page = {
					total: 0, // 默认数据总数
					current: 1, // 默认开始页面
					size: 10, // 每页的数据条数
          params: {
          	isAdmin: '',
            organizationName: '',
          	state: 2,
          	userName: ''
          }
				}
        this.getverifyList(this.page)
			},
      getverifyList(data){ // 获取用户列表
        userListByAdmin(data).then((res)=>{
          this.tableData = res.data.records
          this.page.total = res.data.total
        })
      },
      // getrolelist(row){ // 获取角色初始化列表
      //   initUserRole({userSid: row.sid}).then(res => {
      //     this.roledialog = true
      //     this.rolelist = res.data.roleVoList
      //     this.rolefrom.userSid  = res.data.userSid
      //     this.rolefrom.userName  = res.data.userName
      //     this.rolefrom.roleSid  = res.data.roleSid
      //   })
      // },
      saveUserRole(){
        saveUserRole(this.rolefrom).then(res=>{
          this.roledialog = false
          this.$message({
            type: 'success',
            message: res.msg
          });
        })
      },
      initPwd(row){
        this.$confirm('此操作将初始化该用户密码, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          initPwd({sid: row.sid}).then(res => {
            this.getverifyList(this.page)
            this.$message({
              type: 'success',
              message: res.msg
            });
          })
        })

      },
      userinfo(row) { // 查看用户信息
        this.showuserInfo = true
        getUserINfo({userName: row.userName}).then(res => {
          this.userInfoFrom = res.data
        })
      },
      orgInfo(row){
        this.showOrgInfo = true
        getOrgINfo({organizationSid: row.organizationSid}).then(res => {
          this.OrgInfoFrom = res.data
        })
      },
      delUser(row){
        this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delUser({sid: row.sid}).then(res => {
            this.getverifyList(this.page)
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          })
        })
      }
		},
	}
</script>

<style>
  .el-dialog__footer{
    text-align: center;
  }
</style>

<style lang="scss" scoped="scoped">
  .el-image{
    width: 180px;
    height: 150px;
  }
  .tablerow-click{
    color: #007FFF;
    cursor: pointer;
  }
  .zcxx {
    color: #000;
    width: 98%;
    margin: 0px auto 30px;
    background-color: #f7f9fc;
    border: 1px solid #e6e9f0;
    height: 60px;
    line-height: 60px;

    p {
      font-size: 16px;
      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;
    }

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

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

    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>
