<template>
  <el-dialog :close-on-click-modal="false" title="联盟卡审核" :visible.sync="checkVisible" width="890px">
    <BaseInfo :card="cardInfo"></BaseInfo>
    <span slot="footer" class="dialog-footer">
      <el-button  type="primary"  size="mini" :loading="checkLoading === 2" @click="handleCheck(2)">通过</el-button>
      <el-button size="mini" :loading="checkLoading === 3" type="danger" @click="handleCheck(3)">拒绝</el-button>
    </span>
  </el-dialog>
</template>

<script>
import BaseInfo from './BaseInfo'
import { auditAllianceCardApi } from '@/api/business'

export default {
  components: { BaseInfo },
  data() {
    return {
      checkVisible: false
      ,
      checkLoading: -1,
      cardInfo: {}
    }
  },

  watch: {
    checkVisible(value) {
      if (!value) {
        this.cardInfo = {}
        this.checkLoading = -1
      }
    }
  },

  methods: {
    handleOpen(row) {
      this.checkVisible = true
      this.cardInfo = row
    },
    //  审核
    async handleCheck(state) {
      this.checkLoading = state

      try {
        await auditAllianceCardApi({ allianceCardId: this.cardInfo.id, state })
        this.$message.success('联盟卡审核成功')
        this.checkLoading = false
        this.$emit('success')
        this.checkVisible = false
      } catch (error) {
        this.checkLoading = -1
      }
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-descriptions__header {
  margin-bottom: 10px;
}

.dialog-footer{
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
