<template>
  <div>
    <h4>普通表格</h4>
    <sh-table :tableData="tableData">
      <sh-table-column prop="date" label="日期" width="180">
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="address" label="地址">
      </sh-table-column>
    </sh-table>
    <h4>固定表头</h4>
    <sh-table :tableData="tableData" height="200px">
      <sh-table-column prop="date" label="日期" width="180">
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="address" label="地址">
      </sh-table-column>
    </sh-table>
    <h4>固定列</h4>
    <sh-table :tableData="tableData">
      <sh-table-column
        prop="date"
        label="日期"
        width="180"
        fixed="left"
      >
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="address" label="地址" fixed="right">
      </sh-table-column>
    </sh-table>
    <h4>固定列和头</h4>
    <div style="width: 1000px">
      <sh-table
        :tableData="tableData"
        height="200px"
        ref="table1"
        @row-click="handleRowClick"
      >
        <sh-table-column
          prop="date"
          label="日期"
          width="180"
          fixed="left"
        >
        </sh-table-column>
        <sh-table-column prop="name" label="姓名" width="180">
        </sh-table-column>
        <sh-table-column prop="name" label="姓名" width="180">
        </sh-table-column>
        <sh-table-column prop="name" label="姓名" width="180">
        </sh-table-column>
        <sh-table-column prop="name" label="姓名" width="180">
        </sh-table-column>
        <sh-table-column prop="name" label="姓名" width="180">
        </sh-table-column>
        <sh-table-column prop="address" label="地址">
        </sh-table-column>
      </sh-table>
    </div>
    <h4>单选</h4>
    <sh-table
      ref="radioTable"
      :tableData="tableData"
      :radio="true"
      @radioSelect="select"
      @row-click="radioHandleRowClick"
    >
      <sh-table-column type="selection" width="55">
      </sh-table-column>
      <sh-table-column prop="date" label="日期" width="180">
      </sh-table-column>
      <sh-table-column
        prop="name"
        label="姓名"
        width="180"
        :show-overflow-tooltip="true"
      >
      </sh-table-column>
      <sh-table-column prop="address" label="地址">
      </sh-table-column>
    </sh-table>
    <h4>多选</h4>
    <sh-table
      ref="multipleTable"
      :tableData="tableData"
      @select="select"
      @row-click="handleRowClick"
    >
      <sh-table-column type="selection" width="55">
      </sh-table-column>
      <sh-table-column prop="date" label="日期" width="180">
      </sh-table-column>
      <sh-table-column
        prop="name"
        label="姓名"
        width="180"
        :show-overflow-tooltip="true"
      >
      </sh-table-column>
      <sh-table-column prop="address" label="地址">
      </sh-table-column>
    </sh-table>

    <h4>筛选</h4>
    <sh-table :tableData="tableData">
      <sh-table-column prop="date" label="日期" width="180" sortable>
      </sh-table-column>
      <sh-table-column
        prop="name"
        label="姓名"
        width="180"
        :show-overflow-tooltip="true"
        column-key="date"
        :filters="[
          { text: '王小虎1', value: '王小虎1' },
          { text: '王小虎2', value: '王小虎2' },
          { text: '王小虎3', value: '王小虎3' },
          { text: '王小虎4', value: '王小虎4' },
        ]"
        :filter-method="filterHandler"
      >
      </sh-table-column>
      <sh-table-column prop="address" label="地址">
      </sh-table-column>
    </sh-table>

    <h4>操作栏</h4>
    <sh-table :tableData="tableData">
      <sh-table-column prop="date" label="日期" width="180">
      </sh-table-column>
      <sh-table-column prop="name" label="姓名" width="180">
      </sh-table-column>
      <sh-table-column prop="address" label="地址">
      </sh-table-column>
      <sh-table-column label="操作" showOperation>
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </sh-table-column>
    </sh-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      checkList: [],
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎1",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎2",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎3",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name:
            "上海市普陀区金沙江路上海市普陀区金沙江路上海市普陀区金沙江路上海市普陀区金沙江路",
          address:
            "上海市普陀区金沙江路上海市普陀区金沙江路上海市普陀区金沙江路上海市普陀区金沙江路 1516 弄",
        },
      ],
      selectionList: [],
    };
  },
  methods: {
    select(selection,row) {
      console.log(selection, row,"选中的选项");
    },
    filterHandler(value, row, column) {
      const property = column["property"];
      return row[property] === value;
    },
    handleEdit(index, row) {
      this.$emit("handleEdit", index, row);
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    //点击行触发，选中或不选中复选框
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.toggleRowSelection(row);
    },
    //点击行触发，选中或不选中单选框
    radioHandleRowClick(row, column, event) {
      this.$refs.radioTable.toggleRowSelection(row);
    },
  },
};
</script>