<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-08-27 09:14:54
 * @LastEditors: 无尘
 * @LastEditTime: 2020-10-12 16:15:52
-->
<!--
  部门成员
  <new-depart-member :depart-obj="departObj"></new-depart-member>
  import newDepartMember from '@/components/company/new-depart-member.vue';
 -->
<template>
  <div class="depart-list-body">
    <div class="depart-name-wrap flex flex-space-between">
      <div class="depart-name">
        <span class="font-16 p-r-10 iconfont iconqiye-tianchong color-303133"></span><span class="font-16 color-303133 font-w-600">{{ departObj.departmentName }} （{{ total }}人）</span>
      </div>
      <div class="flex">
        <div class="flex flex-align-center flex-pack-center cursor-pointer font-12 color-909399 hover-303133" @click="toLog">变更日志</div>
        <div class="flex flex-align-center flex-pack-center font-12 color-909399 cursor-pointer hover-303133 use-help-tip" @click="toShowTip">使用帮助</div>
      </div>
    </div>
    <div class="m-t-20">
      <div class="depart-condition-wrap flex flex-space-between ">
        <div>
          <el-input placeholder="搜索姓名/手机号码"  maxlength="50" v-model="searchInput" class="w-274" @keyup.native="value => toInput(value, searchInput)" clearable @clear="clearInput"></el-input>
          <el-select v-model="activeFlag" placeholder="所有状态" class="m-l-10" @change="changeStatus">
            <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>
        </div>

      </div>
      <div class="m-t-20">
        <el-table class="select-table" ref="multipleTable" v-loading="loading" :data="tableData" tooltip-effect="dark" :style="{ width: '100%', minHeight: tableH }">
          <!-- <el-table-column type="selection" width="55"> </el-table-column> @selection-change="handleSelectionChange" -->
          <el-table-column label="姓名" show-overflow-tooltip>
            <template slot-scope="scope">{{ scope.row.staffName || '--' }}</template>
          </el-table-column>
          <el-table-column prop="" label="职务" show-overflow-tooltip>
            <template slot-scope="scope">{{ scope.row.postion || '--' }}</template>
          </el-table-column>
          <el-table-column prop="" label="手机号码" show-overflow-tooltip>
            <template slot-scope="scope">{{ scope.row.nationCode }}-{{ scope.row.phoneNumber }}</template>
          </el-table-column>
          <el-table-column prop="" label="">
            <template slot="header" >
              <el-tooltip class="item" effect="dark" placement="right">
                <div slot="content">
                  是否使用好办4.0小程序
                </div>
                <span style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">使用状态</span>
              </el-tooltip>
            </template>
            <template slot-scope="scope">
              <span :class="['inline-block iconfont iconhuaban', scope.row.activeFlag == 1 ? 'color-2f54eb' : 'color-c0c4cc']"></span>
            </template>
          </el-table-column>
          <el-table-column prop="" label="绑定" show-overflow-tooltip>
            <template slot="header" >
              <el-tooltip class="item" effect="dark" placement="right">
                <div slot="content">员工绑定导购详情，因只能识别企业微信用户usrid且门店与部门不相绑定，<br/>所以虽然在一个部门下，但是可能出现一个人绑定多个导购代码。<br/>即一个用户对应多个导购代码</div>
                <span style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">绑定详情</span>
              </el-tooltip>
            </template>
            <template slot-scope="scope">
              <el-button type="text" @click="showRelateDetail(scope.row)">查看详情</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="" label="操作" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-button type="text" @click="showDetail(scope.row)">成员详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block common-wrap__page text-right m-t-24" v-if="tableData.length != 0">
          <dm-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 30]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </dm-pagination>
        </div>
      </div>
    </div>
    <add-member v-if="memberVisible" :default-depart="defaultDepart" :member-obj="memberObj" @refreshData="refreshData" @changeObj="changeObj"></add-member>
    <related-table v-if="relateShow" :relate-row="relateRow" @closeTable="closeTable"></related-table>
    <help-tip v-if="tipShow" @toCloseTip="toCloseTip"></help-tip>
  </div>
</template>
<script>
import { _debounce } from '@/common/js/public';
import fetch from '@/api/contact.js';
const { getStaffList } = fetch;
// import showMsg from '@/common/js/showmsg';
import addMember from '@/components/company/add-member.vue';
import relatedTable from '@/components/company/related-table.vue';
import helpTip from '@/components/company/help-tip.vue';
export default {
  name: 'DepartList',
  components: {
    addMember,
    relatedTable,
    helpTip
  },
  props: {
    departObj: {
      type: Object,
      default() {
        return {
          departmentId: '',
          departmentName: '',
          wxDepartmentId: '',
          parentId: '',
          isStore: '',
          staffCount: '',
          bindFlag: ''
        };
      }
    }
  },
  data() {
    return {
      searchInput: '',
      activeFlag: '',
      statusOptions: [
        {
          value: '',
          label: '所有状态'
        },
        {
          value: '0',
          label: '未激活'
        },
        {
          value: '1',
          label: '已激活'
        }
      ],
      // 分页参数
      currentPage: 1,
      pageSize: 10,
      total: 0,
      loading: false,
      tableData: [],
      clerkOptions: [],
      // 新增
      memberVisible: false,
      memberObj: {},
      defaultDepart: [],
      multipleSelection: [], // 勾选数据
      // 调整部门
      modVisible: false,
      navData: [],
      relateShow: false,
      relateRow: {},
      tipShow: false
    };
  },
  mounted() {
    const that = this;
    if (Object.keys(that.departObj)) {
      that.currentPage = 1;
      that.getTableList();
    }
  },
  methods: {
    /**
     * @description: 跳转变更日志
     * @author: 无尘
     */
    toLog() {
      window.open('/haoban-4/syncLog');
    },
    /**
     * @description: 修改选择部门
     * @param {Object} obj
     * @author: 无尘
     */
    changeObj(obj) {
      const that = this;
      that.memberVisible = false;
      that.$emit('changeDepart', obj);
    },
    /**
     * @description: 显示提示
     * @author: 无尘
     */
    toShowTip() {
      const that = this;
      that.tipShow = true;
    },
    /**
     * @description: 关闭提示
     * @author: 无尘
     */
    toCloseTip() {
      const that = this;
      that.tipShow = false;
    },
    /**
     * @description: 关联详情
     * @param {Object} row
     * @author: 无尘
     */
    showRelateDetail(row) {
      const that = this;
      that.relateShow = true;
      that.relateRow = row;
    },
    closeTable() {
      const that = this;
      that.relateShow = false;
      that.relateRow = {};
    },
    changeDepart(item, index) {
      const that = this;
      if (index == that.navData.length - 1) {
        return false;
      }
      that.$emit('changeDepart', item);
    },
    /**
     * @description: 可选设置
     * @param {Object} row
     * @param {Number} index
     * @returns {Boolean}
     * @author: 无尘
     **/
    selectInit(row, index) {
      if (row.activeFlag == 1) {
        return false; // 不可勾选
      } else {
        return true; // 可勾选
      }
    },
    /**
     * @description: 输入
     * @param {Object} e
     * @param {String} value
     * @author: 无尘
     */
    toInput: _debounce(function(e, value) {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    }, 500),
    /**
     * @description: 搜索清除
     * @author: 无尘
     */
    clearInput() {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    },
    /**
     * @description: 选择状态
     * @author: 无尘
     */
    changeStatus() {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    },
    /**
     * @description: 显示详情弹窗
     * @param {Object} item
     * @author: 无尘
     */
    async showDetail(item) {
      const that = this;
      that.memberObj = item;
      that.memberVisible = true;
    },
    /**
     * @description: 确认新建后刷新
     * @param {String} res
     * @returns {Boolean}
     * @author: 无尘
     */
    refreshData(res) {
      const that = this;
      that.memberVisible = false;
      that.memberObj = {};
      if (res == 'close') {
        return false;
      }
      that.currentPage = 1;
      that.getTableList();
    },
    /**
     * @description: 勾选
     * @param {Array} val
     * @author: 无尘
     */
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /**
     * @description: 分页---页码变化
     * @param {Number} val
     * @author: 无尘
     */
    handleSizeChange(val) {
      const that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },
    /**
     * @description: 分页---当前页变化
     * @param {Number} val
     * @author: 无尘
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      that.getTableList();
    },
    /**
     * @description: 获取列表数据
     * @returns {Boolean}
     * @author: 无尘
     */
    getTableList() {
      const that = this;
      that.loading = true;
      if (!that.departObj.departmentId) {
        that.loading = false;
        return false;
      }
      let para = {
        departmentId: that.departObj.departmentId,
        activeFlag: that.activeFlag,
        search: that.searchInput || '', // 搜索字段
        pageNum: that.currentPage, // 当前页
        pageSize: that.pageSize // 一页显示个数
      };
      getStaffList(para)
        .then(res => {
          that.loading = false;
          that.tableData = res.result.result || res.result.list || [];
          that.total = res.result.totalCount || res.result.total;
        })
        .catch(function(error) {
          that.loading = false;
        });
    }
  },
  watch: {
    departObj(newData, oldData) {
      const that = this;
      if (Object.keys(newData)) {
        that.currentPage = 1;
        that.getTableList();
      }
    }
  }
};
</script>
<style lang="less" scoped>
.m-b-10 {
  margin-bottom: 10px;
}
.el-breadcrumb__inner.is-link:hover,
.el-breadcrumb__inner a:hover {
  color: #2f54eb;
}
.w-274 {
  width: 274px;
}

.m-l-6 {
  margin-left: 6px;
}

.depart-list-body {
  .depart-id {
    margin-top: 5px;
  }
  .depart-children-list {
    padding: 16px 10px;
    background: #f5f7fa;
  }
  .use-help-tip {
    position: relative;
    margin-left: 10px;
    padding-left: 10px;
    &:before {
      content: "";
      position: absolute;
      left: 0;
      top: 2px;
      height: 10px;
      width: 1px;
      background: #dcdfe6;
    }
  }
  .hover-303133 {
    &:hover {
      color: #303133;
    }
  }
}
.iconhuaban {
  font-size: 24px;
  vertical-align: bottom;
}
.to-log-btn {
  width: 102px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  background: rgba(245, 247, 250, 1);
  &:hover {
    color: #597ef7;
  }
}
.log-icon {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  margin-right: 15px;
  span {
    color: #c0c4cc;
  }
  &:hover {
    background: rgba(240, 245, 255, 1);
    span {
      color: #909399;
    }
  }
}
</style>
