<template>
  <div>
    <el-button size="mini" icon="el-icon-link" type="primary"  @click="onShow">关联账号</el-button>
    <el-dialog title="绑定账号" append-to-body :visible.sync="dialogTableVisible">
      <el-input
          size="small"
          style="margin-top:-20px;width: 300px;margin-bottom:20px;float: right"
          suffix-icon="el-icon-search"
          v-model="param.content.parameter.condition"
          placeholder="登录账号/账号名称/联系方式"
          @keyup.enter.native="listData(param.content.pageNumber = 1)"
          @clear="listData(param.content.pageNumber = 1)"
          clearable>
      </el-input>
      <tableLayout :layout="tablecols" :data="tableData" 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>
      <div style="display:flex;align-items:center;flex-direction:row-reverse;justify-content:space-between">
        <div class="container normal-panel" style="text-align:right">
          <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[20, 50, 100, 200]"
              layout="total,sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
        </div>
        <slot name="footerLeft"></slot>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
  props:['data'],
  data () {
    return {
      dialogTableVisible:false,
      tablecols:[],
      tableData:[],
      total:0,
      currentPage:0,
      param:{
        classname: "sysmanage.develop.optiontype.optiontype",
        method: "optiontypeselect",
        content: {
          pageNumber: 1,
          pageSize: 20,
          typename: "userlistunused",
          parameter: {
            condition:""
          }
        },
      },
      form:{},
    }
  },
  computed:{
    ...mapGetters({
      sys_options:'sys_options',
    })
  },
  methods:{
    onShow () {
      this.listData()
      this.dialogTableVisible = true
    },
    async listData () {
      /*this.$store.dispatch('optiontypeselect','userlistunused')*/
      const res = await this.$api.requested(this.param)
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    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')
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
  },
  mounted () {
    this.tablecols = this.tool.tabelCol(this.$route.name)['unBindtACTable'].tablecols
  }
}

</script>
<style>
</style>