<template>
  <el-dialog title="公海" :close-on-click-modal="false" append-to-body :visible.sync="visible" width="1000px" height="500" @close="closeDialog">
    <div>
      <el-button type="text" icon="el-icon-refresh" style="margin-bottom: 10px" @click="_getTableList">刷新</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="_getTableList" />
    </div>
  </el-dialog>
</template>
<script>
import { getPublicList, pickupClue } from '@/api/zs/clue';
export default {
  name: 'PublicDialog',
  data() {
    return {
      visible: false,
      loading: true,
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        total: 0
      },
      publicList: []
    };
  },
  methods: {
    init() {
      this.visible = true;
      this._getTableList();
    },
    _getTableList() {
      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;
        }
      });
    },

    closeDialog() {
      this.$emit('update:dialog.publicVisible', false);
    },
    handlePickup(item) {
      pickupClue(item).then((resp) => {
        if (resp && resp.code === 200) {
          this.$message.success('拾取成功');
          this._getTableList();
        }
      });
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.followUser2 || row.followUser) {
        return 'warning-row';
      } else {
        return '';
      }
    },
  }
};
    </script>
    