<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      title="选择用户"
      :visible.sync="showTroubleshooting"
      width="70%"
      :close-on-press-escape="false"
      :before-close="handleClose"
      top="5vh"
    >
      <template class="materialInformation">
        <div class="common-page-shadow">
          <div class="common-search-container" ref="contentPanel">
              <el-form v-model="queryParam" :inline="true">
                  <el-form-item label="名称">
                    <el-input
                      size="small"
                      v-model="querys[0].value"
                      clearable
                      placeholder="请输入名称"
                    ></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button
                      size="small"
                      type="danger"
                      icon="el-icon-search"
                      @click="handleSearch"
                      >搜索</el-button
                    >
                    <el-button
                      size="small"
                      icon="el-icon-refresh"
                      @click="handleReset"
                      >重置</el-button
                    >
                  </el-form-item>
              </el-form>
          </div>
          <el-table
            ref="multipleSelection"
            v-loading="loading"
            border
            size="mini"
            :data="tableData"
            height="400px"
            :row-key="rowKey"
            :style="{width: '100%', height: '500px'}"
            :max-height="tableMaxHeight"
            :cell-style="{'text-align': 'center'}"
            :header-cell-style="{'text-align': 'center'}"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              width="55"
              :reserve-selection="true"
            />
            <el-table-column
              type="index"
              width="55"
              label="序号"
            ></el-table-column>
            <el-table-column
              min-width="110"
              sortable
              prop="fullname"
              label="姓名"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              min-width="130"
              sortable
              prop="account"
              label="账号"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              min-width="130"
              sortable
              prop="email"
              label="邮箱"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              min-width="130"
              sortable
              prop="mobile"
              label="手机号码"
              show-overflow-tooltip
            >
            <template slot-scope="scope">
                <div>
                  {{ maskedIdCard(scope.row.mobile) }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              min-width="130"
              sortable
              prop="address"
              label="地址"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              min-width="110"
              sortable
              prop="status"
              label="状态"
              show-overflow-tooltip
            >
              <template v-slot="{row}">
                <el-tag type="warning" v-if="row.status === 0">禁用</el-tag>
                <el-tag type="success" v-if="row.status === 1">正常</el-tag>
                <el-tag type="info" v-if="row.status === -1">未激活</el-tag>
                <el-tag type="danger" v-if="row.status === -2">离职</el-tag>
              </template>
            </el-table-column>
          </el-table>
          <div style="float:right;margin-top:10px">
            <el-pagination
              ref="paginationPanel"
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryParam.pageBean.page"
              :page-sizes="[20, 30, 40, 50]"
              :page-size="queryParam.pageBean.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="queryParam.pageBean.total"
            >
            </el-pagination>
          </div>
        </div>
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleSave">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {TableMixin} from '@/mixins/tableMixin'
import basicData from '@/api/basicData'
export default {
  name: 'CmgtSaftyDangerCheckplanFormDialogTroubleshooting', // 排查计划明细
  props: {
    useOrgList: Array
  },
  data() {
    return {
      showTroubleshooting: false, // 控制弹层显示与隐藏
      multipleSelection: [],
      selectedValue: [],
      treeData: [],
      params:{},
      filterText: '',
      defaultProps: {
        id: 'code',
        label: 'name',
        isLeaf: 'leaf'
      },
      querys: [
        {
          group: 'main',
          operation: 'LIKE',
          parentGroup: '',
          property: 'fullname',
          relation: 'AND',
          value: ''
        },
      ],
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0
        }
      }
    }
  },
  mixins: [TableMixin],
  created() {
    this.loadData()
  },
  methods: {
    rowKey(row) {
      return row.id
    },
    //搜索
    handleSearch() {
      this.loadData()
    },
    //重置
    handleReset() {
      this.params={}
      this.loadData()
    },
    //显示弹框
    add() {
      this.showTroubleshooting = true
      this.loadData()
    },
    // 获取list
    loadData() {
      // this.loading = true
      this.tableData = []
      this.queryParam.querys = []
      if(this.querys[0].value){
        this.queryParam.querys.push(this.querys[0])
      }
      if(this.querys[1].value){
        this.queryParam.querys.push(this.querys[1])
      }
      this.$http.post('${portal}/enterprise/v1/getUserList',this.queryParam).then(res=>{
        this.tableData = res.data.value.rows
          this.queryParam.pageBean = {
            page: res.data.value.page,
            pageSize: res.data.value.pageSize,
            total:res.data.value.total
          }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      if (this.multipleSelection.length > 1) {
          this.$refs.multipleSelection.toggleRowSelection(
              this.multipleSelection[0],
              false
          )
      }
    },
    // 点击关闭按钮
    handleClose() {
      this.$refs.multipleSelection.clearSelection()
      this.showTroubleshooting = false
    },
    // 保存按钮
    handleSave() {
      let list = this.multipleSelection
      this.$emit('addDetail', list)
      this.handleClose()
    },
    handleCurrentChange(page) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, page}
      this.loadData()
    },
    handleSizeChange(pageSize) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, pageSize}
      this.loadData()
    },
    maskedIdCard (val) {
   let reg = /^(.{3})(?:\d+)(.{3})$/    // 匹配身份证号前3位和后3位的正则表达式
   if (val) {
       return val.replace(reg, '\$1******\$2')
   }
  },
  }
}
</script>

<style scoped lang="scss">
.dialog-footer {
  width: 100%;
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
/deep/.el-dialog__body {
  display: flex;
}
.common-page-shadow {
  width: 100%;
  margin-left: 15px;
}
.common-search-container {
  padding: 0px;
  padding-left: 10px;
  box-shadow: 0 0 0;
  display: block;
}
/deep/.el-dialog__body {
  height: 100%;
}

</style>
