<template>
  <el-dialog v-dialogDrag width="45%" :title="title" :close-on-click-modal="false" :before-close="cancel"
    :visible.sync="diaFlage">
    <el-form :model="form" ref="backDialog" label-width="100px" class="demo-dynamic">
      <el-form-item label="备份路径" :rules="[{ required: true, message: '请输入备份路径'}]" prop="path">
        <el-input clearable v-model="form.path" size="small">
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('backDialog')" size="mini">提交</el-button>
        <el-button type="info" @click="cancel" size="mini">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
  import {
    backupDB,
    getTable
  } from "@/api/dataManagement/dataBackups"
  import {
    message
  } from '@/utils/common';
  export default {
    props: {
      title: {
        type: String,
        default: () => "数据备份",
      },
      diaFlage: {
        type: Boolean,
        default: () => false,
      },
    },
    data() {
      return {
        form: {
          path: ""
        }
      }
    },
    methods: {
      cancel() {
        this.$refs['backDialog'].resetFields();
        this.$emit("cancel")
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {

            backupDB(this.form).then(res => {
              message("success", "备份成功", 3000)
              this.cancel()
              this.$emit("getData")
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
    },


  }

</script>
<style lang="scss" scoped>
  .demo-dynamic {
    padding: 20px 0;
  }

</style>
