<template>
  <div>

    <el-form  label-width="80px" :model="engine"  :inline="true" class="demo-form-inline" size="small">
      <el-form-item label="规则名称">
        <el-input v-model="engine.name"></el-input>
      </el-form-item>
      <el-form-item label="规则类型">
        <el-input v-model="engine.type"></el-input>
      </el-form-item>
      <el-form-item label="是否激活">
        <el-input v-model="engine.isActivate"></el-input>
      </el-form-item>
      <el-form-item label="规则状态">
        <el-input v-model="engine.status"></el-input>
      </el-form-item>
      <el-button @click="findSelectSourceList()">
        查询
      </el-button>
    </el-form>



    <el-button
      type="warning"
      plain
      icon="el-icon-download"
      size="mini"
      @click="findSelectSourceExport"
      v-hasPermi="['source:data:export']"
    >导出
    </el-button>


    <el-button
      icon="el-icon-delete"
      plain
      size="mini"
      type="danger"
      @click="insert()"
    >新增
    </el-button>


    <el-dialog title="添加数据源接入" :visible.sync="dialogFormVisible" >

      <el-form :model="engine">
        <el-form-item label="接入源名称">
          <el-input v-model="engine.id"></el-input>
        </el-form-item>
        <el-form-item label="数据来源系统名称">
          <el-input v-model="engine.name"></el-input>
        </el-form-item>
        <el-form-item label="主机地址">
          <el-input v-model="engine.type"></el-input>
        </el-form-item>
        <el-form-item label="主机端口">
          <el-input v-model="engine.scope"></el-input>
        </el-form-item>
        <el-form-item label="数据接入类型">
          <el-input v-model="engine.engineCode"></el-input>
        </el-form-item>
        <el-form-item label="数据库名称">
          <el-input v-model="engine.isActivate"></el-input>
        </el-form-item>
        <el-form-item label="数据库用户">
          <el-input v-model="engine.status"></el-input>
        </el-form-item>
        <el-form-item label="数据库密码">
          <el-input v-model="engine.description"></el-input>
        </el-form-item>

      </el-form>


      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>

    </el-dialog>






    <el-table :data="arr" style="width: 100%">

      <el-table-column label="编号" prop="id"></el-table-column>
      <el-table-column label="名称" prop="name"></el-table-column>
      <el-table-column label="类型" style="color: #13ce66" prop="type">
        <template v-slot="scope">
          <span v-if="scope.row.type==1">数据字段</span>
          <span v-if="scope.row.type==2">基本类型</span>
          <span v-if="scope.row.type==3">时间类型</span>
          <span v-if="scope.row.type==4">普通类型</span>
          <span v-if="scope.row.type==4">介入类型</span>
        </template>
      </el-table-column>
      <el-table-column label="作用域"  style="color: blue" prop="scope">
        <template v-slot="scope">
          <span v-if="scope.row.scope==1">数据字段</span>
          <span v-if="scope.row.scope==2">记录</span>
          <span v-if="scope.row.scope==3">数据集</span>
          <span v-if="scope.row.scope==4">数据类型</span>
          <span v-if="scope.row.scope==5">日志</span>
        </template>
      </el-table-column>
      <el-table-column label="引擎编码" prop="engineCode"></el-table-column>
      <el-table-column label="是否激活" style="color: red" prop="isActivate">
        <template v-slot="scope">
          <span v-if="scope.row.isActivate==1">已激活</span>
          <span v-if="scope.row.isActivate==2">未激活</span>
        </template>
      </el-table-column>
      <el-table-column label="状态"  style="color: #787be8" prop="status">

        <template v-slot="scope">
          <span v-if="scope.row.status==1">开启</span>
          <span v-if="scope.row.status==2">关闭</span>
        </template>

      </el-table-column>
      <el-table-column label="描述" prop="description"></el-table-column>




      <el-table-column
        align="right">
        <template slot-scope="scope">

          <el-button
            icon="el-icon-delete"
            size="mini"
            type="text"
            @click="handleDelete(scope.row.id)">删除</el-button>

          <el-button
            icon="el-icon-service"
            size="mini"
            type="text"
            @click="handUpdate(scope.row.id)">规则维护</el-button>


        </template>

      </el-table-column>

    </el-table>


  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {insertAdd} from "@/api/etl/switch";
import {del, insert, selectEngineList, update} from "@/api/engine/engine";
export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"

    return {
      engineReq:{

      },
      engine:{

      },
      arr:[],
      dialogFormVisible:false
    };
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    insert(){
      this.dialogFormVisible = true
      insert(this.engine).then(res =>{
        this.$message.success(res.msg || "添加成功")
      })
      this.engine = {}
    },
    findSelectSourceList(){
      selectEngineList().then(res=>{
          this.arr=res.data;
      })
    },
    handleDelete(id){
      del(id).then(res =>{
        this.$message.success(res.msg || "删除成功")
      })
    },
    handUpdate(){
      update(this.engine).then(res =>{
        this.$message.success(res.msg || "修改成功")
      })
    },
    findSelectSourceExport(){
      this.download('engine/engine/export', {
        ...this.engineReq
      }, `source_${new Date().getTime()}.xlsx`)
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.findSelectSourceList();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
<style scoped>

</style>
