<template>
  <div>
    <el-toolbar align="right">
      <el-input v-model="searchTitle" @keyup.enter.native="searchClickHandler" placeholder="请输入名称或别名" style="width:270px;">
        <el-button slot="append" @click="searchClickHandler" icon="search" title="查询"></el-button>
      </el-input>
    </el-toolbar>
    <!--调查投票列表-->
    <el-table ref="multipleTable" :data="vote" :data-read-url="getVoteDataGrid" :page-size="10" :auto-get-data="false" tooltip-effect="dark" style="width:100%," @selection-change="selectionChange">
      <el-table-column type="selection" width="36" align="center"></el-table-column>
      <el-table-column show-overflow-tooltip prop="title"  label="名称"></el-table-column>
      <el-table-column show-overflow-tooltip prop="code"  label="别名"></el-table-column>
      <el-table-column show-overflow-tooltip prop="statusName"  label="状态"></el-table-column>
      <el-table-column label="操作" align="right">
        <template slot-scope="scope">
          <el-button @click.stop="previewClickHandler(scope.row.ID)" type="text" title="预览">
            <i class="fa fa-search f16"></i></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

export default {
  data() {
    return {
      searchTitle: '', // 条件查询
      vote: [], // "投票调查"集合
      selectedRows: [] // 选中行
    }
  },
  methods: {
    init() {
      this.searchTitle = ''
      this.searchClickHandler()
    },
    // 预览待实现
    previewClickHandler(ID) {
      window.open(`preview.html?ID=${ID}&type=Vote`)
    },
    selectionChange(selection) {
      this.selectedRows = selection
    },
    // 初始化数据
    getVoteDataGrid() {
      return [
        '/ui/votes',
        {
          params: {
            title: encodeURI(encodeURI(this.searchTitle)),
            typeID: 'published'
          }
        }
      ]
    },
    // 条件查询
    searchClickHandler() {
      this.$refs.multipleTable.getData()
    },
    confirm() {
      if (!this.selectedRows || this.selectedRows.length === 0) {
        this.$alert('请先选择一条记录', '提示', {
          type: 'info'
        })
        return
      }
      let html = ''
      this.selectedRows.forEach(row => {
        if (row) {
          html += '<div style="text-align: center;"><span id="' + row.ID + '" _jsonpath="' + row.previewPath + '" _id="' + row.ID + '" ztype="zvote" class="edui-faked-vote"></span></div>'
        }
      })
      // console.log('html:'+html)
      window.editor.execCommand('insertHTML', html)
      window.dialog.close(false)
    }
  }
}
</script>
