<template>
<div class="list">
        <div class="system-table-search">
      <div class="flex-h">
        <el-form :inline="true" :model="filterData" class="demo-form-inline">
          <el-form-item label="">
            <el-input v-model="filterData.name" placeholder="姓名"></el-input>
          </el-form-item>
          <el-form-item label="">
            <el-input v-model="filterData.phone" placeholder="电话"></el-input>
          </el-form-item>
          <el-form-item label="">
            <el-select v-model="filterData.status" placeholder="状态">
              <el-option
                      v-for="item in optionsStatus"
                      :key="item.status"
                      :label="item.label"
                      :value="item.status">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <select-building v-model="filterData.buildingId"></select-building>
          </el-form-item>
          <el-form-item label="">
            <el-input v-model="filterData.personTags" placeholder="标签"></el-input>
          </el-form-item>
          <el-form-item label="">
            <el-button
                    size="mini"
                    type="primary" @click="search">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="flex-item flex-h">
        <el-button size="mini" type="success" @click='addDynamic'>新增</el-button>
      </div>
      <div class="moreFilter"></div>
    </div>
  <el-table
    :data="list || []"
    style="width: 100%">
    <el-table-column
      prop="name"
      label="姓名">
    </el-table-column>
    <el-table-column
      prop="tel"
      label="电话">
    </el-table-column>
    <el-table-column
      prop="hotNum"
      label="人气">
      <template slot-scope="scope">{{ scope.row.hotNum || 0 }}</template>
    </el-table-column>
    <el-table-column
      prop="likeNum"
      label="点赞">
      <template slot-scope="scope">{{ scope.row.likeNum || 0 }}</template>
    </el-table-column>
    <el-table-column   label="状态">
      <template slot-scope="scope">
        <span :style="{color:(scope.row.status == 1?'':'red')}" >{{scope.row.status == 1 ? '启用' : '禁用'}}</span>
      </template>
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作">
      <template slot-scope="scope">
        <el-button type="text" @click="toDetail(scope.row)" size="small">{{scope.row.status == 1?'停用':'启用'}}</el-button>
        <el-button type="text" @click="toDetail(scope.row)" size="small">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    small
    style="margin-top:10px;"
    layout="prev, pager, next"
    :current-page.sync="pageNavi.current"
    :pageSize="pageNavi.size"
    :total="pageNavi.total || 0"
    @current-change="getList"
  >
  </el-pagination>
</div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";

const { mapActions: mapPersonActions } = createNamespacedHelpers("persons");

export default {
  name: "consultant-list",
  data() {
    return {
      filterData: {
        name: "",
        phone: "",
        status: '',
        buildingId: '',
        personTags: ''
      },
      list: [],
      optionsStatus: [
        {
          label: '启用',
          status: 0
        },
        {
          label: '停用',
          status: 1
        }
      ],
      pageNavi: {
        current: 1,
        size: 20,
        total: 0
      },
      searchName: ""
    };
  },
  computed: {},
  methods: {
    ...mapPersonActions(["getConsultants"]),
    getList() {
      const pageNumber = this.pageNavi.current || 1;
      const pageSize = this.pageNavi.size;

      this.getConsultants({
        ...this.filterData,
        pageNumber,
        pageSize
      })
        .then(res => {
          const { records, ...pageNavi } = res;

          this.list = records;
          this.pageNavi = pageNavi;
        })
        .catch(err => {
          this.$notify.error(err.msg || err.message);
        });
    },
    addDynamic() {
      this.$router.push({ name: "consultant.edit" });
    },
    toDetail(row) {
      this.$router.push({
        name: "consultant.edit",
        params: { id: row.personId }
      });
    },
    search() {
      this.pageNavi.current = 1;
      this.getList();
    },
    newPage(page) {
      this.$router.replace({ name: "consultant.list", query: { page } });
    }
  },
  created() {
    this.pageNavi.current = this.$route.query.page || 1;

    this.getList();
  }
};
</script>

<style lang="scss" scoped>
.list {
  .header {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
}
.system-table-search {
  width: calc(100% - 40px);
  margin: 20px auto 0;
}

.system-table-search li {
  margin-right: 20px;
}

.system-table-search ul {
  font-size: 0;
  white-space: nowrap;
}

.system-table-search ul > li {
  display: inline-block;
}

.flex-h {
  display: flex;
  align-items: center;
}

.flex-item {
  flex: 1;
  -webkit-flex: 1;
  position: relative;
  overflow: hidden;
}
</style>
