<template>
  <div>
    <!--人工干预框-->
    <el-dialog title="人工干预" :visible.sync="isShow"  @open="dialogOpen" append-to-body>
      <div style="text-align: center;">
        <div>添加积分设置积分值为正数，减少积分设置为负数，请输入-1000到1000之间的整数，不允许为0！</div>
        <el-input-number v-model="addScore" :min="-1000" :max="1000"></el-input-number>
      </div>
      <div slot="footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" @click="changeScoreHandler" :loading="handlerLoading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import util from '@src/common/util.js'
export default {
  props: {
    show: {
      type: Boolean,
      required: true,
      default: false
    },
    memberId: {
      type: [Number, String],
      required: true,
      default: '' || 0
    },
    intervetionScoreType: {
      type: String,
      required: true,
      default: ''
    }
  },
  data() {
    return {
      addScore: 1,
      handlerLoading: false,
      memberScores: [] // 会员积分
    }
  },
  computed: {
    isShow: {
      get() {
        return this.show
      },
      set(val) {
        this.$emit('update:show', val)
      }
    }
  },
  methods: {
    // 添加事件
    dialogOpen() {
      this.handlerLoading = false
    },
    // 人工干预确定
    async changeScoreHandler() {
      if (!this.addScore || this.addScore === 0) {
        this.$message.error('输入积分有误，请重新输入！')
        return
      }
      this.handlerLoading = true
      let data = await axios.put(`/ui/member/${this.memberId}/intervention`, {
        scoreType: this.intervetionScoreType,
        addScore: this.addScore
      })
      util.showResponseMessage(data.data)
      if (data.data.status === 1) {
        let scoresData = await axios.get(`/ui/member/${this.memberId}/bindmemberscores`)
        this.memberScores = scoresData.data.data
        this.isShow = false
        this.addScore = 1
        this.handlerLoading = false
        this.$emit('callback', this.memberScores)
      } else {
        this.handlerLoading = false
      }
    }
  }
}
</script>
