<!--
 * @Descripttion: 关联详情
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-08-27 09:14:54
 * @LastEditors: 无尘
 * @LastEditTime: 2020-09-09 15:47:35
-->

<!--
  绑定详情
  <related-table :relate-row="relateRow"  @closeTable="closeTable"></related-table>
  import relatedTable from '@/components/company/related-table.vue';
 -->
<template>
  <el-dialog title="绑定详情" :visible.sync="dialogVisible" width="995px" :before-close="handleClose">
    <div class="overstore-tip">
      <div class="flex flex-space-between">
        <div></div>
        <el-button type="primary" @click="toAddRelate">新建绑定</el-button>
      </div>
    </div>
    <div class="m-t-20">
      <el-table class="select-table" ref="multipleTable" height="500" :data="tableData" tooltip-effect="dark" :style="{ width: '100%' }">
        <el-table-column label="导购code" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.clerkCode || '--' }}</template>
        </el-table-column>
        <el-table-column prop="" label="导购姓名" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.clerkName || '--' }}
          </template>
        </el-table-column>
        <el-table-column prop="" label="导购手机号" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.nationCode || '--' }}-{{ scope.row.clerkPhoneNumber || '--' }}
          </template>
        </el-table-column>
        <el-table-column prop="" label="绑定商户" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.enterpriseName || '--' }}
          </template>
        </el-table-column>
        <el-table-column prop="" label="绑定门店" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.storeName || '--' }}
          </template>
        </el-table-column>
        <el-table-column prop="" label="绑定时间" show-overflow-tooltip>
          <template slot-scope="scope">
            <div class="color-606266 line-18">{{ scope.row.createTime | timeStampToYmd }}</div>
            <div class="color-606266 line-18">{{ scope.row.createTime | timeStampToHms }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="操作" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-button type="text" @click="toUnbind(scope.row)">解绑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <add-relate v-if="addShow" :depart-obj="relateRow" @refreshData="refreshData"></add-relate>
  </el-dialog>
</template>
<script>
import addRelate from '@/components/company/add-relate.vue';
import fetch from '@/api/contact.js';
const { getStaffRelation, delStaffRelation } = fetch;
import showMsg from '@/common/js/showmsg';
// import { _debounce } from '@/common/js/public';
export default {
  name: 'RelatedTable',
  components: {
    addRelate
  },
  props: {
    relateRow: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data() {
    return {
      dialogVisible: true,
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      tableData: [],
      addShow: false
    };
  },
  mounted() {
    const that = this;
    if (Object.keys(that.relateRow).length) {
      that.getTableList();
    }
  },
  methods: {
    /**
     * @description: 刷新数据
     * @param {String} data
     * @return {Boolean}
     * @author: 无尘
     */
    refreshData(data) {
      const that = this;
      that.addShow = false;
      if (data == 'close') {
        return false;
      }
      that.getTableList();
    },
    cancel() {
      const that = this;
      that.$emit('closeTable', 'close');
    },
    /**
     * @description: 添加绑定
     * @author: 无尘
     */
    toAddRelate() {
      const that = this;
      that.addShow = true;
    },
    /**
     * @description: 解绑
     * @param {Object} row
     * @author: 无尘
     */
    toUnbind(row) {
      const that = this;
      that
        .$confirm(`导购账号（${row.clerkName}）已绑定${row.bindStaffName}，是否确认解绑？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          that.postUnbind(row);
        })
        .catch(() => {});
    },
    postUnbind(row) {
      const that = this;
      let para = {
        staffId: row.bindStaffId,
        clerkId: row.clerkId
      };
      delStaffRelation(para)
        .then(res => {
          that.getTableList();
          if (res.code == '0000') {
            showMsg.showmsg('解绑成功', 'success');
          }else {
            that.$message({
              message: res.message || '未知错误',
              type: 'warning'
            });
          }
        })
        .catch(function(error) {

        });
    },
    handleClose() {
      const that = this;
      that.tableData = [];
      that.$emit('closeTable');
    },
    /**
     * @description: 路由跳转
     * @param {String} path
     * @author: 无尘
     */
    changeRoute(path) {
      this.$router.push(path);
    },

    /**
     * @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: 获取列表数据
     * @author: 无尘
     */
    getTableList() {
      const that = this;
      let para = {
        staffId: that.relateRow.staffId
      };
      getStaffRelation(para)
        .then(res => {
          that.tableData = res.result || [];
        })
        .catch(function(error) {

        });
    }
  },
  watch: {
    relateRow(newData, oldData) {
      const that = this;
      if (Object.keys(newData).length) {
        that.getTableList();
      }
    }
  }
};
</script>
<style type="text/less" lang="less" scoped>
.span-dot {
  display: inline-block;
  vertical-align: middle;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 3px;
  &.bg-33af4a  {
    background: #33af4a ;
  }
  &.bg-f5222d {
    background: #f5222d;
  }
}
.bg-82C5FF {
  background: #82c5ff;
}
.color-508CEE {
  color: #508cee;
}
.color-FF585C {
  color: #ff585c;
}
.line-h-18 {
  line-height: 18px;
}
.tooltip-text {
  width: 100%;
  white-space: pre-wrap;
  word-break: break-all;
}
.w-293 {
  width: 293px;
}
.w-191 {
  width: 191px;
}
.el-alert--info {
  background: rgba(240, 245, 255, 1);
  border-radius: 2px;
  border: 1px solid rgba(133, 165, 255, 1);
  -webkit-box-align: flex-start;
  -webkit-align-items: flex-start;
  -ms-flex-align: flex-start;
  align-items: flex-start;
  .el-alert__icon {
    font-size: 12px;
    padding-top: 3px;
  }
}
.my-customer-wrap {
  height: 100%;
}
.right-content {
  /*width: 100%;*/
  padding: 0 20px 20px 20px;
  min-height: calc(100% - 160px);
  .right-box {
    background: #fff;
    min-height: 500px;
    padding: 0px;
    .apps-content {
      .apps-content-right {
        width: 100%;
        padding: 20px;
        background: #fff;
        .overstore-body {
          background: #fff;
        }
        .daily-set-wrap {
          height: 100%;
          background: #fff;
        }
        .app-detail-wrap {
          height: 100%;
          background: #fff;
        }
        .common-set-wrap {
          height: 100%;
          background: #fff;
        }
      }
    }
  }
}
</style>
