<template>
  <div class="app-container">
    <div class="app-header-top" style="width: 100%;float: right;margin-bottom: 10px;">
      <div class="app-title">当前机构：{{ clubTitle }} </div>
      <el-button type="primary" icon="el-icon-back" style="float: right;" @click="backToList">返回</el-button>
    </div>
    <div class="filter-container">
      <div class="filter-control">
        <span style="width: auto;">姓名:</span>
        <el-input v-model="listQuery.linkName" style="width:130px;" placeholder="请输入姓名" clearable @keyup.enter.native="getList" @clear="getList" />
      </div>
      <div class="filter-control">
        <span style="width: auto;">手机号:</span>
        <el-input v-model="listQuery.mobile" style="width:130px;" placeholder="请输入手机号" clearable @keyup.enter.native="getList" @clear="getList" />
      </div>
      <div class="filter-control">
        <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
      </div>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
    >
      <el-table-column label="姓名" align="center" prop="linkName" />
      <el-table-column label="手机号码" align="center" prop="mobile" />
      <el-table-column align="center" label="绑定时间" prop="bindTime">
        <template slot-scope="{row}">
          <span v-if="row.bindTime">{{ row.bindTime }}</span>
          <span v-else>暂未绑定</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="添加时间" prop="addTime" />
    </el-table>
    <pagination v-show="total>20" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
    <template>
      <el-backtop style="right: 40px; bottom: 40px;">
        <i class="el-icon-upload2" />
      </el-backtop>
    </template>
  </div>
</template>

<script>
import { getOperatorList } from '@/api/club'
import Pagination from '@/components/Pagination'

export default {
  components: { Pagination },
  data() {
    return {
      pageNum: 0,
      list: null,
      clubTitle: this.$route.query.name,
      listLoading: true,
      total: 0,
      listQuery: {
        pageNum: 1,
        pageSize: 20,
        clubId: this.$route.query.clubId,
        linkName: '',
        mobile: ''
      }
    }
  },
  computed: {
    organizeId() {
      return this.$store.getters.organizeId
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      this.listLoading = true
      try {
        const res = await getOperatorList(this.listQuery)
        const data = res.data
        this.pageNum = data.index
        this.list = data.results
        this.total = data.totalRecord
        this.listLoading = false
      } catch (error) {
        this.listLoading = false
      }
    },
    rexpStautsText(status) {
      let text = ''
      switch (status) {
        case '1':
          text = '有效'
          break
        case '2':
          text = '已使用'
          break
        case '3':
          text = '已失效'
          break
      }
      return text
    },
    rexpStautsColor(status) {
      let textColor = ''
      switch (status) {
        case '1':
          textColor = '#E6A441'
          break
        case '2':
          textColor = '#417DE6'
          break
        case '3':
          textColor = '#C5C5C5'
          break
      }
      return textColor
    },
    backToList() {
      this.$store.dispatch('tagsView/delView', this.$route).then(() => {
        this.$nextTick(() => {
          this.$router.replace({
            path: '/club/list'
          })
        })
      })
    }
  }
}
</script>
<style lang="scss">
  .app-title{
    line-height: 40px;
    font-size: 18px;
    font-weight: bold;
    color: #999999;
    margin-bottom:10px;
    color: #417DE6;
    float: left;
  }
</style>
