<template>
  <el-dialog
    :visible.sync="visible"
    v-bind="modalOptions"
    append-to-body
  >
    <el-form
      ref="formData"
      :model="formData"
      :rules="formRules"
      size="mini"
      label-suffix=":"
      label-width="150px"
    >
      <el-form-item label="审核状态" prop="state">
        <el-radio-group v-model="formData.state">
          <el-radio label="1">报名成功</el-radio>
          <el-radio label="2">报名失败</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" maxlength="520" :rows="3" show-word-limit />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button size="mini" @click="handleClose">取 消</el-button>
        <el-button type="primary" size="mini" @click="handleSubmit">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import { activExamine } from '@/api/active'

export default {
  name: 'RegistrationReview',
  components: {
  },
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '620px',
        title: ''
      },
      visible: false,
      formData: {
        signId: '', // 报名id
        state: '1', // 审核状态 1-报名成功 2-报名失败
        remark: '' // 备注
      },
      formRules: {
        signId: [
          { required: true, message: '缺少报名信息' }
        ],
        state: [
          { required: true, message: '请选择状态' }
        ],
        remark: [
          { required: false, message: '请输入备注' }
        ]
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    initList() {
    },
    handleOpen(params = {}) {
      this.modalOptions.title = params.signId ? '店铺的报名审核' : '--'
      this.visible = true
      this.initList()
      if (params.signId) {
        // this.getInfo(params.signId)
      } else {
        this.$refs.formData && this.$refs.formData.resetFields()
      }
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await xxx({ id })
        this.formData = Object.assign(this.$options.data().formData, res.data, {
          signId: res.data.signId || ''
        })
        this.$nextTick(() => {
          this.$refs.formData && this.$refs.formData.validate()
        })
      } finally {
        loading.close()
      }
    },
    handleSubmit() {
      this.$refs.formData.validate(async (valid) => {
        if (valid) {
          const loading = this.$loading({ text: '加载中' })
          try {
            const { ...otps } = this.formData
            const params = {
              ...otps
            }
            await activExamine(params)
            loading.close()
            this.$message({ message: `处理成功!`, type: 'success' })
            this.$emit('success')
            this.visible = false
          } catch (e) {
            loading.close()
          } finally {
            loading.close()
          }
        } else {
          this.$message({ message: '请输入相关信息', type: 'warning' })
          return false
        }
      })
    }
  }
}
</script>

