<template>
  <div>
    <el-button size="small" icon="el-icon-link" type="primary" style="background:#52C41A;border:1px solid #52C41A;float:right" @click="onShow">关联账号</el-button>
    <el-dialog title="绑定账号" append-to-body :visible.sync="dialogTableVisible">
      <tableLayout :layout="tablecols" :data="sys_options" height="400px">
        <template v-slot:opreation="scope">
          <el-popconfirm
            class="inline-16"
            title="确定要绑定员工账号吗?"
            @confirm="bindAccount(scope)">
            <el-button slot="reference" type="text" size="small">绑定账号</el-button>
          </el-popconfirm>
        </template>
      </tableLayout>
    </el-dialog>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
  props:['data'],
  data () {
    return {
      dialogTableVisible:false,
      tablecols:[],
      form:{},
    }
  },
  computed:{
    ...mapGetters({
      sys_options:'sys_options',
    })
  },
  methods:{
    onShow () {
      this.listData()
      this.dialogTableVisible = true
    },
    listData () {
      this.$store.dispatch('optiontypeselect','userlistunused')
    },
    bindAccount (scope) {
      this.data.birthday = ''
      this.form = Object.assign({},this.form,this.data)
      this.form.userid = scope.data.userid
      this.onSave()
    },
    async onSave () {
      const res = await this.$api.requested({
        "classname": "webmanage.hr.hr",
        "method": "insertormodify_hr",
        "content": this.form
      })
      if (res.code === 0)  return this.$notify({
          title: '失败',
          message: res.data,
          type: 'error'
        });

        this.$notify({
          title: '成功',
          message: '绑定成功',
          type: 'success'
        });

        this.dialogTableVisible = false
        this.$emit('onSuccess')
    },
  },
  mounted () {
    this.tablecols = this.tool.tabelCol(this.$route.name)['unBindtACTable'].tablecols
  }
}

</script>
<style>
</style>