<template>
  <div>
    <div class="warp">
      <div class="dataconfig">数据源配置</div>
      <div class="formbox">
        <div class="content">
          <div class="contenttil">
            <div class="title">数据库注册</div>

            <el-form
              label-position="top"
              label-width="80px"
              :model="formLabelAlign"
              ref="ruleForm"
            >
              <el-form-item label="数据库类型" class="datatype datadate">
                <el-select
                  v-model="formLabelAlign.databaseType"
                  placeholder="数据库类型"
                  style="width: 300px; text-align: center"
                >
                  <el-option label="mysql" value="mysql"></el-option>
                  <el-option label="sqlserver" value="sqlserver"></el-option>
                  <el-option label="dm" value="dm"></el-option>
                  <el-option label="oracle" value="oracle"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="数据库名" class="datadate">
                <el-input v-model="formLabelAlign.databaseName"></el-input>
              </el-form-item>
              <el-form-item label="数据库IP" class="datadate">
                <el-input v-model="formLabelAlign.databaseIp"></el-input>
              </el-form-item>
              <el-form-item label="用户名" class="datadate">
                <el-input v-model="formLabelAlign.username"></el-input>
              </el-form-item>
              <el-form-item label="密码" class="datadate">
                <el-input v-model="formLabelAlign.password"></el-input>
              </el-form-item>
              <el-form-item label="端口号" class="datadate">
                <el-input v-model="formLabelAlign.portNumber"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')"
                style="width: 300px;border-radius: 20px;margin-top: 20px;"  
                >提交</el-button
                >
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>

      <!-- <div :class="{ hidden: hidden }" class="pagination-container">
        <el-pagination
          :background="background"
          :current-page.sync="currentPage"
          :page-size.sync="pageSize"
          :layout="layout"
          :page-sizes="pageSizes"
          :pager-count="pagerCount"
          :total="total"
          v-bind="$attrs"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div> -->
    </div>
  </div>
</template>
<script>
import { getList, addSave } from "@/api/system/data";
import { scrollTo } from "@/utils/scroll-to";
// import {
//   listUser,
//   getUser,
//   delUser,
//   addUser,
//   updateUser,
//   resetUserPwd,
//   changeUserStatus,
//   deptTreeSelect,
// } from "@/api/system/user";
// import { getToken } from "@/utils/auth";
// import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Pagination",
  props: {
    total: {
      required: true,
      type: Number,
      required:true,
    },
    page: {
      type: Number,
      default: 1,
    },
    limit: {
      type: Number,
      default: 20,
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50];
      },
    },
    // 移动端页码按钮的数量端默认值5
    pagerCount: {
      type: Number,
      default: document.body.clientWidth < 992 ? 5 : 7,
    },
    layout: {
      type: String,
      default: "total, sizes, prev, pager, next, jumper",
    },
    background: {
      type: Boolean,
      default: true,
    },
    autoScroll: {
      type: Boolean,
      default: true,
    },
    hidden: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      formLabelAlign: {},
    };
  },
  computed: {
    currentPage: {
      get() {
        return this.page;
      },
      set(val) {
        this.$emit("update:page", val);
      },
    },
    pageSize: {
      get() {
        return this.limit;
      },
      set(val) {
        this.$emit("update:limit", val);
      },
    },
  },
  mounted() {
    // 获取列表
    getList().then((res) => {
      console.log(res);
      // 获取列表后的操作
    });
  },
  methods: {
    handleSizeChange(val) {
      if (this.currentPage * val > this.total) {
        this.currentPage = 1;
      }
      this.$emit("pagination", { page: this.currentPage, limit: val });
      if (this.autoScroll) {
        scrollTo(0, 800);
      }
    },
    handleCurrentChange(val) {
      this.$emit("pagination", { page: val, limit: this.pageSize });
      if (this.autoScroll) {
        scrollTo(0, 800);
      }
    },
    submitForm(formName) {
      console.log(this.formLabelAlign);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 这个是提交后端，新增接口，数据直接填写就可以了。
          addSave(this.formLabelAlign).then((res) => {
            console.log(res);
            // 新增成功后，操作的东西，写这里
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss">
.pagination-container {
  background: #fff;
  padding: 32px 16px;
}
.pagination-container.hidden {
  display: none;
}
.el-input {
  width: 300px;
}
.formbox {
  background-color: #f5f5fa;
}
.dataconfig {
  background-color: #f5f5fa;
  font-size: 26px;
  /* margin: 20px 0px 0px 20px; */
  padding: 15px 0px 0px 15px;
}
.title {
  margin: 15px 0px 20px 0px;
}

.el-form-item--medium .el-form-item__label {
    line-height: 10px !important;
}
.el-form--label-top .el-form-item__label {
    float: none;
    display: inline-block;
    text-align: left;
    padding: 10px 0 9px 0 !important;
}
.content {
  width: 800px;
  margin: 0 auto;
  height: 700px;
  border: 2px solid #fff;
  border-radius: 15px;
  background-color: #fff;
 
}


/* .el-form el-form--label-top{
  margin: 0 auto;
} */
.contenttil{
 width: 400px;
 height: 670px;
 margin:0 auto;
 background-color: #fff;
 border: 2px solid #fff;
 border-radius: 15px;
}
.title {
  color: #3366ff;
  font-size: 28px;
}
/* el-form-item .datatype .datadate .el-form-item--medium>.el-form-item__label{
  padding: 10px 0px 0px 0px !important;
} */
/* .el-form-item{
  padding: 10px 0 0px 0 !important;
} */

/* .el-form-item--medium .el-form-item__label {
    line-height: 36px !important;
}
.el-form--label-top .el-form-item__label {
    float: none;
    display: inline-block;
    text-align: left;
    padding: 10px 0 0px 0 !important;
} */

.el-form-item {
    margin-bottom: 10px !important;
}
</style>
