<template>
  <div>
    <el-button type="text" icon="el-icon-refresh" style="margin-bottom: 10px" @click="handleQuery">刷新</el-button>
    <el-table v-loading="loading" :data="publicList" border :row-class-name="tableRowClassName">
      <el-table-column label="创建时间" prop="consultTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.consultTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="线索来源" prop="source" width="100" />
      <el-table-column label="姓名" prop="name" width="100" />
      <el-table-column label="位置" prop="address" min-width="160" />
      <el-table-column label="意向状态" prop="intentionState" width="100" />
      <el-table-column label="备注" prop="clueMemo" min-width="150" />
      <el-table-column label="操作" fixed="right" width="80">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handlePickup(scope.row)">获取</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination :total="queryParams.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" :page-sizes="[50, 100]" @pagination="getList" />
  </div>
</template>
<script>
import { getPublicList, pickupClue } from '@/api/zs/clue';
export default {
  name: 'PublicTable',
  data() {
    return {
      publicList: [],
      loading: true,
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        total: 0
      }
    };
  },
  mounted() {
    this.getList();
    // this.timer = setInterval(() => {
    //   this.getList()
    // }, 5000)
  },
  methods: {
    getList() {
      this.loading = true;
      getPublicList(this.queryParams).then((resp) => {
        if (resp && resp.code === 200) {
          this.publicList = resp.rows;
          this.loading = false;
          this.queryParams.total = resp.total;
        }
      });
    },
    handlePickup(item) {
      pickupClue(item).then((resp) => {
        if (resp && resp.code === 200) {
          this.$message.success('拾取成功');
          this.getList();
        }
      });
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.followUser2 || row.followUser) {
        return 'warning-row';
      } else {
        return '';
      }
    },
    handleQuery() {
      this.loading = true;
      this.getList();
    }
  }
};
</script>

<style scope>
.el-table .warning-row {
  background: oldlace;
}
</style>
