<!-- 同行人展示列表 -->
<template>
  <el-dialog title="同行人" :visible.sync="dialogVisible" width="800px" :before-close="handleCancel">
    <el-table v-loading="loading" stripe border :data="tableList" width="100%">
      <el-table-column label="用户昵称" prop="nickname" />
      <el-table-column label="手机号码" prop="mobile" />
      <el-table-column label="部门" prop="dept">
        <template slot-scope="{row}">
          <div>
            {{row.dept.name}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="人数">
        <template>
          <div>
            1
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="{row}">
          <div>
            <el-button icon="el-icon-delete" type="text" @click="handleDel(row.id)"> 删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取 消</el-button>
      <el-button type="primary" @click="handleConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: '',
  props: {
    isOpen: Boolean,
    userList: Array,
    selectIds: Array
  },
  data() {
    return {
      dialogVisible: false,
      loading: false,
      tableList: [],
    }
  },
  watch: {
    isOpen: {
      handler(val) {
        this.dialogVisible = val
        if (val) {
          this.handleInit()
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    handleDel(id) {
      this.$confirm("你确定要删除同行人吗", "提示", {
        confirmButtonText: "确 认",
        cancelButtonText: "取 消"
      }).then(() => {
        console.log('tableList..', this.tableList);
        this.tableList = this.tableList.filter(item => item.id !== id)
      })
    },
    handleCancel() {
      this.$emit('onCancel')
    },
    handleConfirm() {
      this.$emit('onConfirm', this.tableList.map((item => item.id)))
    },
    handleInit() {
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.tableList = this.userList.filter(item => this.selectIds.includes(item.id))
      }, 300)
    },
  }
}

</script>
<style lang='scss' scoped>
</style>