<template>
  <div class="module_content">
    <el-card class="commont-cart">
      <div class="project-name">
        <!-- <p>{{ $route.matched[1].meta.title }}</p> -->
      </div>
      <div class="search-header">
        <div class="tool-common-wrap">
          <div class="search-wrap">
            <quick-query ref="quick" :placeholder="placeholder" :is-date="false" @quickSearch="quickSearch" />
          </div>
          <div class="btn-wrap">
            <el-button type="primary" @click="addcode('add')" >添加</el-button>
            <el-button type="primary" @click="rest()" > 刷新 </el-button>
          </div>
        </div>
      </div>
      <el-form ref="searchForm" :model="searchForm" @submit.native.prevent>
        <div class="tableWrap">
          <!-- 表格主体 -->
          <el-table
            ref="singleTable"
            :data="tableList"
            v-loading="tableLoading"
            highlight-current-row
            @current-change="handleCurrentChange"
            style="width: 100%">
            <el-table-column type="index" label="序号" width="50">
            </el-table-column>
            <el-table-column
              prop="name"
              label="名称"
              width="300">
              <template slot-scope="scope">
              <el-link class="table-link"  @click="edit(scope.row)"
              :type="currentRow && currentRow.id && scope.row.id && currentRow.id === scope.row.id ? 'primary' : '' "  >{{scope.row.name}}</el-link>
              <!-- <span >{{scope.row.name}}</span> -->
              </template>
            </el-table-column>
            <el-table-column
              prop="code"
              label="状态码"
              width="300">
            </el-table-column>
            <el-table-column
              prop="description"
              show-overflow-tooltip
              label="描述"
              >
            </el-table-column>
            <el-table-column
              prop="operate"
              label="操作"
              width="300">
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="编辑" :enterable="false" placement="top"> <el-button class="icon-button" content="编辑" type="text" icon="el-icon-edit" @click="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="del(scope.row)" style="margin-left:20px"></el-button></el-tooltip>
          </template>
            </el-table-column>
          </el-table>
          <!-- 分页 -->
          <div slot="header" class="clearfix" style="color:#fff">
            1
          </div>
          <div class="block">
            <el-pagination
              :page-size="page.pageSize"
              :current-page.sync="page.pageNum"
              background
              @current-change="getDataCurrent()"
              :total="page.total">
            </el-pagination>
          </div>
        </div>
      </el-form>
      <div class="right-content">
        <status-list ref="child" :dialogFormVisible="dialogFormVisible" @confirm="handleSubmit()" :currentRow="currentRow" :content="content" :flag="flag" @closedialog="closedialog" @closepop="closepop"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import StatusList from './StatusList'
import QuickQuery from '@/components/quickquery/QuickQuery'
import { queryStatus, deleteStatus } from '@/api/esb_service'
import EsbServiceListMixins from '@/mixins/esb_service_list_mixins'

export default {
  mixins: [EsbServiceListMixins],
  components: {
    StatusList,
    QuickQuery
  },
  data() {
    return {
      dialogFormVisible: false,
      flag: '',
      content: '',
      quickQueryKeys: ['name', 'code', 'description'],
      sort: {
        orderby: 'createon',
        sort: 'desc'
      },
      placeholder: '名称、描述、状态码'
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    closedialog() {
      this.dialogFormVisible = false
    },
    closepop() {
      this.flag = ''
    },
    edit(item) {
      this.dialogFormVisible = true
      this.content = '修改'
    },
    lookFlowNode() {
      this.dialogVisible = true
    },
    async getData() {
      this.tableLoading = true
      const rt = await queryStatus({
        logic: this.logic,
        filters: this.filters,
        ...this.sort,
        ...this.page
      }).catch(e => {
        this.tableLoading = false
        return Promise.reject(e)
      })
      if (rt.status === '200') {
        this.tableLoading = false
        this.tableList = rt.data.list || []
        this.page.total = rt.data.total
        return Promise.resolve(rt)
      } else {
        this.tableLoading = false
      }
    },
    del(item) {
      this.$confirm('确定删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.tableLoading = true
        deleteStatus(item.id).then((rt) => {
          this.tableLoading = false
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.getDataCurrent()
        }).catch(e => {
          this.tableLoading = false
        })
      }).catch(() => {})
    },
    addcode(type, item) {
      this.flag = 'none'
      this.dialogFormVisible = true
      // this.$refs.child.add()
      this.userHandle('add')
      this.content = '确定'
    },
    quickQueryData() {
      this.tableLoading = true
      queryStatus({
        logic: this.logic,
        filters: this.filters,
        ...this.sort,
        ...this.page
      }).then(rt => {
        if (rt.status === '200') {
          this.tableLoading = false
          this.tableList = rt.data.list || []
          this.page.total = rt.data.total
          return Promise.resolve(rt)
        } else {
          this.tableLoading = false
        }
      }).catch(e => {
        this.tableLoading = false
        return Promise.reject(e)
      })
    }
  }
}
</script>

<style lang="css" scoped>
.module_content{
  padding: 10px 10px;
}
.left-content {
  width: 401px!important;
}

</style>
<style lang="scss">
.el-table .cell {
  white-space: nowrap;
}
</style>
