<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-select v-model="searchForm.FGS_ID" clearable placeholder="请选择分公司">
                  <el-option v-for="item in fgsList" :key="item.CORPINFO_ID" :label="item.CORP_NAME" :value="item.CORPINFO_ID" />
                </el-select>
              </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>
        <div class="app-statistical">
      <span>
        本企业共有员工:<i>{{ userNum }}</i>人
      </span>
        </div>
        <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="NUM" label="已关联人数" />
          <el-table-column label="操作">
            <template slot-scope="{row}">
              <el-button type="primary" icon="el-icon-edit" size="mini" @click="handleEdit(row)">进入</el-button>
              <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-form ref="form" :model="form" label-width="150px" style="width: 500px;">
        <el-form-item label="选择关联分公司" prop="REVIEW_TIME">
          <el-select v-model="form.FGS_ID" clearable placeholder="请选择要关联的分公司">
            <el-option v-for="item in fgsList" :key="item.CORPINFO_ID" :label="item.CORP_NAME" :value="item.CORPINFO_ID" />
          </el-select>
        </el-form-item>
      </el-form>
      <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>
</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,
      treeLoading: false,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 10
      },
      form: {
        FGS_ID:'',
        CORPINFO_ID: JSON.parse(sessionStorage.getItem('user')).CORPINFO_ID,
        USER_ID:JSON.parse(sessionStorage.getItem('user')).USER_ID
      },
      total: 0,
      KEYWORDS: '',
      ISFLOW: '',
      DEPART_STATE: '',
      varList: [],
      multipleSelectionAll: [], // 所有选中的数据包含跨页数据
      multipleSelection: [], // 当前页选中的数据
      dialogType: 'saveUser',
      disabledLCSelect: false,
      displayLCSelect: 'display: block',
      disabledLCInput: true,
      displayLCInput: 'display: none',
      LearnerCategoryList: [],
      searchForm: {
        FGS_ID: ''
      },
      config: config,
      dialogVisible: false,
      roleList: [],
      postList: [],
      dialogFormDaoru: false,
      daoruFrom: {
        FFILE: '',
        FFILEName: ''
      },
      PARENTID: '0',
      fgsList: [],
      userNum: '',
      datePage: 0,
      USER_ID: '',
      LOGIN_USER: JSON.parse(sessionStorage.getItem('user')).USER_ID
    }
  },
  watch: {

  },
  created() {
    this.getList();
    this.hasButton()
  },
  methods: {
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.searchForm.FGS_ID = ''
      this.getList()
    },
    getList() {
      this.listLoading = true
      requestFN(
        '/corpFgs/list?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          ...this.searchForm,
          CORPINFO_ID: JSON.parse(sessionStorage.getItem('user')).CORPINFO_ID
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.fgsList = data.fgsList
        this.userNum = data.userNum
        console.log(this.varList)
        this.total = data.page.totalResult
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getRowKey(row) {
      return row.CORP_FGS_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
    },
    confirm() {
        if(!this.form.FGS_ID){
          this.$message.error('请选择要关联的分公司');
          return;
        }
          this.listLoading = true
          requestFN(
            '/corpFgs/add',
            {
              ...this.form
            }
          ).then((data) => {
            if(data.result=='fail'){
        this.$message.error(data.msg);
          }
          this.form.FGS_ID = '';
          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(
        '/corpFgs/delete',
        {
          FGS_ID:row.FGS_ID,
          CORPINFO_ID: row.CORPINFO_ID,
          USER_ID:JSON.parse(sessionStorage.getItem('user')).USER_ID,
          CORP_FGS_ID:row.CORP_FGS_ID
    }
    ).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
    })
    },
    // 编辑
    handleEdit(row) {
      this.$parent.FGS_ID = row.FGS_ID
      this.$parent.CORPINFO_ID = row.CORPINFO_ID
      this.$parent.activeName = 'Edit'
    },
  }
}
</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;
}

.app-statistical {
  padding: 8px 20px 8px 20px;
  border: 1px solid #abdcff;
  background-color: #f0faff;
  position: relative;
  border-radius: 4px;
  color: #515a6e;
  line-height: 16px;
  margin-bottom: 15px;

  span {
    margin-right: 20px;
    font-size: 12px;

    i {
      font-style: normal;
      font-weight: 700;
      color: rgb(45, 140, 240);
    }
  }
}
</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>
