<template>
  <div class="layout-no-cols right-list-toolbar right-list-panel-card">
    <!-- 工具栏 -->
    <el-toolbar>
    <!-- <el-row> -->
      <el-col :span="14">
        <el-button @click="add" priv="ContentAdvance.PublishPoint.Add"><i class="fa fa-plus"></i>新建</el-button>&nbsp;
      </el-col>
      <el-col :span="10" class="search-box-r tool-search-box-r">
        <el-input v-model="searchWord" placeholder="请输入发布点名称" @keyup.enter.native="loadingPublishPointData" class="search-bar-algin-toolbar"></el-input>
        <span class="search-icon"><i class="fa fa-search" @click="loadingPublishPointData" title="查询"></i></span>
      </el-col>
    <!-- </el-row> -->
    </el-toolbar>
    <el-list-view ref="publishPointList" :data-read-url="getDataURL" :pageSize="10">
      <template slot-scope="row">
        <div class="panel-card">
          <el-row> <a class="list-card-title" href="javascript:void(0)" @click.stop="gotoDetailPage(row.ID)">{{row.name}}</a> </el-row>
          <el-row>
            <el-col :span="6"><span>源目录：</span> <em>{{row.sourceDir || '无'}}</em> </el-col>
            <el-col :span="7"><span>URL前缀：</span> <em>{{row.URLPrefix || '无'}}</em> </el-col>
            <el-col :span="6"><span>备注：</span> <em>{{row.memo || '无'}}</em> </el-col>
            <el-col :span="5">
              <el-button @click.stop="gotoDetailPage(row.ID)" type="text" priv="ContentAdvance.PublishPoint.Save" title="编辑">
                <i class="fa fa-edit"></i>编辑
              </el-button>
              <el-button @click.stop="del(row.ID)" type="text" priv="ContentAdvance.PublishPoint.Delete" title="删除">
                <i class="fa fa-times"></i>删除
              </el-button>
            </el-col>
          </el-row>
        </div>
      </template>
    </el-list-view>
  </div>
</template>

<script>
import util from '@src/common/util.js'

export default {
  data() {
    return {
      searchWord: '' // 通过发布点名称查找发布点
    }
  },
  methods: {
    gotoDetailPage(ID) {
      this.$router.push(`${this.$route.path}/${ID}`)
    },
    getDataURL() {
      return [
        '/ui/publishpoint',
        {
          params: {
            searchWord: encodeURIComponent(this.searchWord)
          }
        }
      ]
    },
    // 加载发布点数据
    async loadingPublishPointData() {
      this.$refs.publishPointList && (await this.$refs.publishPointList.getData())
    },
    //  添加发布点
    add() {
      this.$router.push(`${this.$route.path}/new`)
    },
    //  删除发布点
    async del(ID) {
      try {
        await this.$confirm('确定删除吗？删除后无法恢复。是否继续删除？', '删除确认', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        let res = await axios.delete(`/ui/publishpoint/${ID}`)
        util.showResponseMessage(res.data)
        if (res.data.status === 1) {
          this.loadingPublishPointData()
        }
      } catch (e) {

      }
    }
  }
}
</script>
