<template>
  <div>
    <div style="overflow:auto">
      <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-table ref="imageplayers" :data-read-url="imagePlayerUrl" :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="name"  label="名称"></el-table-column>
        <el-table-column show-overflow-tooltip prop="code"  label="别名"></el-table-column>
        <el-table-column show-overflow-tooltip prop="addTime"  label="添加时间">
           <template slot-scope="scope">
            {{scope.row.addTime | fixDateTime}}
          </template>
        </el-table-column>
        <el-table-column label="查看" align="right">
          <template slot-scope="scope">
            <el-button @click.stop="preview(scope.row)" type="text" title="查看">
              <i class="fa fa-search f16"></i></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import util from '@src/common/util.js'
export default {
  props: {
    ID: {
      type: [String, Number]
    },
    catalogID: {
      type: [String, Number]
    }
  },
  filters: {
    fixDateTime: function(val) {
      return util.formatDate(val, 'yyyy-MM-dd HH:mm')
    }
  },
  data() {
    return {
      searchContent: '',
      searchTitle: '', // 条件查询
      selectedRows: [] // 选中行
    }
  },
  methods: {
    init() {
      this.searchTitle = ''
      this.searchClickHandler()
    },
    selectionChange(selection) {
      this.selectedRows = selection
    },
    // 双击编辑
    preview(row) {
      window.open(`preview.html?&ID=${row.ID}&type=ImagePlayer`)
    },
    // 初始化数据
    imagePlayerUrl() {
      return [
        '/ui/imageplayer',
        {
          params: {
            searchContent: encodeURIComponent(this.searchContent)
          }
        }
      ]
    },
    // 条件查询
    searchClickHandler() {
      this.$refs.imageplayers.getData()
    },
    async confirm() {
      if (!this.selectedRows || this.selectedRows.length === 0) {
        this.$alert('请先选择一条记录', '提示', {
          type: 'info'
        })
        return
      }
      let resp = await axios.put(`/ui/imageplayereditor/${this.selectedRows[0].ID}/addimage/${this.ID}`, {'ArticleID': this.catalogID})
      if (resp.data.status === 1) {
        util.showSuccess(resp.data.message)
        setTimeout(function() {
          window.dialog.close(false)
        }, 3000)
      } else {
        util.showErrorMessageBox(resp.data.message)
      }
    }
  }
}
</script>
