<template>
  <el-dialog title="本次借阅评价" :visible.sync="visible" v-dialogDrag width="45%" :close-on-click-modal="false"
    :before-close="cancel">
    <div class="dia-box">
      <el-form :model="form"  ref="ruleForm" label-width="138px">
        <el-form-item label="是否满意：">
            <el-radio-group v-model="form.flag" :disabled="isView">
                <el-radio :label="0">满意</el-radio>
                <el-radio :label="1">不满意</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item label="档案利用效果反馈：">
            <el-input type="textarea" :disabled="isView" v-model="form.note"></el-input>
        </el-form-item>
        <el-form-item v-if="!isView">
          <el-button :loading="btnloading" type="primary" size="mini" @click="submitForm('ruleForm')">
            提交
          </el-button>
          <el-button size="mini" @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
  import { message } from "@/utils/common";
  export default {
    name: "DiaApply",
    props: {
      visible: {
        type: Boolean,
        default: () => false
      },
      // 区分评价新增和详情页
      isView: {
        type: Boolean,
        default: () => false
      },
    },
    data() {
      return {
        btnloading: false,
        form: {
          flag: '',
          note: ''
        },
      };
    },
    methods: {
      cancel() {
        this.$refs.ruleForm.resetFields();
        this.$emit("cancel");
      },
      submitForm(formName) {
        if(this.form.flag === ''){
          message('warning','请选择是否满意', 2000)
          return false;
        }
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.btnloading = true;
            this.$emit("submit", this.form);
          } else {
            return false;
          }
        });
      }
    }
  };

</script>

<style lang="scss" scoped>
 .dia-box{

 }
</style>
