<template>
  <div class="autoIndex">
    <div class="pageTitle">
      历史版本（保留30天）
    </div>
    <div class="classTab">
      <div v-for="item in tagList"
           v-bind:key="item.tagname"
           @click="changeTab($event, item.tagname)">
        <span>|</span>
        {{item.tagname}}
      </div>
    </div>
    <div class="searchArea">
      <el-input v-model="search.DataId"
                size="small"
                style="width:140px"
                placeholder="请输入DataId"></el-input>
      <el-input v-model="search.Group"
                size="small"
                style="width:140px"
                placeholder="请输入Group"></el-input>
      <el-button type="primary"
                 size="small"
                 @click="queryData"
                 icon="el-icon-search">查询</el-button>
    </div>
    <div class="pageTitle">
      查询结果：共查到{{num}}条满足条件的数据
    </div>
    <div class="tableArea">
      <el-table @filter-change="filterChange"
                v-loading="tableLoading"
                ref="singleTable"
                :data="tableData"
                :height="tableHeight"
                border
                drag-column
                class="yt-table-no-srcoll"
                highlight-current-row
                style="width: 100%">
        <el-table-column prop="DataId"
                         label="DataId"
                         min-width="200"></el-table-column>
        <el-table-column prop="Group"
                         label="Group"
                         min-width="200"></el-table-column>
        <el-table-column prop="Lastupdatetime"
                         label="最后更新时间:"
                         min-width="200"></el-table-column>
        <el-table-column label="操作"
                         align="center"
                         width="120">
          <template slot-scope="scope">
            <el-button type="text"
                       size="small"
                       @click="editRow(scope.row)">详情</el-button>
            <el-button type="text"
                       size="small"
                       @click="deleteRow(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- <el-dialog :close-on-click-modal="closeFlag"
               v-if="dialogFormVisible"
               width="500px"
               :title="title"
               :visible.sync="dialogFormVisible">
      <el-form label-position="left"
               :model="form"
               :rules="rules"
               ref="form"
               :label-width="formLabelWidth">
        <el-form-item label="DataId"
                      prop="DataId">
          <el-input v-model="form.DataId"></el-input>
        </el-form-item>
        <el-form-item label="Group"
                      prop="Group">
          <el-input v-model="form.Group"></el-input>
        </el-form-item>
        <el-form-item label="最后更新时间:"
                      prop="Lastupdatetime">
          <el-input v-model="form.Lastupdatetime"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer"
           class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary"
                   @click="setForm">确 定</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>
<script>
export default {
  name: 'test',
  data () {
    return {
      num: 10,
      tagList: [{ tagname: '测试1' }, { tagname: '测试2' }, { tagname: 'test' }, { tagname: 'test2' }],
      closeFlag: false,
      tableLoading: false, // 表格loading
      title: '新增',
      tableHeight: '750px',
      tableData: [
        {
          DataId: 1111,
          Group: 2222,
          Lastupdatetime: '2018/12/21'
        }
      ],
      search: {
        customerName: ''
      },
      dialogFormVisible: false,
      form: {
        DataId: '',
        Group: '',
        Lastupdatetime: '' },
      formLabelWidth: '80px',
      rules: {
        DataId: [
          { required: true, message: '请输入DataId', trigger: 'blur' }
        ]
      }
    }
  },
  mounted: function () {
    let h = document.body.clientHeight;
    this.tableHeight = h - 270;
    this.queryData();
  },
  watch: {
    dialogFormVisible: function (newV, oldV) {
      if (!newV) {
        this.cleraForm();
      }
    }
  },
  methods: {
    filterChange (filters) {
      let that = this;
      that.setFilterDatas(that.$refs.singleTable.columns, that.$refs.singleTable.tableData, ['DataId', 'Group', 'Lastupdatetime']);
    },
    queryData: function () {
      let that = this;
      that.tableLoading = true;
      that.axios.get('/pass/v1/customerinfos/', {
        params: that.search
      }
      ).then(function (response) {
        if (response) {
          that.tableData = response.data.list;
          // 清空过滤
          that.$refs.singleTable.clearFilter();
          // 设置过滤数据 setFilterDatas(列数组对象, 数据, 需要过滤的字段, 列名转义对象)
          that.setFilterDatas(that.$refs.singleTable.columns, that.tableData, ['DataId', 'Group', 'Lastupdatetime']);
        }
        that.tableLoading = false;
      }).catch(function () {
        that.tableLoading = false;
      });
    },
    deleteRow: function (row) {
      let that = this;
      that.$confirm('确认刪除？')
        .then(_ => {
          that.axios.delete('pass/v1/customerinfos/' + row.id
          ).then(function (response) {
            that.queryData();
          }).catch(function () {
          });
        })
        .catch(_ => { });
    },
    cleraForm: function () {
      let that = this;
      that.form = {
        DataId: '',
        Group: '',
        Lastupdatetime: '' }
    },
    changeTab: function (event, item) {
      $(event.target).siblings().removeClass('choiceItem');
      $(event.target).addClass('choiceItem');
      this.choiceTag = item;
    }
  }
}
</script>
<style>
.autoIndex {
  padding: 10px;
}
.searchArea {
  padding: 0px 0px 10px 0px;
}
.floatR {
  float: right;
}
.classTab {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  background: #eee;
  border-bottom: solid 1px #cecccc;
  text-align: left;
}

.classTab div {
  display: inline-block;
  cursor: pointer;
  color: #666;
  font-size: 12px;
  margin-right: 10px;
}

.classTab div span {
  margin: 0 5px;
  color: #666;
}

.classTab div:hover {
  color: #00c1de;
}

.choiceItem {
  color: #00c1de !important;
}

.pageTitle {
  width: 100%;
  height: 40px;
  line-height: 40px;
  border-left: solid 2px #0099cc;
  padding: 0 5px;
  font-size: 16px;
  color: #000;
  margin-bottom: 10px;
}
.pageTitle span {
  font-size: 12px;
  color: #ccc;
  margin-left: 10px;
}
</style>
