<template>
  <el-dialog
    :title="dialogData.title"
    :visible.sync="dialogData.visible"
    width="30%"
  >

    <div v-if="dialogData.type===1" class="audit">
      <el-form label-width="80px">
        <el-form-item>
          <el-radio-group v-model="formParams.status">
            <el-radio :label="2">审核通过</el-radio>
            <el-radio :label="3">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="formParams.auditRemark"
            type="textarea"
          />
        </el-form-item>
      </el-form>
    </div>
    <div v-else class="clean">
      <p>确认要清退本商家吗?</p>
      <p>清退后商家的所有商品将退出本次活动</p>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">{{ dialogData.type===1 ? '确 定': '清 退' }}</el-button>
      <el-button @click="cancel">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import Marketing from '@/api/Marketing'
export default {
  props: {
    dialogData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      formParams: {
        auditRemark: '',
        status: 3,
        id: this.dialogData.id
      }
    }
  },
  methods: {
    cancel() {
      this.$emit('closed', false)
    },
    confirm() {
      if (this.dialogData.type === 1) {
        this.auditPromotion()
      } else {
        this.closeApplyInfo()
      }
    },
    async auditPromotion() {
      const res = await Marketing.auditPromotion(Object.assign({}, this.formParams, { id: this.dialogData.id } ) )
      const resData = res.data
      if (resData.code === 0) {
        this.$message({
          type: 'success',
          message: '审核成功'
        })
        this.$emit('applyShop')
        this.cancel()
      }
    },
    async closeApplyInfo() {
      const res = await Marketing.closeApplyInfo({ id: this.dialogData.id })
      const resData = res.data
      if (resData.code === 0) {
        this.$message({
          type: 'success',
          message: '清退成功'
        })
        this.$emit('applyShop')
        this.cancel()
      }
    }
  }
}
</script>

<style scoped lang='less'>
.clean {
    p {
        text-align: center;
        &:nth-child(2) {
            color: #888888;
        }
    }
}
</style>
