<template>
    <div class="pane-up-wrap right-list-toolbar">
      <el-toolbar>
        <el-button @click="addDocsQueryPostion" priv="Search.WeightsConfig.AddQueryPositionConfig">
          <i class="fa fa-plus"></i> 新建
        </el-button>
      </el-toolbar>
      <div>
        <el-table data-read-url="/ui/docsquerypositionconfig" :page-size="10" :auto-get-data="false"  ref="datatable" @selection-change="tableSelectionChange">
          <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
          <el-table-column type="selection" align="center" width="80"></el-table-column>
          <el-table-column label="检索词" width="300" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-button type="text" class="table-title-button" :title="scope.row.query" priv="Search.WeightsConfig.EditQueryPositionConfig" @click.stop="editDocsQueryPostion(scope.row)">{{scope.row.query}}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column prop="contentTypeName" label="内容类型" width="100"></el-table-column>
          <el-table-column prop="title" label="标题" show-overflow-tooltip></el-table-column>
          <el-table-column prop="position" label="位置下标" width="100"></el-table-column>
          <el-table-column label="操作" align="right" width="80">
            <template slot-scope="scope">
              <el-button @click.stop="editDocsQueryPostion(scope.row)" priv="Search.WeightsConfig.EditQueryPositionConfig" type="text" title="编辑">
                <i class="fa fa-edit f16"></i>
              </el-button>
              <el-button @click.stop="deleteDocsQueryPostion(scope.row)" priv="Search.WeightsConfig.DeleteQueryPositionConfig" type="text" title="删除">
                <i class="fa fa-remove f16"></i>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

    </div>
</template>

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

export default {
  data() {
    return {
      dataLoading: false,
      selectedRows: [],
      configData: [] // Docs检索位置配置数据
    }
  },
  methods: {
    // 加载Docs检索位置配置表格数据
    loadConfigData() {
      !!this.$refs.datatable && this.$refs.datatable.getData()
    },

    // 新建Docs检索位置配置按钮点击事件
    addDocsQueryPostion() {
      let path = `${this.$route.path}/new`.replace(/\/\//g, '/')
      this.$router.push(path)
    },

    // 编辑Docs检索位置配置按钮点击事件
    editDocsQueryPostion(row) {
      let path = `${this.$route.path}/${row.ID}`.replace(/\/\//g, '/')
      this.$router.push(path)
    },

    // 删除Docs检索位置配置按钮点击事件
    async deleteDocsQueryPostion(row) {
      let ids = []
      if (!row || !row.ID) {
        for (let row of this.selectedRows) {
          ids.push(row.ID)
        }
      } else {
        ids = Array.of(row.ID)
      }

      if (!ids || ids.length === 0) {
        this.alert('传入id错误 ！', '系统提示', {type: 'info'})
        return
      }
      try {
        await this.$confirm('确认删除？', '系统提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
      } catch (e) {
        return
      }
      let delIDs = ids.join()
      let res = await axios.delete(`/ui/docsquerypositionconfig/${delIDs}`)
      util.showResponseMessage(res.data)
      if (res.data.status === 1) {
        this.editDocsQueryPostionConfigModal = false
        this.loadConfigData()
      }
    },

    // Docs检索位置配置表格数据行选中事件
    tableSelectionChange(selection) {
      this.selectedRows = selection
      // this.currentDocsQueryPostionConfigData.id = this.selectedRows.length>0 ? this.selectedRows[0].id : null;
    }

  }
}
</script>
