<template>
  <div>
    <el-button style="width: 100%" type="success" icon="el-icon-link" size="small" plain @click="showDialog = true">绑定商户</el-button>

    <sm-user-dialog :show.sync="showDialog" @select="handleSubmit"/>
  </div>
</template>

<script>
import SmUserDialog from '@/components/Business/SmUser/smUserDialog.vue'
import { bindMch } from '@/api/system/device'

export default {
  name: "BindMchButton",
  components: { SmUserDialog },
  props: {
    deviceId: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      showDialog: false,
    }
  },
  methods: {
    handleSubmit(user) {
      this.$confirm(`确定要绑定商户【${user.userName}】吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        bindMch(this.deviceId, user.userId).then(res => {
          if (res.code === 200) {
            this.$message.success("绑定成功");
            this.showDialog = false;
            this.$emit('success');
          }
        })
      })
    }
  }
}
</script>
