<template>
  <el-dialog title="审核用户上传图片" :close-on-click-modal="false" :visible.sync="open" width="700px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="form.auditStatus" size="small">
          <el-option key="2" label="审核通过" :value="2" />
          <el-option key="3" label="审核失败" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="原因" prop="auditRemark" v-if="form.auditStatus === 3">
        <el-input v-model="form.auditRemark" placeholder="请输入原因" type="textarea" :rows="2"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addUserPictures } from '@/api/xq/userPictures'

export default {
  components: {
  },
  data () {
    return {
      open: false,
      form:{
        id: undefined,
        auditStatus: undefined,
        auditRemark: undefined,
      },
      // 表单校验
      rules: {
        auditStatus: [
          { required: true, message: "数据不能为空", trigger: "blur" }
        ],
        auditRemark: [
          { required: true, message: "数据不能为空", trigger: "blur" }
        ],
      },
      buttonLoading: false,
    }
  },
  created() {
  },
  methods: {
    init (id) {
      this.open = true;
      this.form.id = id
      this.form.auditStatus = undefined
      this.form.auditRemark = undefined
    },
    // 表单提交
    submitForm () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          addUserPictures(this.form).then(data => {
            this.$modal.msgSuccess("新增图片成功");
            this.buttonLoading = false;
            this.open = false
            this.$emit('refreshDataList')
          }).finally(() => {
            this.buttonLoading = false;
          });
        }
      })
    },
  }
}
</script>
