<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 400px;max-width:400px;">
      <q-card-section>
        <div class="text-h6">{{objOption.MenuId==0?'新增问卷调查信息':'修改问卷调查信息'}}</div>
      </q-card-section>
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh">
        <div class="text-caption q-mb-lg q-px-md text-grey-6">问卷调查信息</div>
        <div class="row wrap">
          <q-input filled stack-label maxlength="40" :dense="false" v-model="objOption.Title" ref="Title"
            class="col-12 q-pr-lg q-pb-lg" label="问卷名称" :rules="[val => !!val || '请填问卷名称']" />
        </div>
      </q-card-section>
      <q-separator />
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeSaveForm" />
        <q-btn label="立即提交" color="accent q-px-md" style="font-weight:400 !important" :loading="saveLoading"
          @click="setSurvey" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<script>
  import {
    saveEducationSurveyMain,
  } from '../../api/common/common'
  export default {
    props: {
      saveObj: {
        type: Object,
        default: null
      }
    },
    data() {
      return {
        persistent: true,
        objOption: {
          Id: 0, //编号
          Title: "", //问题名称
        },
        optionTitle: "",
        saveLoading: false,
      }
    },
    created() {

    },
    mounted() {
      this.initObj()
    },
    methods: {
      //初始化表单
      initObj() {
        if (this.saveObj && this.saveObj.Id > 0) {
          this.objOption.Id = this.saveObj.Id;
          this.objOption.Title = this.saveObj.Title;
          this.optionTitle = "修改调查文件"
        } else {
          this.optionTitle = "新增调查问卷"
          this.objOption.Id = 0;
        }
      },
      //关闭弹窗
      closeSaveForm() {
        this.$emit('close')
        this.persistent = false
      },
      //保存菜单
      setSurvey() {
        this.saveLoading = true;
        saveEducationSurveyMain(this.objOption).then(res => {
          this.saveLoading = false
          this.$q.notify({
            icon: 'iconfont icon-chenggong',
            color: 'accent',
            timeout: 2000,
            message: '数据保存成功！',
            position: 'top'
          })
          this.$emit("success")
          this.closeSaveForm()
        }).catch(() => {
          this.saveLoading = false
        })
      }
    },
  }

</script>
