<template>
  <div class="content" v-loading="tableLoading">
    <el-card shadow="never">
      <el-form ref="searchForm" :model="searchForm" @submit.native.prevent>
        <el-row class="tool-common-wrap">
          <el-col :span="6">
            <div class="search-wrap">
              <el-input placeholder="请输入名称搜索" v-model="searchForm.subject" @keyup.enter.native="search">
                <span slot="append" @click="search"><i class="iconfont icon-sousuo2"></i></span>
              </el-input>
            </div>
          </el-col>
          <el-col :span="12">
            <reload />
            <el-tooltip effect="dark" content="添加" :enterable="false" placement="top">
              <el-button
                type="text"
                icon="el-icon-circle-plus-outline"
                @click="operationHandle('add')"
                style="font-size: 16px;" />
            </el-tooltip>
            <!-- <el-button type="primary">批量删除</el-button> -->
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :data="tableList"
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
        style="width: 100%; margin: 15px 0">
        <el-table-column type="index" label="序号" width="50">
        </el-table-column>
        <el-table-column prop="name" label="名称" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="host" label="属性名" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="port" label="类型" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="domainInfoDTO.name" label="变量值" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="操作" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="编辑" :enterable="false" placement="top">
              <el-button
                class="icon-button"
                type="text"
                icon="el-icon-edit-outline"
                @click.native.prevent="operationHandle('edit', scope.row)">
              </el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除" :enterable="false" placement="top">
              <el-button
                class="icon-button"
                type="text"
                icon="el-icon-delete"
                @click.native.prevent="handleDelete(scope.row)">
              </el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :page-size="page.pageSize"
        :current-page.sync="page.pageNum"
        background
        @current-change="requestData()"
        :total="page.total"></el-pagination>
    </el-card>
    <VariablesAdd v-model="dialogVisible" :checkItem="checkItem" @confirm="requestData" />
  </div>
</template>

<script>
import { queryServer, deleteServer } from '@/api/esb_service'
import VariablesAdd from './VariablesAdd'

export default {
  components: {
    VariablesAdd
  },
  data() {
    return {
      // 高级搜索框
      searchForm: {},
      tableLoading: false,
      tableList: [],
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      dialogVisible: false,
      checkItem: {}
    }
  },
  mounted() {
    // this.requestData()
  },
  methods: {
    search() {
      this.page.pageNum = 1
      this.requestData()
    },
    requestData() {
      this.tableLoading = true
      queryServer({
        filters: [
          {
            key: 'name',
            opt: 'LIKE',
            type: 'S',
            value: this.searchForm.subject
          }
        ],
        orderby: 'createon',
        sort: 'desc',
        pageNum: this.page.pageNum,
        pageSize: this.page.pageSize
      }).then((rt) => {
        this.tableList = rt.data.list || []
        this.page.total = rt.data.total
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    operationHandle(type, item) {
      this.checkItem = type === 'edit' ? Object.assign({}, item) : {}
      this.dialogVisible = true
    },
    handleDelete(item) {
      this.$confirm('确定删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableLoading = true
        deleteServer(item.id).then((rt) => {
          this.tableLoading = false
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.requestData()
        }).catch(e => {
          this.tableLoading = false
        })
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
