<template>
  <el-dialog
    custom-class="party-dialog"
    title="驳回原因"
    :visible.sync="dialogVisible"
    width="468px"
    :before-close="handleClose"
  >
    <div class="dialog-content">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        label-position="top"
        class="party-form"
      >
        <el-form-item label="请填写驳回原因" prop="remarks">
          <el-input
            v-model="form.remarks"
            placeholder="请填写"
            type="textarea"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer btn-group">
      <el-button @click="handleClose()">取 消</el-button>
      <el-button type="primary" @click="handleSubmit()">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        status: 2,
        content: "",
        type: 3, //0,看板；1 视频；2 学习内容；3 账号禁用
      },
      rules: {
        content: [
          { required: true, message: "请填写驳回原因", trigger: "change" },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    // 弹窗关闭
    handleClose() {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.handleReset();
        })
        .catch((_) => {});
    },
    handleReset() {
      this.dialogVisible = false;
      this.$refs.form.resetFields();
      this.form = {
        remarks: "",
        type: "ACCOUNT",
      };
    },
    // 提交
    handleSubmit() {
      // 校验用户输入值
      let _this = this;
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$https(
            {
              method: "put",
              url: "audit/update",
              authType: this.backToken,
            },
            _this.form
          )
            .then((res) => {
              this.handleReset();
              if (res.status == 200) {
                if (res.data.resultCode == 200) {
                  this.$message({
                    type: "success",
                    message: res.data.message,
                  });
                  this.$emit("success", true);
                } else {
                  this.$message.error(res.data.message);
                }
              } else {
                this.$message.error(res.data);
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.form-row {
  display: flex;
  justify-content: space-between;
}
</style>