<template>
  <m-dialog title="修改表名" :visible.sync="show" @submit="handleSubmit">
    <MForm ref="form" :items="formItems" v-model="formValues" v-loading="loading"></MForm>
  </m-dialog>
</template>

<script>
import MForm from '@/components/MForm'
import MDialog from '@/components/Dialog'
import {
  saveDataBase
} from '@/api/dataChart'
export default {
  name: 'modelTrainTableSubmit',
  components: {
    MDialog,
    MForm
  },
  data () {
    return {
      show: false,
      formItems: [
        {
          label: 'tables',
          key: 'tables',
          type: 'textarea',
          placeholder: '请输入表名，表名使用逗号分隔，支持 schema.table 的格式',
          rows: 8,
          rules: [v => !!v || '不能为空']
        }
      ],
      formValues: {},
      id: null,
      loading: false
    }
  },
  methods: {
    open (id) {
      this.id = id
      this.show = true
    },
    async handleSubmit () {
      if (!this.$refs.form.validate()) return
      this.loading = true
      try {
        await saveDataBase(this.id, this.formValues)
        this.$snackbar.success('更新成功')
        this.show = false
        this.$emit('success')
      } catch (error) {
        this.$snackbar.error(error)
      } finally {
        this.loading = false
      }
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
