<template>
  <div class="icons-container">
    <el-container>
      <el-main>
        <el-form label-width="100px">
          <el-row>
            <el-col :span="4">
              <el-form-item label="关键字搜索">
                <el-input v-model="searchForm.KEYWORDS" style="width: 150px" placeholder="请输入关键字"/>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label-width="20px">
                <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">
                  搜索
                </el-button>
                <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
                  重置
                </el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table v-loading="listLoading" ref="multipleTable" :data="varList" :row-key="getRowKey" :header-cell-style="{'font-weight': 'bold','color': '#000'}" tooltip-effect="dark" border fit highlight-current-row>
          <el-table-column :reserve-selection="true" type="selection" width="55" align="center" />
          <el-table-column type="index" label="序号" width="50" align="center" />
          <el-table-column prop="FGS_NAME" label="分公司名称" />
          <el-table-column prop="NAME" label="姓名" />
          <el-table-column prop="PHONE" label="电话" />
          <el-table-column prop="IS_SPECIAL_JOB" label="是否特殊工种">
            <template slot-scope="scope">
              <span v-if="scope.row.IS_SPECIAL_JOB=='0'">否</span>
              <span v-else>是</span>
            </template>
          </el-table-column>
          <el-table-column prop="ISFLOW" label="是否流动人员" >
            <template slot-scope="scope">
              <span v-if="scope.row.ISFLOW=='0'">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="{row}">
              <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDel(row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="page-btn-group">
          <div>
            <el-button v-show="add" type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
          </div>
          <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
        </div>
      </el-main>
    </el-container>
    <div/>
    <el-dialog :visible.sync="dialogFormEdit" title="人员关联分公司" width="600px">
        <el-table v-loading="userListLoading" ref="userListTable" :data="userList" @selection-change="handleSelectionChange" :row-key="getRowUserKey" :header-cell-style="{'font-weight': 'bold','color': '#000'}" tooltip-effect="dark" border fit highlight-current-row >
          <el-table-column :reserve-selection="true" type="selection" width="45" align="center" />
          <el-table-column type="index" label="序号" width="50" align="center" />
          <el-table-column prop="NAME" label="姓名" />
          <el-table-column prop="PHONE" label="电话" />
          <el-table-column prop="IS_SPECIAL_JOB" label="是否特殊工种">
            <template slot-scope="scope">
              <span v-if="scope.row.IS_SPECIAL_JOB=='0'">否</span>
              <span v-else>是</span>
            </template>
          </el-table-column>
          <el-table-column prop="ISFLOW" label="是否流动人员" >
            <template slot-scope="scope">
              <span v-if="scope.row.ISFLOW=='0'">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
        </el-table>
      <div class="page-btn-group">
        <div/>
        <pagination :total="usertotal" :page.sync="userListQuery.page" :limit.sync="userListQuery.limit" @pagination="getUserList" />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirm">确 认</el-button>
        <el-button @click="dialogFormEdit = false">取 消</el-button>
      </div>
    </el-dialog>
    <div class="ui-foot">
      <el-button plain type="info" @click="goBack">返 回</el-button>
    </div>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import SelectTree from '@/components/SelectTree'
import { upload } from '@/utils/upload'
export default {
  components: { Pagination, SelectTree },
  directives: { waves },
  data() {
    return {
      dayTime: [],
      dialogFormEdit: false,
      dialogFormEditState: false,
      listLoading: true,
      userListLoading:true,
      treeLoading: false,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 10
      },
      userListQuery: {
        page: 1,
        limit: 10
      },
      form: {
        FGS_ID:'',
        CORPINFO_ID: '',
        USER_ID:JSON.parse(sessionStorage.getItem('user')).USER_ID
      },
      total: 0,
      usertotal: 0,
      KEYWORDS: '',
      ISFLOW: '',
      DEPART_STATE: '',
      varList: [],
      multipleSelectionAll: [], // 所有选中的数据包含跨页数据
      multipleSelection: [], // 当前页选中的数据
      dialogType: 'saveUser',
      disabledLCSelect: false,
      displayLCSelect: 'display: block',
      disabledLCInput: true,
      displayLCInput: 'display: none',
      LearnerCategoryList: [],
      searchForm: {
        FGS_ID:'',
        CORPINFO_ID: '',
        KEYWORDS: ''
      },
      config: config,
      dialogVisible: false,
      roleList: [],
      postList: [],
      dialogFormDaoru: false,
      daoruFrom: {
        FFILE: '',
        FFILEName: ''
      },
      PARENTID: '0',
      fgsList: [],
      userList:[],
      selectedRows:[], //人员选中的数据
      USER_ID: '',
      LOGIN_USER: JSON.parse(sessionStorage.getItem('user')).USER_ID,
    }
  },
  watch: {

  },
  created() {
    this.form.FGS_ID = this.$parent.FGS_ID;
    this.searchForm.FGS_ID = this.$parent.FGS_ID;
    this.form.CORPINFO_ID = this.$parent.CORPINFO_ID;
    this.searchForm.CORPINFO_ID = this.$parent.CORPINFO_ID;
    this.getList();
    this.hasButton()
  },
  mounted() {
    this.handleEdit(this.$parent.USER_ID)
    this.getDict()
  },
  methods: {
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.searchForm.KEYWORDS = ''
      this.getList()
    },
    goBack() {
      this.$parent.activeName = 'List'
    },
    getList() {
      this.listLoading = true
      requestFN(
        '/corpUserFgs/list?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          ...this.searchForm
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.fgsList = data.fgsList
        console.log(this.varList)
        this.total = data.page.totalResult
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getUserList(){
      this.userListLoading = true
      requestFN(
        '/corpUserFgs/userList?showCount=' + this.userListQuery.limit + '&currentPage=' + this.userListQuery.page,
        {
          FGS_ID:this.searchForm.FGS_ID,
          CORPINFO_ID:this.searchForm.CORPINFO_ID
    }
    ).then((data) => {
        this.userListLoading = false
      this.userList = data.varList
      console.log(this.varList)
      this.usertotal = data.page.totalResult
    }).catch((e) => {
        this.userListLoading = false
    })
    },
    getRowKey(row) {
      return row.CORP_USER_FGS_ID
    },
    getRowUserKey(row) {
      return row.USER_ID
    },
    // 判断按钮权限，用于是否显示按钮
    hasButton() {
      var keys = 'user:add,user:del,user:edit'
      requestFN(
        '/head/hasButton',
        {
          keys: keys
        }
      ).then((data) => {
        this.add = data.userfhadminadd
      this.del = data.userfhadmindel
      this.edit = data.userfhadminedit
    }).catch((e) => {
        this.listLoading = false
    })
    },
    handleAdd() {
      this.dialogFormEdit = true;
      this.getUserList();
      this.$refs.userListTable.clearSelection();

    },
    confirm() {
        if(this.selectedRows.length==0){
          this.$message.error('请选择要关联的人员');
          return;
        }
        var userIds = '';
        for(var i =0 ;i<this.selectedRows.length;i++){
          if(i == 0){
            userIds = this.selectedRows[0].USER_ID;
          }else {
            userIds += ',';
            userIds += this.selectedRows[i].USER_ID;
          }
        }
          this.listLoading = true
          requestFN(
            '/corpUserFgs/add',
            {
              ...this.form,
              userIds: userIds
            }
          ).then((data) => {
            if(data.result=='fail'){
        this.$message.error(data.msg);
          }
          this.listLoading = false
          this.dialogFormEdit = false
          this.varList = []
          this.listQuery.page = 1
          this.getList()
        }).catch((e) => {
            this.listLoading = false
        })
    },
    handleDel(row){
      this.listLoading = true
      requestFN(
        '/corpUserFgs/delete',
        {
          CORP_USER_FGS_ID:row.CORP_USER_FGS_ID,
          USER_ID:JSON.parse(sessionStorage.getItem('user')).USER_ID
    }
    ).then((data) => {
      this.listLoading = false
      this.dialogFormEdit = false
      this.varList = []
      this.listQuery.page = 1
      this.getList()
    }).catch((e) => {
        this.listLoading = false
    })
    },
    //行选中
    handleSelectionChange(selection){
      this.selectedRows = selection;
    },
  }
}
</script>

<style lang="scss" scoped>

.el-dialog__body{
  padding: 0;
  background: red;
}
.mark_up{
  margin-bottom:20px;
  margin-left: 110px;
}
.icons-container {
  margin: 0;
  overflow: hidden;

  .grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .icon-item {
    margin-bottom: 10px;
    height: 70px;
    text-align: center;
    width: 100px;
    float: left;
    font-size: 24px;
    color: #24292e;
    cursor: pointer;
    span {
      display: block;
      font-size: 14px;
      margin-top: 10px;
    }

  }

  .disabled {
    pointer-events: none;
  }
}
.filter-btn-group{
  position: relative;
}
.filter-flot{
  position: absolute;
  right: 0;
  top: 0;
}
.uploader{
  width: 570px;
  display: flex;
  align-items: center;
}
.el-form-item__content{
  line-height: 1;
}
.uo-flex{
  display: flex
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  border: 1px dashed #d9d9d9;
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

</style>

<style lang="sass" scoped>
.el-row
  margin-bottom: 16px
  &:last-child
    margin-bottom: 0
    .form-group
      display: flex
      align-items: center
      margin-right: 20px
      .form-label
        padding: 9px 15px
        font-size: 14px
        width: 240px
        font-weight: 400
        line-height: 20px
        text-align: right
        margin-bottom: 0
        .star
          color: red
          padding-right: 4px
      .input-block
        flex: 1
        min-height: 36px
        position: relative

  .disContent
    padding: 0 20px
    display: flex
    align-items: center
    flex-wrap: wrap
    .img-div
      position: relative
      margin: auto 10px 10px 10px
      width: 20px
      height: 20px
      border-radius: 4px
      &>img
        width: 2%
        height: 3%

      .disContent-hide
        position: absolute
        width: 100%
        height: 100%
        border-radius: 4px
        background-color: rgba(48, 48, 48, 0.59)
        display: none
        top: 0
        left: 0

        .Delete
          position: absolute
          bottom: 14px
          right: 10px
          font-size: 16px
          color: white
          cursor: pointer

          .editCss
            .Delete
              font-size: 16px
              right: 90px

        .yuLan
          position: absolute
          bottom: 23px
          right: 50px
          font-size: 16px
          color: white
          cursor: pointer

        .yuLanImg
          position: absolute
          bottom: 0
          right: 0
          width: 100%
          height: 100%
          opacity: 0

    .img-div:hover .disContent-hide
      display: block

    .pitchCss
      border: 1px solid #202e78
      transition: all linear 0.1s
      width: 116px
      height: 116px
</style>
