<template>
  <el-dialog
    :title="text"
    :visible="dialogVisible"
    :width="width"
    :before-close="handleClose"
  >
    <Form
      ref="form"
      class="form"
      :form-arr="formArr"
      :form-data="formData"
    />
    <span
      slot="footer"
      class="dialog-footer"
    >
      <el-button @click="handleClose">取 消</el-button>
      <el-button
        type="primary"
        @click="handleSubmit"
      >确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import Form from '../../../components/form';

export default {
  name: 'NewDialog',
  components: {
    Form,
  },
  props: {
    text: {
      type: String,
      default: '新增',
      required: false,
    },
    width: {
      type: String,
      default: '60%',
      required: false,
    },
    dialogVisible: Boolean,
    formArr: {
      type: Array,
      required: true,
    },
    formData: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
    };
  },
  methods: {
    handleSubmit() {
      if (this.$refs.form.submitForm()) {
        this.$emit('onSubmit', this.formData);
      }
    },
    handleClose() {
      this.$emit('onClose', false);
    },
  },
};
</script>
