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

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

<script>
import userDialog from "@/components/Business/User/UserDialog.vue";
import { bindMch } from "@/api/bst/device";

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