list.vue 7.45 KB
Newer Older
Davve's avatar
Davve committed
1 2 3 4 5 6 7
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input :placeholder="'搜素'" v-model="listQuery.filter.value" style="width: 180px;" class="filter-item" @keyup.enter.native="handleFilter"/>
      <el-select v-model="listQuery.filter.key" :placeholder="'搜索字段'" clearable class="filter-item" style="width: 110px">
        <el-option v-for="item in SearchTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
Davve's avatar
Davve committed
8
      <el-select v-model="listQuery.filter.is_online" :placeholder="'是否在线'" clearable class="filter-item" style="width: 110px">
Davve's avatar
Davve committed
9 10 11 12 13
        <el-option v-for="item in OnlineTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-select v-model="listQuery.filter.is_recommend" :placeholder="'是否推荐'" clearable class="filter-item" style="width: 110px">
        <el-option v-for="item in recommendTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
Davve's avatar
Davve committed
14 15
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">创建</el-button>
16 17
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('offline')">下线</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('online')">上线</el-button>
Davve's avatar
Davve committed
18
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('is_recommend')">推荐</el-button>
Davve's avatar
Davve committed
19 20
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
Davve's avatar
Davve committed
21 22
      <el-table-column type="selection"  align="center"></el-table-column>
      <el-table-column align="center" label="小组ID ">
Davve's avatar
Davve committed
23
        <template slot-scope="scope">
24
          <router-link :to="'/group/edit/'+scope.row.id" class="link-type">
Davve's avatar
Davve committed
25 26 27 28 29
          <span>{{ scope.row.id }}</span>
            </router-link>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
30
      <el-table-column  align="center" label="小组名称">
Davve's avatar
Davve committed
31
        <template slot-scope="scope">
32
          <span>{{ scope.row.name }}</span>
Davve's avatar
Davve committed
33 34 35
        </template>
      </el-table-column>

Davve's avatar
Davve committed
36
      <el-table-column  align="center" label="小组简介">
Davve's avatar
Davve committed
37
        <template slot-scope="scope">
Davve's avatar
Davve committed
38
          <span>{{ scope.row.description }}</span>
Davve's avatar
Davve committed
39 40 41 42
        </template>
      </el-table-column>


Davve's avatar
Davve committed
43
      <el-table-column  align="center" label="明星数">
Davve's avatar
Davve committed
44
        <template slot-scope="scope">
45
          <span>{{ scope.row.star_nums }}</span>
Davve's avatar
Davve committed
46 47 48
        </template>
      </el-table-column>

Davve's avatar
Davve committed
49
      <el-table-column  align="center" label="用户数">
Davve's avatar
Davve committed
50
        <template slot-scope="scope">
Davve's avatar
Davve committed
51
          <router-link :to="{path: '/user/list/', query: {group_id: scope.row.id}}" class="link-type">
52
          <span>{{ scope.row.user_nums }}</span>
Davve's avatar
Davve committed
53
          </router-link>
54 55 56
        </template>
      </el-table-column>

Davve's avatar
Davve committed
57
      <el-table-column  align="center" label="帖子数">
58
        <template slot-scope="scope">
Davve's avatar
Davve committed
59
          <router-link :to="{path: '/topic/list/', query: {group_id: scope.row.id}}" class="link-type">
60 61 62 63 64
          <span>{{ scope.row.topic_nums }}</span>
            </router-link>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
65
      <el-table-column  align="center" label="组长">
66 67 68 69 70
        <template slot-scope="scope">
          <span>{{ scope.row.creator.name }}</span>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
71
      <el-table-column  align="center" label="是否在线">
72 73 74 75 76
        <template slot-scope="scope">
          <el-tag :type="scope.row.is_online | isOnlineFilter">{{ scope.row.is_online==1 ? '是' : '否' }}</el-tag>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
77
      <el-table-column  align="center" label="是否推荐">
78 79
        <template slot-scope="scope">
          <el-tag :type="scope.row.is_recommend | isOnlineFilter">{{ scope.row.is_recommend==1 ? '是' : '否' }}</el-tag>
Davve's avatar
Davve committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
        </template>
      </el-table-column>


    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" style="margin-left: 150px;" @pagination="getList" />

  </div>
</template>

<script>
import { fetchList, OffLineOrOnLine } from '@/api/group'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import waves from '@/directive/waves'

export default {
  name: 'GroupList',
  components: { Pagination },
  directives: { waves },
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  filters: {
    isOnlineFilter(status) {
      const statusMap = {
        1: 'success',
        0: 'info',
      }
      return statusMap[status]
    },
    genderFilter(status) {
      const statusMap = {
        '男': 'success',
        '女': 'info',
        '全部': 'danger'
      }
      return statusMap[status]
    },
  },
Davve's avatar
Davve committed
117 118 119 120 121
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
122
      multipleSelection: [],
Davve's avatar
Davve committed
123 124
      del_list: [],
      listQuery: {
Davve's avatar
Davve committed
125
        page: 0,
Davve's avatar
Davve committed
126 127 128 129
        limit: 10,
        filter: {
          value: '',
          key: '',
Davve's avatar
Davve committed
130 131
          is_online: '',
          is_recommend: '',
Davve's avatar
Davve committed
132 133 134
        },
      },
      SearchTypeOptions:[
135
        {'key': 'id', 'display_name': '小组ID'},
Davve's avatar
Davve committed
136 137 138 139 140 141 142 143 144 145
        {'key': 'name', 'display_name': '小组名称'},
      ],
      OnlineTypeOptions: [
        {'key': 0, 'display_name': '否'},
        {'key': 1, 'display_name': '是'},
      ],
      recommendTypeOptions: [
        {'key': 0, 'display_name': '否'},
        {'key': 1, 'display_name': '是'},
      ],
Davve's avatar
Davve committed
146 147 148 149 150 151 152 153
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
Davve's avatar
Davve committed
154 155
      this.listQuery.star_id = this.$route.query.star_id || ''
      this.listQuery.user_id = this.$route.query.user_id || ''
Davve's avatar
Davve committed
156
      fetchList(this.listQuery).then(response => {
Davve's avatar
Davve committed
157
        console.log(response.data.data.data)
Davve's avatar
Davve committed
158 159 160 161 162
        this.list = response.data.data.data
        this.total = response.data.data.total
        this.listLoading = false
      })
    },
163 164 165
    handleSelectionChange(val) {
        this.multipleSelection = val;
    },
Davve's avatar
Davve committed
166 167 168 169 170 171 172 173 174
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleFilter() {
Davve's avatar
Davve committed
175
      this.listQuery.page = 1
Davve's avatar
Davve committed
176 177 178
      this.getList()
    },
    handleCreate() {
Davve's avatar
Davve committed
179
      this.$router.push('/group/create')
180 181 182 183 184 185 186 187
    },
    handleOfflineOrOnline(val){
      const length = this.multipleSelection.length;
      let str = '';
      this.del_list = this.del_list.concat(this.multipleSelection);
      for (let i = 0; i < length; i++) {
          if (val === 'offline'){
            this.multipleSelection[i].is_online = 0
Davve's avatar
Davve committed
188 189 190 191
          }else if (val == 'is_recommend'){
             this.multipleSelection[i].is_recommend = 1
          }
          else{
192 193 194 195 196 197 198
            this.multipleSelection[i].is_online = 1
          }
          str += this.multipleSelection[i].id + ' ';
      }
      OffLineOrOnLine({type:val, ids:str}).then(response => {
        this.multipleSelection = [];
        this.$message.success(response.data.data.message);
Davve's avatar
Davve committed
199 200 201 202

        setTimeout(() => {
              this.$router.go(0)
            }, 1000)
203 204
      })
    },
Davve's avatar
Davve committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>