import routerUserMenu from '@/mixins/router-user-menu'
import breadcrumbComponent from '@/components/breadcrumb.vue'
/**
 * 页面组件设置
 *
 *  version = "1.0.0";
 *  author = "王森";
 *  email = "wang.sen@data-u.com";
 * */
export default {
  name: 'detail',
  components: {
    breadcrumbComponent,
  },
  mixins: [routerUserMenu],
  data() {
    return {
      // 组件id（修改和查看）
      id: false,
      // 新建对象
      tableInfo: {
        // tableName: "",
        tableComment: "",
        databaseId: "",
        ddl: ''
      },
      // 页面打开类型，0：新建，1：查看，2：修改
      dialogState: 0,
      //上级行业
      databaseOptions: [],
      // defaultProps: {
      //   children: 'children',
      //   label: 'name'
      // }
    }
  },
  computed: {
    // 组件设置是否只读
    readonly: {
      // getter
      get: function () {
        return (this.dialogState === 1)
      },
      // setter
      set: function (newValue) {}
    }
  },
  mounted() {
    // 初始化
    this.init()
  },
  methods: {
    //  如果有id，则获取id对应的部门信息赋值给formInfo
    init() {
      this.getDatabaseOptions()
    },

    //获取数据库下拉列表
    getDatabaseOptions() {
      this.$api.storage.listDatabaseOption().then(res => {
        this.databaseOptions = res.data
      })
    },



    // 提交保存
    add() {
      let _this = this
      // 判断组件设置是否通过验证
      this.$refs.tableInfo.validate((valid) => {
        if (valid) {
          // 提交后台并在成功后回到上一页
          let params = _this.tableInfo
          _this.$api.storage.createTableByDDL(params)
            .then(res => {
              if (res.code == 1) {
                _this.$message.success(res.msg)
                _this.go('MetaData')
              }
            })
        } else {
          return false
        }
      })
    },
  }
}
